MarabouNetworkONNX¶
- Top contributors (to current version):
Kyle Julian
This file is part of the Marabou project. Copyright (c) 2017-2019 by the authors listed in the file AUTHORS in the top-level source directory) and their institutional affiliations. All rights reserved. See the file COPYING in the top-level source directory for licensing information.
MarabouNetworkONNX represents neural networks with piecewise linear constraints derived from the ONNX format
-
class
maraboupy.MarabouNetworkONNX.
MarabouNetworkONNX
(filename, inputNames=None, outputName=None)[source]¶ Bases:
maraboupy.MarabouNetwork.MarabouNetwork
Constructs a MarabouNetworkONNX object from an ONNX file
- Parameters
filename (str) – Path to the ONNX file
inputNames – (list of str, optional): List of node names corresponding to inputs
outputName – (string, optional): Name of node corresponding to output
- Returns
marabouNetworkONNX
-
addAbsConstraint
(b, f)[source]¶ Function to add a new Abs constraint
- Parameters
b (int) – Variable representing input of the Abs constraint
f (int) – Variable representing output of the Abs constraint
-
addDisjunctionConstraint
(disjuncts)[source]¶ Function to add a new Disjunction constraint
- Parameters
disjuncts (list of list of Equations) – Each inner list represents a disjunct
-
addEquality
(vars, coeffs, scalar)[source]¶ Function to add equality constraint to network
\[\sum_i vars_i * coeffs_i = scalar\]- Parameters
vars (list of int) – Variable numbers
coeffs (list of float) – Coefficients
scalar (float) – Right hand side constant of equation
-
addEquation
(x)[source]¶ Function to add new equation to the network
- Parameters
x (
Equation
) – New equation to add
-
addInequality
(vars, coeffs, scalar)[source]¶ Function to add inequality constraint to network
\[\sum_i vars_i * coeffs_i \le scalar\]- Parameters
vars (list of int) – Variable numbers
coeffs (list of float) – Coefficients
scalar (float) – Right hand side constant of inequality
-
addMaxConstraint
(elements, v)[source]¶ Function to add a new Max constraint
- Parameters
elements (set of int) – Variable representing input to max constraint
v (int) – Variable representing output of max constraint
-
addRelu
(v1, v2)[source]¶ Function to add a new Relu constraint
- Parameters
v1 (int) – Variable representing input of Relu
v2 (int) – Variable representing output of Relu
-
addSignConstraint
(b, f)[source]¶ Function to add a new Sign constraint
- Parameters
b (int) – Variable representing input of Sign
f (int) – Variable representing output of Sign
-
evaluate
(inputValues, useMarabou=True, options=None, filename='evaluateWithMarabou.log')[source]¶ Function to evaluate network at a given point
- Parameters
inputValues (list of np arrays) – Inputs to evaluate
useMarabou (bool) – Whether to use Marabou solver or TF/ONNX, defaults to True
options (
Options
) – Object for specifying Marabou options, defaults to Nonefilename (str) – Path to redirect output if using Marabou solver, defaults to “evaluateWithMarabou.log”
- Returns
Values representing the output of the network or None if output cannot be computed
- Return type
(np array)
-
evaluateWithMarabou
(inputValues, filename='evaluateWithMarabou.log', options=None)[source]¶ Function to evaluate network at a given point using Marabou as solver
- Parameters
inputValues (list of np arrays) – Inputs to evaluate
filename (str) – Path to redirect output if using Marabou solver, defaults to “evaluateWithMarabou.log”
options (
Options
) – Object for specifying Marabou options, defaults to None
- Returns
Values representing the output of the network or None if system is UNSAT
- Return type
(np array)
-
evaluateWithoutMarabou
(inputValues)[source]¶ Try to evaluate the network with the given inputs using ONNX
- Parameters
inputValues (list of numpy array) – Input values representing inputs to network
- Returns
Output values of neural network
- Return type
(numpy array)
-
findError
(inputValues, options=None, filename='evaluateWithMarabou.log')[source]¶ Function to find error between Marabou solver and TF/Nnet at a given point
- Parameters
inputValues (list of np arrays) – Input values to evaluate
options (
Options
) –filename (str) – Path to redirect output if using Marabou solver, defaults to “evaluateWithMarabou.log”
- Returns
Values representing the error in each output variable
- Return type
(np array)
-
lowerBoundExists
(x)[source]¶ Function to check whether lower bound for a variable is known
- Parameters
x (int) – Variable to check
-
saveQuery
(filename='')[source]¶ Serializes the inputQuery in the given filename
- Parameters
filename – (string) file to write serialized inputQuery
-
setLowerBound
(x, v)[source]¶ Function to set lower bound for variable
- Parameters
x (int) – Variable number to set
v (float) – Value representing lower bound
-
setUpperBound
(x, v)[source]¶ Function to set upper bound for variable
- Parameters
x (int) – Variable number to set
v (float) – Value representing upper bound
-
solve
(filename='', verbose=True, options=None)[source]¶ Function to solve query represented by this network
- Parameters
filename (string) – Path for redirecting output
verbose (bool) – If true, print out solution after solve finishes
options (
Options
) – Object for specifying Marabou options, defaults to None
- Returns
- tuple containing:
vals (Dict[int, float]): Empty dictionary if UNSAT, otherwise a dictionary of SATisfying values for variables
stats (
Statistics
): A Statistics object to how Marabou performed
- Return type
(tuple)