Skip to main content

autoFRK: Automatic Fixed Rank Kriging. The Python version with PyTorch

Project description

autoFRK-python

PyPI Version Downloads License: GPL v3

autoFRK-python is a Python implementation of the R package autoFRK v1.4.3 (Tzeng S et al., 2021). autoFRK provides a Resolution Adaptive Fixed Rank Kriging (FRK) approach for handling regular and irregular spatial data, reducing computational cost through multi-resolution basis functions.

Features

  • Spatial modeling based on multi-resolution basis functions
  • Supports single or multiple time points
  • Offers approximate or EM-based model estimation
  • Suitable for global latitude-longitude data
  • Implemented in PyTorch, supporting CPU and GPU

Installation

Install via pip:

pip install autoFRK

Install directly from GitHub:

pip install git+https://github.com/Josh-test-lab/autoFRK-python.git

Or clone and install manually:

git clone https://github.com/Josh-test-lab/autoFRK-python.git
cd autoFRK-python
pip install .

Usage

1. Import and Initialize

import torch
from autoFRK import AutoFRK

# Initialize the autoFRK model
model = AutoFRK(dtype=torch.float64, device="cpu")

2. Model Fitting

# Assume `data` is (n, T) observations and `loc` is (n, d) spatial coordinates
data = torch.randn(100, 1)  # Example data
loc = torch.rand(100, 2)    # Example 2D coordinates

result = model.forward(
    data=data,
    loc=loc,
    maxit=50,
    tolerance=1e-6,
    method="fast",          # "fast" or "EM"
    n_neighbor=3,
    maxK=50,
    calculate_with_spherical=False
)

print(result.keys())
# ['M', 's', 'negloglik', 'w', 'V', 'G', 'LKobj', 'calculate_with_spherical']

forward() returns a dictionary including:

  • M: Covariance matrix of random effects
  • s: Measurement error variance
  • negloglik: Final negative log-likelihood
  • w: Estimated random effects for each time point
  • V: Prediction error covariance of w
  • G: Basis function matrix used

3. Predicting New Data

# Assume `newloc` contains new spatial coordinates
newloc = torch.rand(20, 2)

pred = model.predict(
    obj=result,
    newloc=newloc,
    se_report=True
)

print(pred['pred.value'].shape)  # Predicted values
print(pred.get('se'))            # Standard errors

predict() can optionally return standard errors (se_report=True). If obj is not provided, the most recent forward() result is used.

Advanced Settings

forward() supports various parameters:

Parameter Description Default
mu Mean value (scalar or tensor) 0.0
D Measurement error covariance None (identity matrix used)
G Basis function matrix (optional) None (TPS basis auto-generated)
finescale Include fine-scale process η[t] False
maxit Maximum iterations 50
tolerance Convergence tolerance 1e-6
maxK Maximum number of basis functions Auto-set based on n
method Model estimation method "fast"
n_neighbor Number of neighbors for fast method 3
calculate_with_spherical Use spherical distance calculation False

Example Code

import torch
from autoFRK import AutoFRK

# Generate fake data
n, T = 200, 1
data = torch.randn(n, T)
loc = torch.rand(n, 2)

# Initialize model
model = AutoFRK(device="cpu")

# Fit model
res = model.forward(
    data=data,
    loc=loc,
    maxit=100,
    method="fast"
)

# Predict new data
newloc = torch.rand(10, 2)
pred = model.predict(obj=res, newloc=newloc, se_report=True)

print("Predicted values:", pred['pred.value'])
print("Prediction standard errors:", pred.get('se'))

Experimental Features

  • Spherical coordinate basis function computation

Authors

License

License: GPL v3

  • GPL (>= 3)

Development and Contribution

  • Built with PyTorch, supporting GPU acceleration
  • Report bugs or request features on GitHub issues

References

Citation

  • To cite the Python package autoFRK-python in publications use:
  Yao-Chih Hsu (2025). _autoFRK-python: Automatic Fixed Rank Kriging. The Python version with PyTorch_. Python package version 1.0.0, 
  <https://github.com/Josh-test-lab/autoFRK-python>.
  • A BibTeX entry for LaTeX users is:
  @Manual{,
    title = {autoFRK-python: Automatic Fixed Rank Kriging. The Python version with PyTorch},
    author = {Yao-Chih Hsu},
    year = {2025},
    note = {Python package version 1.0.0},
    url = {https://github.com/Josh-test-lab/autoFRK-python},
  }
  • To cite the original R package autoFRK:
  Tzeng S, Huang H, Wang W, Nychka D, Gillespie C (2021). _autoFRK: Automatic Fixed Rank Kriging_. R package version 1.4.3,
  <https://CRAN.R-project.org/package=autoFRK>.
  • A BibTeX entry for the original R package is:
  @Manual{,
    title = {autoFRK: Automatic Fixed Rank Kriging},
    author = {ShengLi Tzeng and Hsin-Cheng Huang and Wen-Ting Wang and Douglas Nychka and Colin Gillespie},
    year = {2021},
    note = {R package version 1.4.3},
    url = {https://CRAN.R-project.org/package=autoFRK},
  }

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

autofrk-1.0.0.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

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

autofrk-1.0.0-py3-none-any.whl (70.7 kB view details)

Uploaded Python 3

File details

Details for the file autofrk-1.0.0.tar.gz.

File metadata

  • Download URL: autofrk-1.0.0.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for autofrk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 544b71cfaeccb6395564bbad2c634a3f6c19fa61690ed712dd63dfdbadbd8ba7
MD5 51e5cee2ac99964fd3ef2191ce050b8e
BLAKE2b-256 a6cb095f19ec85aac46909724feca0fdd6eaf52ee119b2a72861339ddd17ebca

See more details on using hashes here.

File details

Details for the file autofrk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: autofrk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 70.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for autofrk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 271826cdd2cedeec72780dbc4a521a84a667fb632866980ed27403b76febc9f3
MD5 9c2fea8a5d8e56a51e8fe115194a3fb3
BLAKE2b-256 e3a38175756fa397cc0bfc1982b92accf3dedf3e615a1bb76e5ec3910f45729a

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