Skip to main content

Highly Adaptive Principal Components

Project description

HAPC: Highly Adaptive Prinicipal Components

A fast and flexible machine learning library for nonparametric high-dimensional regression and classification with guarantees.

Installation

Prerequisites

  • Python 3.8+
  • C++ compiler (g++, clang, or MSVC)
  • CMake 3.15+
  • Eigen3

Quick Install

pip install hapc

Prebuilt wheels are published for Linux (manylinux2014, x86_64), macOS (Intel + Apple Silicon) and Windows, for CPython 3.8–3.12. No compiler, CMake or Eigen is needed when a wheel is available.

Linux / HPC clusters

The Linux wheels use the manylinux2014 baseline (glibc 2.17), so pip install hapc works out of the box on HPC login/compute nodes — no conda toolchain, devtoolset, or sysroot setup required:

pip install hapc

If you must build from the source distribution (niche architecture, very old Python, or an air-gapped node), provide a C++17 compiler and either let CMake fetch Eigen automatically (needs network) or install Eigen and let find_package(Eigen3) find it:

# with conda compilers (recommended on HPC)
conda install -c conda-forge cxx-compiler cmake eigen
pip install hapc --no-binary hapc

Install from GitHub (latest development version)

pip install git+https://github.com/meixide/hapc.git

Or with editable install for development:

git clone https://github.com/meixide/hapc.git
cd hapc
pip install -e .

Install build dependencies

If installation fails, you may need to install build dependencies:

macOS:

brew install cmake eigen

Ubuntu/Debian:

sudo apt-get install cmake libeigen3-dev build-essential

Windows:

pip install cmake
# Install Visual Studio Build Tools or use conda
conda install -c conda-forge eigen

Quick Start

import numpy as np
from hapc.single import single_pcghal
from hapc.cv import pcghal_cv

# Generate sample data
X = np.random.randn(100, 5)
Y = X[:, 0] + 0.5 * X[:, 1] + np.random.randn(100) * 0.1

# Single fit with fixed lambda
result = single_pcghal(X, Y, maxdeg=2, npc=5, single_lambda=0.01)
print(f"Risk: {result.optimizer_output.risk:.6f}")

# Cross-validation to select lambda
lambdas = np.logspace(-4, 0, 10)
cv_result = pcghal_cv(X, Y, maxdeg=2, npc=5, lambdas=lambdas, nfolds=5)
print(f"Best lambda: {cv_result.best_lambda:.6f}")

# Make predictions
X_test = np.random.randn(20, 5)
result = single_pcghal(X, Y, maxdeg=2, npc=5, single_lambda=0.01, predict=X_test)
print(f"Predictions: {result.predictions}")

Usage

Regression

from hapc.single import single_pcghal

result = single_pcghal(
    X, Y,
    maxdeg=2,        # Maximum degree of interactions
    npc=10,          # Number of principal components
    single_lambda=0.01,
    predict=X_test   # Optional: test data for predictions
)

Classification

from hapc.single import single_pcghal

result = single_pcghal(
    X, Y_binary,
    maxdeg=2,
    npc=10,
    single_lambda=0.01,
    predict=X_test
)

Cross-Validation

from hapc.cv import pcghal_cv

cv_result = pcghal_cv(
    X, Y,
    maxdeg=2,
    npc=10,
    lambdas=np.logspace(-4, 0, 20),
    nfolds=5
)
print(cv_result.best_lambda)

API Reference

hapc.single.single_pcghal()

Fit PC-GHAL with a single lambda value.

Parameters:

  • X (ndarray, shape (n, p)): Input features
  • Y (ndarray, shape (n,)): Response variable
  • maxdeg (int): Maximum degree of interactions
  • npc (int): Number of principal components
  • single_lambda (float): Regularization parameter
  • max_iter (int, default=100): Maximum iterations
  • tol (float, default=1e-6): Convergence tolerance
  • verbose (bool, default=False): Print progress
  • predict (ndarray, optional): Test data for predictions
  • center (bool, default=True): Center the design matrix

