!
Archived versionYou are viewing documentation for v0.2.0. View latest (v0.4.0) docs

vectorphile

v0.2.0 Archived

A unified, research-first ML/DL Python library. One import covers tensors, autograd, deep learning, JAX-style transforms, classical ML, gradient boosting, manifold learning, visualization, I/O, and more — built from first principles with an original API.

Overview

vectorphile v0.2.0 replaces the fragmented ecosystem of NumPy + SciPy + Pandas + Scikit-learn + XGBoost + LightGBM + CatBoost + PyTorch + JAX + Matplotlib + Seaborn with a single coherent API rooted in one tensor primitive and one autodiff engine. See v0.4.0 docs for the latest features.

Installation

Requires Python 3.9 or later. NumPy and SciPy are the core dependencies.

TerminalPython
pip install vectorphile                  # core (numpy + scipy)
pip install "vectorphile[viz]"            # + matplotlib
pip install "vectorphile[io]"             # + pyarrow, h5py, netCDF4
pip install "vectorphile[full]"           # everything
pip install "vectorphile[dev]"            # + pytest, ruff
!

This is an archived release. For new projects, install vectorphile v0.4.0: pip install vectorphile==0.3.0

Quick Start

quickstart.pyPython
import vectorphile as vp
from vectorphile.utils.data import TensorDataset, DataLoader

X = vp.randn(1000, 20)
y = (X[:, 0] + X[:, 1] > 0).astype('int32')

loader = DataLoader(TensorDataset(X, y), batch_size=64, shuffle=True)

model     = vp.nn.Sequential(
    vp.nn.Linear(20, 64),
    vp.nn.BatchNorm1d(64),
    vp.nn.GELU(),
    vp.nn.Dropout(0.3),
    vp.nn.Linear(64, 2),
)
criterion = vp.nn.CrossEntropyLoss()
optimizer = vp.optim.AdamW(model.parameters(), lr=1e-3, weight_decay=1e-4)
scheduler = vp.optim.CosineAnnealingLR(optimizer, T_max=20)

for epoch in range(20):
    for X_b, y_b in loader:
        optimizer.zero_grad()
        loss = criterion(model(X_b), y_b)
        loss.backward()
        optimizer.step()
    scheduler.step()
    print(f"Epoch {epoch+1:02d}  loss={loss.item():.4f}")

Tensors

vp.core

The Tensor is the central primitive. Set requires_grad=True for gradient tracking.

tensor_ops.pyPython
import vectorphile as vp

x = vp.randn(3, 4)
y = vp.ones(4, 5)
z = x @ y                        # (3, 5) matmul

a = vp.zeros(5, 1) + vp.randn(1, 8)   # broadcast -> (5, 8)
b = a.reshape(5, 2, 4)
c = b.permute(2, 0, 1)                 # (4, 5, 2)

m = z.mean()
s = z.sum(axis=1, keepdims=True)
mx, idx = z.max(axis=0)

x_f16 = x.astype('float16')
arr = x.numpy()
t   = vp.from_numpy(arr)

Autograd

vp.autograd

Reverse-mode automatic differentiation with dynamic computation graph.

autograd.pyPython
x = vp.tensor([2.0, 3.0], requires_grad=True)
w = vp.tensor([[1.0, 0.5], [0.5, 1.0]])

h = x @ w
y = (h ** 2 + vp.log(h.abs() + 1)).sum()
y.backward()

print(x.grad)   # dy/dx

with vp.no_grad():
    logits = model(X_test)   # no graph, no grads

Transforms

vp.transforms

JAX-inspired functional transforms: grad, vmap, jit, jacobian, hessian, checkpoint.

transforms.pyPython
import vectorphile as vp

def loss(w):
    return ((w * 2 - 3) ** 2).sum()

grad_fn = vp.transforms.grad(loss)
g = grad_fn(vp.tensor([1.0, 2.0]))

val_grad = vp.transforms.value_and_grad(loss)
val, g   = val_grad(vp.tensor([1.0, 2.0]))

