chassis¶
Convenience functions for optimizing MuyGPyS.gp.muygps.MuyGPS
objects
Currently wraps scipy.optimize.opt
multiparameter optimization using
the objective function MuyGPyS.optimize.objective.loo_crossval()
in order
to optimize a specified subset of the hyperparameters associated with a
:class:’MuyGPyS.gp.muygps.MuyGPS’ object.
- MuyGPyS.optimize.chassis.scipy_optimize_from_indices(muygps, batch_indices, batch_nn_indices, train_features, train_targets, loss_method='mse', verbose=False)[source]¶
Optimize a model using scipy directly from the data.
Use this method if you do not need to retain the distance matrices used for optimization.
See the following example, where we have already created a
batch_indices
vector and abatch_nn_indices
matrix usingMuyGPyS.neighbors.NN_Wrapper
, and initialized aMuyGPyS.gp.muygps.MuyGPS
modelmuygps
.Example
>>> from MuyGPyS.optimize.chassis import scipy_optimize_from_indices >>> scipy_optimize_from_tensors( ... muygps, ... batch_indices, ... batch_nn_indices, ... train_features, ... train_features, ... train_responses, ... loss_method='mse', ... verbose=True, ... ) parameters to be optimized: ['nu'] bounds: [[0.1 1. ]] sampled x0: [0.8858425] optimizer results: fun: 0.4797763813693626 hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64> jac: array([-3.06976666e-06]) message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL' nfev: 16 nit: 5 njev: 8 status: 0 success: True x: array([0.39963594])
- Parameters
muygps (
MuyGPS
) – The model to be optimized.batch_indices (
ndarray
) – A vector of integers of shape(batch_count,)
identifying the training batch of observations to be approximated.batch_nn_indices (
ndarray
) – A matrix of integers of shape(batch_count, nn_count)
listing the nearest neighbor indices for all observations in the batch.train_features (
ndarray
) – The full floating point training data matrix of shape(train_count, feature_count)
.train_targets (
ndarray
) – A matrix of shape(train_count, feature_count)
whose rows are vector-valued responses for each training element.loss_method (
str
) – Indicates the loss function to be used.verbose (
bool
) – bool If True, print debug messages.
- Return type
ndarray
- Returns
The list of optimized hyperparameters of shape
(opt_count)
. Mostly useful for validation.
- MuyGPyS.optimize.chassis.scipy_optimize_from_tensors(muygps, batch_targets, batch_nn_targets, crosswise_dists, pairwise_dists, loss_method='mse', verbose=False)[source]¶
Optimize a model using existing distance matrices.
Use this method if you need to retain the distance matrices used for later use.
See the followin example, where we have already created a
batch_indices
vector and abatch_nn_indices
matrix usingMuyGPyS.neighbors.NN_Wrapper
, acrosswise_dists
matrix usingMuyGPyS.gp.distance.crosswise_distances()
andpairwise_dists
usingMuyGPyS.gp.distance.pairwise_distances()
, and initialized aMuyGPyS.gp.muygps.MuyGPS
modelmuygps
.Example
>>> from MuyGPyS.optimize.chassis import scipy_optimize_from_tensors >>> scipy_optimize_from_tensors( ... muygps, ... batch_indices, ... batch_nn_indices, ... crosswise_dists, ... pairwise_dists, ... train_responses, ... loss_method='mse', ... verbose=True, ... ) parameters to be optimized: ['nu'] bounds: [[0.1 1. ]] sampled x0: [0.8858425] optimizer results: fun: 0.4797763813693626 hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64> jac: array([-3.06976666e-06]) message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL' nfev: 16 nit: 5 njev: 8 status: 0 success: True x: array([0.39963594])
- Parameters
muygps (
MuyGPS
) – The model to be optimized.batch_targets (
ndarray
) – Matrix of floats of shape(batch_count, response_count)
whose rows give the expected response for each batch element.batch_nn_targets (
ndarray
) – Tensor of floats of shape(batch_count, nn_count, response_count)
containing the expected response for each nearest neighbor of each batch element.crosswise_dists (
ndarray
) – Distance matrix of floats of shape(batch_count, nn_count)
whose rows give the distances between each batch element and its nearest neighbors.pairwise_dists (
ndarray
) – Distance tensor of floats of shape(batch_count, nn_count, nn_count)
whose second two dimensions give the pairwise distances between the nearest neighbors of each batch element.loss_method (
str
) – Indicates the loss function to be used.verbose (
bool
) – If True, print debug messages.
- Return type
ndarray
- Returns
The vector of
(opt_count)
optimized hyperparameters. Mostly useful for validation.