Loading...
Searching...
No Matches
gpr::capi::ScalarSurrogate Class Reference

#include <gpr/capi/gpridge.hpp>

Classes

struct  Hyperparameters
struct  Prediction

Public Member Functions

 ScalarSurrogate ()=default
 ScalarSurrogate (gpr_sgp_t h, adopt_t) noexcept
 ~ScalarSurrogate ()
 ScalarSurrogate (const ScalarSurrogate &)=delete
ScalarSurrogate & operator= (const ScalarSurrogate &)=delete
 ScalarSurrogate (ScalarSurrogate &&other) noexcept
ScalarSurrogate & operator= (ScalarSurrogate &&other) noexcept
void reset () noexcept
gpr_sgp_t handle () const noexcept
 operator bool () const noexcept
int dimension () const noexcept
int n_observations () const
void set_kernel (BqKernel kernel)
void set_mean_basis (BqBasis basis)
void set_hyperparameters (const Hyperparameters &hyper)
Hyperparameters hyperparameters () const
void observe (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &noise_var, int n_obs)
 noise_var is empty for rows that share the noise variance.
double fit (bool optimize=false, int n_starts=8)
 Returns the log marginal likelihood of the conditioned surrogate.
Prediction predict (const std::vector< double > &x_queries, int n_queries, double query_noise_var=0.0) const
 query_noise_var of zero gives the latent standard deviation.

Static Public Member Functions

static ScalarSurrogate create (int dimension, BqKernel kernel=BqKernel::SquaredExponential)

Detailed Description

Owner of a gpr_sgp_t: a scalar GP for a noisy oracle. Arrays are row-major, one row per point.

Definition at line 1001 of file gpridge.hpp.

Constructor & Destructor Documentation

◆ ScalarSurrogate() [1/4]

gpr::capi::ScalarSurrogate::ScalarSurrogate ( )
default

◆ ScalarSurrogate() [2/4]

gpr::capi::ScalarSurrogate::ScalarSurrogate ( gpr_sgp_t h,
adopt_t  )
inlinenoexcept

Definition at line 1004 of file gpridge.hpp.

1004: handle_(h) { }

◆ ~ScalarSurrogate()

gpr::capi::ScalarSurrogate::~ScalarSurrogate ( )
inline

Definition at line 1005 of file gpridge.hpp.

1006 {
1007 reset();
1008 }

◆ ScalarSurrogate() [3/4]

gpr::capi::ScalarSurrogate::ScalarSurrogate ( const ScalarSurrogate & )
delete

◆ ScalarSurrogate() [4/4]

gpr::capi::ScalarSurrogate::ScalarSurrogate ( ScalarSurrogate && other)
inlinenoexcept

Definition at line 1012 of file gpridge.hpp.

1013 : handle_(other.handle_), dimension_(other.dimension_)
1014 {
1015 other.handle_ = nullptr;
1016 }

Member Function Documentation

◆ create()

ScalarSurrogate gpr::capi::ScalarSurrogate::create ( int dimension,
BqKernel kernel = BqKernel::SquaredExponential )
inlinestaticnodiscard

Definition at line 1028 of file gpridge.hpp.

1030 {
1031 gpr_sgp_t h = gpr_sgp_create(dimension, static_cast<int>(kernel));
1032 if (!h) throw Error(gpr_last_status(), gpr_last_error_message());
1034 out.dimension_ = dimension;
1035 return out;
1036 }
int dimension() const noexcept
Definition gpridge.hpp:1052
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
int gpr_last_status(void)
Status of the last call on this thread that failed (ABI 1.1), like errno: a constructor that returns ...
const char * gpr_last_error_message(void)
The same string as gpr_last_error (ABI 1.6). Never NULL. Fortran and the other bindings call this nam...
struct gpr_sgp_s * gpr_sgp_t
Definition gpridge_c.h:387
gpr_sgp_t gpr_sgp_create(int dimension, int kernel)
Create a scalar surrogate with unit length scales, unit signal variance, a noise variance of 1e-8 and...
constexpr adopt_t adopt
Definition gpridge.hpp:37

◆ dimension()

int gpr::capi::ScalarSurrogate::dimension ( ) const
inlinenodiscardnoexcept

Definition at line 1052 of file gpridge.hpp.

1053 {
1054 return dimension_;
1055 }

◆ fit()

double gpr::capi::ScalarSurrogate::fit ( bool optimize = false,
int n_starts = 8 )
inline

Returns the log marginal likelihood of the conditioned surrogate.

Definition at line 1106 of file gpridge.hpp.

1107 {
1108 double likelihood = 0.0;
1109 check(gpr_sgp_fit_checked(require_handle(), optimize ? 1 : 0, n_starts,
1110 &likelihood));
1111 return likelihood;
1112 }
int gpr_sgp_fit_checked(gpr_sgp_t sgp, int optimize, int n_starts, double *log_marginal_likelihood_out)
Condition the surrogate on the observed rows.
void check(int status)
Definition gpridge.hpp:323

◆ handle()

gpr_sgp_t gpr::capi::ScalarSurrogate::handle ( ) const
inlinenodiscardnoexcept

Definition at line 1044 of file gpridge.hpp.

1045 {
1046 return handle_;
1047 }

◆ hyperparameters()

Hyperparameters gpr::capi::ScalarSurrogate::hyperparameters ( ) const
inlinenodiscard

Definition at line 1084 of file gpridge.hpp.

