https://mooseframework.inl.gov
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 
19 namespace StochasticTools
20 {
21 
23 
25 {
26 public:
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 
62 protected:
63  torch::Tensor _mean;
64  torch::Tensor _stdev;
65 };
66 
67 } // StochasticTools namespace
68 
69 template <>
70 void dataStore(std::ostream & stream, StochasticTools::Standardizer & standardizer, void * context);
71 template <>
72 void dataLoad(std::istream & stream, StochasticTools::Standardizer & standardizer, void * context);
73 
74 #endif
void storeHelper(std::ostream &stream, void *context) const
Helper for dataStore.
Definition: Standardizer.C:118
void dataStore(std::ostream &stream, StochasticTools::Standardizer &standardizer, void *context)
Definition: Standardizer.C:136
void getScaled(torch::Tensor &input) const
Scales the assumed de-scaled input.
Definition: Standardizer.C:110
const torch::Tensor & getMean() const
Get the mean vector.
Definition: Standardizer.h:40
const torch::Tensor & getStdDev() const
Get the standard deviation vector.
Definition: Standardizer.h:42
Enum for batch type in stochastic tools MultiApp.
void getDescaled(torch::Tensor &input) const
De-scales the assumed scaled input.
Definition: Standardizer.C:103
void getDestandardized(torch::Tensor &input) const
De-standardizes (de-centered and de-scaled) the assumed standardized input.
Definition: Standardizer.C:96
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class for standardizing data (centering and scaling)
Definition: Standardizer.h:24
void dataLoad(std::istream &stream, StochasticTools::Standardizer &standardizer, void *context)
Definition: Standardizer.C:143
void getStandardized(torch::Tensor &input) const
Returns the standardized (centered and scaled) of the provided input.
Definition: Standardizer.C:89
void computeSet(const torch::Tensor &input)
Methods for computing and setting mean and standard deviation.
Definition: Standardizer.C:79