Skip to main content

Hierarchical Additive Polynomial Complexity regression

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

Install from GitHub (latest development version)

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

Or with editable install for development:

git clone https://github.com/yourusername/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/yourusername/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-0.1.2.tar.gz (40.1 kB view details)

Uploaded Source

Built Distributions

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

hapc-0.1.2-cp312-cp312-win_amd64.whl (10.7 kB view details)

Uploaded CPython 3.12Windows x86-64

hapc-0.1.2-cp312-cp312-macosx_10_13_universal2.whl (10.6 kB view details)

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

hapc-0.1.2-cp311-cp311-win_amd64.whl (10.7 kB view details)

Uploaded CPython 3.11Windows x86-64

hapc-0.1.2-cp311-cp311-macosx_10_9_universal2.whl (10.6 kB view details)

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

hapc-0.1.2-cp310-cp310-win_amd64.whl (10.7 kB view details)

Uploaded CPython 3.10Windows x86-64

hapc-0.1.2-cp310-cp310-macosx_10_9_universal2.whl (10.6 kB view details)

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

hapc-0.1.2-cp39-cp39-win_amd64.whl (10.7 kB view details)

Uploaded CPython 3.9Windows x86-64

hapc-0.1.2-cp39-cp39-macosx_10_9_universal2.whl (10.6 kB view details)

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

hapc-0.1.2-cp38-cp38-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.8Windows x86-64

hapc-0.1.2-cp38-cp38-macosx_11_0_universal2.whl (10.5 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a375884d9d04ae0d217bcf6bd008556359dffc565d916832a9b1bcd3963e2726
MD5 14ce3c6cea11e8aa6291a1e51240f92d
BLAKE2b-256 71a836cde49e0885210570b658d59f766755c3d9e5fa48b0a941c47f8b99424b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6d61aa54b9f4366c3491f56104a33c07f3ecb2378bc68741d6486cff7bc1a7c3
MD5 cb06a819604b78cfb9bac10a1e2893c5
BLAKE2b-256 a1d048ab0b077a9c5d27b9e39138819e901d7fe1d1625b626a2475b002cf184a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 43789f24c460f5717f0235e76eed07e639217ac80a30b30425fbbe800f61d9b7
MD5 1471c3ae67889754ff31e861a99c3e02
BLAKE2b-256 3989d2141ac1ada1841f3e70214b31d7cc46323241917f175e54d6eefcc3352c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 25d2364410524c01861f27ae8cb7bb7feb95feff4a29ddc2648e279833362989
MD5 9ece80daebf19e7c8902a98d9ad82c0b
BLAKE2b-256 f82a73e1144f2d742889e987d0ae39a3174f345708442758da16a6812a9df508

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6c2f5e8ae7ff62415d3101b84022f47a390e516ea55fac0385286d1e2c0f4cee
MD5 d4f3083245e77472b2a173513b1abb7a
BLAKE2b-256 c6b2de30cc7117e70cda524ed55ac008b0b892fc125b1c842b05d65a15f7a4c3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6b28da9e8b7c076cdfe20929c594e85736333d24ae6afd6a50048d2910a92789
MD5 7222f80cf77f664163a231620cacbad4
BLAKE2b-256 77f002a12ff461294acdf71ad3e521fee568a734517df2bb868d3693e6e688d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9e200f90dcd39b8933a97677ddce041474557f8c29f3cc2a67356f466cb6852d
MD5 deaa31a2223b4eddcda1d01fe5f444e2
BLAKE2b-256 061e4a8b105eb5995fa92692b878d4cf70a49e1708916d2cc740697ab63a3785

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 dd8cdace107109b2721166ab85decad4ad0c1cde37ead5b1adc3655ada46a477
MD5 7b15323a6ee8867065d21cea268f75ea
BLAKE2b-256 ed972b9b99cfb7fbeb9b06115916d55ede80b2dfe0563b81b100bf71ecb21735

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.2-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 10.6 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.12

File hashes

Hashes for hapc-0.1.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6152356658f594587f1b1e3496a02237fd1073a6f13a3c28e413567d8e525942
MD5 f4a98c4e7a257547c25473744cebfd32
BLAKE2b-256 0fbacd8febf462e1df5e745524dea4508003133bf3578e7406bb75db5a33e716

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hapc-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b0e2e9d6559acc98d6fb7880cb9e447200d7a3877bb322d24ddeb71338155b3c
MD5 76186426976e8fa874366f3168f334aa
BLAKE2b-256 37fdf38a5c747459ddf30cefbdfed4aee574d9c10811a216c94c6cbfeb0e8d03

See more details on using hashes here.

File details

Details for the file hapc-0.1.2-cp38-cp38-macosx_11_0_universal2.whl.

File metadata

  • Download URL: hapc-0.1.2-cp38-cp38-macosx_11_0_universal2.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: CPython 3.8, macOS 11.0+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for hapc-0.1.2-cp38-cp38-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 18a751ff81d8d2242b5907c8a82dd0770388d1d6f38e2a4a3538af77754dd8cb
MD5 b82e1f2a9437040a7bfdf45069a7fa1e
BLAKE2b-256 0dfb132259676060db36587af1b002cd7412a8625fc039963b3581d72ff75565

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