physbo.blm package
Subpackages
Module contents
Bayesian Linear Model
- class physbo.blm.Model(lik, prior, options={})[source]
Bases:
object
Baysean 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)[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)[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)[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
- 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)[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:
BasePredictor
Predictor 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
- fit(training, num_basis=None, comm=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
- 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)[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.
- 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)[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
- 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)[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)
- Return type:
numpy.ndarray
- get_post_samples(training, test, N=1, alpha=1.0)[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)
- Return type:
numpy.ndarray
- get_predict_samples(training, test, N=1)[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)
alpha (float) – noise for sampling source (default: 1.0)
- Return type:
numpy.ndarray (N x len(test))
- prepare(training)[source]
initializes model by using training data set
- Parameters:
training (physbo.variable) – dataset for training
- update(training, test)[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.