eml.net package¶
Submodules¶
eml.net.describe module¶
-
class
eml.net.describe.DNRActLayer(lb, ub, ylb, yub)[source]¶ Bases:
eml.net.describe.DNRLayerClass used to shape neural network’s activation layer
Therefore layers caracterized by an activation function.
Parameters: -
bias(*idx)[source]¶ Get the bias associated to the neurons in the current layer
Raises: NotImplementedError– If not implemented in the instance
-
evaluate(data)[source]¶ Evalueates the output of the layer given a input
Raises: NotImplementedError– If not implemented in the instance
-
neuron(*idx)[source]¶ Get specific neuron in the current layer
Parameters: idx ((int, int)) – Index layer, neuron Returns: Neuron Return type: eml.net.describe.DNRActNeuron
-
neurons()[source]¶ Get the neurons in the current activaiton layer
Returns: List of Neuron – List of the neurons in the current layer Return type: list( eml.net.describe.DNRLayer)
-
reset_bounds()[source]¶ Reset lower and upper bounds of the current layer
Raises: NotImplementedError– If not implemented in the instance
-
update_ylb(value, tol=0.0001)[source]¶ Updates output lower bounds of the layer
Parameters: Returns: Acknowledge – True if executed succesfully, False otherwise
Return type:
-
update_yub(value, tol=0.0001)[source]¶ Updates output upper bounds of the layer
Parameters: Returns: Acknowledge – True if executed succesfully, False otherwise
Return type:
-
weights(*idx)[source]¶ Get the weights associated to the neurons in the current layer
Raises: NotImplementedError– If not implemented in the instance
-
-
class
eml.net.describe.DNRActNeuron(layer, idx)[source]¶ Bases:
eml.net.describe.DNRNeuronClass used to shape neural network’s activation neurons
Therefore neurons with an activation function
-
layer_¶ Layer where the neuron is located
Type: eml.net.describe.DNRLayer
Parameters: - layer (obj:eml.net.describe.DNRLayer) – Layer where the neuron is located
- idx (int) – Index of the neuron
-
activation()[source]¶ Get the activation function of the neuron
Returns: Activation function – activation function of the neuron Return type: keras.activations
-
bias()[source]¶ Get the bias associated to the neurons
Returns: Bias – Value corresponding to the bias of the current neuron Return type: float
-
update_ylb(value, tol=0.0001)[source]¶ Updates output lower bound of the neuron
Parameters: Returns: Acknowledge – True if executed succesfully, False otherwise
Return type:
-
update_yub(value, tol=0.0001)[source]¶ Updates output upper bound of the neuron
Parameters: Returns: Acknowledge – True if executed succesfully, False otherwise
Return type:
-
weights()[source]¶ Get the weight associated to the neuron
Returns: Weight – Value corresponding to the weight of the current neuron Return type: float
-
-
class
eml.net.describe.DNRDense(weights, bias, activation)[source]¶ Bases:
eml.net.describe.DNRActLayerClass used to shape the dense layer of the neural network
-
net_¶ name of the neural network
Type: string
-
activation_¶ Activation function
Type: keras.activations
Parameters: Raises: ValueError– If bias and weight amatrixes are inconsistent-
activation()[source]¶ Get activation function of the layer
Returns: Activation function – Activation function of the layer Return type: keras.activations
-
bias(*idx)[source]¶ Get the bias associated to a specific neuron in the layer
Parameters: idx ((int, int)) – Index of the layer Returns: Bias – Value corresponding to the bias of the current neuron Return type: float
-
connected(*idx)[source]¶ Get the neurons connected to a specific one in the current layer
Parameters: idx ((int, int)) – Coordinates of a specific neuron Yields: Index ((int, int)) – Coordinates to the connected neuron
-
evaluate(data)[source]¶ Evalueates the output of the layer given a input
Parameters: data (list(float)) – Input for the layer Returns: Layer output – Output of the layer Return type: float
-
-
class
eml.net.describe.DNREvaluation(net, evals, yevals)[source]¶ Bases:
objectClass used to shape the neural network evaluator
This class evaluates the results of a neural network buil according to the model at
eml.net.describe.DNRNet-
net_¶ Neural network
Type: eml.net.describe.DNRNet
Parameters: - net (
eml.net.describe.DNRNet) –Neural netwokr evals : list(list(float))
Evaluations of a layer - yeavals (list(list(float))) – Evaluations of an activation layer
-
layer(idx)[source]¶ Get specific evaluation of a layer
Parameters: idx (int) – Index of the layer Returns: Evaluations – Evaluations of the specified layer Return type: list(float)
-
xval(*idx)[source]¶ Get evaluation of a specific neuron
Parameters: idx ((int, int)) – Index of the neuron Returns: Evaluation – Evaluation of the neuron Return type: float
-
-
class
eml.net.describe.DNRInput(input_shape=None, lb=None, ub=None)[source]¶ Bases:
eml.net.describe.DNRLayerClass used to shape the input layer of the neural network
-
net_¶ name of the neural network
Type: string
Parameters: Raises: ValueError– If not enought parameters are specified or the input shape is inconsistent-
connected(*idx)[source]¶ Get the neurons connected to a specific one in the current layer
Parameters: idx ((int, int)) – Coordinates of a specific neuron Returns: Return type: None
-
-
class
eml.net.describe.DNRLayer(lb, ub)[source]¶ Bases:
objectClass used to shape neural network layers
Layer of the network. It is composed by a sequence of neurons with lower and upper bound. Multiple layer together define a neural network.
-
net_¶ Name of the neural network where the layer is in
Type: string
Parameters: -
connected(*idx)[source]¶ Get the neurons connected to a specific one in the current layer
Parameters: idx ((int, int)) – Coordinates of a specific neuron Raises: NotImplementedError– If not implemented in the instanca
-
lb()[source]¶ Get the lower bound of the current layer
Returns: List of lower bounds – List of the lower bound of the current layer Return type: list(float)
-
ltype()[source]¶ Get the type of the layer
Raises: NotImplementedError– If not implemented in the instanca
-
neuron(*idx)[source]¶ Get neuron specific neuron
Every neuron in a network can be identified by a index that specifies the layer and the position in the layer of it.
Parameters: idx ((int, int)) – index Returns: Neuron – Neuron fuond at the index given Return type: eml.net.describe.DNRNeuron
-
neurons()[source]¶ Get all the neurons in this layer
Yields: Neuron ( eml.net.describe.DNRNeuron) – Next neuron in the layer
-
reset_bounds()[source]¶ Reset lower and upper bounds of the current layer
Raises: NotImplementedError– If not implemented in the instanca
-
size()[source]¶ Get size layer
Returns: Size of the layer – Number of neuron in the layer Return type: int
-
ub()[source]¶ Get the upper bound of the current layer
Returns: List of upper bounds – List of the upper bound of the current layer Return type: list(float)
-
-
class
eml.net.describe.DNRNet[source]¶ Bases:
objectClass used to shape the neural network
-
layers_¶ List of layers composing the network
Type: list( eml.net.describe.DNRLayers)
-
add(layer)[source]¶ Add layer to the network
Parameters: layer ( eml.net.describe.DNRLayers) – Layer to addReturns: Return type: None
-
evaluate(data)[source]¶ Evalueates the output of the neural netwokr
Parameters: data (list(float)) – Input for the network Returns: Network output – output of the network given the input Return type: float
-
layer(idx)[source]¶ Get layer with specific index
Parameters: idx (int) – Layer index Returns: Layer – Layer located at the given coordinates Return type: eml.net.describe.DNRLayer
-
layers()[source]¶ Get layers in the network
Yields: Layer ( eml.net.describe.DNRLayers) – Next layer in the network
-
neuron(*idx)[source]¶ Get neuron in a specific location in the network
Parameters: idx ((int, int)) – Index of the neuron, (layer, neuron) Returns: Neuron – Neuron located at the given coordinates Return type: eml.net.describe.DNRNeuron
-
neurons()[source]¶ Get all neurons in the network
Yields: Neuron ( eml.net.describe.DNRNeuron) – Next neuron in the network
-
-
class
eml.net.describe.DNRNeuron(layer, idx)[source]¶ Bases:
objectClass used to shape neural network’s neurons
Layers are build using neurons. Eache neuron has a lower and upper bound. Bound represent the range of value the neuron can have.
-
layer_¶ Layer where the neuron is located
Type: eml.net.describe.DNRLayer
Parameters: - layer (
eml.net.describe.DNRLayer) – Layer where the neuron is located - idx (int) – Identifier of the neuron
-
connected()[source]¶ Get the neurons connected to the current one
Returns: List of nuerons Return type: list( eml.net.describe.DNRNeuron)
-
idx()[source]¶ Get idenfier of the neuron
Returns: Index – Coordinates of layer and neuron in the netwokr Return type: (int, int)
-
layer()[source]¶ Get the layer where the neuron is located
Returns: Layer – Layer where the neuron is located Return type: eml.net.describe.DNRLayer
-
lb()[source]¶ Get the lower bound of the current neuron
Returns: Lower bound – Lower bound of the current neuron Return type: float
-
network()[source]¶ Get the name of the network where the neuron is
Returns: Name – Name of the network Return type: string
-
ub()[source]¶ Get the upper bound of the current neuron
Returns: Upper bound – Upper bound of the current neuron Return type: float
-
-
eml.net.describe.act_eval(activation, value)[source]¶ Evaluates the activation function
Parameters: - activation (
keras.activations) – Activation function, either relu or linear - value (float) – Input of the activation function
Returns: Activation Function Result – Value computed by the activation function
Return type: Raises: ValueError– If activation function is invalid (it is not relu or linear)- activation (
eml.net.embed module¶
-
eml.net.embed.encode(bkd, net, mdl, net_in, net_out, name, verbose=0)[source]¶ Encodes the network in the optimization model.
Codifies each neuron as a variable in the combinatorial problem, while each edge is considered as a constraint on the the neurons connected.
Parameters: - bkd (
eml.backend.cplex_backend.CplexBackend) – Backend Cplex - net (
eml.net.describe.DNRNet) – Network to embed - mdl (
docplex.mp.model.Model) – Model CPLEX - net_in (list(
docplex.mp.linear.Var)) – Input continuous varibles - net_out (
docplex.mp.linear.Var) – Output continuous varibles - name (string) – Name of the network
- verbose (int) – If higher than 0 notifies every neuron embeded
Returns: Descriptor – Descriptor of the neural network
Return type: - bkd (
eml.net.process module¶
-
eml.net.process.fwd_bound_tighthening(bkd, net=None, desc=None, timelimit=None, skip_layers=None, verbose=0)[source]¶ Forward bound tightening via Mixed Integer Linear Programming
Parameters: - bkd (
eml.backend.cplex_backend.CplexBackend) – Cplex backend - net (obj:eml.net.describe.DNRNet) – Neural network of interest (default None)
- desc (
eml.util.ModelDesc) – Model descriptor (default None) - timelimit (int) – Time limit for the process (default None)
- skip_layer (int) – Skips bound tightening for the specified layer (default None)
- verbose (int) – if higher than 0 prints more info on the process (default 0)
Returns: Total time – Time used to perform bound tightening by the optimizer
Return type: Raises: ValueError– Neither a model descriptor or a network where given in input- bkd (
-
eml.net.process.ibr_bounds(net)[source]¶ Internal Based Reasoning Bounding
The bounds of the units in the neural network are updated based on the values evaluated using the activation function
- net :
eml.net.describe.DNRNet - Neural network of interest
Returns: Return type: None - net :