Skip to main content

Python implementation of Arithmetic, quasi arithmetic and other aggregating functions

Project description

Means, Aggregation functions…

Aggregations functions are: - Conjuctive - the final aggregated value will always be influenced by the smallest value among the inputs. - Disjnuctive - the aggregated value will always be influenced by the largest value among the inputs.

Example 1:

# example data
data = [0.2, 0.6, 0.7]
# configure function parameters
func1 = A_amn(p=0.5)
# use aggregation funciton
print(func1(data))

# Combine two aggregations - arithmetic mean and minimum
func2 = Combine2Aggregations(A_ar(), min)
# use combination of aggregation funciton
print(func2(data))

Example2:

To get information about aggregation function you can use __str__() or ‘repr()’ methods.

func1 = A_amn(p=0.5)
print(func1)
>>>A_amn(0.5)

func2 = Combine2Aggregations(A_ar(), A_md())
print(func2)
>>>A_armd

func3 = Combine2Aggregations(A_ar(), A_pw(r=3))
print(func3.__repr__()) # function parameters are printed in order: func1, func2
>>>A_arpw(r=3)

Aggregation functions

Aggregation function [1] is a mapping \(A:[0,1]^n\to[0,1]\), \(n \in \mathbb{N}\), \(n\ge 2\) which is is increasing and fulfills two boundary conditions, namely \(A(0,\dots,0) = 0\), \(A(1,\dots,1) = 1\).

The floowoing aggregation functions are implemented in this library:

\(\mathbf{A_{ar}}\) - Arithmetic mean

\begin{equation*} A_{ar}(x_1,...,x_n)=\frac{1}{n}\sum \limits_{k=1}^{n} x_k \end{equation*}

\(\mathbf{A_{qd}}\) - Quadratic mean

\begin{equation*} A_{qd}(x_1,...,x_n)=\sqrt{\frac{1}{n}\sum \limits_{k=1}^{n} x_k^2} \end{equation*}

\(\mathbf{A_{pr}}\) - Product aggregation

\begin{equation*} A_{pr}(x_1, x_2, \dots, x_n) = \prod_{k=1}^n x_k \end{equation*}

\(\mathbf{A_{gm}}\) - Geometric mean

\begin{equation*} A_{gm}(x_1,...,x_n)=\sqrt[n]{\prod \limits_{k=1}^{n} x_k} \end{equation*}

\(\mathbf{A_{hm}}\) - Harmonic mean

\begin{equation*} A_{hm}(x_1,...,x_n) = \begin{cases} 0, & \text{if } \exists k,\, 1 \leq k \leq n : x_k = 0 \\ \frac{n}{\sum\limits_{k=1}^{n} \frac{1}{x_k}}, & \text{otherwise} \end{cases} \end{equation*}

\(\mathbf{A_{pw}^{(r)}}\) - Power mean

\begin{equation*} A_{pw}^{(r)}(x_1,...,x_n) = \begin{cases} 0, & r < 0, \; \exists k,\, 1 \leq k \leq n : x_k = 0 \\ \Big(\frac{1}{n} \sum\limits_{k=1}^{n} x_k^r \Big)^{\frac{1}{r}}, & \text{otherwise} \end{cases} \end{equation*}

special cases of power means \(A_{\text{pw}}^r\) [1] are: - Arithmetic Mean where r=1; - Quadratic Mean where r=2; - Harmonic Mean where r=-1; - Geometric Mean obtained as the limit \(\lim_{r \to 0} A_{\text{pw}}^r\).


\(\mathbf{A_{ex}^{(r)}}\) - Exponential mean

\begin{equation*} A_{ex}^{(r)}(x_1,...,x_n)= \frac{1}{r}\ln \Big(\frac{1}{n} \sum \limits_{k=1}^{n} e^{rx_k}\Big), \text{where } r \in \mathbb{R}, r \neq 0 \end{equation*}

For computer implementations, to avoid numerical instability (overflow when \(r x_k > 709.78\) or underflow when all \(r x_k < -709.78\)), we use a numerically stable Log-Sum-Exp formulation by shifting the exponents by \(a_{max} = \max_{j} (r x_j)\):

\begin{equation*} A_{ex}^{(r)}(x_1,...,x_n) = \frac{1}{r} \left[ a_{max} + \ln \left( \sum_{i=1}^n e^{r x_i - a_{max}} \right) - \ln(n) \right] \end{equation*}

