Aleator.AutoDiff 0.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aleator.AutoDiff --version 0.4.1
                    
NuGet\Install-Package Aleator.AutoDiff -Version 0.4.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aleator.AutoDiff" Version="0.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aleator.AutoDiff" Version="0.4.1" />
                    
Directory.Packages.props
<PackageReference Include="Aleator.AutoDiff" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aleator.AutoDiff --version 0.4.1
                    
#r "nuget: Aleator.AutoDiff, 0.4.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aleator.AutoDiff@0.4.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aleator.AutoDiff&version=0.4.1
                    
Install as a Cake Addin
#tool nuget:?package=Aleator.AutoDiff&version=0.4.1
                    
Install as a Cake Tool

Aleator.AutoDiff

Gradient-based inference stack of Aleator — capabilities that go beyond the original Scala Figaro:

  • Reverse-mode autodiff tape (Tape, Var, AdMath, AdLinearAlgebra) with stable log-sigmoid / log-sum-exp primitives, unconstraining transforms (Positive, UnitInterval, Bounded, Simplex, Ordered, CholeskyCorrelation, CovarianceCholesky), and differentiable log-densities.
  • JointModel (Build and BuildMinibatch) + UniverseJointBuilder bridge from Aleator elements to a differentiable joint target, including automatic enumeration/marginalization of finite discrete latents and DiscretePosterior.
  • Samplers & checkpoints — HamiltonianMonteCarlo, NoUTurnSampler (windowed warmup, dual averaging, diagonal/dense shrinkage mass-matrix adaptation, SamplerWarmStart, SamplerCheckpointJson, PosteriorSamplesJson, CmdStanCsv).
  • Variational & Laplace inference — MeanFieldAdvi, FullRankAdvi (including SVRG minibatching and VariationalApproximationJson), SteinVariationalGradientDescent, LbfgsOptimizer, LaplaceApproximation, GlmDraws, GlmPredictions.
  • Gaussian processes — composable kernels (RBF, Matérn, linear, …), analytic marginal-likelihood gradients, Fit (Adam) and FitLbfgs (L-BFGS) hyperparameter learning on both GaussianProcessRegression and SparseGaussianProcessRegression (FITC), plus AsDifferentiableTarget().
  • Fused GLMs, splines & survival likelihoods — BernoulliLogitGlm, PoissonLogGlm, NormalIdGlm, NegativeBinomial2LogGlm, DiscreteHazardGlm (CompressedPersonPeriods), WeibullSurvivalGlm, ExponentialSurvivalGlm, BSplineBasis (Cox–de Boor B-splines), and LogDensities.RandomWalkPrior (P-splines).
var model = new JointModel();
var mu = model.Real("mu");
var target = model.Build(s =>
{
    var logp = LogDensities.Normal(s[mu], 0.0, 10.0);
    foreach (var y in data)
        logp += LogDensities.Normal(s.Const(y), s[mu], 1.0);
    return logp;
});
var nuts = new NoUTurnSampler(target, random: new DefaultRandomSource(42));
var draws = nuts.Sample(numSamples: 2000, warmup: 1000);

HMC and NUTS require a finite initial target value and gradient. Non-finite proposals are rejected as divergences; inspect draws.Divergences after sampling.

UniverseJointBuilder reads a model written with Aleator elements. It registers the continuous latents (Add, or AddAllLatents(universe)) and reads the evidence off the model: Observe(element) for one observation, ObserveEvidence(universe) for every scorable one — the supported continuous families and their compound forms, Flip, counts (truncated Poisson included), a Select over a Dirichlet, ObserveIid nodes, with parameters written in element arithmetic. Build refuses a target that leaves out evidence depending on a registered latent, whichever way the latents were registered, because a gradient sampler would otherwise answer with the prior while every diagnostic looks healthy; a likelihood stated by hand is declared with AddFactor(term, accountsFor: element) or EvidenceStatedByCaller(). A built target is a snapshot of the evidence: once an observation, condition or constraint in its universe changes, evaluating it throws StaleTargetException — build a new one.

var builder = new UniverseJointBuilder().AddAllLatents(universe).ObserveEvidence(universe);
var draws = new NoUTurnSampler(builder.Build(), random: new DefaultRandomSource(3)).Sample(2_000, warmup: 1_000);

LbfgsOptimizer reports NoMaximum (not converged) when the gradient vanishes on a posterior that has no mode, and LaplaceApproximation refuses such a point. The ADVI fitters' early stop holds every coordinate within the tolerance. A cancelled GradientChains run returns every chain's partial draws with Cancelled set.

Public result metadata is exposed through read-only snapshots: kernel hyperparameters, GP optimisation history, and variational means, histories, Cholesky rows, and particle rows cannot be changed through an IList cast. UniverseJointBuilder.Latents is instead a live read-only view, so a retained view reflects subsequent Add calls. For compatibility, PosteriorSamples.Draws keeps its IReadOnlyList<double[]> signature; because each row is still a mutable array, every property access returns a fresh deep defensive copy. Cache that returned value when traversing the same draws repeatedly; changing it never affects Mean, Variance, Map, or other sampler diagnostics.

Zero third-party dependencies.

Documentation: atalib.com/docs. Runnable examples: atalib.com/examples.html.

Questions, bug reports and feedback: contact the maintainers through nuget.org. The source repository is private, so there is no public issue tracker yet. Report a suspected vulnerability the same way, with SECURITY: at the start of the subject, and do not disclose it publicly before it is fixed.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Aleator.AutoDiff:

Package Downloads
Aleator.Torch

TorchSharp bridge for Aleator — wraps a TorchSharp tensor program inside an IDifferentiableTarget so HMC/NUTS/ADVI/SVGD can consume neural-network log-densities and amortised encoders.

Aleator.Torch.Managed

TorchSharp bridge for Aleator with a consumer-selected native libtorch runtime.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.1 58 11/21/2026
0.4.1 130 11/12/2026
0.3.0-preview.1 149 9/6/2026