decomon.metrics package

Submodules

decomon.metrics.complexity module

decomon.metrics.complexity.get_graph_complexity(model: Model) int[source]

decomon.metrics.loss module

class decomon.metrics.loss.DecomonLossFusion(*args, **kwargs)[source]

Bases: DecomonLayer

build(input_shape: list[tuple[int | None, ...]]) None[source]
Parameters:

input_shape

Returns:

call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

call_backward(inputs: list[Any], **kwargs: Any) Any[source]
call_no_backward(inputs: list[Any], **kwargs: Any) Any[source]
compute_output_shape(input_shape: list[tuple[int | None, ...]]) tuple[int | None, ...][source]

Compute expected output shape according to input shape

Will be called by symbolic calls on Keras Tensors.

  • We use the original (Keras) layer compute_output_shape() if available to update accordingly the input shapes.

  • Else we simply return the input shapes

Beware, compute_output_shape() is sometimes called by the original keras layer inside its call(), which can be called inside the decomon layer call(). Check this by looking at input_shape (list of shapes or simple shape?)

Parameters:

input_shape

Returns:

get_config() dict[str, Any][source]

Returns the config of the object.

An object config is a Python dictionary (serializable) containing the information needed to re-instantiate it.

original_keras_layer_class

alias of Layer

class decomon.metrics.loss.DecomonRadiusRobust(*args, **kwargs)[source]

Bases: DecomonLayer

build(input_shape: list[tuple[int | None, ...]]) None[source]
Parameters:

input_shape

Returns:

call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

call_backward(inputs: list[Any], **kwargs: Any) Any[source]
call_no_backward(inputs: list[Any], **kwargs: Any) Any[source]
compute_output_shape(input_shape: list[tuple[int | None, ...]]) tuple[int | None, ...][source]

Compute expected output shape according to input shape

Will be called by symbolic calls on Keras Tensors.

  • We use the original (Keras) layer compute_output_shape() if available to update accordingly the input shapes.

  • Else we simply return the input shapes

Beware, compute_output_shape() is sometimes called by the original keras layer inside its call(), which can be called inside the decomon layer call(). Check this by looking at input_shape (list of shapes or simple shape?)

Parameters:

input_shape

Returns:

get_config() dict[str, Any][source]

Returns the config of the object.

An object config is a Python dictionary (serializable) containing the information needed to re-instantiate it.

original_keras_layer_class

alias of Layer

decomon.metrics.loss.build_asymptotic_crossentropy_model(model: DecomonModel) DecomonModel[source]
decomon.metrics.loss.build_crossentropy_model(model: DecomonModel) DecomonModel[source]
decomon.metrics.loss.build_radius_robust_model(model: DecomonModel) DecomonModel[source]
decomon.metrics.loss.get_adv_loss(model: DecomonModel, sigmoid: bool = False, clip_value: float | None = None, softmax: bool = False) Callable[[KerasTensor | Any, KerasTensor | Any], KerasTensor | Any][source]
decomon.metrics.loss.get_lower_loss(model: DecomonModel) Callable[[KerasTensor | Any, KerasTensor | Any], KerasTensor | Any][source]
decomon.metrics.loss.get_model(model: DecomonModel) DecomonModel[source]
decomon.metrics.loss.get_upper_loss(model: DecomonModel) Callable[[KerasTensor | Any, KerasTensor | Any], KerasTensor | Any][source]

decomon.metrics.metric module

class decomon.metrics.metric.AdversarialCheck(*args, **kwargs)[source]

Bases: MetricLayer

Training with symbolic LiRPA bounds for promoting adversarial robustness

call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

adv_score <0 if the predictionis robust on the input convex domain

linear_adv(z_tensor: KerasTensor | Any, y_tensor: KerasTensor | Any, w_u: KerasTensor | Any, b_u: KerasTensor | Any, w_l: KerasTensor | Any, b_l: KerasTensor | Any) KerasTensor | Any[source]
class decomon.metrics.metric.AdversarialScore(*args, **kwargs)[source]

Bases: AdversarialCheck

Training with symbolic LiRPA bounds for promoting adversarial robustness

call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

adv_score <0 if the predictionis robust on the input convex domain

class decomon.metrics.metric.MetricLayer(*args, **kwargs)[source]

Bases: ABC, Layer

abstract call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

get_config() dict[str, Any][source]

Returns the config of the object.

An object config is a Python dictionary (serializable) containing the information needed to re-instantiate it.

class decomon.metrics.metric.MetricMode(value)[source]

Bases: str, Enum

An enumeration.

BACKWARD = 'backward'
FORWARD = 'forward'
class decomon.metrics.metric.UpperScore(*args, **kwargs)[source]

Bases: MetricLayer

Training with symbolic LiRPA bounds for limiting the local maximum of a neural network

call(inputs: list[Any], **kwargs: Any) Any[source]
Parameters:

inputs

Returns:

upper_score <=0 if the maximum of the neural network is lower than the target

linear_upper(z_tensor: KerasTensor | Any, y_tensor: KerasTensor | Any, w_u: KerasTensor | Any, b_u: KerasTensor | Any) KerasTensor | Any[source]
decomon.metrics.metric.build_formal_adv_check_model(decomon_model: DecomonModel) Model[source]

automatic design on a Keras model which predicts a certificate of adversarial robustness

Parameters:

decomon_model

Returns:

decomon.metrics.metric.build_formal_adv_model(decomon_model: DecomonModel) Model[source]

automatic design on a Keras model which predicts a certificate of adversarial robustness

Parameters:

decomon_model

Returns:

decomon.metrics.metric.build_formal_upper_model(decomon_model: DecomonModel) Model[source]

automatic design on a Keras model which predicts a certificate on the local upper bound

Parameters:

decomon_model

Returns:

decomon.metrics.utils module

decomon.metrics.utils.categorical_cross_entropy(inputs: list[KerasTensor | Any], dc_decomp: bool = False, mode: str | ForwardMode = ForwardMode.HYBRID, perturbation_domain: PerturbationDomain | None = None) list[KerasTensor | Any][source]

Module contents