Fumagalli_Motta_Tarantino_2020.Models.Distributions

 1import scipy.stats
 2
 3
 4class NormalDistribution:
 5    """
 6    Represents a normal distribution function.
 7
 8    Parameters for the distribution:
 9    - loc: mean of the normal  distribution
10    - scale: standard deviation of the normal distribution
11    """
12
13    @staticmethod
14    def cumulative(x: float, **kwargs) -> float:
15        """
16        Returns the value of the cumulative distribution function.
17
18        Parameters
19        ----------
20        x: float
21            Value to get the corresponding value of the cumulative distribution function.
22        kwargs
23            Parameters for the distribution (-> see class documentation)
24
25        Returns
26        -------
27        float
28            Value of the cumulative distribution function.
29        """
30        return scipy.stats.norm.cdf(x, **kwargs)
31
32    @staticmethod
33    def inverse_cumulative(q: float, **kwargs) -> float:
34        """
35        Returns the value of the inverse cumulative distribution function (percent point function).
36
37        Parameters
38        ----------
39        q: float
40            Value to get the corresponding value of the inverse cumulative distribution function.
41        kwargs
42            Parameters for the distribution (-> see class documentation)
43
44        Returns
45        -------
46        float
47            Value of the inverse cumulative distribution function.
48        """
49        return scipy.stats.norm.ppf(q, **kwargs)
50
51
52class UniformDistribution(NormalDistribution):
53    """
54    Represents a uniform distribution function ($U_{[loc, loc+scale]}$).
55
56    Parameters for the distribution:
57    - loc: start of distribution
58    - scale: difference added to the start of the beginning of the distribution (-> defines the end of the distribution)
59    """
60
61    @staticmethod
62    def cumulative(x: float, **kwargs) -> float:
63        return scipy.stats.uniform.cdf(x, **kwargs)
64
65    @staticmethod
66    def inverse_cumulative(q: float, **kwargs) -> float:
67        return scipy.stats.uniform.ppf(q, **kwargs)
class NormalDistribution:
 5class NormalDistribution:
 6    """
 7    Represents a normal distribution function.
 8
 9    Parameters for the distribution:
10    - loc: mean of the normal  distribution
11    - scale: standard deviation of the normal distribution
12    """
13
14    @staticmethod
15    def cumulative(x: float, **kwargs) -> float:
16        """
17        Returns the value of the cumulative distribution function.
18
19        Parameters
20        ----------
21        x: float
22            Value to get the corresponding value of the cumulative distribution function.
23        kwargs
24            Parameters for the distribution (-> see class documentation)
25
26        Returns
27        -------
28        float
29            Value of the cumulative distribution function.
30        """
31        return scipy.stats.norm.cdf(x, **kwargs)
32
33    @staticmethod
34    def inverse_cumulative(q: float, **kwargs) -> float:
35        """
36        Returns the value of the inverse cumulative distribution function (percent point function).
37
38        Parameters
39        ----------
40        q: float
41            Value to get the corresponding value of the inverse cumulative distribution function.
42        kwargs
43            Parameters for the distribution (-> see class documentation)
44
45        Returns
46        -------
47        float
48            Value of the inverse cumulative distribution function.
49        """
50        return scipy.stats.norm.ppf(q, **kwargs)

Represents a normal distribution function.

Parameters for the distribution:

  • loc: mean of the normal distribution
  • scale: standard deviation of the normal distribution
@staticmethod
def cumulative(x: float, **kwargs) -> float:
14    @staticmethod
15    def cumulative(x: float, **kwargs) -> float:
16        """
17        Returns the value of the cumulative distribution function.
18
19        Parameters
20        ----------
21        x: float
22            Value to get the corresponding value of the cumulative distribution function.
23        kwargs
24            Parameters for the distribution (-> see class documentation)
25
26        Returns
27        -------
28        float
29            Value of the cumulative distribution function.
30        """
31        return scipy.stats.norm.cdf(x, **kwargs)

Returns the value of the cumulative distribution function.

Parameters
  • x (float): Value to get the corresponding value of the cumulative distribution function.
  • kwargs: Parameters for the distribution (-> see class documentation)
Returns
  • float: Value of the cumulative distribution function.
@staticmethod
def inverse_cumulative(q: float, **kwargs) -> float:
33    @staticmethod
34    def inverse_cumulative(q: float, **kwargs) -> float:
35        """
36        Returns the value of the inverse cumulative distribution function (percent point function).
37
38        Parameters
39        ----------
40        q: float
41            Value to get the corresponding value of the inverse cumulative distribution function.
42        kwargs
43            Parameters for the distribution (-> see class documentation)
44
45        Returns
46        -------
47        float
48            Value of the inverse cumulative distribution function.
49        """
50        return scipy.stats.norm.ppf(q, **kwargs)

Returns the value of the inverse cumulative distribution function (percent point function).

Parameters
  • q (float): Value to get the corresponding value of the inverse cumulative distribution function.
  • kwargs: Parameters for the distribution (-> see class documentation)
Returns
  • float: Value of the inverse cumulative distribution function.
class UniformDistribution(NormalDistribution):
53class UniformDistribution(NormalDistribution):
54    """
55    Represents a uniform distribution function ($U_{[loc, loc+scale]}$).
56
57    Parameters for the distribution:
58    - loc: start of distribution
59    - scale: difference added to the start of the beginning of the distribution (-> defines the end of the distribution)
60    """
61
62    @staticmethod
63    def cumulative(x: float, **kwargs) -> float:
64        return scipy.stats.uniform.cdf(x, **kwargs)
65
66    @staticmethod
67    def inverse_cumulative(q: float, **kwargs) -> float:
68        return scipy.stats.uniform.ppf(q, **kwargs)

Represents a uniform distribution function ($U_{[loc, loc+scale]}$).

Parameters for the distribution:

  • loc: start of distribution
  • scale: difference added to the start of the beginning of the distribution (-> defines the end of the distribution)
@staticmethod
def cumulative(x: float, **kwargs) -> float:
62    @staticmethod
63    def cumulative(x: float, **kwargs) -> float:
64        return scipy.stats.uniform.cdf(x, **kwargs)

Returns the value of the cumulative distribution function.

Parameters
  • x (float): Value to get the corresponding value of the cumulative distribution function.
  • kwargs: Parameters for the distribution (-> see class documentation)
Returns
  • float: Value of the cumulative distribution function.
@staticmethod
def inverse_cumulative(q: float, **kwargs) -> float:
66    @staticmethod
67    def inverse_cumulative(q: float, **kwargs) -> float:
68        return scipy.stats.uniform.ppf(q, **kwargs)

Returns the value of the inverse cumulative distribution function (percent point function).

Parameters
  • q (float): Value to get the corresponding value of the inverse cumulative distribution function.
  • kwargs: Parameters for the distribution (-> see class documentation)
Returns
  • float: Value of the inverse cumulative distribution function.