FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
Core::FMTYieldModelNn Class Referenceabstract

Abstract machine learning yield model based on a neural network. More...

#include <FMTYieldModelNn.h>

Inheritance diagram for Core::FMTYieldModelNn:
[legend]
Collaboration diagram for Core::FMTYieldModelNn:
[legend]

Public Member Functions

virtual ~FMTYieldModelNn ()
 Destructor for FMTYieldModelNn.
 
 FMTYieldModelNn ()=default
 Default constructor for FMTYieldModelNn.
 
 FMTYieldModelNn (const FMTYieldModelNn &rhs)
 Copy constructor for FMTYieldModelNn.
 
const std::vector< double > predict (const Core::FMTYieldRequest &request) const
 Run the machine learning model to predict its outputs for a request.
 
- Public Member Functions inherited from Core::FMTYieldModel
virtual void setModel (Models::FMTModel *p_modelPtr)
 Set the model linked to the yield model.
 
virtual ~FMTYieldModel ()
 Destructor for FMTYieldModel.
 
 FMTYieldModel ()
 Constructor for FMTYieldModel.
 
 FMTYieldModel (const FMTYieldModel &rhs)=default
 Copy constructor for FMTYieldModel.
 
FMTYieldModeloperator= (const FMTYieldModel &rhs)=default
 Default copy assignment operator for FMTYieldModel.
 
const std::string & getModelName () const
 Return the model name.
 
const std::vector< std::string > & getModelYields () const
 Return the model yield names.
 
virtual std::unique_ptr< FMTYieldModelclone () const =0
 clone the yield model.
 
virtual const std::vector< double > predict (const Core::FMTYieldRequest &request) const =0
 Predict the yield for a request.
 
virtual std::unique_ptr< FMTYieldModelpreSolve (const FMTMaskFilter &filter, const std::vector< FMTTheme > &newthemes) const
 Return a presolved copy of the yield model, or the same model by default.
 
virtual std::unique_ptr< FMTYieldModelpostSolve (const FMTMaskFilter &filter, const std::vector< FMTTheme > &basethemes) const
 Return a postsolved copy of the yield model, a clone by default.
 
virtual operator std::string () const
 Return the string representation of the yield model.
 
virtual std::vector< std::vector< double > > getPeriodicValues () const
 Try to turn the yield model into periodic constant values.
 
virtual void clearRandomYieldsCache ()
 Clear the cache of all random yield models.
 
- Public Member Functions inherited from Core::FMTObject
 FMTObject ()
 Default constructor for FMTObject.
 
virtual ~FMTObject ()
 Default virtual destructor for FMTObject.
 
 FMTObject (const std::unique_ptr< Exception::FMTExceptionHandler > exhandler)
 Construct a FMTObject passing in the exception handler of another FMTObject.
 
 FMTObject (const FMTObject &rhs)
 Copy constructor for FMTObject.
 
FMTObjectoperator= (const FMTObject &rhs)
 Copy assignment operator for FMTObject.
 
virtual void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger)
 Pass in the logger of another FMTObject.
 
void passInExceptionHandler (const std::unique_ptr< Exception::FMTExceptionHandler > &exhandler)
 Pass in the exception handler of another FMTObject.
 
void redirectLogToFile (const std::string &location)
 Redirect the log to a specific file, appending to it.
 
virtual void setDefaultLogger ()
 Create and set a default logger to the FMTObject.
 
virtual void setQuietLogger ()
 Create and set a quiet logger to the FMTObject.
 
virtual void setTaskLogger ()
 Create and set a task logger to the FMTObject.
 
virtual void setDebugLogger ()
 Create and set a debug logger to the FMTObject.
 
void setDefaultExceptionHandler ()
 Create and set a default exception handler to the FMTObject.
 
void setQuietExceptionHandler ()
 Create and set a quiet exception handler to the FMTObject.
 
void setDebugExceptionHandler ()
 Create and set a debug exception handler to the FMTObject.
 
void setFreeExceptionHandler ()
 Create and set a free exception handler to the FMTObject.
 
void disableNestedExceptions ()
 Disable the nested exception throw of the exception handler.
 
void enableNestedExceptions ()
 Enable the nested exception throw of the exception handler.
 
void setErrorsToWarnings (const std::vector< Exception::FMTexc > &errors)
 Set a list of errors to be cast to warnings on the exception handler.
 
void setMaxWarningsBeforeSilenced (const size_t &maxwarningcount)
 Set the number of warnings raised before being silenced.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Protected Member Functions

void _validateInputYields (std::vector< std::string > &expectedYields, std::vector< std::string > &inputYields) const
 Validate that there is the expected number of inputs in the model.
 
const std::string & getModelType () const
 Return the model type.
 
const std::vector< float > & _getStandardParamMeans () const
 Return the input variable means used in the standardization process.
 
