QuantGaussVector
QuantGaussVector is a Python library designed for advanced Gaussian Process Regression (GPR) and Classification with integrated quantization and vectorization techniques. This library includes models optimized for parallel processing, making it suitable for high-performance machine learning tasks.
Table of Contents
Overview
QuantGaussVector offers two main models:
- QGVR (Quantized Gaussian Vector Regression): A regression model based on Gaussian Processes that incorporates quantization and vectorization techniques for enhanced performance.
- QVGC (Quantized Vector Gaussian Classification): A classification model that leverages Gaussian Processes for probabilistic predictions, incorporating quantization and vectorization.
These models are designed to handle large datasets efficiently, utilizing parallel processing to accelerate computation.
Theoretical Background
Gaussian Process Regression (GPR)
Gaussian Process Regression (GPR) is a non-parametric, Bayesian approach to regression that models the distribution over functions. It is particularly useful for making predictions with uncertainty estimates. The core idea is to place a Gaussian Process prior over the function to be predicted, and use observed data to update this prior.
Quantization
Quantization in machine learning involves reducing the precision of the numbers used to represent data. This technique can reduce memory usage and computational cost, especially when working with large datasets. In QuantGaussVector, quantization is applied dynamically, with options for min-max scaling to fit data into a lower precision range.
Vectorization
Vectorization is a method of optimizing computations by replacing explicit loops with array operations. This is particularly powerful in Python, where operations on NumPy arrays can be executed in C, leading to significant performance improvements. Both QGVR and QVGC models are fully vectorized to maximize efficiency.
Parallel Processing
Parallel processing divides tasks into smaller subtasks that can be processed simultaneously on multiple cores. In QuantGaussVector, the joblib library is used to parallelize the sampling and prediction steps, enabling the models to handle large datasets more efficiently.
Installation
You can install QuantGaussVector using pip:
pip install QuantGaussVector
Alternatively, you can clone the repository and install the package manually:
git clone https://github.com/MM21B038/QuantGaussVector.git
cd QuantGaussVector
pip install .
Usage
QGVR Model
The QGVR model is used for regression tasks. Here's how you can use it:
from QuantGaussVector import QGVR
# Initialize the model
model = QGVR(kernel='rbf', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, quantize=True)
# Fit the model on training data
model.fit(X_train, y_train)
# Make predictions
y_mean, y_cov = model.predict(X_test)
QVGC Model
The QVGC model is used for classification tasks. Here's how you can use it:
from QuantGaussVector import QVGC
# Initialize the classifier
classifier = QVGC(kernel='linear', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, quantize=True)
# Fit the model on training data
classifier.fit(X_train, y_train)
# Predict probabilities
probabilities, variances = classifier.predict_proba(X_test)
# Predict class labels
predictions = classifier.predict(X_test)
Parameters
kernel: Type of kernel to use ('rbf' or 'linear').length_scale: Length scale for the kernel.sigma_f: Signal variance.sigma_n: Noise variance.alpha: Regularization parameter.n_jobs: Number of parallel jobs.dtype: Data type for computation.quantize: Whether to enable dynamic range quantization.
Examples
Regression with QGVR
import numpy as np
from QuantGaussVector import QGVR
# Example dataset
X_train = np.random.rand(100, 3)
y_train = np.sin(X_train[:, 0]) + np.cos(X_train[:, 1])
X_test = np.random.rand(20, 3)
# Initialize and fit model
model = QGVR(kernel='rbf', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, quantize=True)
model.fit(X_train, y_train)
# Predict
y_mean, y_cov = model.predict(X_test)
print("Predicted mean:", y_mean)
print("Predicted covariance:", y_cov)
Classification with QVGC
import numpy as np
from QuantGaussVector import QVGC
# Example dataset
X_train = np.random.rand(100, 3)
y_train = (X_train[:, 0] + X_train[:, 1] > 1).astype(int)
X_test = np.random.rand(20, 3)
# Initialize and fit classifier
classifier = QVGC(kernel='linear', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, quantize=True)
classifier.fit(X_train, y_train)
# Predict probabilities and classes
probabilities, variances = classifier.predict_proba(X_test)
predictions = classifier.predict(X_test)
print("Predicted probabilities:", probabilities)
print("Predicted classes:", predictions)
API Reference
QGVR
- init(self, kernel='rbf', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, alpha=1e-10, n_jobs=1, dtype=np.float64, quantize=False): Initializes the QGVR model.
- fit(self, X_train, y_train): Fits the model to the training data.
- predict(self, X_test): Predicts the mean and covariance for the test data.
- sample_y(self, X_test, n_samples=3): Generates samples from the posterior distribution.
- log_marginal_likelihood(self): Computes the log marginal likelihood.
- get_params(self): Returns the model parameters.
- set_params(self, **params): Sets the model parameters.
- score(self, X_test, y_true): Computes the mean squared error of the predictions.
QVGC
- init(self, kernel='rbf', length_scale=1.0, sigma_f=1.0, sigma_n=0.1, alpha=1e-10, n_jobs=1, dtype=np.float64, quantize=False): Initializes the QVGC classifier.
- fit(self, X_train, y_train): Fits the classifier to the training data.
- predict_proba(self, X_test): Predicts the probabilities and variances for the test data.
- predict(self, X_test): Predicts the class labels for the test data.
- log_marginal_likelihood(self): Computes the log marginal likelihood.
- get_params(self): Returns the classifier parameters.
- set_params(self, **params): Sets the classifier parameters.
- score(self, X_test, y_test): Computes the accuracy of the predictions.
- decision_function(self, X_test): Computes the decision function for the test data.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Release files for QuantGaussVector 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| quantgaussvector-1.0.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| QuantGaussVector-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / quantgaussvector-1.0.0.tar.gz
| Download URL | quantgaussvector-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
185aa989c01b873f5e7df1474a0c341ab6ca5bb6f59e9b3073e19dccacec9371
|
|
BLAKE2b-256 checksum How to use checksums |
4265808894fd4a71da264f98e8215d2c02053d6338af3cbdf9382fc3624c52af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / QuantGaussVector-1.0.0-py3-none-any.whl
| Download URL | QuantGaussVector-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5bbf38ee41f8129f84da5052695051711354f670bc805f7efebaac1c2d00073
|
|
BLAKE2b-256 checksum How to use checksums |
2a318aa4e560017c975af0b2f4c25d250b9fd1acd82abafe44cb37e7a8a21c88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|