API reference
The functions of vipyr documented here, by topic and family. A function's page gives its signature, parameters, result fields, errors, an example with its output, and what it is checked against.
Data
vp.features Features on event tables
Per-entity features with state, called on a pandas DataFrame. vipyr
-
delinquency - Days past due, worst in 12 months, ever cured after 60+ (catalog/delinquency.viv).
-
ewma - Gap-aware EWMA with resets (catalog/ewma.viv).
-
sessions - Gap-based sessions per user (catalog/sessions.viv).
-
since_last - Seconds since the last event of a kind, and of any kind (catalog/since_last.viv).
-
streaks - Consecutive active days (catalog/streaks.viv).
-
velocity - Trailing-window counts, sum and distinct count (catalog/velocity.viv).
Statistics
vp.stats Statistics
Probability distributions, the special functions under them, descriptive statistics, least squares with inference, and generalized linear models. vipyr
-
describe - The mean, variance, skewness and kurtosis of a sample, with sums that keep their digits.
-
glm - Generalized linear models by R's IRLS: binomial, Poisson, Gamma and Gaussian, with R's warnings.
-
ols - Least squares with statsmodels' inference table, by pivoted QR, checked against NIST's certified results.
-
quantile - Sample quantiles of Hyndman and Fan's nine types, as R's quantile() computes them.
Machine learning
vp.gpt Language models
A small GPT (nanoGPT's shape, the speedrun's Muon and Adam) trained on text, sampled, and returned as named arrays. vipyr
-
attention - The attention weights of every head of a GPT for one prompt.
-
generate - Continue a prompt with a trained GPT, one sampled token at a time.
-
loss - The mean next-token cross-entropy of a GPT on a text.
-
train - Train a small GPT on a text, character by character, and get the model back as named arrays.
Finance
vp.finance Option pricing
Black-Scholes, binomial trees, Heston by Fourier-cosine series, finite differences. vipyr
-
bs_greeks - Black-Scholes delta, gamma and vega of one option.
-
bs_price - The Black-Scholes price of a European option on a stock with continuous dividend yield q.
-
cn_american_put - The American put by Crank-Nicolson on M space intervals over [0, Smax] and Nt time steps, of which the first `implicit` are fully implicit (two half-size steps each).
-
crr_price - The CRR value with N steps: u = exp(sigma sqrt(dt)), d = 1/u, the risk-neutral up probability p = (exp((r - q) dt) - d) / (u - d), values rolled back from maturity; an American option takes the larger of continuing and exercising at every node.
-
heston_cos - Heston prices of European options on one stock for an array of strikes, with N cosine terms and the truncation half-width L standard deviations.
-
implied_vol - The implied volatility of one quote, or NaN when the price is outside the no-arbitrage bounds.
Science
vp.scf Quantum chemistry
Hartree-Fock for molecules in Gaussian basis sets. vipyr-chem
-
run - Restricted or unrestricted Hartree-Fock for a molecule in a Gaussian basis set, with PySCF's names, shapes and units.
vp.dft Electronic structure of solids
Plane-wave density-functional theory of crystals. vipyr-chem
-
pw - The iterative engine: the same Kohn-Sham calculation as dft/pwdft.viv, without ever forming the Hamiltonian as a matrix.
vp.nuclear Nuclear structure
Mean-field and shell-model calculations of nuclei. vipyr-nuclear
-
shell_model - The lowest states of a nucleus in the nuclear shell model: Z valence protons and N valence neutrons outside a closed core, in one of the shipped spaces (the sd shell with USDB, the p shell with Cohen-Kurath), or in a .sps and .int pair read from disk.
-
skyrme_hf - The Skyrme-Hartree-Fock ground state of a spherical closed-shell nucleus: binding energy, radii, single-particle levels and densities, with the forces SLy4, SLy5, SIII or SkM*.
vp.plasma Plasma physics
Kinetic simulations of a collisionless plasma. vipyr-plasma
-
landau - Landau damping of a Langmuir wave, computed from the Vlasov-Poisson equations and checked against the exact root of the dispersion relation.
vp.statmech Statistical mechanics
Lattice models sampled by Monte Carlo, checked against exact solutions. vipyr
-
ising - The two-dimensional Ising model on an L by L square lattice with periodic edges, sampled by Metropolis (checkerboard order) or Wolff clusters at temperature T, coupling J and field h.
Math
vp.special Special functions
Functions with no closed form that physics codes call in their inner loops. vipyr
-
boys - The Boys functions F_0(T) ..
-
faddeeva_w - The Faddeeva function w(z) = exp(-z^2) erfc(-i z).
-
plasma_z - The plasma dispersion function Z(zeta) = i sqrt(pi) w(zeta) and its derivative Z'(zeta) = -2 (1 + zeta Z(zeta)), anywhere in the plane.
vp.linalg Linear algebra
The Euclidean norm, and SciPy-named aliases of vp.control's solvers. vipyr
-
enorm - The Euclidean norm of x, with no overflow or underflow in the sum of squares (MINPACK enorm).
-
lqr -
Alias of
vp.control.lqr. -
schur -
Alias of
vp.control.schur. -
solve_care -
Alias of
vp.control.care. -
solve_lyapunov -
Alias of
vp.control.lyapunov.
vp.ode Differential equations
Stiff and non-stiff initial value problems: Dormand-Prince, Radau IIA and BDF, with events, exact Jacobians and batches. vipyr
-
batch - Solve one initial value problem for many parameter sets and initial states in one call.
-
solve - Solve an initial value problem y' = f(t, y, p), stiff or not, with the right-hand side in Viv.
vp.optimize Fitting and optimization
Nonlinear least squares, curve fitting with parameter covariances and root finding by MINPACK's Levenberg-Marquardt, the residuals compiled with it. vipyr
-
curve_fit - Fit a model's parameters to data by least squares and estimate their covariance, as SciPy's curve_fit.
-
least_squares - Minimize a sum of squares of nonlinear residuals by MINPACK's Levenberg-Marquardt, with the residuals in Viv.
-
root - Solve a square nonlinear system F(x) = 0 by Levenberg-Marquardt, as SciPy's root(method='lm').
vp.gguf Model files
GGUF files, the format of ggml and llama.cpp: metadata, the tensor table, and tensors dequantized from ggml's number formats. vipyr
-
read - Read a GGUF file's metadata and tensor table.
-
tensor - One tensor of a GGUF file, dequantized to float32.
vp.randla Randomized linear algebra
Low-rank approximations and trace estimates from random sketches. vipyr
-
rp_cholesky - Randomly pivoted Cholesky: F with A ~ F F^T.
-
trace_hutchpp - Hutch++'s trace estimate from m products.
vp.liquids Simulation of liquids
Molecular dynamics and Monte Carlo of the Lennard-Jones liquid, from Allen and Tildesley's examples, with g(r), diffusion and the equation of state they are tested against. vipyr-liquids
-
diffusion - Time correlation functions of a trajectory and the diffusion coefficient they give: the velocity autocorrelation function <v(0) .
-
eos - The Lennard-Jones equation of state at one state point, from the fits of Thol et al.: pressure, energy, heat capacities, chemical potential and activity for the full potential, the same moved to the potential cut (not shifted) at 2.5 sigma by the long-range and delta corrections, and for the potential cut and shifted at 2.5 sigma, with the residual free energy and its derivatives behind each.
-
error_calc - How correlation between successive values changes the error of a time average, shown on a series whose correlation time is known exactly.
-
mc_npt - Metropolis Monte Carlo of Lennard-Jones atoms at constant N, P and T, the potential cut (not shifted) at r_cut.
-
mc_nvt - Metropolis Monte Carlo of Lennard-Jones atoms at constant N, V and T, the potential cut (not shifted) at r_cut.
-
md_nve - Molecular dynamics of Lennard-Jones atoms at constant N, V and E: velocity Verlet in a periodic cubic box, the potential cut and shifted at r_cut.
-
md_nvt - Molecular dynamics of Lennard-Jones atoms at constant N, V and T, the temperature held by a Nose-Hoover chain of three thermostats, integrated by the time-reversible splitting of Martyna, Tuckerman, Tobias and Klein (1996): velocity Verlet for the atoms, wrapped in quarter and half steps of the chain.
-
pair_distribution - The pair distribution function g(r) of a set of configurations of N atoms in a periodic cubic box: a histogram of every pair's separation (nearest image) out to half the box, divided by what an ideal gas of the same density would give in each spherical shell.
Dynamics and control
vp.control Control
LQR gains, Riccati and Lyapunov solvers, and closed-loop simulation of a cart-pole. vipyr
-
care - The stabilizing solution X of A^T X + X A - X B R^-1 B^T X + Q = 0, as scipy.linalg.solve_continuous_are(A, B, Q, R).
-
cartpole_model - The cart-pole linearized about the upright: A = df/ds (4 by 4) and B = df/du (4 by 1), by central differences of step h on the nonlinear dynamics, so the linear model is the one the simulation runs.
-
lqr - The linear-quadratic regulator for xdot = A x + B u with cost int x^T Q x + u^T R u: the gain K = R^-1 B^T P, m by n, with u = -K x, and the Riccati solution P.
-
lyapunov - The X with A X + X A^T = Q, as scipy.linalg.solve_continuous_lyapunov(A, Q).
-
schur - The real Schur decomposition A = Z T Z^T: T quasi-triangular, Z orthogonal.
-
simulate - The nonlinear cart-pole under the state feedback u = -K s, from the state s0 for `steps` steps of dt (fourth-order Runge-Kutta, the force held over each step).
Power systems
vp.power Power systems
AC and DC power flow on MATPOWER cases: Newton-Raphson, fast-decoupled and DC. vipyr
-
contingency - N-1 contingency analysis: every branch and generator outage solved by AC power flow, with DC PTDF/LODF screening.
-
cpf - The continuation power flow: the PV curve of a transfer into one bus, through the nose.
-
interconnect - A generator-interconnection study: violations before and after the project, distribution factors, and the transfer limit.
-
read_raw - Read a PSS/E RAW file (revisions 32 to 34) into MATPOWER's arrays.
-
runpf - Solve the AC or DC power flow of a MATPOWER case: bus voltages, generator outputs and branch flows.
-
short_circuit - Three-phase short-circuit currents by IEC 60909 at the buses of a case.
Ports of upstream codes are distributions too, each under its upstream's license: ports.