Package: femtograd 0.3.1

femtograd: Automatic Differentiation for Statistical Computing

Provides automatic differentiation via reverse-mode AD (backpropagation) for first-order gradients and forward-over-reverse AD for Hessian computation. Includes log-likelihood functions for exponential family distributions (normal, exponential, Poisson, binomial, gamma, beta, negative binomial, Weibull, Pareto), MLE optimization via fit() with base R generics (coef, vcov, confint, logLik, AIC/BIC), hypothesis testing (likelihood ratio, Wald), profile likelihood, bootstrap inference, and model diagnostics. Designed for pedagogy and modern statistics rather than large-scale ML.

Authors:Alexander Towell [aut, cre]

femtograd_0.3.1.tar.gz
femtograd_0.3.1.zip(r-4.7)femtograd_0.3.1.zip(r-4.6)femtograd_0.3.1.zip(r-4.5)
femtograd_0.3.1.tgz(r-4.6-any)femtograd_0.3.1.tgz(r-4.5-any)
femtograd_0.3.1.tar.gz(r-4.7-any)femtograd_0.3.1.tar.gz(r-4.6-any)
femtograd_0.3.1.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
femtograd/json (API)

# Install 'femtograd' in R:
install.packages('femtograd', repos = c('https://queelius.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/queelius/femtograd/issues

Pkgdown/docs site:https://queelius.github.io

On CRAN:

Conda:

automatic-differentiationbackpropagationmaximum-likelihoodhessianstatisticscomputational-graphinferencepedagogy

4.18 score 1 stars 12 scripts 76 exports 1 dependencies

Last updated from:50193c0c1d. Checks:7 NOTE, 2 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64NOTE180
source / vignettesOK546
linux-release-x86_64NOTE182
macos-release-arm64NOTE160
macos-oldrel-arm64NOTE112
windows-develNOTE140
windows-releaseNOTE164
windows-oldrelNOTE185
wasm-releaseOK111

Exports:backwardbfgsbootstrap_fitboundedcheck_convergencecheck_hessiancompareconfint_mleconfint_profilediagnosticsdiv_safedofdualdual_numexp_safefemtofitfind_mlefisher_informationfisher_scoringfitget_dataget_data<-gradgradientgradient_ascentgradient_descenthessianinv_boundedinv_positiveinv_probabilityis_dualis_significant_atis_valuelbfgsline_searchlog_safelog_sigmoidlog1p_safelogitloglik_bernoulliloglik_betaloglik_binomialloglik_exponentialloglik_gammaloglik_logisticloglik_negbinomloglik_normalloglik_paretologlik_poissonloglik_weibulllogsumexplower_boundedlrtnewton_raphsonobserved_infopositiveprimalprobabilityprofile_loglikpvalrelusese_reliablesigmoidsigmoid_stablesoftmaxsoftplusstd_errorstangenttest_statupper_boundedvalvaluevcov_matrixwald_testzero_grad

Dependencies:R6

Architecture of an AD Engine
Introduction | Tier 0: Graph-per-Call (femtograd today) | What happens under the hood | The cost profile | Why this is the right choice for pedagogy | Tier 1: Tape-Based Tracing | The idea | What this buys you | The trade-off | Tier 2: Compiled Backends | C++ via Rcpp | GPU acceleration | The abstraction boundary | Where femtograd Chooses to Live | Summary

Last update: 2026-02-02
Started: 2026-02-02

Getting Started with femtograd
Introduction | Creating Differentiable Values | Building Computations | Computing Gradients | Resetting Gradients | Maximum Likelihood Estimation | Using Base R Generics | Built-in Distributions | Example: Exponential Distribution | Parameter Constraints | Model Comparison | Next Steps

Last update: 2026-02-02
Started: 2026-02-02

How Automatic Differentiation Works
Why Automatic Differentiation? | The Computational Graph | The Forward Pass | Reverse-Mode AD (Backpropagation) | Step by Step | Gradient Accumulation | Why Reverse Mode? | Second Derivatives: Forward-over-Reverse | Dual Numbers | Connection to Statistics | Fisher Information and Standard Errors | Newton-Raphson Optimization | Summary

Last update: 2026-02-02
Started: 2026-02-02

Statistical Inference with femtograd
Overview | Running Example | Wald Inference | Standard Errors | Confidence Intervals | Wald Test | Likelihood Ratio Tests | Model Comparison | Profile Likelihood | Bootstrap Inference | Model Diagnostics | What Can Go Wrong | Inference Summary

Last update: 2026-02-02
Started: 2026-02-02

Survival Analysis from Scratch
Introduction | Parametric Survival: The Weibull Model | Fitting Without Censoring | Handling Right Censoring | Simulating Censored Data | Fitting the Censored Model | Testing Shape = 1 (Is Exponential Adequate?) | Adding Covariates: Accelerated Failure Time Model | Interpreting the Treatment Effect | Is Treatment Significant? | Summary

Last update: 2026-02-02
Started: 2026-02-02

Readme and manuals

Help Manual

Help pageTopics
Subtraction for value objects-.value
Multiplication for value objects*.value
Division for value objects/.value
Power operation for value objects.^.value
Addition for value objects+.value
Absolute value for value objectsabs.value
Analysis of variance for femtofit modelsanova.femtofit
Generic function for the Backward pass for automatic differentiation (finds the gradient of every sub-node in the computational graph with respect to 'e'). In other words, it is responsible for computing the gradient with respect to 'e'.backward
Default implementation does not propagate gradients. For instance, if we have a constant, then the partial of the constant is not meaningful.backward.default
Backward pass for value objectsbackward.value
BFGS quasi-Newton optimizerbfgs
Bootstrap Inferencebootstrap
Bootstrap standard errors and confidence intervalsbootstrap_fit
Transform to bounded intervalbounded
Check convergence diagnosticscheck_convergence
Check Hessian propertiescheck_hessian
Compare multiple fitted modelscompare
Compute confidence intervals from MLE resultsconfint_mle
Profile confidence intervalsconfint_profile
Confidence intervals from bootstrapconfint.bootstrap_result
Cosine function for value objectscos.value
Model Diagnosticsdiagnostics diagnostics.femtofit
Digamma (psi) function for value objectsdigamma.value
Log-likelihood functions for exponential family distributionsdistributions
Safe division (handles division by zero)div_safe
Extract degrees of freedom from hypothesis testdof dof.hypothesis_test
dual R6 class for forward-mode automatic differentiationdual
Create a dual numberdual_num
Stable exp function (with overflow protection)exp_safe
Exponential function for value objectsexp.value
Constructor for femtofit objectscoef.femtofit confint.femtofit femtofit logLik.femtofit nobs.femtofit print.femtofit print.summary.femtofit summary.femtofit vcov.femtofit
Find MLE with standard errorsfind_mle
Compute observed Fisher information matrixfisher_information
Fisher scoring optimizerfisher_scoring
Fit a model via maximum likelihoodfit
Statistical model fitting with automatic differentiationfitting
Retrieve the data stored by an objectget_data get_data.default get_data.value get_data<- get_data<-.default get_data<-.value
Gradient of 'x' with respect to 'e' in 'backward(e)', e.g., dx/de. (applies the chain rule)grad
Default gradient is zero matrixgrad.default
Gradient of a 'value' object 'x' with respect to 'e' in 'backward(e)', e.g., dx/de. (applies the chain rule)grad.value
Compute gradient as a numeric vectorgradient
Gradient ascent/descent optimizergradient_ascent
Gradient descent (minimize)gradient_descent
Compute Hessian matrix via forward-over-reverse automatic differentiationhessian
Hypothesis Testing for Fitted Modelshypothesis_tests
Inverse of bounded transforminv_bounded
Inverse of positive transforminv_positive
Inverse of probability transforminv_probability
Inverse transforms for recovering original scaleinverse_transforms
Check if object is a dual numberis_dual
Check if test is significant at given levelis_significant_at is_significant_at.hypothesis_test
Check if an object is of class valueis_value
L-BFGS optimizer (limited memory BFGS)lbfgs
Log-gamma function for value objectslgamma.value
Backtracking line search (Armijo condition)line_search
Safe logarithm (handles zeros)log_safe
Log-sigmoid (numerically stable)log_sigmoid
Natural logarithm for value objectslog.value
Log1p with underflow protection (deprecated alias for log1p)log1p_safe
Log(1+x) for value objectslog1p.value
Logit function for value objectslogit
Bernoulli distribution log-likelihoodloglik_bernoulli
Beta distribution log-likelihoodloglik_beta
Binomial distribution log-likelihoodloglik_binomial
Exponential distribution log-likelihoodloglik_exponential
Gamma distribution log-likelihoodloglik_gamma
Logistic regression log-likelihood (binary)loglik_logistic
Negative binomial log-likelihoodloglik_negbinom
Normal (Gaussian) log-likelihoodloglik_normal
Pareto distribution log-likelihoodloglik_pareto
Poisson distribution log-likelihoodloglik_poisson
Weibull distribution log-likelihoodloglik_weibull
Log-Sum-Exp (numerically stable)logsumexp
Transform to lower-bounded intervallower_bounded
Likelihood Ratio Testlrt
Mean for value objectsmean.value
Newton-Raphson optimizernewton_raphson
Observed Fisher information matrixobserved_info observed_info.femtofit
Optimization routines for maximum likelihood estimationoptimization
Plot profile likelihoodplot.profile_likelihood
Transform to positive valuespositive
Predictions from a fitted modelpredict.femtofit
Extract primal from dual or return value unchangedprimal
Print anova table for femtofitprint.anova.femtofit
Print method for bootstrap resultsprint.bootstrap_result
Print methods for diagnostic objectsprint.convergence_check print.hessian_check print.model_diagnostics
Print method for likelihood ratio testprint.likelihood_ratio_test
Print model comparisonprint.model_comparison
Print method for profile likelihoodprint.profile_likelihood
Print value object and its computational graphprint.value
Print method for Wald testprint.wald_test
Transform to probability valuesprobability
Profile Likelihoodprofile_likelihood
Compute profile likelihood for a parameterprofile_loglik
Extract p-value from hypothesis testpval pval.hypothesis_test
ReLU activation function for value objectsrelu
Standard errors from a fitted modelse se.femtofit
Check if standard errors are reliablese_reliable
Sigmoid activation function for value objectssigmoid
Stable sigmoid functionsigmoid_stable
Sine function for value objectssin.value
Softmax function (numerically stable)softmax
Softplus function for value objectssoftplus
Square root for value objectssqrt.value
Numerical stability utilities for automatic differentiationstability
Compute standard errors from Hessianstd_errors
Sum for dual numberssum.dual
Summation for value objectssum.value
Summary for bootstrap resultssummary.bootstrap_result
Extract tangent from dual or return 0tangent
Hyperbolic tangent for value objectstanh.value
Extract test statistic from hypothesis testtest_stat test_stat.hypothesis_test
Parameter Transformation Helperstransforms
Trigamma function for value objectstrigamma.value
Transform to upper-bounded intervalupper_bounded
'value' object constructorval
value R6 classvalue
Compute variance-covariance matrix from Hessianvcov_matrix
Wald Test for Model Parameterswald_test wald_test.default wald_test.femtofit
Reset gradients to zerozero_grad zero_grad.default zero_grad.list zero_grad.value