nnopinf.operators.StandardLagrangianOperator#

class nnopinf.operators.StandardLagrangianOperator(n_outputs, depends_on, n_hidden_layers, n_neurons_per_layer, activation=<built-in method tanh of type object>, name='StandardLagrangianOperator')[source]#

Bases: Module

\(f: x \mapsto \nabla_x \mathcal{L}(x)\)

Constructs a Lagrangian operator that returns the gradient of a scalar network with respect to the state.

Parameters:
  • n_outputs (int) – Output dimension of the operator.

  • depends_on (tuple of nnopinf.Variable) – The variables the operator depends on.

  • n_hidden_layers (int) – Number of hidden layers in the network.

  • n_neurons_per_layer (int) – Number of neurons in each hidden layer.

  • activation (PyTorch activation function (e.g., torch.tanh)) – Activation function used at each hidden layer.

  • name (string) – Operator name. Used when saving to file.

forward(inputs, return_jacobian=False)[source]#

Forward pass of operator

Parameters:
  • inputs (dict(str, np.array)) – Dictionary of input data in the form of arrays referenced by the variable name, i.e., inputs[‘x’] = np.ones(3)

  • return_jacobian (bool, optional) – If True, return the (approximate) Jacobian in addition to the output.

set_scalings(input_scalings_dict, output_scaling)[source]#

Store input and output scaling factors for the Lagrangian operator.

Parameters:
  • input_scalings_dict (dict) – Mapping from variable name to the corresponding feature-wise input scaling vector.

  • output_scaling (tensor-like) – Feature-wise scaling vector for the operator output.