Line data Source code
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 : 10 : #pragma once 11 : 12 : #include "MooseTypes.h" 13 : #include <vector> 14 : #include "DataIO.h" 15 : 16 : namespace StochasticTools 17 : { 18 : 19 : /// Class for standardizing data (centering and scaling) 20 : 21 176 : class Standardizer 22 : { 23 : public: 24 : Standardizer() = default; 25 : 26 : /// Methods for setting mean and standard deviation directly 27 : /// Sets mean=0, std=1 for n variables 28 : void set(const Real & n); 29 : /// Sets mean and std for a single variable 30 : void set(const Real & mean, const Real & stdev); 31 : /// Sets mean and std for a n variables variable 32 : void set(const Real & mean, const Real & stdev, const Real & n); 33 : /// Sets mean and std directly using provided vectors 34 : void set(const std::vector<Real> & mean, const std::vector<Real> & stdev); 35 : 36 : /// Get the mean vector 37 : const std::vector<Real> & getMean() const { return _mean; } 38 : /// Get the standard deviation vector 39 : const std::vector<Real> & getStdDev() const { return _stdev; } 40 : 41 : /// Methods for computing and setting mean and standard deviation 42 : void computeSet(const RealEigenMatrix & input); 43 : 44 : /// Helper for dataStore 45 : void storeHelper(std::ostream & stream, void * context) const; 46 : 47 : /// Returns the standardized (centered and scaled) of the provided input 48 : void getStandardized(RealEigenMatrix & input) const; 49 : 50 : /// De-standardizes (de-centered and de-scaled) the assumed standardized input 51 : void getDestandardized(RealEigenMatrix & input) const; 52 : 53 : /// De-scales the assumed scaled input 54 : void getDescaled(RealEigenMatrix & input) const; 55 : 56 : protected: 57 : std::vector<Real> _mean; 58 : std::vector<Real> _stdev; 59 : }; 60 : 61 : } // StochasticTools namespace 62 : 63 : template <> 64 : void dataStore(std::ostream & stream, StochasticTools::Standardizer & standardizer, void * context); 65 : template <> 66 : void dataLoad(std::istream & stream, StochasticTools::Standardizer & standardizer, void * context);