Generic Predictor Constraint

pyscipopt_ml.add_predictor_constr(scip_model, predictor, input_vars, output_vars=None, unique_naming_prefix='p_', **kwargs)

Formulate predictor in PySCIPOpt model.

The formulation predicts the values of output_vars using input_vars according to predictor.

Parameters:
  • scip_model (PySCIPOpt Model) – The pyscipopt model where the predictor should be inserted.

  • predictor – The predictor to insert.

  • input_vars (list or np.ndarray) – Decision variables used as input for predictor in scip_model.

  • output_vars (list or np.ndarray, optional) – Decision variables used as output for predictor in scip_model.

  • unique_naming_prefix (str, optional) – A unique naming prefix that is used before all variable and constraint names. This parameter is important if the SCIP model is later printed to file and many predictors are added to the same SCIP model.

Returns:

Object containing information about what was added to scip_model to insert the predictor in it

Return type:

AbstractPredictorConstr

Note

The parameters input_vars and output_vars can be either

  • Lists of variables (List of lists etc. for higher dimensional input)

  • np.ndarray of variables

For internal use in the package they are cast into a np.ndarray of variables

They should have dimensions that conform with the input/output of the predictor. We denote by n_samples the number of samples (or objects) that we want to predict with our predictor. We denote by n_features the dimension of the input of the predictor. We denote by n_output the dimension of the output.

The input_vars are therefore of shape (n_samples, n_features) and the output_vars of shape (n_samples, n_outputs). In the case of output_vars not being passed, appropriate variables will be automatically created. In the case of n_samples == 1 the first dimension can simply be removed from the input.

class pyscipopt_ml.modelling.base_predictor_constraint.AbstractPredictorConstr(scip_model, input_vars, output_vars=None, unique_naming_prefix='', skip_validate=False, **kwargs)

Base class to store all information of embedded ML model by :py:func`pyscipopt_ml.add_predictor_constr`.

This class is the base class to store everything that is added to a SCIP model when a trained predictor is inserted into it. Depending on the type of the predictor, a class derived from it will be returned by pyscipopt_ml.add_predictor_constr().

Warning

Users should usually never construct objects of this class or one of its derived classes. They are returned by the pyscipopt_ml.add_predictor_constr() and other functions.

abstract get_error(eps)

Returns error in SCIP’s solution with respect to prediction from input.

Returns:

errorpyscipopt_ml.modelling.base_predictor_constr.AbstractPredictorConstr.output Assuming that we have a solution for the input and output variables x, y. Returns the absolute value of the differences between predictor.predict(x) and y. Where predictor is the regression / classification model represented by this object.

Return type:

ndarray of same shape as

Raises:

NoSolution – If the SCIP model has no solution (either was not optimized or is infeasible).

property input

Returns the input variables of embedded predictor.

Returns:

output

Return type:

np.ndarray

property input_values

Returns the values for the input variables if a solution is known.

Returns:

input_vals

Return type:

np.ndarray

Raises:

NoSolution – If SCIP has no solution (either was not optimized or is infeasible).

property output

Output variables of embedded predictor.

Returns:

output

Return type:

np.ndarray

property output_values

Returns the values for the output variables if a solution is known.

Returns:

output_value

Return type:

np.ndarray

Raises:

NoSolution – If SCIP has no solution (either was not optimized or is infeasible).

print_stats(file=None)

Print statistics on model additions stored by this class.

This function prints detailed statistics on the variables and constraints that were added to the model.

Parameters:

file (None, optional) – Text stream to which output should be redirected. By default, this is sys.stdout.