const std::vector< float > & _getStandardParamVars () const
 Return the input variable variances used in the standardization process.
 
const std::vector< std::string > & getModelOutputNames () const
 Return the model output names.
 
virtual const std::vector< double > getInputValues (const Graph::FMTPredictor &predictor) const =0
 Return the input values based on a predictor.
 
const void removeNans (std::vector< float > &input) const
 Replace nan values with default values.
 
 FMTYieldModelNn (const boost::property_tree::ptree &jsonProps, std::vector< std::string > &inputYields)
 Construct a FMTYieldModelNn from a JSON tree and an input yield name list.
 
- Protected Member Functions inherited from Core::FMTObject
template<class Archive >
void forceSave (Archive &ar, const unsigned int version) const
 Force the serialization to save useful information, which the default FMTObject serialization does not.
 
template<class Archive >
void forceLoad (Archive &ar, const unsigned int version)
 Force the serialization to load useful information, which the default FMTObject serialization does not.
 
void checkSignals () const
 Check if the user has sent a ctrl-c signal using boost::python to FMT.
 
void setCplHandler ()
 Pass the FMT exception handler to the GDAL exception handler (GDAL only).
 

Static Protected Member Functions

static const std::vector< std::string > _getNextLineAndSplitIntoTokens (std::istream &str)
 Read a CSV file line by line, splitting into tokens.
 
static const std::vector< float > _standardize (std::vector< float > &input, const std::vector< float > &means, const std::vector< float > &vars)
 Apply the standardization feature scaling to the inputs of a machine learning model.
 
- Static Protected Member Functions inherited from Core::FMTObject
static std::chrono::time_point< std::chrono::high_resolution_clock > getClock ()
 Return a clock of the current time.
 
template<class chrono >
static double getDuration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock as a double.
 
static std::string getDurationInSeconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock in seconds as a string.
 
static void _logStack ()
 Log the stack trace...
 
static void _terminate ()
 Raise an error with the boost stacktrace.
 
static void _abort (int p_signal)
 Raise an error with the boost stacktrace on abort.
 

Protected Attributes

std::unique_ptr< Ort::Session > m_sessionPtr
 
const std::string m_JSON_PROP_MODEL_TYPE = "modelType"
 
const std::string m_JSON_PROP_MODEL_YIELDS = "modelYields"
 
const std::string m_JSON_PROP_MODEL_OUTPUTS = "outputNames"
 
const std::string m_JSON_PROP_STAND_FILE_PATH = "csvStandardisationFile"
 
std::string m_modelType
 
std::vector< float > m_standardParamMeans = {}
 
std::vector< float > m_standardParamVars = {}
 
std::vector< std::string > m_modelOutputs = {}
 
- Protected Attributes inherited from Core::FMTYieldModel
std::string m_modelName
 
std::vector< std::string > m_modelYields = {}
 
const std::string m_JSON_PROP_MODEL_NAME = "modelFileName"
 
Models::FMTModelm_modelPtr =nullptr
 

Static Protected Attributes

static std::unique_ptr< Ort::Env > m_envPtr
 
static const float m_UNKNOWN_DISTURBANCE_CODE
 
- Static Protected Attributes inherited from Core::FMTObject
static std::unique_ptr< Exception::FMTExceptionHandler_exhandler
 A shared pointer to the exception handler.
 
static std::unique_ptr< Logging::FMTLogger_logger
 A shared pointer to the logger.
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::FMTObject
static Logging::FMTLoggergetLogger ()
 get a pointer to the actual logger.
 
static Exception::FMTExceptionHandlergetExceptionHandler ()
 get a pointer to the actual exception handler.
 
static std::string getRuntimeLocation ()
 Return the location of the FMT shared library.
 
static unsigned long long getAvailableMemory ()
 Return the available memory in bytes.
 
static void setTerminateStack ()
 will write the stack in the log when terminate called and raise a function failed.
 
static void setAbortStack ()
 will write the stack in the log when abort called with SIGABRT and raise a function failed.
 

Detailed Description

Abstract machine learning yield model based on a neural network.

Constructor & Destructor Documentation

◆ ~FMTYieldModelNn()

virtual Core::FMTYieldModelNn::~FMTYieldModelNn ( )
virtual

Destructor for FMTYieldModelNn.

◆ FMTYieldModelNn() [1/3]

Core::FMTYieldModelNn::FMTYieldModelNn ( )
default

Default constructor for FMTYieldModelNn.

◆ FMTYieldModelNn() [2/3]

Core::FMTYieldModelNn::FMTYieldModelNn ( const FMTYieldModelNn rhs)

Copy constructor for FMTYieldModelNn.

Parameters
[in]rhsthe FMTYieldModelNn to copy.

