https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | List of all members
StochasticTools::Standardizer Class Reference

Class for standardizing data (centering and scaling) More...

#include <Standardizer.h>

Public Member Functions

 Standardizer ()=default
 
void set (const Real &n)
 Methods for setting mean and standard deviation directly Sets mean=0, std=1 for n variables. More...
 
void set (const Real &mean, const Real &stdev)
 Sets mean and std for a single variable. More...
 
void set (const Real &mean, const Real &stdev, const Real &n)
 Sets mean and std for a n variables variable. More...
 
void set (const std::vector< Real > &mean, const std::vector< Real > &stdev)
 Sets mean and std directly using provided vectors. More...
 
const std::vector< Real > & getMean () const
 Get the mean vector. More...
 
const std::vector< Real > & getStdDev () const
 Get the standard deviation vector. More...
 
void computeSet (const RealEigenMatrix &input)
 Methods for computing and setting mean and standard deviation. More...
 
void storeHelper (std::ostream &stream, void *context) const
 Helper for dataStore. More...
 
void getStandardized (RealEigenMatrix &input) const
 Returns the standardized (centered and scaled) of the provided input. More...
 
void getDestandardized (RealEigenMatrix &input) const
 De-standardizes (de-centered and de-scaled) the assumed standardized input. More...
 
void getDescaled (RealEigenMatrix &input) const
 De-scales the assumed scaled input. More...
 

Protected Attributes

std::vector< Real_mean
 
std::vector< Real_stdev
 

Detailed Description

Class for standardizing data (centering and scaling)

Definition at line 21 of file Standardizer.h.

Constructor & Destructor Documentation

◆ Standardizer()

StochasticTools::Standardizer::Standardizer ( )
default

Member Function Documentation

◆ computeSet()

void StochasticTools::Standardizer::computeSet ( const RealEigenMatrix input)

Methods for computing and setting mean and standard deviation.

Definition at line 58 of file Standardizer.C.

Referenced by StochasticTools::GaussianProcess::standardizeData(), and StochasticTools::GaussianProcess::standardizeParameters().