1085 {
1087 out.length_scales.resize(static_cast<std::size_t>(dimension_));
1089 require_handle(), out.length_scales.data(),
1090 out.length_scales.size(), &out.signal_variance,
1091 &out.noise_variance));
1092 return out;
1093 }
int gpr_sgp_get_hyperparameters_checked(gpr_sgp_t sgp, double *length_scales_out, size_t length_scales_len, double *signal_variance_out, double *noise_variance_out)
Read the hyperparameters, as set or as the last fit left them.

◆ n_observations()

int gpr::capi::ScalarSurrogate::n_observations ( ) const
inlinenodiscard

Definition at line 1056 of file gpridge.hpp.

1057 {
1058 return gpr_sgp_n_observations(require_handle());
1059 }
int gpr_sgp_n_observations(gpr_sgp_t sgp)
Number of observed rows, or 0 for NULL or a dead handle.

◆ observe()

void gpr::capi::ScalarSurrogate::observe ( const std::vector< double > & x,
const std::vector< double > & y,
const std::vector< double > & noise_var,
int n_obs )
inline

noise_var is empty for rows that share the noise variance.

Definition at line 1096 of file gpridge.hpp.

1098 {
1100 require_handle(), x.data(), x.size(), y.data(), y.size(),
1101 noise_var.empty() ? nullptr : noise_var.data(), noise_var.size(),
1102 n_obs, dimension_));
1103 }
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
int gpr_sgp_observe_checked(gpr_sgp_t sgp, const double *X, size_t X_len, const double *y, size_t y_len, const double *noise_var, size_t noise_var_len, int n_obs, int n_dims)
Append observed rows.

◆ operator bool()

gpr::capi::ScalarSurrogate::operator bool ( ) const
inlineexplicitnodiscardnoexcept

Definition at line 1048 of file gpridge.hpp.

1049 {
1050 return handle_ != nullptr;
1051 }

◆ operator=() [1/2]

ScalarSurrogate & gpr::capi::ScalarSurrogate::operator= ( const ScalarSurrogate & )
delete

◆ operator=() [2/2]

ScalarSurrogate & gpr::capi::ScalarSurrogate::operator= ( ScalarSurrogate && other)
inlinenoexcept

Definition at line 1017 of file gpridge.hpp.

1018 {
1019 if (this != &other) {
1020 reset();
1021 handle_ = other.handle_;
1022 dimension_ = other.dimension_;
1023 other.handle_ = nullptr;
1024 }
1025 return *this;
1026 }

◆ predict()

Prediction gpr::capi::ScalarSurrogate::predict ( const std::vector< double > & x_queries,
int n_queries,
double query_noise_var = 0.0 ) const
inlinenodiscard

query_noise_var of zero gives the latent standard deviation.

Definition at line 1120 of file gpridge.hpp.

1123 {
1125 out.mean.resize(static_cast<std::size_t>(n_queries));
1126 out.std.resize(static_cast<std::size_t>(n_queries));
1128 require_handle(), x_queries.data(), x_queries.size(), n_queries,
1129 dimension_, query_noise_var, out.mean.data(), out.mean.size(),
1130 out.std.data(), out.std.size()));
1131 return out;
1132 }
int gpr_sgp_predict_checked(gpr_sgp_t sgp, const double *X_queries, size_t X_len, int n_queries, int n_dims, double query_noise_var, double *mean_out, size_t mean_len, double *std_out, size_t std_len)
Predict mean and standard deviation at query rows.

◆ reset()

void gpr::capi::ScalarSurrogate::reset ( )
inlinenoexcept

Definition at line 1038 of file gpridge.hpp.

1039 {
1040 if (handle_) gpr_sgp_destroy(handle_);
1041 handle_ = nullptr;
1042 }
void gpr_sgp_destroy(gpr_sgp_t sgp)
Destroy a handle from gpr_sgp_create. Destroying NULL or a live handle clears gpr_last_status(); a de...

◆ set_hyperparameters()

void gpr::capi::ScalarSurrogate::set_hyperparameters ( const Hyperparameters & hyper)
inline

Definition at line 1077 of file gpridge.hpp.

1078 {
1080 require_handle(), hyper.length_scales.data(),
1081 hyper.length_scales.size(), hyper.signal_variance,
1082 hyper.noise_variance));
1083 }
int gpr_sgp_set_hyperparameters_checked(gpr_sgp_t sgp, const double *length_scales, size_t length_scales_len, double signal_variance, double noise_variance)
Set the hyperparameters.

◆ set_kernel()

void gpr::capi::ScalarSurrogate::set_kernel ( BqKernel kernel)
inline

Definition at line 1061 of file gpridge.hpp.

1062 {
1063 check(gpr_sgp_set_kernel(require_handle(), static_cast<int>(kernel)));
1064 }
int gpr_sgp_set_kernel(gpr_sgp_t sgp, int kernel)
Select the radial shape. The observations and hyperparameters stay; the surrogate needs a new gpr_sgp...

◆ set_mean_basis()

void gpr::capi::ScalarSurrogate::set_mean_basis ( BqBasis basis)
inline

Definition at line 1065 of file gpridge.hpp.

1066 {
1067 check(
1068 gpr_sgp_set_mean_basis(require_handle(), static_cast<int>(basis)));
1069 }
int gpr_sgp_set_mean_basis(gpr_sgp_t sgp, int basis)
Select the mean with a gpr_bq_basis_t value: GPR_BQ_BASIS_NONE (zero, the default),...

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