jijzepttools.blackbox_optimization.surrogate_model#

Submodules#

Classes#

BFMParams

Parameters for the Bayesian Factorization Machine surrogate model.

BFMSurrogateModel

Bayesian Factorization Machine (BFM) surrogate model.

BOCSParams

Parameters for BOCS (Bayesian Optimization of Combinatorial Structures) surrogate model.

BOCSSurrogateModel

BOCS (Bayesian Optimization of Combinatorial Structures) surrogate model.

FMParams

Parameters for Factorization Machine surrogate model.

FMSurrogateModel

Factorization Machine surrogate model implementation.

SurrogateModel

Abstract base class for surrogate models in blackbox optimization.

SurrogateModelParams

Base class for all surrogate model parameters.

Package Contents#

class BFMParams#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModelParams

Parameters for the Bayesian Factorization Machine surrogate model.

init_stdev, alpha0, beta0, gamma_0, mu_0, reg_0の詳細は以下を参照 参考: tohtsky/myFM

latent_dim#

Dimension of latent factors.

Type:

int, default=5

tune#

Number of burn-in sweeps for Gibbs sampling.

Type:

int, default=100

draws#

Number of samples to average after burn-in.

Type:

int, default=10

init_stdev#

FMのパラメータ初期値の標準偏差

Type:

float

alpha0, beta0

alpha, lambda_w, lambda_vの事前ガンマ分布の形状を決定するパラメータ

Type:

float

gamma_0#

パラメータの正規事前分布の平均mu_w, mu_vが従うハイパー事前分布(正規分布)の精度

Type:

float

mu_0#

パラメータの正規事前分布の平均mu_w, mu_vが従うハイパー事前分布(正規分布)の平均

Type:

float

reg_0#

バイアス項 w0が従う正規事前分布の精度

Type:

float

latent_dim: int = 5#
tune: int = 100#
draws: int = 10#
init_stdev: float = 0.1#
alpha_0: float = 1.0#
beta_0: float = 1.0#
gamma_0: float = 1.0#
mu_0: float = 0.0#
reg_0: float = 1.0#
class BFMSurrogateModel(params: BFMParams | None = None, random_seed: int = 42)#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModel

Bayesian Factorization Machine (BFM) surrogate model.

This model wraps the BFM implementation and provides the SurrogateModel interface. It’s effective for problems where interactions between variables are important.

Parameters:

params (BFMParams, optional) – Parameters for the model. If None, default parameters are used.

params = None#
bfm_regressor#
fit(x: numpy.ndarray, y: numpy.ndarray) None#

Fit the BFM model to the data using Gibbs sampling.

Parameters:
  • x (np.ndarray, shape (n_samples, n_features)) – Input features.

  • y (np.ndarray, shape (n_samples,)) – Target values.

predict(x: numpy.ndarray) numpy.ndarray#

Predict target values using the fitted BFM model.

surrogate_to_ommx_objective(decision_variables: list[ommx.v1.DecisionVariable])#

Create an OMMX expression from the fitted BFM model.

Parameters:

decision_variables (list[ommx.v1.DecisionVariable]) – Decision variables from the OMMX instance.

class BOCSParams#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModelParams

Parameters for BOCS (Bayesian Optimization of Combinatorial Structures) surrogate model.

random_seed#

Random seed for reproducibility.

Type:

int, optional

draws#
Number of MCMC samples to draw.

drawed samples are used for the mean of coefficients for the optimization.

Type:

int, default=10

tune#

Number of burn-in iterations.

Type:

int, default=100

warm_start#

Whether to continue from the previous Gibbs chain.

Type:

bool, default=False

random_seed: int | None = None#
draws: int = 10#
tune: int = 100#
warm_start: bool = False#
class BOCSSurrogateModel(params: BOCSParams | None = None)#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModel

BOCS (Bayesian Optimization of Combinatorial Structures) surrogate model.

This model uses sparse Bayesian linear regression on quadratic features to approximate the objective function. It automatically generates quadratic interaction terms and applies Bayesian regularization.

Parameters:

params (BOCSParams, optional) – Parameters for the model. If None, default parameters are used.

