:py:mod:`mlair.model_modules.probability_models` ================================================ .. py:module:: mlair.model_modules.probability_models .. autoapi-nested-parse:: >>> MyCustomisedModel().model.compile(**kwargs) == MyCustomisedModel().compile(**kwargs) True Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: mlair.model_modules.probability_models.MyUnetProb mlair.model_modules.probability_models.MyCNNProb mlair.model_modules.probability_models.VarDense mlair.model_modules.probability_models.ProbTestModel mlair.model_modules.probability_models.ProbTestModel2 mlair.model_modules.probability_models.ProbTestModel3 mlair.model_modules.probability_models.ProbTestModel4 mlair.model_modules.probability_models.ProbTestModelMixture mlair.model_modules.probability_models.DenseVariationalCustom mlair.model_modules.probability_models.Convolution2DReparameterizationCustom Functions ~~~~~~~~~ .. autoapisummary:: mlair.model_modules.probability_models.prior_trainable mlair.model_modules.probability_models.nll mlair.model_modules.probability_models.posterior mlair.model_modules.probability_models.prior Attributes ~~~~~~~~~~ .. autoapisummary:: mlair.model_modules.probability_models.__author__ mlair.model_modules.probability_models.__date__ mlair.model_modules.probability_models.tfd mlair.model_modules.probability_models.tfb mlair.model_modules.probability_models.tfpl mlair.model_modules.probability_models.mylayer .. py:data:: __author__ :annotation: = Felix Kleinert .. py:data:: __date__ :annotation: = 2022-07-08 .. py:data:: tfd .. py:data:: tfb .. py:data:: tfpl .. py:class:: MyUnetProb(input_shape: list, output_shape: list, num_of_training_samples: int) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:method:: prior(kernel_size, bias_size, dtype=None) :staticmethod: .. py:method:: posterior(kernel_size, bias_size, dtype=None) :staticmethod: .. py:class:: MyCNNProb(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` Taken fromhttps://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6 and modified to our data .. py:method:: loss_fn(y_true, y_pred) :staticmethod: .. py:method:: custom_normal_prior(dtype, shape, name, trainable, add_variable_fn) :staticmethod: .. py:method:: laplace_prior(dtype, shape, name, trainable, add_variable_fn) :staticmethod: .. py:method:: approximate_kl(q, p, q_tensor) :staticmethod: .. py:method:: conv_reparameterization_layer(self, filters, kernel_size, activation) .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:class:: VarDense(units, make_posterior_fn, make_prior_fn, kl_weight=None, kl_use_exact=False, activation=None, use_bias=True, activity_regularizer=None, **kwargs) Bases: :py:obj:`tensorflow.keras.layers.Layer` .. py:method:: call(self, inputs) .. py:method:: get_config(self) .. py:function:: prior_trainable(kernel_size, bias_size=0, dtype=None) .. py:class:: ProbTestModel(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:class:: ProbTestModel2(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:class:: ProbTestModel3(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:class:: ProbTestModel4(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:class:: ProbTestModelMixture(input_shape: list, output_shape: list) Bases: :py:obj:`mlair.model_modules.AbstractModelClass` The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow. The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: set_compile_options(self) This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {'optimizer': None, 'loss': None, 'metrics': None, 'loss_weights': None, 'sample_weight_mode': None, 'weighted_metrics': None, 'target_tensors': None } :return: .. py:function:: nll(y_true, y_pred) This function should return the negative log-likelihood of each sample in y_true given the predicted distribution y_pred. If y_true is of shape [B, E] and y_pred has batch shape [B] and event_shape [E], the output should be a Tensor of shape [B]. .. py:function:: posterior(kernel_size, bias_size, dtype=None) .. py:function:: prior(kernel_size, bias_size, dtype=None) .. py:class:: DenseVariationalCustom Bases: :py:obj:`tfpl` Trying to implement a DensVar that can be stored: https://github.com/tensorflow/probability/commit/0ca065fb526b50ce38b68f7d5b803f02c78c8f16# .. py:method:: get_config(self) .. py:class:: Convolution2DReparameterizationCustom Bases: :py:obj:`tfpl` .. py:method:: get_config(self) .. py:data:: mylayer