box_qp_model


class BoxQPModel(c, method_type)[source]#

Bases: Module

Generates the model required for post-processing using torch. Utilizing the Adam or ASGD or LBFGS optimization methods by calling the function func_post_torch or func_post_LBFGS.

Parameters:

torch.nn.Module – Base class for all neural network modules.

BoxQPModel class initialization.

Parameters:
  • c (torch.tensor) – The values for each

  • solver. (variable of the problem in the solution found by the) –

  • method_type (MethodType) – The type of method to be used in post-processing.

forward(q_matrix, v_vector)[source]#

The forward method is called when we use the neural network to make a prediction. The forward method is called from the __call__ function of nn.Module, so that when we run model(input), the forward method is called.

Parameters:
  • q_matrix (torch.tensor) – The Q matrix describing the BoxQP problem

  • v_vector (torch.tensor) – The V vector describing the BoxQP problem.

Returns:

Objective function.

Return type:

torch.tensor

func_post_LBFGS(c, q_matrix, v_vector)[source]#

Generates the objective function as a scalar torch object. This should be used when post-processing for each batch separately.

Parameters:
  • c (torch.tensor) – The values for each

  • solver. (variable of the problem in the solution found by the) –

  • q_matrix (torch.tensor) – The Q matrix describing the BoxQP problem

  • v_vector (torch.tensor) – The V vector describing the BoxQP problem.

Returns:

Objective function.

Return type:

torch.tensor

func_post_torch(c, q_matrix, v_vector)[source]#

Generates the objective function as vector torch object. This should be used when post-processing in parallel for all batches.

Parameters:
  • c (torch.tensor) – The values for each

  • solver. (variable of the problem in the solution found by the) –

  • q_matrix (torch.tensor) – The Q matrix describing the BoxQP problem

  • v_vector (torch.tensor) – The V vector describing the BoxQP problem.

Returns:

Objective function.

Return type:

torch.tensor