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

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.3.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.3-cp312-cp312-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.12Windows x86-64

hapc-0.1.3-cp312-cp312-macosx_10_13_universal2.whl (10.5 kB view details)

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

hapc-0.1.3-cp311-cp311-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.11Windows x86-64

hapc-0.1.3-cp311-cp311-macosx_10_9_universal2.whl (10.5 kB view details)

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

hapc-0.1.3-cp310-cp310-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.10Windows x86-64

hapc-0.1.3-cp310-cp310-macosx_10_9_universal2.whl (10.5 kB view details)

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

hapc-0.1.3-cp39-cp39-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.9Windows x86-64

hapc-0.1.3-cp39-cp39-macosx_10_9_universal2.whl (10.5 kB view details)

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

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

Uploaded CPython 3.8Windows x86-64

hapc-0.1.3-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.3.tar.gz.

File metadata

  • Download URL: hapc-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 b7d87287ed3a030a0bfe9321b95d7693f9cca0ef8b98a589844ca44b949eae85
MD5 67d5ef4f746154e5a662c48826b444f9
BLAKE2b-256 8ca101e1c389452ce0d89de42cbd418a9be05f6aedc0fa7615d7fa904f8c05d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 10.6 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1302c45cd61bc906492652dafdae9b95b57e1e3aa259c2f393f620f1b1ab35e1
MD5 6d6b5ef1ba5f4fb0cebddbf17b3055e0
BLAKE2b-256 3d4daed1876a73d97b9fa16e6db434a44d8d463c33344fb67bd42cf0f9a66c8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a2d50e6f7203c31761c8e11e21e8f507f6d71e3c900b51a91604c511bf50f5ec
MD5 b4fb96d35b00e4f1e47e224c1afb4c97
BLAKE2b-256 2c13d39b5687973d392ed309fd65a03516db5d98f063caf81ab1d8227e9122e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 10.6 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 21e28454d8d0526fc08e45fa1dad3fdc8dce67aa607702153bb018e9ff14be6b
MD5 e47ff63286f928cae453b24797798160
BLAKE2b-256 b2ace744db10c0b251c5b9e0659885eff934224a90bdee8df13d58c2a4782840

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e09fa9e4e91bcb7d964545179151c58f1a6d9e5b5996e29e57aecf3285ab1fdc
MD5 ac40522062fe7966ec83999344d1db91
BLAKE2b-256 846511b2f7f3c2f19f0aaf2c88b7e6a73d8968c8e2f6ddf8748b107d6bb1b504

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 10.6 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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e2bde6129f2bb3af7697fba6c4f6a59182bbcde01d09559fc09eaa10cb9a7e91
MD5 17ac72f8b49df5c7af4f45190aaf5936
BLAKE2b-256 94d8da3320c59e0e1c0952ef7d3ffcc2bc5b2b57e26f2eac325bbb3c2784b4a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hapc-0.1.3-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 30f3275a43e59e4addabcdcea037f012a9bda7d20db395d8f9c9e6d786d8e5cb
MD5 d0c029061c3ea0170a87b8f78390b4d9
BLAKE2b-256 955e056cbe579b0cdf71ddc6537298f6908f4b487654eee8dfbe870b4fbf24ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 10.6 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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ba86c5fd739a54f6d7f0b795ee89163561707eb26744ace659b3f6b1d646ea8c
MD5 24e4ce87e1b729ff224274a53face20b
BLAKE2b-256 9b5dc51ba74d167bad6f9097e049dcd357335d9f477e2812c525f5e5b73ff096

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 10.5 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.3-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 bfe3de405c8b189b399aedc216bdff1670ccb6f02720a8caeccea934a5d36252
MD5 021b24d1d834a84b875950e4163acf75
BLAKE2b-256 e072c0b7c0de736a7094d1778c296ea6a5a11c8fb58eb94e3197e8544e45c5f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2d140c8e86cdbcbc09777ccfe20591c6892061b86c1ad4f88e663367bceeada1
MD5 188ebb08a33501fec36e8f02e15523c4
BLAKE2b-256 720652a0a30440c6ceab0e0df3766260a410632f217cbcd06048f9af337e41a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hapc-0.1.3-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.3-cp38-cp38-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 2a7ba98723b20f6a6c8e6f127593368fe9d65e218287bb3a946135b7229f8bce
MD5 02f3e743613d780fe2df01a7f8e8238c
BLAKE2b-256 32c151958ceea11df966f3cb815231adf7e949f224366fa59ca23726ed13c510

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