physbo.blm package
Subpackages
Module contents
Bayesian Linear Model
- class physbo.blm.Model(lik, prior, options={})[ソース]
ベースクラス:
objectBaysean Linear Model
- prior
prior distribution of weights
- Type:
physbo.blm.prior.Gauss
- lik
kernel
- Type:
- nbasis
number of features in random feature map
- Type:
int
- stats
auxially parameters for sampling
- Type:
Tuple
- method
sampling method
- Type:
str
- get_permutation_importance(X, t, n_perm: int, comm=None, split_features_parallel=False, rng=None)[ソース]
Calculating permutation importance of model
- パラメータ:
X (numpy.ndarray) -- inputs
t (numpy.ndarray) -- target (label)
n_perm (int) -- number of permutations
comm (MPI.Comm) -- MPI communicator
- 戻り値:
numpy.ndarray -- importance_mean
numpy.ndarray -- importance_std
- get_post_fcov(X, Psi=None, diag=True)[ソース]
calculates posterior covariance of model
- パラメータ:
X (numpy.ndarray) -- inputs
Psi (numpy.ndarray) -- feature maps (default: blm.lik.linear.basis.get_basis(X))
diag (bool) -- if True, returns only variances as a diagonal matrix (default: True)
- 戻り値:
Returned shape is (num_points) if diag=true, (num_points, num_points) if diag=false, where num_points is the number of points in X.
- 戻り値の型:
numpy.ndarray
- get_post_fmean(X, Psi=None, w=None)[ソース]
calculates posterior mean of model (function)
- パラメータ:
X (numpy.ndarray) -- inputs
Psi (numpy.ndarray) -- feature maps
w (numpy.ndarray) -- weight
- post_sampling(Xtest, Psi=None, N=1, alpha=1.0, rng=None)[ソース]
draws samples of mean value of model
- パラメータ:
Xtest (numpy.ndarray) -- inputs
Psi (numpy.ndarray) -- feature maps (default:
blm.lik.get_basis(Xtest))N (int) -- number of samples (default: 1)
alpha (float) -- noise for sampling source
- 戻り値の型:
numpy.ndarray
- predict_sampling(Xtest, Psi=None, N=1, rng=None)[ソース]
draws samples from model
- パラメータ:
Xtest (numpy.ndarray) -- inputs
Psi (numpy.ndarray) -- feature map (default:
blm.lik.get_basis(Xtest))N (int) -- number of samples (default: 1)
- 戻り値の型:
numpy.ndarray (N x len(Xtest))
- prepare(X, t, Psi=None)[ソース]
initializes model by using the first training dataset
- パラメータ:
X (numpy.ndarray) -- inputs
t (numpy.ndarray) -- target (label)
Psi (numpy.ndarray) -- feature maps
- sampling(w_mu=None, N=1, alpha=1.0, rng=None)[ソース]
draws samples of weights
- パラメータ:
blm (physbo.blm.core.Model) -- model
w_mu (numpy.ndarray) -- mean of weight
N (int) -- the number of samples (default: 1)
alpha (float) -- noise for sampling source (default: 1.0)
- 戻り値:
samples of weights
- 戻り値の型:
numpy.ndarray
- class physbo.blm.Predictor(config, model=None)[ソース]
ベースクラス:
BasePredictorPredictor using Baysean linear model
- blm
- Type:
- config
configuration
- Type:
physbo.misc.SetConfig
- パラメータ:
config (physbo.misc.SetConfig) -- configuration
model (physbo.gp.core.Model)
- draw_post_sample_params(training, alpha=1.0, objective_index=0, rng=None)[ソース]
draws one sample of the posterior weight parameters
Together with
evaluate_post_sample, this splits Thompson sampling into a random "draw" part and a deterministic "evaluate" part. Under MPI, the sample can be drawn on rank 0, broadcast, and evaluated on all ranks so that every rank scores its candidates with the same posterior sample.- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
alpha (float) -- noise for sampling source (default: 1.0)
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
rng (rng object, optional) -- random number generator (default: global numpy.random state)
- 戻り値:
sampled weight parameters (nbasis,)
- 戻り値の型:
numpy.ndarray
- evaluate_post_sample(w_hat, test, objective_index=0)[ソース]
evaluates a posterior weight sample at test points (deterministic)
- パラメータ:
w_hat (numpy.ndarray) -- weight parameters drawn by
draw_post_sample_paramstest (physbo.variable) -- inputs
objective_index (int) -- Index of objective column to use when test.Z is 3D (default: 0)
- 戻り値:
sampled function values at the test points
- 戻り値の型:
numpy.ndarray
- fit(training, num_basis=None, comm=None, objective_index=0, rng=None)[ソース]
fit model to training dataset
- パラメータ:
training (physbo.variable) -- dataset for training
num_basis (int) -- the number of basis (default: self.config.predict.num_basis)
comm (MPI.Comm) -- MPI communicator
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- get_basis(X)[ソース]
calculates feature maps Psi(X)
- パラメータ:
X (numpy.ndarray) -- inputs
- 戻り値:
Psi -- feature maps
- 戻り値の型:
numpy.ndarray
- get_post_fcov(training, test, diag=True, objective_index=0)[ソース]
calculates posterior variance-covariance matrix of model
- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
test (physbo.variable) -- inputs
diag (bool) -- If true, only variances (diagonal elements) are returned.
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- 戻り値:
Returned shape is (num_points) if diag=true, (num_points, num_points) if diag=false, where num_points is the number of points in test.
- 戻り値の型:
numpy.ndarray
- get_post_fmean(training, test, objective_index=0)[ソース]
calculates posterior mean value of model
- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
test (physbo.variable) -- inputs
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- 戻り値:
Returned shape is (num_points), where num_points is the number of points in test.
- 戻り値の型:
numpy.ndarray
- get_post_params(training, test, objective_index=0)[ソース]
calculates posterior weights
- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
test (physbo.variable) -- inputs (not used)
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- 戻り値の型:
numpy.ndarray
- get_post_samples(training, test, N=1, alpha=1.0, objective_index=0, rng=None)[ソース]
draws samples of mean values of model
- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
test (physbo.variable) -- inputs
N (int) -- number of samples (default: 1)
alpha (float) -- noise for sampling source (default: 1.0)
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- 戻り値の型:
numpy.ndarray
- get_predict_samples(training, test, N=1, objective_index=0, rng=None)[ソース]
draws samples of values of model
- パラメータ:
training (physbo.variable) -- training dataset. If already trained, the model does not use this.
test (physbo.variable) -- inputs
N (int) -- number of samples (default: 1)
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- 戻り値の型:
numpy.ndarray (N x len(test))
- prepare(training, objective_index=0)[ソース]
initializes model by using training data set
- パラメータ:
training (physbo.variable) -- dataset for training
objective_index (int) -- Index of objective column to use when training.t is 2D (default: 0)
- update(training, test, objective_index=0)[ソース]
updates the model.
If not yet initialized (prepared), the model will be prepared by
training. Otherwise, the model will be updated bytest.- パラメータ:
training (physbo.variable) -- training dataset for initialization (preparation). If already prepared, the model ignore this.
test (physbo.variable) -- training data for update. If not prepared, the model ignore this.
objective_index (int) -- Index of objective column to use when training.t or test.t is 2D (default: 0)