59 {
60  _mean.clear();
61  _stdev.clear();
62  unsigned int num_samples = input.rows();
63  unsigned int n = input.cols();
64  // comptue mean
65  RealEigenVector mean = input.colwise().mean();
66  // Compute standard deviation
67  RealEigenVector stdev =
68  ((input.rowwise() - mean.transpose()).colwise().squaredNorm() / num_samples)
69  .transpose()
70  .array()
71  .sqrt();
72  // Store in std:vector format
73  _mean.resize(n);
74  _stdev.resize(n);
75  RealEigenVector::Map(&_mean[0], n) = mean;
76  RealEigenVector::Map(&_stdev[0], n) = stdev;
77 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector

◆ getDescaled()

void StochasticTools::Standardizer::getDescaled ( RealEigenMatrix input) const

De-scales the assumed scaled input.

Definition at line 97 of file Standardizer.C.

Referenced by GaussianProcessSurrogate::evaluate().

98 {
99  Eigen::Map<const RealEigenVector> stdev(_stdev.data(), _stdev.size());
100  input = input.array().rowwise() * stdev.transpose().array();
101 }
std::vector< Real > _stdev
Definition: Standardizer.h:58

◆ getDestandardized()

void StochasticTools::Standardizer::getDestandardized ( RealEigenMatrix input) const

De-standardizes (de-centered and de-scaled) the assumed standardized input.

Definition at line 88 of file Standardizer.C.

Referenced by GaussianProcessSurrogate::evaluate().

89 {
90  Eigen::Map<const RealEigenVector> mean(_mean.data(), _mean.size());
91  Eigen::Map<const RealEigenVector> stdev(_stdev.data(), _stdev.size());
92  input =
93  (input.array().rowwise() * stdev.transpose().array()).rowwise() + mean.transpose().array();
94 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ getMean()

const std::vector<Real>& StochasticTools::Standardizer::getMean ( ) const
inline

Get the mean vector.

Definition at line 37 of file Standardizer.h.

Referenced by LibtorchANNSurrogate::evaluate().

37 { return _mean; }
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ getStandardized()

void StochasticTools::Standardizer::getStandardized ( RealEigenMatrix input) const

Returns the standardized (centered and scaled) of the provided input.

Definition at line 80 of file Standardizer.C.

Referenced by GaussianProcessSurrogate::evaluate(), StochasticTools::GaussianProcess::standardizeData(), and StochasticTools::GaussianProcess::standardizeParameters().

81 {
82  Eigen::Map<const RealEigenVector> mean(_mean.data(), _mean.size());
83  Eigen::Map<const RealEigenVector> stdev(_stdev.data(), _stdev.size());
84  input = (input.rowwise() - mean.transpose()).array().rowwise() / stdev.transpose().array();
85 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ getStdDev()

const std::vector<Real>& StochasticTools::Standardizer::getStdDev ( ) const
inline

Get the standard deviation vector.

Definition at line 39 of file Standardizer.h.

Referenced by LibtorchANNSurrogate::evaluate().

39 { return _stdev; }
std::vector< Real > _stdev
Definition: Standardizer.h:58

◆ set() [1/4]

void StochasticTools::Standardizer::set ( const Real n)

Methods for setting mean and standard deviation directly Sets mean=0, std=1 for n variables.

Definition at line 16 of file Standardizer.C.

Referenced by dataLoad(), GaussianProcessTrainer::postTrain(), LibtorchANNTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().

17 {
18  _mean.clear();
19  _stdev.clear();
20  for (unsigned int ii = 0; ii < n; ++ii)
21  {
22  _mean.push_back(0);
23  _stdev.push_back(1);
24  }
25 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ set() [2/4]

void StochasticTools::Standardizer::set ( const Real mean,
const Real stdev 
)

Sets mean and std for a single variable.

Definition at line 28 of file Standardizer.C.

29 {
30  _mean.clear();
31  _stdev.clear();
32  _mean.push_back(mean);
33  _stdev.push_back(stdev);
34 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ set() [3/4]

void StochasticTools::Standardizer::set ( const Real mean,
const Real stdev,
const Real n 
)

Sets mean and std for a n variables variable.

Definition at line 37 of file Standardizer.C.

38 {
39  _mean.clear();
40  _stdev.clear();
41  for (unsigned int ii = 0; ii < n; ++ii)
42  {
43  _mean.push_back(mean);
44  _stdev.push_back(stdev);
45  }
46 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ set() [4/4]

void StochasticTools::Standardizer::set ( const std::vector< Real > &  mean,
const std::vector< Real > &  stdev 
)

Sets mean and std directly using provided vectors.

Definition at line 49 of file Standardizer.C.

50 {
51  mooseAssert(mean.size() == stdev.size(),
52  "Provided mean and standard deviation vectors are of differing size.");
53  _mean = mean;
54  _stdev = stdev;
55 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57

◆ storeHelper()

void StochasticTools::Standardizer::storeHelper ( std::ostream &  stream,
void context 
) const

Helper for dataStore.

Definition at line 105 of file Standardizer.C.

Referenced by dataStore().

106 {
107  unsigned int n = _mean.size();
108  dataStore(stream, n, context);
109  for (unsigned int ii = 0; ii < n; ++ii)
110  dataStore(stream, _mean[ii], context);
111  for (unsigned int ii = 0; ii < n; ++ii)
112  dataStore(stream, _stdev[ii], context);
113 }
std::vector< Real > _stdev
Definition: Standardizer.h:58
std::vector< Real > _mean
Definition: Standardizer.h:57
void dataStore(std::ostream &stream, StochasticTools::Standardizer &standardizer, void *context)
Definition: Standardizer.C:119

Member Data Documentation

◆ _mean

std::vector<Real> StochasticTools::Standardizer::_mean
protected

Definition at line 57 of file Standardizer.h.

Referenced by computeSet(), getDestandardized(), getMean(), getStandardized(), set(), and storeHelper().

◆ _stdev

std::vector<Real> StochasticTools::Standardizer::_stdev
protected

The documentation for this class was generated from the following files: