A set of python modules for functional data analysis and partial functional linear modeling
Project description
pflm is a Python package for functional data analysis and partial functional linear modelling with L1/L2 regularisation via ADMM (Alternating Direction Method of Multipliers).
It is inspired by the MATLAB PACE toolkit and the R package fdapace, and aims to bring equivalent capabilities to Python users with a familiar scikit-learn estimator interface (fit / predict).
Key Features
Functional PCA — mean / covariance smoothing, eigen decomposition, score estimation (conditional-expectation or numerical integration), with automatic PC-selection via FVE, AIC, or BIC.
Partial Functional Linear Model — combine scalar and functional predictors (via FPCA scores) in a single regularised regression.
ElasticNet via ADMM — elastic-net solver supporting Gaussian, Binomial, Poisson, Gamma, Tweedie, and Multinomial families.
Local polynomial smoothing — 1D and 2D kernel regression with GCV / CV bandwidth selection (Polyfit1DModel, Polyfit2DModel).
Fast interpolation — Cython-backed 1D / 2D linear and cubic-spline interpolation (interp1d, interp2d).
Synthetic data generation — FunctionalDataGenerator for reproducible simulation studies.
Package Structure
pflm.fpca FPCA, data generator, result containers
pflm.smooth Local polynomial regression (1D / 2D)
pflm.interp Fast 1D / 2D interpolation
pflm.pflm PartialFunctionalLinearModel, FPCAConfig
pflm.pflm.utils ElasticNet, LinearModelFamily
pflm.utils FlattenFunctionalData, trapz, helpers
Documentation
Full documentation (API reference, user guide, examples): https://chingchuan-chen.github.io/pflm/
Installation
From GitHub (recommended)
pip install git+https://github.com/ChingChuan-Chen/pflm.git
pip will build the Cython extensions automatically via meson-python.
Requirements: Python ≥ 3.10, a C/C++ compiler, numpy ≥ 1.22, scipy ≥ 1.14, scikit-learn ≥ 1.5.
Development install
git clone https://github.com/ChingChuan-Chen/pflm.git
cd pflm
pip install "meson-python>=0.17.1" "meson>=1.3" "ninja" "Cython>=3.0.10"
pip install -e .
Docker development
To reproduce a Linux build-and-test environment locally, use the dev Docker image:
docker build -f Dockerfile.dev -t pflm-dev .
docker run --rm -v "$PWD":/work -w /work pflm-dev \
bash -lc 'python -m pip install --verbose --no-build-isolation --editable .[tests] --config-settings editable-verbose=true && pytest . -v'
If you use make, the equivalent commands are:
make docker-build
make docker-test
Quick Start
Functional PCA
import numpy as np
from scipy.special import j0
from pflm.fpca import FunctionalDataGenerator, FunctionalPCA
# Regular time grid
t = np.linspace(0.0, 10.0, 201)
# Generate 50 synthetic functional curves
gen = FunctionalDataGenerator(
t,
lambda tt: np.sin(tt) * 0.5,
lambda tt: 1.0 + 0.2 * np.cos(tt),
j0,
variation_prop_thresh=0.99,
)
y_list, t_list = gen.generate(n=50, seed=42)
# Fit FPCA
fpca = FunctionalPCA(num_points_reg_grid=101)
fpca.fit(t_list, y_list)
print("Selected #PCs:", fpca.num_pcs_)
print("Eigenvalues:", fpca.fpca_model_params_.fpca_lambda)
print("Score matrix shape:", fpca.xi_.shape)
Partial Functional Linear Model
from pflm.pflm.partial_flm import PartialFunctionalLinearModel
rng = np.random.default_rng(0)
scalar = rng.standard_normal((50, 3))
response = scalar @ np.array([1.0, -0.5, 0.3]) + rng.normal(0, 0.2, 50)
model = PartialFunctionalLinearModel()
model.fit([t_list], [y_list], scalar, response)
print("Coefficients:", model.linear_model_.coef_)
ElasticNet
from pflm.pflm.utils import ElasticNet
X = rng.standard_normal((200, 5))
y = X @ np.array([1.5, -2.0, 0.0, 0.0, 3.0]) + rng.normal(0, 0.5, 200)
reg = ElasticNet(alpha=0.1, l1_ratio=0.5).fit(X, y)
print("Coefficients:", reg.coef_)
1D Smoothing
from pflm.smooth import Polyfit1DModel
X = np.linspace(0, 1, 200)
y = np.sin(2 * np.pi * X) + rng.normal(0, 0.1, 200)
model = Polyfit1DModel().fit(X, y)
print("Bandwidth:", model.bandwidth_)
yq = model.predict(np.linspace(0, 1, 50))
Contributing
pflm is under active development. Contributions, bug reports, and feature requests are welcome — please open an issue or pull request on GitHub.
License
MIT — see LICENSE.
Reference
fdapace: Functional Data Analysis and Empirical Dynamics, https://cran.r-project.org/web/packages/fdapace/index.html.
PACE: Principal Analysis by Conditional Expectation, https://www.stat.ucdavis.edu/PACE/
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 Distributions
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 pflm-0.1.0.tar.gz.
File metadata
- Download URL: pflm-0.1.0.tar.gz
- Upload date:
- Size: 155.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54467633f31efdd762e31172a851c4c0698ae4dabc2302ad23ac9aa8b5b53069
|
|
| MD5 |
07ac4c109a0d8e008c1716fd1452b34a
|
|
| BLAKE2b-256 |
6b8d6895cb9a126a138e7d16cab6ea5ec3df407745e69a8640719f8f3fdd6232
|
Provenance
The following attestation bundles were made for pflm-0.1.0.tar.gz:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0.tar.gz -
Subject digest:
54467633f31efdd762e31172a851c4c0698ae4dabc2302ad23ac9aa8b5b53069 - Sigstore transparency entry: 1238727745
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pflm-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 990.0 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fa494649324d6f7d130c225b90e40160363f24ebe42030b4eb8353f39bff4db
|
|
| MD5 |
5716a5792825fbe2ed8d312ae7995d9d
|
|
| BLAKE2b-256 |
311d75c38bafb3341f1db8dfc75ec1b31b3a9ca9fa6c079955c22b977fcfb330
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp313-cp313-win_amd64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp313-cp313-win_amd64.whl -
Subject digest:
4fa494649324d6f7d130c225b90e40160363f24ebe42030b4eb8353f39bff4db - Sigstore transparency entry: 1238727755
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pflm-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb1c7be98cc7b7ade770038ff8ece9a8c937087907a80b2bd9c84f45e1ed8ec7
|
|
| MD5 |
bc641c880d95cd0063a5e36c7ecbdf5a
|
|
| BLAKE2b-256 |
34ba5747871ba704623361dbbb255048142f1529f7650b7ae8ad923147860a9b
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
eb1c7be98cc7b7ade770038ff8ece9a8c937087907a80b2bd9c84f45e1ed8ec7 - Sigstore transparency entry: 1238727801
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pflm-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 993.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e434228f6ac1362e38affe33cf56331e2bfe79a284c66331389e9c1c770d8db5
|
|
| MD5 |
1343c97a08cc2f35de7b419d6e1bb147
|
|
| BLAKE2b-256 |
a19a7f5ef68c5a39a334f2b16173df2004451eff16c425c8fc5ab78576b7c526
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp312-cp312-win_amd64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp312-cp312-win_amd64.whl -
Subject digest:
e434228f6ac1362e38affe33cf56331e2bfe79a284c66331389e9c1c770d8db5 - Sigstore transparency entry: 1238727812
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pflm-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49d65acb7def102d058a310678f1e72d5b0386ebfda4cff1276ec841d6787fe6
|
|
| MD5 |
1b67f01ee4a38f388ddd93d4c4206865
|
|
| BLAKE2b-256 |
a7f47d0cf365f85a2cabfe5d421f72a535f2d4af96db849d8e602bd2cad7af06
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
49d65acb7def102d058a310678f1e72d5b0386ebfda4cff1276ec841d6787fe6 - Sigstore transparency entry: 1238727796
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pflm-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40e5d6d786c6ff494d34776e328e6812b489bfc481f47baa9fea652d87ce992b
|
|
| MD5 |
ba257af4f1615a34014d6e66920a26a0
|
|
| BLAKE2b-256 |
b3952ddb66ed9b09189482dfbb7b90d0e3ba33ce5e6940c2734fdb78a72f0257
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp311-cp311-win_amd64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp311-cp311-win_amd64.whl -
Subject digest:
40e5d6d786c6ff494d34776e328e6812b489bfc481f47baa9fea652d87ce992b - Sigstore transparency entry: 1238727785
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pflm-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84e6a38af25da0faa89bcc88a583fa006e1a84b77245acf3ee1187c55f1d0cac
|
|
| MD5 |
afdc9598b73f0fcb8e3e204c97fb93c8
|
|
| BLAKE2b-256 |
cf58a543e219d8177bb904221988a64abf063467041d1c7ffe2cd45b64ae2486
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
84e6a38af25da0faa89bcc88a583fa006e1a84b77245acf3ee1187c55f1d0cac - Sigstore transparency entry: 1238727829
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pflm-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c0e2a1e0b6f2a3d97fbd61c3dcb5ac4f899db2856a75b766eea8dacb8627845
|
|
| MD5 |
78bac918f5c1386e88906f746b620e2e
|
|
| BLAKE2b-256 |
9eab4b16fd68ee61082b18a7e9ce5ab024ee4575eec47a1ae5ae54c8bf05e0c8
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp310-cp310-win_amd64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp310-cp310-win_amd64.whl -
Subject digest:
0c0e2a1e0b6f2a3d97fbd61c3dcb5ac4f899db2856a75b766eea8dacb8627845 - Sigstore transparency entry: 1238727808
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pflm-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pflm-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03f9c0213743d37baa0b6bd77defb4a4864ecb2b470e49ddd0fab5967b333362
|
|
| MD5 |
79143fc12944a7d097577cf529591eb0
|
|
| BLAKE2b-256 |
96c4192fc1b223e24f786320286a3cb0f50b561442e088591f212e1be6d847f7
|
Provenance
The following attestation bundles were made for pflm-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
python-package.yml on ChingChuan-Chen/pflm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pflm-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
03f9c0213743d37baa0b6bd77defb4a4864ecb2b470e49ddd0fab5967b333362 - Sigstore transparency entry: 1238727773
- Sigstore integration time:
-
Permalink:
ChingChuan-Chen/pflm@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChingChuan-Chen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@a80aeb34ca19d359ff0f6c9e006502e20b2c7956 -
Trigger Event:
push
-
Statement type: