pyraliddemo.example.math

MATH MODULE.

This module provides examples of how write mathematical functions according to the standards proposed by this template.

Warning

The RST304 error is supressed througout the package to allow sphinxcontrib-bibtex citations.

add_two_ints(first_value: int, second_value: int)int[source]

Add Two Integers.

A simple example function demonstatring the addition of two integer values and the return of the sum.

Parameters
  • first_value (int) – First integer value

  • second_value (int) – Second integer value

Returns

Result of addition

Return type

int

Raises

TypeError – For invalid input types.

Examples

python
>>> from pyraliddemo.example.math import add_two_ints
>>> add_two_ints(1, 2)
3

Notes

This function implements the following equation

\[z = x + y\]

where \(x\in\mathbb{Z}\) is the first input integer, \(y\in\mathbb{Z}\) is the second input integer and \(z\in\mathbb{Z}\) is the resulting sum.

drake_equation(drake_parameters: list)int[source]

Drake’s Equation.

A very basic implementation of Drake’s equation as an example of how to cite known equations.

Parameters

drake_parameters (list) – List of parameters of the Drake equation (see Notes).

Returns

The number of civilizations in our galaxy with which communication might be possible (i.e. which are on our current past light cone).

Return type

int

Examples

python
>>> from pyraliddemo.example.math import drake_equation
>>> drake_equation([1, 0.2, 1, 1, 1, 0.1, 1000])
20

Notes

This function implements the following equation from [Drake65]

\[N = R_* \cdot f_p \cdot n_e \cdot f_l \cdot f_i \cdot f_c \cdot L\]

where:

  • \(R_*\) is the average rate of star formation in our galaxy,

  • \(f_p\) is the fraction of those stars that have planets,

  • \(n_e\) is the average number of planets that can potentially support life per star that has planets,

  • \(f_l\) is the fraction of planets that could support life that actually develop life at some point,

  • \(f_i\) is the fraction of planets with life that actually go on to develop intelligent life (civilizations),

  • \(f_c\) is the fraction of civilizations that develop a technology that releases detectable signs of their existence into space,

  • and \(L\) is the length of time for which such civilizations release detectable signals into space.

mad(input_data: numpy.ndarray)float[source]

Median Absolute Deviation.

This method calculates the median absolute deviation (MAD) of some input data.

Note

Implementation taken from ModOpt

Parameters

input_data (numpy.ndarray) – Input data array

Returns

MAD value

Return type

float

Examples

python
>>> import numpy as np
>>> from pyraliddemo.example.math import mad
>>> data = np.arange(9).reshape(3, 3)
>>> mad(data)
2.0

Notes

The MAD is calculated as follows:

\[\mathrm{MAD} = \mathrm{median}\left(|X_i - \mathrm{median}(X)|\right)\]

where \(X\) is the input data array and \(X_i\) is a given element.

add_two_floats(first_value: float, second_value: float)float[source]

Add Two Floats.

Add two float values.

Parameters
  • first_value (float) – First float value

  • second_value (float) – Second float value

Returns

Result of addition

Return type

float

Raises

TypeError – For invalid input types.