jac_fn = vp.transforms.jacobian(lambda x: x ** 2)
J      = jac_fn(vp.tensor([1.0, 2.0, 3.0]))

batched_fn = vp.transforms.vmap(lambda x: x ** 2 + 1)
out        = batched_fn(vp.randn(32, 10))

@vp.transforms.jit
def fast_forward(x, w):
    return vp.sigmoid(x @ w)

Neural Networks

vp.nn

Composable layer primitives inheriting from Module.

model.pyPython
model = vp.nn.Sequential(
    vp.nn.Linear(784, 512),
    vp.nn.BatchNorm1d(512),
    vp.nn.GELU(),
    vp.nn.Dropout(p=0.3),
    vp.nn.Linear(512, 256),
    vp.nn.LayerNorm(256),
    vp.nn.SiLU(),
    vp.nn.Linear(256, 10),
)

logits = model(vp.randn(32, 784))
loss   = vp.nn.CrossEntropyLoss()(logits, y)
loss.backward()

model.train()
model.eval()

Available layers

CategoryLayers
Linear / EmbeddingLinear, Embedding
ConvolutionalConv2d, ConvTranspose2d (via nn.F)
PoolingMaxPool1d/2d/3d, AvgPool1d/2d/3d, AdaptiveAvgPool1d/2d, AdaptiveMaxPool2d, GlobalAvgPool2d
RecurrentRNNCell, LSTMCell, GRUCell, RNN, LSTM, GRU (bidirectional, multi-layer, dropout)
AttentionMultiheadAttention, TransformerEncoderLayer, TransformerEncoder, TransformerDecoderLayer, TransformerDecoder, Transformer, PositionalEncoding
NormalizationBatchNorm1d, BatchNorm2d, LayerNorm, GroupNorm, InstanceNorm1d/2d/3d, RMSNorm, LocalResponseNorm
ActivationReLU, LeakyReLU, ELU, GELU, SiLU, Mish, Hardswish, SELU, Sigmoid, Tanh, Softmax, LogSoftmax
RegularizationDropout, Dropout2d, AlphaDropout (via F)
ContainersSequential, ModuleList, ModuleDict, ParameterList, ParameterDict

RNN / Attention / Transformer

vp.nn

Full sequence modelling: RNN, LSTM, GRU with bidirectional and multi-layer support; MultiheadAttention; full Encoder-Decoder Transformer.

sequence_models.pyPython
# LSTM
lstm  = vp.nn.LSTM(input_size=64, hidden_size=128, num_layers=2,
                    bidirectional=True, batch_first=True, dropout=0.2)
out, (h, c) = lstm(vp.randn(32, 50, 64))

# GRU
gru   = vp.nn.GRU(input_size=64, hidden_size=128, batch_first=True)
out, h = gru(vp.randn(32, 50, 64))

# Multi-head Attention
attn  = vp.nn.MultiheadAttention(embed_dim=256, num_heads=8, dropout=0.1)
out, weights = attn(query, key, value)

# Full Transformer
transformer = vp.nn.Transformer(
    d_model=256, nhead=8,
    num_encoder_layers=6, num_decoder_layers=6,
    dim_feedforward=1024, dropout=0.1,
)
out = transformer(src, tgt)

Functional API & Initializers

vp.nn.F · vp.nn.init

vp.nn.F exposes all layer operations as stateless functions.vp.nn.init provides all standard weight initialization schemes.

Optimizers & Schedulers

vp.optim
optim.pyPython
opt_sgd    = vp.optim.SGD(model.parameters(), lr=0.01, momentum=0.9, nesterov=True)
opt_adam   = vp.optim.Adam(model.parameters(), lr=1e-3)
opt_adamw  = vp.optim.AdamW(model.parameters(), lr=1e-3, weight_decay=1e-2)

sched_step    = vp.optim.StepLR(optimizer, step_size=30, gamma=0.1)
sched_cosine  = vp.optim.CosineAnnealingLR(optimizer, T_max=100, eta_min=1e-6)
sched_plateau = vp.optim.ReduceLROnPlateau(optimizer, patience=10, factor=0.5)
sched_one     = vp.optim.OneCycleLR(optimizer, max_lr=0.01, total_steps=1000)

