jijzepttools.blackbox_optimization#
Submodules#
- jijzepttools.blackbox_optimization.bayesian_factorization_machine
- jijzepttools.blackbox_optimization.bbo_ommx
- jijzepttools.blackbox_optimization.benchmark
- jijzepttools.blackbox_optimization.bocs
- jijzepttools.blackbox_optimization.demo
- jijzepttools.blackbox_optimization.factorization_machine
- jijzepttools.blackbox_optimization.fm_opt
- jijzepttools.blackbox_optimization.problem
- jijzepttools.blackbox_optimization.sparse_bayesian_linear_reg
- jijzepttools.blackbox_optimization.surrogate_model
- jijzepttools.blackbox_optimization.workflow
Classes#
Factorization Machine model |
|
Sparse Bayesian Linear Regression using Horseshoe prior distribution. |
|
Package Contents#
- class BOCSWorkflow(random_seed: int | None = None, coef_mean=True, flip_postprocess4uniq: bool = False)#
Bases:
jijzepttools.blackbox_optimization.workflow.BlackboxOptimizationWorkflow
- sbr#
- coef_mean = True#
- create_quadratic_terms(x: numpy.ndarray) numpy.ndarray #
- train(state)#
- generate_instance(state) tuple[dict, float] #
- run(x: numpy.ndarray, y: numpy.ndarray, blackbox_func: Callable, solver: Callable, n_iter: int, draws: int = 1, tune: int = 1)#
- class FactorizationMachine(n_features: int, latent_dim: int)#
Bases:
torch.nn.Module
Factorization Machine model
`math f(x|w, v) = w0 + Σwi*xi + ΣΣ<vj, vk>xj*xk = w0 + Σwi*xi + 1/2*(Σ(vi*xi)^2 - Σ(vi^2*xi^2)) `
- n_features#
- latent_dim#
- linear#
- quad#
- forward(x)#
- property v#
- property w#
- property w0#
- class FMTrainer(n_features: int, latent_dim: int, optimizer_params: dict | None = None)#
- model#
- fit(x_numpy: numpy.ndarray, y_numpy: numpy.ndarray, n_epochs: int)#
- predict(x: numpy.ndarray) numpy.ndarray #
- property x#
- property y#
- get_qubo() tuple[numpy.ndarray, float] #
- class FMOWorkflow(n_features, latent_dim, optimizer_params: dict | None = None, flip_postprocess4uniq: bool = False)#
Bases:
jijzepttools.blackbox_optimization.workflow.BlackboxOptimizationWorkflow
- fm_trainer#
- train(state)#
- generate_instance(state) tuple[numpy.ndarray, float] #
- run(x: numpy.ndarray, y: numpy.ndarray, blackbox_func: Callable, solver: Callable, n_iter: int, n_epochs: int)#
- class SparseBayesianLinearRegression(random_seed: int | None = None, warm_start: bool = False, keep_one_trace: bool = True)#
Sparse Bayesian Linear Regression using Horseshoe prior distribution.
This class implements Bayesian linear regression with automatic sparsity induction through the Horseshoe prior. The model assumes:
y_i ~ Normal(β_0 + β^T x_i, sigma^2)
where β_0 is the bias term and β are the regression coefficients. The coefficients are combined as theta = (β_0, β) and sampled together via the sample_theta method.
The Horseshoe prior automatically determines which coefficients should be shrunk towards zero (sparse) and which should remain active, without requiring manual hyperparameter tuning.
Gibbs Sampling Parameters: - theta = (β_0, β): Regression coefficients (feature coefficients + bias) - sigma^2: Observation noise variance - lambda^2: Local shrinkage parameters (one per coefficient) - tau^2: Global shrinkage parameter - nu, xi: Auxiliary variables for efficient sampling
All parameters are treated as random variables and sampled from their posterior distributions - no fixed hyperparameters are used.
Each fit() call appends results to the internal trace list. The learned model parameters from the most recent fit() are stored in trace[-1].coef and trace[-1].bias: - coef: shape (draws, n_features) - regression coefficients β for input features - bias: shape (draws,) - bias terms β_0
Each contains draws posterior samples, where coefficient order follows the input feature order in x.
- rs#
- warm_start = False#
- keep_one_trace = True#
- fit(x: numpy.ndarray, y: numpy.ndarray, draws: int = 10, tune: int = 100)#
- predict(x: numpy.ndarray) numpy.ndarray #
Predict using the most recent trace of coefficients and bias.
- Parameters:
x (np.ndarray, shape (n_samples, n_features)) – Input features for prediction.
- Returns:
Predicted values.
- Return type:
np.ndarray, shape (n_samples,)
- class BlackboxOptimizationWorkflow(*, bb_problem: jijzepttools.blackbox_optimization.problem.BlackboxProblem | None = None, flip_postprocess4uniq: bool = False)#
- workflow#
- train(state: BlackboxState) None #
- generate_instance(state: BlackboxState)#
- solve(instance)#
- run_blackbox(state: BlackboxState, x)#
- flip_postprocess4uniq(state: BlackboxState, new_x: numpy.ndarray)#
- check_iter(state: BlackboxState)#
- run(x: numpy.ndarray, y: numpy.ndarray, blackbox_func: Callable, solver: Callable, n_iter: int, **params)#