probabilistic_model.learning.nyga_distribution
==============================================

.. py:module:: probabilistic_model.learning.nyga_distribution


Classes
-------

.. autoapisummary::

   probabilistic_model.learning.nyga_distribution.InductionStep
   probabilistic_model.learning.nyga_distribution.NygaDistribution


Module Contents
---------------

.. py:class:: InductionStep

   Class for performing induction in the NygaDistributions.


   .. py:attribute:: data
      :type:  numpy.array

      The entire sorted and unique data points



   .. py:attribute:: cumulative_weights
      :type:  numpy.array

      The cumulative log_weights of the samples in the dataset.



   .. py:attribute:: cumulative_log_weights
      :type:  numpy.array

      The cumulative logarithmic log_weights of the samples in the dataset.



   .. py:attribute:: begin_index
      :type:  int

      Included index of the first sample.



   .. py:attribute:: end_index
      :type:  int

      Excluded index of the last sample.



   .. py:attribute:: nyga_distribution
      :type:  NygaDistribution

      The Nyga Distribution to mount the quantile distributions into and read the parameters from.



   .. py:property:: variable

      The variable of the distribution.



   .. py:property:: min_samples_per_quantile

      The minimal number of samples per quantile.



   .. py:property:: min_likelihood_improvement

      The relative, minimal likelihood improvement needed to create a new quantile.



   .. py:method:: left_connecting_point() -> float

      Calculate the left connecting point.



   .. py:property:: number_of_samples

      The number of samples in the induction step.



   .. py:property:: total_weights

      The total sum of log_weights of the samples in the induction step.



   .. py:property:: total_log_weights

      The total sum of logarithmic log_weights of the samples in the induction step.



   .. py:method:: left_connecting_point_from_index(index) -> float

      Calculate the left connecting point given some beginning index.

      :param index: The index of the left datapoint.



   .. py:method:: right_connecting_point() -> float

      Calculate the right connecting point.



   .. py:method:: right_connecting_point_from_index(index) -> float

      Calculate the right connecting point given some ending index.

      :param index: The index of the right datapoint.



   .. py:method:: create_uniform_distribution() -> probabilistic_model.distributions.UniformDistribution

      Create a uniform distribution from this induction step.



   .. py:method:: create_uniform_distribution_from_indices(begin_index: int, end_index: int) -> probabilistic_model.distributions.UniformDistribution

      Create a uniform distribution from the datapoint at `begin_index` to the datapoint at `end_index`.

      :param begin_index: The index of the first datapoint.
      :param end_index: The index of the last datapoint.



   .. py:method:: sum_weights_from_indices(begin_index: int, end_index: int) -> float

      Sum the log_weights from `begin_index` to `end_index`.



   .. py:method:: sum_weights()

      Sum the log_weights of this induction step.



   .. py:method:: sum_log_weights_from_indices(begin_index: int, end_index: int) -> float

      Sum the logarithmic log_weights from `begin_index` to `end_index`.



   .. py:method:: sum_log_weights()

      Sum the logarithmic log_weights of this induction step.



   .. py:method:: compute_best_split() -> Tuple[float, Optional[int]]

      Compute the best split of the data.

      The best split of the data is computed by evaluating the log likelihood of every possible split and memorizing
      the best one.

      :return: The maximum log likelihood and the best split index.



   .. py:method:: log_likelihood_without_split() -> float

      Calculate the log likelihood without splitting.

      :return: The log likelihood without splitting.



   .. py:method:: log_likelihood_of_split_side(split_index: int, connecting_point: float) -> float

      Calculate the log likelihood of a split side.

      This method automatically determines if this is the left or right side of the split.

      :param split_index: The index of the split.
      :param connecting_point: The connecting point.

      :return: The log likelihood of the split.



   .. py:method:: construct_left_induction_step(split_index: int) -> typing_extensions.Self

      Construct the left induction step.

      :param split_index: The index of the split.



   .. py:method:: construct_right_induction_step(split_index: int) -> typing_extensions.Self

      Construct the right induction step.

      :param split_index: The index of the split.



   .. py:method:: improvement_is_good_enough(maximum_log_likelihood: float) -> bool

      Check if the improvement is good enough.
      :param maximum_log_likelihood: The improved maximum log likelihood.
      :return: Rather the improvement is good enough



   .. py:method:: induce() -> List[typing_extensions.Self]

      Perform one induction step.

      :return: The (possibly empty) list of new induction steps.



.. py:class:: NygaDistribution

   Bases: :py:obj:`random_events.utils.SubclassJSONSerializer`


   A Nyga distribution is a way to learn a deterministic mixture of uniform distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:attribute:: min_likelihood_improvement
      :type:  float
      :value: 0.01


      The relative, minimal likelihood improvement needed to create a new quantile.



   .. py:attribute:: min_samples_per_quantile
      :type:  int
      :value: 2


      The minimal number of samples per quantile.



   .. py:attribute:: probabilistic_circuit
      :type:  probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit


   .. py:method:: fit(data: numpy.array, weights: Optional[numpy.array] = None) -> probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit

      Fit the distribution to the data.

      :param data: The data to fit the distribution to.
      :param weights: The optional log_weights of the data points.

      :return: The fitted distribution.



   .. py:method:: to_json() -> Dict[str, Any]


   .. py:method:: _from_json(json_data: Dict[str, Any]) -> typing_extensions.Self
      :classmethod:


      Create a variable from a json dict.
      This method is called from the from_json method after the correct subclass is determined and should be
      overwritten by the respective subclass.

      :param data: The json dict
      :return: The deserialized object



   .. py:method:: empty_copy() -> typing_extensions.Self


   .. py:method:: from_uniform_mixture(mixture: probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit) -> probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit
      :staticmethod:


      Construct a Nyga Distribution from a mixture of uniform distributions.
      The mixture does not have to be deterministic.

      :param mixture: An arbitrary, univariate mixture of uniform distributions
      :return: A Nyga Distribution describing the same function.



   .. py:method:: all_union_of_mixture_points_with(other: typing_extensions.Self)

      Computes all possible union intervals of mixture points when combining two intervals.

      Returns: list of closed intervals representing all mixture points between distributions



   .. py:method:: event_of_higher_density(other: typing_extensions.Self, own_node_weights, other_node_weights) -> random_events.product_algebra.Event


