autopycoin.layers.QuantileLayer#

class autopycoin.layers.QuantileLayer(*args, **kwargs)[source]#

Integrates a quantiles attribute to the layer.

This layer aims to be inherited. During compilation if the model is a autopycoin.models.QuantileModel it can propagate to this layer a quantiles attribute which can be added to its internal weights shape during building phase with the get_additional_shapes method.

Usually, you will use this layer inside a autopycoin.models.QuantileModel hence the transpose operation needed to fit the keras norm (see post_processing method) is not usefull here. Hence we created an apply_quantiles_transpose attribute accessible in constructor which decides if the layer has to transpose the outputs tensors and to convert them into autopycoin.extension_type.QuantileTensor. by default, it is set to False but if you decides to use this layer inside tf.keras.Model set it to True.

Notes

def build(self, inputs_shape):
    self.get_additional_shapes(0) + output_shape # get the quantile shape and add it where you need it
Attributes
has_quantilesbool

Return True if quantiles exists else False.

quantileslist[List[float]] or None

Return quantiles attribute.

n_quantileslist[int] or int

Return the number of quantiles.

get_additional_shapes(index: int) Union[List[int], List[None]][source]#

Return the shape to add to your layers.

How works this method: If you defined two autopycoin.losses.QuantileLossError in your model with two differents quantiles attribute for your two outputs tensors then index=0 will access the shape associated to the first quantiles attribute. Else it gives an empty list.

property has_quantiles: bool#

Return True if quantiles exists else False.

property n_quantiles: List[List[int]]#

Return the number of quantiles.

post_processing(outputs: Union[List[Union[tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor]], tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor], **kwargs: dict) Union[List[Union[tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor]], tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor][source]#

Convert the outputs to QuantileTensor and apply transpose operation.

The quantiles dimension is put to the last dimension to fit with keras norms. There is a difference with its equivalent Model implementation, we can’t check with losses if they have a quantile attribute hence apply_quantiles_transpose is set to False by default and if you need to implement a layer with transpose operation you have to set it to True.

The only check used is to ensure that quantile dimension is present in the outputs tensors.

preprocessing(inputs: Union[List[Union[tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor]], tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor]) Union[List[Union[tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor]], tensorflow.python.framework.ops.Tensor, autopycoin.extension_type.QuantileTensor, autopycoin.extension_type.UnivariateTensor][source]#

No preprocessing for QuantileModel

property quantiles: List[List[float]]#

Return quantiles attribute.