MarabouNetwork

Top contributors (to current version):
  • Christopher Lazarus

  • Shantanu Thakoor

  • Andrew Wu

  • 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.

MarabouNetwork defines an abstract class that represents neural networks with piecewise linear constraints

class maraboupy.MarabouNetwork.MarabouNetwork[source]

Bases: object

Abstract class representing general Marabou network

numVars[source]

Total number of variables to represent network

Type

int

equList[source]

Network equations

Type

list of Equation

reluList[source]

List of relu constraint tuples, where each tuple contains the backward and forward variables

Type

list of tuples

maxList[source]

List of max constraint tuples, where each tuple conatins the set of input variables and output variable

Type

list of tuples

absList[source]

List of abs constraint tuples, where each tuple conatins the input variable and the output variable

Type

list of tuples

signList[source]

List of sign constraint tuples, where each tuple conatins the input variable and the output variable

Type

list of tuples

lowerBounds[source]

Lower bounds of variables

Type

Dict[int, float]

upperBounds[source]

Upper bounds of variables

Type

Dict[int, float]

inputVars[source]

Input variables

Type

list of numpy arrays

outputVars[source]

Output variables

Type

numpy array

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

clear()[source]

Reset values to represent empty network

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 None

  • filename (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)

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)

getMarabouQuery()[source]

Function to convert network into Marabou InputQuery

Returns

InputQuery

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)

upperBoundExists(x)[source]

Function to check whether upper bound for a variable is known

Parameters

x (int) – Variable to check