\(\mathbf{A_{lm}}\) - Lehmer mean

\begin{equation*} A_{lm}(x_1,...,x_n)= \begin{cases} 0, & r\leq 1, \exists_{1 \leq k \leq n} x^{k} = 0 \\ \frac{\sum \limits_{k=1}^{n}x_k^r}{\sum \limits_{k=1}^{n}x_k^{r-1}}, & \text{otherwise} \end{cases} \end{equation*}

\(\mathbf{A_{amn}^{(p)}}\) - Arithmetic minimum mean

\begin{equation*} A_{amn}^{(p)}(x_1,...,x_n)=\frac{p}{n}\sum \limits_{k=1}^{n} x_k+ (1-p) \min \limits_{1 \leq k \leq n}x_k, p \in [0, 1] \end{equation*}

\(\mathbf{A_{amx}^{(p)}}\) - Arithmetic maximum mean

\begin{equation*} A_{amx}^{(p)}(x_1,...,x_n)=\frac{p}{n}\sum \limits_{k=1}^{n} x_k+ (1-p) \max \limits_{1\leq k \leq n}x_k, p \in [0, 1] \end{equation*}

OWA

In the case of n = 2 (when only two values are aggregated) the calculation of the median and the Olympic aggregation are reduced to the case of calculating the arithmetic mean of the given values.

\(\mathbf{A_{md}}\) - Median - ordered weighted aggregation

\begin{equation*} A_{md}(x_1,\dots,x_n) = \begin{cases} y_{(n+1)/2},&\text{if $n$ is odd}\\ \frac{y_{n/2}+y_{(n/2)+1}}{2},&\text{if $n$ is even} \end{cases}, \end{equation*}

\(\mathbf{A_{ol}}\) - Olimpic aggregation

\begin{equation*} A_{ol}(x_1,\dots,x_n) = \frac{1}{n-2} \sum \limits_{k=2}^{n-1} y_k, \quad \text{where } \{y_1, \dots, y_n\} = \{x_1, \dots, x_n\},\ y_1 \leq y_2 \leq \dots \leq y_n. \end{equation*}

\(\mathbf{A_{oln}^{(p)}}\) - Olimpic aggregation

We can specify how many greatest and smallest records remove

\begin{equation*} A_{oln}^{(p)}(x_1,\dots,x_n) = \frac{1}{n-2p} \sum \limits_{k=p+1}^{n-p} y_k, \quad \text{where } \{y_1, \dots, y_n\} = \{x_1, \dots, x_n\},\ y_1 \leq y_2 \leq \dots \leq y_n, p \in \mathbb{N}, p\geq 1 \end{equation*}

\(\mathbf{A_{ln}}\) - Logaritmic aggregation [2]

\begin{align*} A_{ln}\left(x_1, x_2, \ldots, x_n\right)=(n-1) ! \sum_{i=1}^n \frac{x_i}{\prod_{\substack{j=1 \\ j \neq i}}^n \log \left(x_i / x_j\right)} \end{align*}

\(\mathbf{A^{(p)}_{A_1,A_2}}\) - Convex combinations of aggregation functions

We can construct covex combination of aggregation functions as \(A^{(p)}_{A_1,A_2}=pA_1+(1-p)A_2\), where \(A_1, A_2\) are aggregation functions and \(p \in [0,1]\).

References

  1. Beliakov, G., Bustince, H., and Calvo, T.: A practical Guide to Averaging Functions. Berlin: Springer Vol. 329, 2016.

  2. Mustonen, Seppo. (2010). Logarithmic mean for several arguments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aggregationslib-0.1.6.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aggregationslib-0.1.6-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file aggregationslib-0.1.6.tar.gz.

File metadata

  • Download URL: aggregationslib-0.1.6.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for aggregationslib-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e889cb522e8792b7c9cad7176ae86ab9d988967aa4b5491839c41e82ade66362
MD5 91183eb9fed22b306306377a6f81ab11
BLAKE2b-256 f1f5e6e60b27fc469ef75981dec2c5a7268a7bfe915128b6ea20897e12aeddda

See more details on using hashes here.

File details

Details for the file aggregationslib-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for aggregationslib-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 94af65142882ec65ecfca4f7258134eedd358946273be58bff5a2a0f2dd74031
MD5 ab6eb491fedd6819c8ee733f73980085
BLAKE2b-256 b5efb69f64646b5ad87429750c9b27d1e3ff325a1db0e946f6a3c833ac12febe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page