Dakota  Version 6.21
Explore and Predict with Confidence
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Python Class Reference

The Python class constructs a surrogate via python and has it ready for Dakota use. More...

Inheritance diagram for Python:
Surrogate

Public Member Functions

 Python (const std::string &module_and_class_name)
 Constructor that sets moduleAndClassName and does not build. More...
 
 Python (const MatrixXd &samples, const MatrixXd &response, const std::string &module_and_class_name)
 Constructor sets moduleAndClassName and builds the python surrogate. More...
 
 ~Python ()
 Default destructor.
 
void default_options () override
 Construct and populate the defaultConfigOptions.
 
virtual bool diagnostics_available () override
 
void build (const MatrixXd &samples, const MatrixXd &response) override
 Build the python surrogate using specified build data. More...
 
VectorXd value (const MatrixXd &eval_points) override
 Evaluate the scalar python surrogate at a set of prediction points. More...
 
VectorXd values (const MatrixXd &eval_points) override
 Evaluate the field python surrogate at a set of prediction points. More...
 
MatrixXd gradient (const MatrixXd &eval_points) override
 Evaluate the gradient of the python scalar surrogate at a set of prediction points. More...
 
MatrixXd hessian (const MatrixXd &eval_point) override
 Evaluate the Hessian of the python scalar surrogate at a single point. More...
 
std::shared_ptr< Surrogateclone () const override
 clone derived Surrogate class for use in cross-validation
 
- Public Member Functions inherited from Surrogate
 Surrogate ()
 Constructor that uses defaultConfigOptions and does not build.
 
 Surrogate (const ParameterList &param_list)
 Constructor that sets configOptions but does not build. More...
 
 Surrogate (const MatrixXd &samples, const MatrixXd &response, const ParameterList &param_list)
 Constructor for the Surrogate that sets configOptions and builds the surrogate (does nothing in the base class). More...
 
virtual ~Surrogate ()
 Default destructor.
 
MatrixXd gradients (const MatrixXd &eval_points)
 Evaluate the gradient of the field Surrogate at a set of prediction points. More...
 
virtual MatrixXd hessians (const MatrixXd &eval_point)
 Evaluate the Hessian of the field Surrogate at a set of prediction points. More...
 
void variable_labels (const std::vector< std::string > &var_labels)
 Set the variable/feature names. More...
 
const std::vector< std::string > & variable_labels () const
 Get the (possibly empty) variable/feature names. More...
 
void response_labels (const std::vector< std::string > &resp_labels)
 Set the response/QoI names. More...
 
const std::vector< std::string > & response_labels () const
 Get the (possibly empty) response/QoI names. More...
 
void set_options (const ParameterList &options)
 Set the Surrogate's configOptions. More...
 
void get_options (ParameterList &options)
 Get the Surrogate's configOptions. More...
 
void print_options ()
 Print the Surrogate's configOptions.
 
VectorXd evaluate_metrics (const StringArray &mnames, const MatrixXd &points, const MatrixXd &ref_values)
 Evalute metrics at specified points (within surrogates)
 
VectorXd cross_validate (const MatrixXd &samples, const MatrixXd &response, const StringArray &mnames, const int num_folds=5, const int seed=20)
 Perform K-folds cross-validation (within surrogates)
 
template<typename DerivedSurr >
void save (const DerivedSurr &surr_out, const std::string &outfile, const bool binary)
 Serialize a derived (i.e. non-base) surrogate model. More...
 
template<typename DerivedSurr >
void load (const std::string &infile, const bool binary, DerivedSurr &surr_in)
 Load a derived (i.e. non-base) surrogate model. More...
 

Private Member Functions

void initialize_python ()
 Initialize python interpreter and callback module.
 

Private Attributes

std::string moduleAndClassName
 Name of python callback module file.
 
bool ownPython
 true if this class created the interpreter instance
 
bool pyModuleActive
 true if python callback module is valid
 
py::object pySurrogate
 python Surrogate class
 
bool isField
 flag for field-based surrogates
 
int verbosity
 Verbosity level.
 

Additional Inherited Members

- Static Public Member Functions inherited from Surrogate
template<typename SurrHandle >
static void save (const SurrHandle &surr_out, const std::string &outfile, const bool binary)
 serialize Surrogate to file (typically through shared_ptr<Surrogate>, but Derived& or Derived* okay too)
 