sblr#
draws = 10#
tune = 100#
n_features: int | None = None#
triu_indices: numpy.ndarray | None = None#
fit(x: numpy.ndarray, y: numpy.ndarray) None#

Fit the BOCS model to the data.

This involves: 1. Generating quadratic interaction terms 2. Fitting sparse Bayesian linear regression

Parameters:
  • x (np.ndarray, shape (n_samples, n_features)) – Input features.

  • y (np.ndarray, shape (n_samples,)) – Target values.

predict(x: numpy.ndarray) numpy.ndarray#

Predict target values using the fitted BOCS model.

This generates quadratic interaction terms for the input features and uses the fitted model to make predictions.

Parameters:

x (np.ndarray, shape (n_samples, n_features)) – Input features.

Returns:

Predicted target values.

Return type:

np.ndarray, shape (n_samples,)

surrogate_to_ommx_objective(decision_variables: list[ommx.v1.DecisionVariable])#

Create OMMX expression for the fitted BOCS model.

Notes: - The order of the decision variables is the same as the order of the features.

Parameters:

decision_variables (list[ommx.v1.DecisionVariable]) – Decision variables from OMMX instance.

class FMParams#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModelParams

Parameters for Factorization Machine surrogate model.

latent_dim#

Dimension of latent factors in FM.

Type:

int, default=5

n_epochs#

Number of training epochs.

Type:

int, default=100

optimizer_params#

Parameters for PyTorch optimizer (e.g., {‘lr’: 0.001, ‘weight_decay’: 1e-4}).

Type:

dict, default={}

batch_size#

Batch size for training.

Type:

int, default=1

latent_dim: int = 5#
n_epochs: int = 100#
optimizer_params: dict#
batch_size: int = 1#
class FMSurrogateModel(n_features: int, params: FMParams | None = None)#

Bases: jijzepttools.blackbox_optimization.surrogate_model.interface.SurrogateModel

Factorization Machine surrogate model implementation.

This model uses second-order feature interactions to approximate the objective function. The mathematical form is: f(x) = w0 + Σ wi*xi + ΣΣ <vi,vj>*xi*xj

Parameters:
  • n_features (int) – Number of input features.

  • params (FMParams, optional) – Parameters for the model. If None, default parameters are used.

n_features#
fm_trainer#
fit(x: numpy.ndarray, y: numpy.ndarray) None#

Fit the Factorization Machine to the data.

Parameters:
  • x (np.ndarray, shape (n_samples, n_features)) – Input features.

  • y (np.ndarray, shape (n_samples,)) – Target values.

predict(x: numpy.ndarray) numpy.ndarray#

Predict target values using the fitted FM model.

surrogate_to_ommx_objective(decision_variables: list[ommx.v1.DecisionVariable])#

Create OMMX expression for the fitted FM model.

Parameters:

decision_variables (list[ommx.v1.DecisionVariable]) – Decision variables from OMMX instance.

class SurrogateModel#

Bases: abc.ABC

Abstract base class for surrogate models in blackbox optimization.

This interface provides a unified way to interact with different surrogate models such as Factorization Machine and BOCS. The typical workflow is: 1. Instantiate a concrete surrogate model with parameters 2. Fit the model to observed data using fit() 3. Create optimization objective using create_optimization_model()

abstract fit(x: numpy.ndarray, y: numpy.ndarray) None#

Fit the surrogate model to observed data.

Parameters:
  • x (np.ndarray, shape (n_samples, n_features)) – Input features from blackbox function evaluations.

  • y (np.ndarray, shape (n_samples,)) – Target values for a single objective.

abstract surrogate_to_ommx_objective(decision_variables: list[ommx.v1.DecisionVariable])#

Create an OMMX expression representing the surrogate model objective.

Parameters:

decision_variables (list[ommx.v1.DecisionVariable]) – List of decision variables from the OMMX instance.

class SurrogateModelParams#

Base class for all surrogate model parameters.

This class serves as a base for parameter classes used by different surrogate models (e.g., FMParams, BOCSParams). Each concrete implementation should define the specific parameters needed for that model type.

This provides a unified interface for parameter classes of different surrogate models, allowing for type-safe and extensible parameter handling.