DataLoader

vp.utils.data
dataloader.pyPython
from vectorphile.utils.data import TensorDataset, DataLoader

dataset = TensorDataset(X_train, y_train)
loader  = DataLoader(dataset, batch_size=64, shuffle=True)

Classical ML

vp.ml

60+ estimators across every classical ML category.

classical_ml.pyPython
from vectorphile import ml

X_tr, X_te, y_tr, y_te = ml.train_test_split(X, y, test_size=0.2, stratify=y)
scaler = ml.StandardScaler()
X_tr   = scaler.fit_transform(X_tr)

clf = ml.RandomForestClassifier(n_estimators=200)
clf.fit(X_tr, y_tr)
print(ml.accuracy_score(y_te, clf.predict(X_te)))
CategoryAlgorithms
LinearLinearRegression, Ridge, Lasso, ElasticNet, LogisticRegression, Perceptron
TreesDecisionTreeClassifier, DecisionTreeRegressor
EnsemblesRandomForestClassifier/Regressor, ExtraTreesClassifier/Regressor, BaggingClassifier/Regressor, AdaBoostClassifier/Regressor, VotingClassifier/Regressor, StackingClassifier/Regressor
BoostingXGBClassifier/Regressor, LGBMClassifier/Regressor/Ranker, CatBoostClassifier/Regressor/Ranker
NeighborsKNeighborsClassifier, KNeighborsRegressor
SVMSVC, SVR
Naive BayesGaussianNB, MultinomialNB, BernoulliNB
ClusteringKMeans, DBSCAN, AgglomerativeClustering, GaussianMixture
DecompositionPCA, TruncatedSVD, NMF, FastICA
AnomalyIsolationForest, LocalOutlierFactor, EllipticEnvelope, OneClassSVM
ManifoldTSNE (Barnes-Hut), UMAP, MDS, Isomap, LocallyLinearEmbedding, SpectralEmbedding
PreprocessingStandardScaler, MinMaxScaler, RobustScaler, LabelEncoder, OneHotEncoder, PolynomialFeatures
Feature SelectVarianceThreshold, SelectKBest, SelectPercentile, RFE, RFECV, SelectFromModel, chi2, f_classif, mutual_info
PipelinePipeline, ColumnTransformer, FeatureUnion, make_pipeline
Model Selectiontrain_test_split, KFold, StratifiedKFold, cross_val_score, GridSearchCV, RandomizedSearchCV
Metricsaccuracy, precision, recall, f1, roc_auc, log_loss, r2, MAE, MSE, RMSE, confusion_matrix, silhouette_score

Architecture

v0.2.0 flat module layout. See v0.4.0 architecture for the expanded layout with 15+ new modules.

directory structure (v0.2.0)Python
vectorphile/
+-- __init__.py          <- top-level API (v0.2.0)
+-- core/                <- Tensor, ops
+-- autograd/            <- reverse-mode autodiff engine
+-- nn/                  <- layers, activations, losses, attention, norm
|   +-- functional.py    <- 50+ stateless ops
|   +-- init.py          <- weight initialization
+-- optim/               <- optimizers + LR schedulers
+-- transforms/          <- grad, vmap, jit, jacobian, hessian
+-- ml/                  <- 60+ ML estimators
+-- data/                <- DataFrame, Series, GroupBy
+-- integrate/           <- quad, solve_ivp
+-- interpolate/         <- CubicSpline, griddata
+-- spatial/             <- KDTree, ConvexHull
+-- ndimage/             <- filters, morphology
+-- polynomial/          <- Chebyshev, Legendre
+-- ma/                  <- masked arrays
+-- io/                  <- Parquet, HDF5, WAV
+-- viz/                 <- 20+ plot types
+-- hub/                 <- save/load model
+-- quantization/        <- INT8/INT4/FP16 PTQ
+-- linalg/, stats/, fft/, signal/, sparse/
+-- utils/data/          <- DataLoader