template<typename SurrHandle >
static void load (const std::string &infile, const bool binary, SurrHandle &surr_in)
 serialize Surrogate from file (typically through shared_ptr<Surrogate>, but Derived& or Derived* okay too)
 
static std::shared_ptr< Surrogateload (const std::string &infile, const bool binary)
 serialize Surrogate from file through pointer to base class (must have been saved via same data type)
 
- Public Attributes inherited from Surrogate
util::DataScaler dataScaler
 DataScaler class for a Surrogate's build samples.
 
double responseOffset = 0.
 Response offset.
 
double responseScaleFactor = 1.
 Response scale factor.
 
- Protected Attributes inherited from Surrogate
int numSamples
 Number of samples in the Surrogate's build samples.
 
int numVariables
 Number of features/variables in the Surrogate's build samples.
 
std::vector< std::string > variableLabels
 Names of the variables/features; need not be populated.
 
int numQOI
 Number of quantities of interest predicted by the surrogate. For scalar-valued surrogates numQOI = 1.
 
std::vector< std::string > responseLabels
 Names of the responses/QoIs; need not be populated.
 
ParameterList defaultConfigOptions
 Default Key/value options to configure the surrogate.
 
ParameterList configOptions
 Key/value options to configure the surrogate - will override defaultConfigOptions.
 

Detailed Description

The Python class constructs a surrogate via python and has it ready for Dakota use.

Constructor & Destructor Documentation

◆ Python() [1/2]

Python ( const std::string &  module_and_class_name)

Constructor that sets moduleAndClassName and does not build.

Parameters
[in]module_and_class_nameName of python module file containing callback functions

References Python::initialize_python().

◆ Python() [2/2]

Python ( const MatrixXd samples,
const MatrixXd response,
const std::string &  module_and_class_name 
)

Constructor sets moduleAndClassName and builds the python surrogate.

Parameters
[in]samplesMatrix of data for surrogate construction - (num_samples by num_features)
[in]responseVector of targets for surrogate construction - (num_samples by num_qoi = 1; only 1 response is supported currently).
[in]module_and_class_nameName of python module file containing callback functions

References Python::build(), and Python::initialize_python().

Member Function Documentation

◆ build()

void build ( const MatrixXd samples,
const MatrixXd response 
)
overridevirtual

Build the python surrogate using specified build data.

Parameters
[in]samplesMatrix of data for surrogate construction - (num_samples by num_features)
[in]responseVector of targets for surrogate construction - (num_samples by num_qoi = 1; only 1 response is supported currently).

Implements Surrogate.

References Surrogate::configOptions, Python::isField, Python::moduleAndClassName, Python::pyModuleActive, Python::pySurrogate, and Python::verbosity.

Referenced by Python::Python().

◆ value()

VectorXd value ( const MatrixXd eval_points)
overridevirtual

Evaluate the scalar python surrogate at a set of prediction points.

Parameters
[in]eval_pointsMatrix of prediction points - (num_pts by num_features).
Returns
Values of the python surrogate at the prediction points - (num_pts)

Reimplemented from Surrogate.

References Python::pyModuleActive, and Python::pySurrogate.

◆ values()

VectorXd values ( const MatrixXd eval_points)
overridevirtual

Evaluate the field python surrogate at a set of prediction points.

Parameters
[in]eval_pointsMatrix of prediction points - (num_pts by num_features).
Returns
Values of the python surrogate at the prediction points - (num_pts)

Reimplemented from Surrogate.

References Python::pyModuleActive, and Python::pySurrogate.

◆ gradient()

MatrixXd gradient ( const MatrixXd eval_points)
overridevirtual

Evaluate the gradient of the python scalar surrogate at a set of prediction points.

Parameters
[in]eval_pointsCoordinates of the prediction points - (num_pts by num_features).
Returns
Matrix of gradient vectors at the prediction points - (num_pts by num_features).

Reimplemented from Surrogate.

References Python::moduleAndClassName, Python::pyModuleActive, and Python::pySurrogate.

◆ hessian()

MatrixXd hessian ( const MatrixXd eval_point)
overridevirtual

Evaluate the Hessian of the python scalar surrogate at a single point.

Parameters
[in]eval_pointCoordinates of the prediction point - (1 by num_features).
Returns
Hessian matrix at the prediction point - (num_features by num_features).

Reimplemented from Surrogate.

References Python::moduleAndClassName, Python::pyModuleActive, and Python::pySurrogate.


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