physbo.blm package
Subpackages
Module contents
Bayesian Linear Model
- class physbo.blm.Model(lik, prior, options={})[source]
Bases:
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)[source]
Calculating permutation importance of model
- Parameters:
X (numpy.ndarray) – inputs
t (numpy.ndarray) – target (label)
n_perm (int) – number of permutations
comm (MPI.Comm) – MPI communicator
- Returns:
numpy.ndarray – importance_mean
numpy.ndarray – importance_std
- get_post_fcov(X, Psi=None, diag=True)[source]
calculates posterior covariance of model
- Parameters:
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)
- Returns:
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.
- Return type:
numpy.ndarray
See also
- get_post_fmean(X, Psi=None, w=None)[source]
calculates posterior mean of model (function)
- Parameters:
X (numpy.ndarray) – inputs
Psi (numpy.ndarray) – feature maps
w (numpy.ndarray) – weight
See also
- post_sampling(Xtest, Psi=None, N=1, alpha=1.0, rng=None)[source]
draws samples of mean value of model
- Parameters:
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
- Return type:
numpy.ndarray
- predict_sampling(Xtest, Psi=None, N=1, rng=None)[source]
draws samples from model
- Parameters:
Xtest (numpy.ndarray) – inputs
Psi (numpy.ndarray) – feature map (default:
blm.lik.get_basis(Xtest))N (int) – number of samples (default: 1)
- Return type:
numpy.ndarray (N x len(Xtest))
- prepare(X, t, Psi=None)[source]
initializes model by using the first training dataset
- Parameters:
X (numpy.ndarray) – inputs
t (numpy.ndarray) – target (label)
Psi (numpy.ndarray) – feature maps
See also
- sampling(w_mu=None, N=1, alpha=1.0, rng=None)[source]
draws samples of weights
- Parameters:
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)
- Returns:
samples of weights
- Return type:
numpy.ndarray
See also
- class physbo.blm.Predictor(config, model=None)[source]
Bases:
BasePredictorPredictor using Baysean linear model
- blm
- Type:
- config
configuration
- Type:
physbo.misc.SetConfig
- Parameters:
config (physbo.misc.SetConfig) – configuration
model (physbo.gp.core.Model)
See also
- draw_post_sample_params(training, alpha=1.0, objective_index=0, rng=None)[source]
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.- Parameters:
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)
- Returns:
sampled weight parameters (nbasis,)
- Return type:
numpy.ndarray
- evaluate_post_sample(w_hat, test, objective_index=0)[source]
evaluates a posterior weight sample at test points (deterministic)
- Parameters:
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)
- Returns:
sampled function values at the test points
- Return type:
numpy.ndarray
- fit(training, num_basis=None, comm=None, objective_index=0, rng=None)[source]
fit model to training dataset
- Parameters:
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)[source]
calculates feature maps Psi(X)
- Parameters:
X (numpy.ndarray) – inputs
- Returns:
Psi – feature maps
- Return type:
numpy.ndarray
- get_post_fcov(training, test, diag=True, objective_index=0)[source]
calculates posterior variance-covariance matrix of model
- Parameters:
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)
- Returns:
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.
- Return type:
numpy.ndarray
- get_post_fmean(training, test, objective_index=0)[source]
calculates posterior mean value of model
- Parameters:
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)
- Returns:
Returned shape is (num_points), where num_points is the number of points in test.
- Return type:
numpy.ndarray
- get_post_params(training, test, objective_index=0)[source]
calculates posterior weights
- Parameters:
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)
- Return type:
numpy.ndarray
- get_post_samples(training, test, N=1, alpha=1.0, objective_index=0, rng=None)[source]
draws samples of mean values of model
- Parameters:
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)
- Return type:
numpy.ndarray
- get_predict_samples(training, test, N=1, objective_index=0, rng=None)[source]
draws samples of values of model
- Parameters:
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)
- Return type:
numpy.ndarray (N x len(test))
- prepare(training, objective_index=0)[source]
initializes model by using training data set
- Parameters:
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)[source]
updates the model.
If not yet initialized (prepared), the model will be prepared by
training. Otherwise, the model will be updated bytest.- Parameters:
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)