Returns:

  • result.optimizer_output.alpha: Coefficients
  • result.optimizer_output.risk: Final risk
  • result.optimizer_output.iter: Iterations until convergence
  • result.predictions: Predictions on test data (if provided)

hapc.cv.pcghal_cv()

Cross-validation to select lambda.

Parameters:

  • lambdas (ndarray): Grid of lambda values to test
  • nfolds (int, default=5): Number of CV folds
  • ...other parameters same as single_pcghal

Returns:

  • cv_result.best_lambda: Optimal lambda
  • cv_result.mses: CV errors for each lambda
  • cv_result.best_model: Fitted model with best lambda
  • cv_result.predictions: Predictions on test data (if provided)

Contributing

Contributions welcome! The C++ core is shared between R and Python packages.

git clone https://github.com/meixide/hapc.git
cd hapc
pip install -e .
pytest

License

MIT License - see LICENSE file

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

hapc-2.3.1.tar.gz (63.5 kB view details)

Uploaded Source

Built Distributions

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

hapc-2.3.1-cp312-cp312-win_amd64.whl (527.3 kB view details)

Uploaded CPython 3.12Windows x86-64

hapc-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (289.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

hapc-2.3.1-cp312-cp312-macosx_10_13_universal2.whl (465.3 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

hapc-2.3.1-cp311-cp311-win_amd64.whl (522.1 kB view details)

Uploaded CPython 3.11Windows x86-64

hapc-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (291.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

hapc-2.3.1-cp311-cp311-macosx_10_9_universal2.whl (460.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

hapc-2.3.1-cp310-cp310-win_amd64.whl (520.0 kB view details)

Uploaded CPython 3.10Windows x86-64

hapc-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (289.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

hapc-2.3.1-cp310-cp310-macosx_10_9_universal2.whl (457.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

hapc-2.3.1-cp39-cp39-win_amd64.whl (520.2 kB view details)

Uploaded CPython 3.9Windows x86-64

hapc-2.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (289.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

hapc-2.3.1-cp39-cp39-macosx_10_9_universal2.whl (458.0 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

hapc-2.3.1-cp38-cp38-win_amd64.whl (520.0 kB view details)

Uploaded CPython 3.8Windows x86-64

hapc-2.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

hapc-2.3.1-cp38-cp38-macosx_10_9_universal2.whl (457.2 kB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file hapc-2.3.1.tar.gz.

File metadata

  • Download URL: hapc-2.3.1.tar.gz
  • Upload date:
  • Size: 63.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1.tar.gz
Algorithm Hash digest
SHA256 329b566ea870a30a153a9d291a5b1177dabadad5994d626baf60ca18e31b9c4d
MD5 eb64743ddd6b3a9bf4b6192a5b62f33f
BLAKE2b-256 202f1f1d400848b3b338bdc0eeb374428a469d41152a4b07bbdad5ea81a29f17

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: hapc-2.3.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 527.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 18de930127401e4f11dbfe2161d228215d549f469ff3982e29e93f4fb9b6e989
MD5 25aca4768245e9dcb9943202b6efef57
BLAKE2b-256 fc15c3d8833ef7ef02691054a086a51991631e24d231d885f7a3265913fe93ef

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be35d769f06f07e88432f2a99766f635a3cd87156eb36684348489cd9926bc32
MD5 1ab9ff1ff9ba9253626a77c5c646e642
BLAKE2b-256 1706a2321bb7abeb6ee1599f680d4a758da311ef9fdf2d36dbf965fd2034ecaa

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 af40f631b4fc77c5eadc3b516f931f192ca1dbf3b2604774b45eb94260521a1f
MD5 f4d3398749e16344eb281bb8f409e15e
BLAKE2b-256 63b2c0f4c150deb1b66c293d8b8fd957780c238ff39cb612cd957bd7d9c61159

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: hapc-2.3.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 522.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d7d10b6ce414bcee035cc806c3d50437aaca395df8565ed19642c822ac0617e0
MD5 473cced904f5d055aae3a4798794085d
BLAKE2b-256 7c42c8e01556eb2c46f634c17c4ad0598382db714c4bcf4f2f612368ba74b880

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dbfa61d5e2b239fc286f031586860fa966b7861e7e7cd06417197c110ec17e3
MD5 2a407071d2a668ca5fef5ebe57130818
BLAKE2b-256 5f9ec88fb3eb4c7054bb857e93812b572562dfe5b13f19c941773ed155295e1e

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 810a38aa566a78a528cc4aa16d77ca1dd95275ceb82b4c5935f2210da93bffaf
MD5 b2d6e72b596e9ef628b642a31c18641f
BLAKE2b-256 132666c212e2668a41ff2e09ab3d0f5df69f64719cf44edd93a407ba6b8d42a2

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: hapc-2.3.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 520.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 879f4caacb4842e6f5364afc5015328a8d62bb42f33baf434850a3d2326f89d6
MD5 58bf26883c5e05944a031acc19bee447
BLAKE2b-256 f33a82d08405283a4e776b52edead372aaad1c1b850cc6b3c4209c5fbe3b46e7

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b71a6f1841fed33f55f2b2a91aa90ac60db125c7dfa75d46c74575f80d72baa8
MD5 8ba79efe193b9c29dd85a6a1e5ddff72
BLAKE2b-256 820bea3e9c790ff4ed40dd6130da230a9c5ab3b956ada617cd24c41ffad7cd9e

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 280619d1e67838ca91d27fc6658869150ecec585e9363b21f343e13e7646a1ee
MD5 9659624beb4fd0ff66fc2fae42225e44
BLAKE2b-256 306470a963e0609bbdc01b925d9ba99ef15b7f9ab82346af2b68e0002735432c

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: hapc-2.3.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 520.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e0048a1aacb9c9b80d1237c6cadeea60f4881d1ac6bfaf6a89cdd6d0e1bd305f
MD5 b305645bf1de8cf9382b96f0490c88bc
BLAKE2b-256 7e680b26c8228831dd5573544fb53e087d61b6a1ec3182ff1b256206a4cf2a68

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a68fa5fd03ef1701217d78cfad0e10c353004595e6b50f65ca2e2e88c4dea508
MD5 3f0572fa66c3f78d856f8c91a75091d1
BLAKE2b-256 b4601218af23b8d7c95ffe4c2ed8acb2876ddb8eb270fc35a5113bf808e86173

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

  • Download URL: hapc-2.3.1-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 458.0 kB
  • Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3b00bb0e7d7168598cc8635211afad44d5ea7f70792b08249fdea68567fc9d8b
MD5 87dee2666c89777760b2772833d4c695
BLAKE2b-256 5fcb8f5f945626123e52b6cc28269c13482be183040549a910d27d91f508ae31

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: hapc-2.3.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 520.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0a0691e3756d5e7fdc55e19d2c5097396bd828ef3534c4283552a5ac811bbcec
MD5 083350eb171a66d434969aba591bde9d
BLAKE2b-256 447a960b2c6e1f21f523446b2ec0781fce40ef93ad4a94c8cd85b042ccb2bead

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hapc-2.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b591d3941ba0616b5d5fa18a35a8d6a5ab25d7b22144fa7cc120775b1282ba87
MD5 9774c9bfdf0f1f69dde6daea7ab6c517
BLAKE2b-256 a7efdfdeb404a8f7891caf2e6c5dfbe402180883ed8753d0e66f83a4afb25f64

See more details on using hashes here.

File details

Details for the file hapc-2.3.1-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

  • Download URL: hapc-2.3.1-cp38-cp38-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 457.2 kB
  • Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hapc-2.3.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 71a5baedc3d463929b7cca1c686db76d6b1c77dbb85639f524c43a3c9f1ac757
MD5 b364499625cd53205f055812d08d84b3
BLAKE2b-256 4bb2d33c72eef3b2982b6449b09a9d77b75d8cf0be079bf394b5fb79f36ac3c6

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