A package for characteristic functions inversion.
Project description
Characteristic functions inversion package
The characteristic function is the Fourier transform of a random variable distribution. One of the ways to define the distribution law is to define a characteristic function. In many probabilistic models, only the characteristic functions are available to us, and not the densities themselves, which complicates the modeling process and the evaluation of numerical characteristics. The reconstruction of the distribution function or density of a random variable by its characteristic function by analytical methods is often an extremely difficult task, therefore it is necessary to resort to the use of numerical methods.
Installation
Clone the repository:
git clone https://github.com/lilyreber/Numerical-inversion-of-characteristic-functions.git
Install dependencies:
poetry install
Usage example
import numpy as np
import matplotlib.pyplot as plt
import cfinversion.CharFuncInverter.Bohman.BohmansInverters as bi
from cfinversion.Distributions.uniform import Unif
from cfinversion.Standardizer import Standardizer
# Uniform distribution parameters
a = -100
b = 20
unif_distr = Unif(a, b)
# Create an array of points for plotting
t = np.linspace(-200, 200, 1000)
# Calculate the exact distribution function for uniform distribution
unif_cdf = unif_distr.cdf(t)
# Standardization of a random variable
m = (a + b) / 2 # Expectation
var = ((b - a) ** 2) / 12 # Variance
st = Standardizer(m=m, sd=(var**0.5))
# The characteristic function of a standardized random variable
z_chr = st.standardize_chf(unif_distr.chr)
# Initialization and configuration of the inverter (Bohmann method)
inverter = bi.BohmanE(N=1e3)
inverter.fit(z_chr)
# Approximate distribution function for a standardized random variable
approx_z_cdf = inverter.cdf
# Approximate distribution function for the initial random variable
approx_cdf = st.unstandardize_cdf(approx_z_cdf)
approx_cdf_values = approx_cdf(t)
# Plotting graphs
plt.figure(figsize=(10, 6))
plt.plot(t, unif_cdf, label="The exact distribution function", linewidth=2, color="blue")
plt.plot(t, approx_cdf_values, label="Approximate distribution function", linestyle="--", linewidth=2, color="red")
plt.title("Comparison of exact and approximate distribution functions", fontsize=16)
plt.xlabel("x", fontsize=14)
plt.ylabel("F(x)", fontsize=14)
plt.legend(fontsize=12)
plt.grid(True, linestyle="--", alpha=0.7)
plt.axvline(x=a, color="green", linestyle=":", label=f"a = {a}")
plt.axvline(x=b, color="purple", linestyle=":", label=f"b = {b}")
plt.legend(fontsize=12)
plt.tight_layout()
plt.show()
Requirements
- python 3.10+
- numpy 2.2.0+
- scipy 1.15.0+
- matplotlib 3.9.3+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfinversion-1.0.1.tar.gz.
File metadata
- Download URL: cfinversion-1.0.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b82597d4e229e2787910c6878d4d763ac414f1ba00cdc18b2925a0a6fc161a31
|
|
| MD5 |
e43e74ef6831d7305a398762ce372983
|
|
| BLAKE2b-256 |
aa5c9b11879d68b855dc7f31595f56ec1e9662316723cd71f0513a2b4cb894b9
|
File details
Details for the file cfinversion-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cfinversion-1.0.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52bec57a11d593c5d986ded54a59412972c1dfca2116976eb839e2fc317fa391
|
|
| MD5 |
f90dde253d2f67ca9725e5b2537e8252
|
|
| BLAKE2b-256 |
ed1fa834a37d0572a444c1ac1531fc2b028a4e29a761722818f2bed62a8513eb
|