{"id":34701373,"url":"https://github.com/ai-ahmed/gen_fex","last_synced_at":"2026-05-25T01:32:02.015Z","repository":{"id":327002405,"uuid":"783923703","full_name":"AI-Ahmed/gen_fex","owner":"AI-Ahmed","description":"Probabilistic PCA and PKPCA for Stochastic Feature Extraction and Missing Data Reconstruction","archived":false,"fork":false,"pushed_at":"2025-12-02T04:34:21.000Z","size":1713,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-28T13:11:16.005Z","etag":null,"topics":["bayesian","chex","distrax","finance","jax","pkpca","ppca","probabilistic","probabilistic-models","python","quantitative-finance","stochastic"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AI-Ahmed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-08T21:00:52.000Z","updated_at":"2025-12-02T04:34:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/AI-Ahmed/gen_fex","commit_stats":null,"previous_names":["ai-ahmed/gen_fex","ai-ahmed/stochastic_fex"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/AI-Ahmed/gen_fex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AI-Ahmed%2Fgen_fex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AI-Ahmed%2Fgen_fex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AI-Ahmed%2Fgen_fex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AI-Ahmed%2Fgen_fex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AI-Ahmed","download_url":"https://codeload.github.com/AI-Ahmed/gen_fex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AI-Ahmed%2Fgen_fex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33107582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","chex","distrax","finance","jax","pkpca","ppca","probabilistic","probabilistic-models","python","quantitative-finance","stochastic"],"created_at":"2025-12-24T22:52:31.360Z","updated_at":"2026-05-16T15:07:04.932Z","avatar_url":"https://github.com/AI-Ahmed.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Probabilistic Feature Extraction in JAX\n\n[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](LICENSE)\n[![JAX](https://img.shields.io/badge/backend-JAX-red.svg)](https://github.com/google/jax)\n[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n## Overview\n\n**gen_fex** is a high-performance library for **Probabilistic Feature Extraction** and **Generative Modeling**, built on top of [JAX](https://github.com/google/jax). It is designed to handle high-dimensional, sparse time-series data, making it particularly effective for financial modeling in high-risk regimes.\n\nThis repository accompanies the manuscript **\"Generative Modeling for High-Dimensional Sparse Data: Probabilistic Feature Extraction in High-Risk Financial Regimes\"**. It implements robust probabilistic models that outperform conventional methods in capturing non-linear, time-dependent features, especially during volatile market conditions.\n\n## ✨ Key Features\n\n- **🚀 JAX-Accelerated**: Leverages JAX for high-performance numerical computing and automatic differentiation.\n- **scikit-learn Compatible**: Fully compatible with the `scikit-learn` API (`fit`, `transform`, `inverse_transform`), allowing seamless integration into existing ML pipelines.\n- **High-Dimensional Efficiency**: Automatically handles the \"Transpose Trick\" (Dual formulation) to efficiently process datasets where features ($D$) far exceed samples ($N$).\n- **Missing Data Imputation**: Robust reconstruction of missing values in sparse datasets.\n- **Advanced Models**:\n  - **PPCA (Probabilistic PCA)**: A probabilistic framework for PCA that handles noise and missing data.\n  - **PKPCA (Probabilistic Kernel PCA)**: Extends PPCA with kernel methods (e.g., RBF) and Wishart processes to capture non-linear structures.\n\n## 🛠️ Installation\n\n### Prerequisites\n\n- Python **3.10** or newer.\n\n### Install via pip\n\nYou can install the package directly from GitHub:\n\n```bash\npip install git+https://github.com/AI-Ahmed/gen_fex.git\n```\n\n### Development Installation\n\nIf you want to contribute or modify the code:\n\n1. **Clone the repository:**\n\n   ```bash\n   git clone https://github.com/AI-Ahmed/gen_fex.git\n   cd gen_fex\n   ```\n\n2. **Install using Flit:**\n\n   ```bash\n   pip install flit\n   flit install --deps develop --extras test --symlink\n   ```\n\n## 🚀 Quick Start\n\nHere is a simple example of how to use the `PPCA` and `PKPCA` classes.\n\n```python\nimport numpy as np\nfrom gen_fex import PPCA, PKPCA\n\n# 1. Generate synthetic high-dimensional data (Samples \u003c Features)\n# Shape: (N_samples, D_features)\nN, D = 100, 1000\ndata = np.random.rand(N, D)\n\n# 2. Initialize Models\n# We choose a latent dimension q\nq = 50\nppca = PPCA(q=q)\npkpca = PKPCA(q=q)\n\n# 3. Fit Models\n# The models automatically handle the high-dimensional nature (N \u003c D)\nprint(\"Fitting PPCA...\")\nppca.fit(data, use_em=True, verbose=1)\n\nprint(\"Fitting PKPCA...\")\npkpca.fit(data, use_em=True, verbose=1)\n\n# 4. Transform (Dimensionality Reduction)\nlatent_ppca = ppca.transform()\nlatent_pkpca = pkpca.transform()\n\nprint(f\"Original Shape: {data.shape}\")\nprint(f\"PPCA Latent Shape: {latent_ppca.shape}\")   # (q, D) - Latent features\nprint(f\"PKPCA Latent Shape: {latent_pkpca.shape}\") # (q, D) - Latent features\n\n# Note: The model decomposes X approx W @ Z\n# W: (N, q) - Sample embeddings\n# Z: (q, D) - Latent features (returned by transform)\n\n# 5. Reconstruction (Inverse Transform)\nrecon_ppca = ppca.inverse_transform(latent_ppca)\nprint(f\"Reconstructed Shape: {recon_ppca.shape}\")\n```\n\n## 🧮 Mathematical Background\n\n### Probabilistic PCA (PPCA)\n\nPPCA in the matrix-variate setting models the observed data matrix $P ∈ ℝ^{N×D}$ using\nlatent variables $Z ∈ ℝ^{q×N}$ with a linear Gaussian generative structure:\n\n$$\nP = WZ + \\mu + E\n$$\n\nwhere:\n\n- \\$W \\in \\mathbb{R}^{N \\times q}\\$ is the loading matrix,\n- \\$\\mu \\in \\mathbb{R}^{N \\times D}\\$ is the mean matrix,\n- \\$E \\in \\mathbb{R}^{N \\times D}\\$ is the noise matrix.\n\nThe latent variables follow an isotropic Gaussian:\n\n$$\nZ \\sim \\mathcal{N}(0, I_q)\n$$\n\nand the noise is modeled using a matrix-variate Gaussian distribution:\n\n$$\nE \\sim \\mathcal{N}_{N \\times D}\n( 0,\\ \\sigma^2 I_N,\\ I_D ).\n$$\n\n### Dual Formulation \u0026 The Transpose Trick\n\nFor high-dimensional data where the number of features $D$ is much larger than the number of samples $N$ (\\$D \\gg N\\$), standard PCA is computationally expensive ( \\$O(D^3)\\$ ). **gen_fex** implements the **Dual PPCA** formulation (often called the \"Transpose Trick\"), which operates on the N×N Gram matrix instead of the D×D covariance matrix, significantly reducing computational cost to \\$O(N^3)\\$.\n\n### Probabilistic Kernel PCA (PKPCA)\n\nPKPCA extends this by mapping data into a non-linear feature space using a kernel function (e.g., RBF). Our implementation utilizes a **Wishart Process** prior for the covariance matrix, allowing for robust uncertainty quantification in the kernel space.\n\n## 📊 Results \u0026 Performance\n\nWe evaluate our models on high-dimensional sparse financial data. Below are comparisons of model performance and reconstruction quality.\n\n### Model Performance Comparison\n\n![Model Performance Comparison](docs/model_performance_comp.jpg)\n*Fig. 2. Comparison of the negative log-likelihood (`ℓ`) between high-dimensional PPCA and PKPCA over 20 iterations (T4 GPU).*\n\n### Reconstructed Data Comparison\n\n![Reconstructed Data Comparison](docs/reconstructed_data_comparsion.jpg)\n*Fig. 8. Monthly reconstructed correlation between PPCA and PKPCA for assets in the R2 regime. PKPCA shows a clear divergence from PPCA, particularly between the IT and Materials sectors, reflecting sector-specific performance during this period.*\n\n## 📁 Directory Structure\n\n```text\n.\n├── gen_fex/            # Source code\n│   ├── _ppcax.py       # PPCA implementation\n│   └── _pkpcax.py      # PKPCA implementation\n├── tests/              # Unit tests\n├── pyproject.toml      # Project configuration\n└── README.md           # Documentation\n```\n\n## 🧪 Running Tests\n\nTo ensure everything is working correctly, run the test suite:\n\n```bash\npytest tests/test.py\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository.\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`).\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`).\n4. Push to the branch (`git push origin feature/AmazingFeature`).\n5. Open a Pull Request.\n\n## 📄 License\n\nThis project is licensed under the [Apache License 2.0](LICENSE).\n\n## 📣 Citation\n\nIf you use this software in your research, please cite our manuscript:\n\n```bibtex\n@article{ATWA2026113376,\ntitle = {Generative modeling for high-dimensional sparse data: Probabilistic feature extraction in high-risk financial regimes},\njournal = {Engineering Applications of Artificial Intelligence},\nvolume = {164},\npages = {113376},\nyear = {2026},\nissn = {0952-1976},\ndoi = {https://doi.org/10.1016/j.engappai.2025.113376},\nurl = {https://www.sciencedirect.com/science/article/pii/S0952197625034074},\nauthor = {Ahmed Nabil Atwa and Mohamed Kholief and Ahmed Sedky},\nkeywords = {Probabilistic principal component analysis, Probabilistic kernel principal component analysis, Wishart process, Missing value imputation, Information-driven bars, Hierarchical risk parity}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-ahmed%2Fgen_fex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fai-ahmed%2Fgen_fex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-ahmed%2Fgen_fex/lists"}