https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Standardizer.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9#ifdef MOOSE_LIBTORCH_ENABLED
10
11#pragma once
12
13#include "MooseTypes.h"
14#include <vector>
15#include "DataIO.h"
16
17#include "LibtorchUtils.h"
18
19namespace StochasticTools
20{
21
23
25{
26public:
27 Standardizer() = default;
28
31 void set(const Real & n);
33 void set(const Real & mean, const Real & stdev);
35 void set(const Real & mean, const Real & stdev, const Real & n);
37 void set(const std::vector<Real> & mean, const std::vector<Real> & stdev);
38
40 const torch::Tensor & getMean() const { return _mean; }
42 const torch::Tensor & getStdDev() const { return _stdev; }
43
45 void computeSet(const torch::Tensor & input);
46
48 void storeHelper(std::ostream & stream, void * context) const;
49
51 void getStandardized(torch::Tensor & input) const;
52
54 void getDestandardized(torch::Tensor & input) const;
55
57 void getDescaled(torch::Tensor & input) const;
58
60 void getScaled(torch::Tensor & input) const;
61
62protected:
63 torch::Tensor _mean;
64 torch::Tensor _stdev;
65};
66
67} // StochasticTools namespace
68
69template <>
70void dataStore(std::ostream & stream, StochasticTools::Standardizer & standardizer, void * context);
71template <>
72void dataLoad(std::istream & stream, StochasticTools::Standardizer & standardizer, void * context);
73
74#endif
void dataLoad(std::istream &stream, StochasticTools::Standardizer &standardizer, void *context)
void dataStore(std::ostream &stream, StochasticTools::Standardizer &standardizer, void *context)
Class for standardizing data (centering and scaling)
void set(const Real &n)
Methods for setting mean and standard deviation directly Sets mean=0, std=1 for n variables.
void getDescaled(torch::Tensor &input) const
De-scales the assumed scaled input.
const torch::Tensor & getStdDev() const
Get the standard deviation vector.
void getDestandardized(torch::Tensor &input) const
De-standardizes (de-centered and de-scaled) the assumed standardized input.
void getStandardized(torch::Tensor &input) const
Returns the standardized (centered and scaled) of the provided input.
const torch::Tensor & getMean() const
Get the mean vector.
void getScaled(torch::Tensor &input) const
Scales the assumed de-scaled input.
void storeHelper(std::ostream &stream, void *context) const
Helper for dataStore.
void computeSet(const torch::Tensor &input)
Methods for computing and setting mean and standard deviation.
Enum for batch type in stochastic tools MultiApp.