Skip to main content

A package for characteristic functions inversion.

Project description

Characteristic functions inversion package

Tests GitHub License

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.cf_inverter.bohman.bohman_inverters 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()

example

Requirements

  • python 3.10+
  • numpy 2.2.0+
  • scipy 1.15.0+
  • matplotlib 3.9.3+

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

cfinversion-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

cfinversion-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file cfinversion-0.1.0.tar.gz.

File metadata

  • Download URL: cfinversion-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.11 Darwin/23.6.0

File hashes

Hashes for cfinversion-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a67e2ffb6a1bb1fa37da725a5b5f385e2eea24c08c7d434004fa75c9cb81853d
MD5 a8d49efe07c06f3365d52eff6d675e79
BLAKE2b-256 63e9c1bbea0a43584c8f68f22a3e2729b5303661a3dd3655c9ddb86be6a52ba1

See more details on using hashes here.

File details

Details for the file cfinversion-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cfinversion-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.11 Darwin/23.6.0

File hashes

Hashes for cfinversion-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea8f7d06bb44b13e762df8a277ea6d6191f53d0c59b930897d67011aa0748b9
MD5 335279d791de0832a684c83c7ca858e3
BLAKE2b-256 5ba494d4e3050117f9d0b72d090e312f1ba856fb8faf58c1c989a96cf1e774c7

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