◆ FMTYieldModelNn() [3/3]

Core::FMTYieldModelNn::FMTYieldModelNn ( const boost::property_tree::ptree jsonProps,
std::vector< std::string > &  inputYields 
)
protected

Construct a FMTYieldModelNn from a JSON tree and an input yield name list.

Parameters
[in]jsonPropsthe JSON properties.
[in,out]inputYieldsthe input yield names.

Member Function Documentation

◆ _getNextLineAndSplitIntoTokens()

static const std::vector< std::string > Core::FMTYieldModelNn::_getNextLineAndSplitIntoTokens ( std::istream &  str)
staticprotected

Read a CSV file line by line, splitting into tokens.

Parameters
[in,out]strthe input stream.
Returns
the tokens of the line.

◆ _getStandardParamMeans()

const std::vector< float > & Core::FMTYieldModelNn::_getStandardParamMeans ( ) const
protected

Return the input variable means used in the standardization process.

Returns
the standard parameter means.

◆ _getStandardParamVars()

const std::vector< float > & Core::FMTYieldModelNn::_getStandardParamVars ( ) const
protected

Return the input variable variances used in the standardization process.

Returns
the standard parameter variances.

◆ _standardize()

static const std::vector< float > Core::FMTYieldModelNn::_standardize ( std::vector< float > &  input,
const std::vector< float > &  means,
const std::vector< float > &  vars 
)
staticprotected

Apply the standardization feature scaling to the inputs of a machine learning model.

Parameters
[in,out]inputthe input values.
[in]meansthe means.
[in]varsthe variances.
Returns
the standardized values.

◆ _validateInputYields()

void Core::FMTYieldModelNn::_validateInputYields ( std::vector< std::string > &  expectedYields,
std::vector< std::string > &  inputYields 
) const
protected

Validate that there is the expected number of inputs in the model.

Parameters
[in,out]expectedYieldsthe expected yields.
[in,out]inputYieldsthe input yields.

◆ getInputValues()

virtual const std::vector< double > Core::FMTYieldModelNn::getInputValues ( const Graph::FMTPredictor predictor) const
protectedpure virtual

Return the input values based on a predictor.

Parameters
[in]predictorthe predictor.
Returns
the input values.

Implemented in Core::FMTYieldModelNep, and Core::FMTYieldModelPools.

◆ getModelOutputNames()

const std::vector< std::string > & Core::FMTYieldModelNn::getModelOutputNames ( ) const
protected

Return the model output names.

Returns
the model output names.

◆ getModelType()

const std::string & Core::FMTYieldModelNn::getModelType ( ) const
protected

Return the model type.

Returns
the model type.

◆ predict()

const std::vector< double > Core::FMTYieldModelNn::predict ( const Core::FMTYieldRequest request) const
virtual

Run the machine learning model to predict its outputs for a request.

Parameters
[in]requestthe yield request.
Returns
the predicted values.

Implements Core::FMTYieldModel.

◆ removeNans()

const void Core::FMTYieldModelNn::removeNans ( std::vector< float > &  input) const
protected

Replace nan values with default values.

Parameters
[in,out]inputthe input values.

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Member Data Documentation

◆ m_envPtr

std::unique_ptr<Ort::Env> Core::FMTYieldModelNn::m_envPtr
staticprotected

◆ m_JSON_PROP_MODEL_OUTPUTS

const std::string Core::FMTYieldModelNn::m_JSON_PROP_MODEL_OUTPUTS = "outputNames"
protected

◆ m_JSON_PROP_MODEL_TYPE

const std::string Core::FMTYieldModelNn::m_JSON_PROP_MODEL_TYPE = "modelType"
protected

◆ m_JSON_PROP_MODEL_YIELDS

const std::string Core::FMTYieldModelNn::m_JSON_PROP_MODEL_YIELDS = "modelYields"
protected

◆ m_JSON_PROP_STAND_FILE_PATH

const std::string Core::FMTYieldModelNn::m_JSON_PROP_STAND_FILE_PATH = "csvStandardisationFile"
protected

◆ m_modelOutputs

std::vector<std::string> Core::FMTYieldModelNn::m_modelOutputs = {}
protected

◆ m_modelType

std::string Core::FMTYieldModelNn::m_modelType
protected

◆ m_sessionPtr

std::unique_ptr<Ort::Session> Core::FMTYieldModelNn::m_sessionPtr
protected

◆ m_standardParamMeans

std::vector<float> Core::FMTYieldModelNn::m_standardParamMeans = {}
protected

◆ m_standardParamVars

std::vector<float> Core::FMTYieldModelNn::m_standardParamVars = {}
protected

◆ m_UNKNOWN_DISTURBANCE_CODE

const float Core::FMTYieldModelNn::m_UNKNOWN_DISTURBANCE_CODE
staticprotected

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