datascience

module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT

README

datascience logo

datascience

Data Science and Machine Learning in Go
A zero-dependency Go library for probabilistic models, deep learning, numerical computing, and quantitative analysis

MIT License Go Version Zero Dependencies CI Status


Overview

datascience is a comprehensive pure Go library for data science and machine learning. It provides probabilistic graphical models (full pgmpy parity), a TensorFlow-compatible deep learning framework, BLAS-optimized numerical computing, and quantitative finance tools — all with zero third-party dependencies.

Every numerical, graph-theoretic, statistical, and tabular operation is implemented from scratch in Go within the project's internal libraries. This eliminates supply-chain risk and simplifies deployment.

Installation

go get github.com/asymmetric-effort/datascience

Requires Go 1.26 or later.

Quick Start

Build a Bayesian network and run inference:

package main

import (
    "fmt"
    "log"

    "github.com/asymmetric-effort/datascience/example_models"
    "github.com/asymmetric-effort/datascience/lib/pgm/inference"
)

func main() {
    bn := example_models.Student()
    if err := bn.CheckModel(); err != nil {
        log.Fatalf("Model validation failed: %v", err)
    }

    markovFactors, _ := bn.ToMarkovFactors()
    ve := inference.NewVariableElimination(markovFactors)
    evidence := map[string]int{"D": 0, "I": 1}
    result, _ := ve.Query([]string{"G"}, evidence)

    for i, state := range bn.GetStates("G") {
        prob := result.GetValue(map[string]int{"G": i})
        fmt.Printf("P(G=%s | D=Easy, I=High) = %.4f\n", state, prob)
    }
}

Train a neural network:

package main

import (
    "github.com/asymmetric-effort/datascience/lib/numgo"
    "github.com/asymmetric-effort/datascience/lib/tensorflow/keras"
    "github.com/asymmetric-effort/datascience/lib/tensorflow/nn/layer"
    "github.com/asymmetric-effort/datascience/lib/tensorflow/nn/loss"
)

func main() {
    model := keras.NewSequential()
    model.Add(layer.NewDense(128, "relu"))
    model.Add(layer.NewDense(10, "softmax"))
    model.Compile(loss.CategoricalCrossEntropy, 0.001)

    X := numgo.NewNDArray([]int{100, 784}, nil) // training data
    Y := numgo.NewNDArray([]int{100, 10}, nil)  // labels
    model.Fit(X, Y, 10, 32) // epochs=10, batch=32
}

Libraries

Library Replaces Description
lib/numgo NumPy N-dimensional arrays, broadcasting, linear algebra, BLAS L1/2/3
lib/scigo SciPy Statistics, distributions, optimization, FFT, SDE solvers, Black-Scholes, portfolio optimization
lib/tabgo Pandas DataFrames, CSV I/O, filtering, aggregation, rolling analytics
lib/graphgo NetworkX Graph data structures, algorithms, d-separation, moralization
lib/gpu PyTorch/Pyro Compute backend abstraction (CPU fallback included)
lib/pgm pgmpy Probabilistic graphical models — 13 model types, 7 inference algorithms, 11 learning algorithms
lib/tensorflow TensorFlow/Keras Neural networks — Dense, Conv2D, LSTM, GRU, Attention, BatchNorm, optimizers, loss functions

Probabilistic Graphical Models (lib/pgm)

Models (13 types)

Bayesian Network, Discrete Bayesian Network, Markov Network, Discrete Markov Network, Dynamic Bayesian Network, Factor Graph, Cluster Graph, Junction Tree, Naive Bayes, Markov Chain, Linear Gaussian BN, Functional BN, Structural Equation Model (SEM)

Inference (7 algorithms)

Variable Elimination, Belief Propagation, MPLP, Approximate Inference, Causal Inference (do-calculus, backdoor/frontdoor), Dynamic BN Inference, MAP/MPE queries

Learning (11+ algorithms)

MLE, Bayesian Estimation, EM, Linear Gaussian MLE, SEM Estimation, Hill Climb, Exhaustive Search, PC, GES, MMHC, Tree Search, Expert-in-the-Loop, LLM-assisted discovery, IV estimation, Mirror Descent

File I/O (7 formats)

BIF, XMLBIF, UAI, NET, XBN, XDSL, POMDPX

Deep Learning (lib/tensorflow)

Layers

Dense, Conv2D, LSTM, GRU, Attention, BatchNorm, Dropout, Embedding, Flatten, MaxPool2D

Training

Sequential model, SGD/Adam/RMSProp optimizers, MSE/CrossEntropy/Huber loss, callbacks, learning rate schedules, regularizers, metrics

Utilities

GradientTape (automatic differentiation), Variable (trainable state), model save/load, dataset loading, image processing, weight initializers

Quantitative Finance (lib/scigo, lib/tabgo)

  • Black-Scholes pricing (European calls/puts, Greeks, implied volatility)
  • Binomial tree and Monte Carlo pricing
  • SDE solvers (Euler-Maruyama, Milstein)
  • Ito calculus (Brownian motion, GBM, Ornstein-Uhlenbeck)
  • Markowitz mean-variance portfolio optimization
  • QP solver with active-set method
  • Rolling correlation, beta, alpha, R-squared, PCA
  • Rolling Sharpe, Sortino, max drawdown, VaR, CVaR

Project Structure

datascience/
  lib/
    numgo/             Numerical arrays and BLAS
    scigo/             Scientific computing
    graphgo/           Graph algorithms
    tabgo/             Tabular data and analytics
    gpu/               Compute backend
    pgm/               Probabilistic graphical models
      models/            13 model types
      inference/         7 inference algorithms
      learning/          11+ learning algorithms
      sampling/          Forward and Gibbs sampling
      readwrite/         7 file format readers/writers
      factors/           CPD/JPD representations
      metrics/           Scoring and evaluation
      ...
    tensorflow/        Deep learning
      keras/             Sequential model, training
      nn/                Layers, loss, optimizers, activations
      variable/          Trainable variables
      gradtape/          Automatic differentiation
      ...
  examples/            Runnable example programs
  example_models/      Pre-built canonical networks
  tests/               Cross-validation fixtures
  website/             Project website

Documentation

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for guidelines on development workflow, testing, commit conventions, and the zero-dependency policy.

Security

To report a security vulnerability, see SECURITY.md. Do not open public issues for security concerns.

License

datascience is released under the MIT License.

Copyright (c) 2026 Asymmetric Effort, LLC.

Directories

Path Synopsis
Package example_models provides factory functions that return fully parameterized, well-known Bayesian networks from the literature.
Package example_models provides factory functions that return fully parameterized, well-known Bayesian networks from the literature.
examples
basic_bn command
Command basic_bn demonstrates building a Bayesian network, adding CPDs, validating the model, and running a variable elimination query.
Command basic_bn demonstrates building a Bayesian network, adding CPDs, validating the model, and running a variable elimination query.
bif_io command
Command bif_io demonstrates writing a Bayesian network to BIF format and reading it back, verifying the round-trip preserves structure and CPDs.
Command bif_io demonstrates writing a Bayesian network to BIF format and reading it back, verifying the round-trip preserves structure and CPDs.
causal_inference command
Command causal_inference demonstrates causal reasoning with a Bayesian network, showing the difference between observational P(Y|X=1) and interventional P(Y|do(X=1)) queries, and computing the ATE.
Command causal_inference demonstrates causal reasoning with a Bayesian network, showing the difference between observational P(Y|X=1) and interventional P(Y|do(X=1)) queries, and computing the ATE.
datasets
Package datasets provides well-known Bayesian network datasets as embedded CSV data, comparable to pgmpy's built-in datasets.
Package datasets provides well-known Bayesian network datasets as embedded CSV data, comparable to pgmpy's built-in datasets.
sampling command
Command sampling demonstrates forward sampling and likelihood-weighted sampling from a Bayesian network, comparing empirical marginals with exact inference results.
Command sampling demonstrates forward sampling and likelihood-weighted sampling from a Bayesian network, comparing empirical marginals with exact inference results.
structure_learning command
Command structure_learning demonstrates learning a Bayesian network structure from synthetic data using HillClimbSearch with BIC scoring.
Command structure_learning demonstrates learning a Bayesian network structure from synthetic data using HillClimbSearch with BIC scoring.
internal
safepath
Package safepath provides file path validation to prevent directory traversal attacks.
Package safepath provides file path validation to prevent directory traversal attacks.
lib
gpu
Package gpu provides a compute backend abstraction for accelerated factor operations.
Package gpu provides a compute backend abstraction for accelerated factor operations.
graphgo
Package graphgo provides graph data structures and algorithms including directed and undirected graphs, topological sort, d-separation, clique finding, and moralization.
Package graphgo provides graph data structures and algorithms including directed and undirected graphs, topological sort, d-separation, clique finding, and moralization.
numgo
Package numgo provides n-dimensional array operations, linear algebra, and numerical primitives.
Package numgo provides n-dimensional array operations, linear algebra, and numerical primitives.
pgm/base
Package base provides the foundational graph types used by all datascience models: DAG, PDAG, UndirectedGraph, ADMG, MAG, and SimpleCausalModel.
Package base provides the foundational graph types used by all datascience models: DAG, PDAG, UndirectedGraph, ADMG, MAG, and SimpleCausalModel.
pgm/ci_tests
Package ci_tests provides conditional independence tests for discrete, continuous, and multivariate data used in structure learning.
Package ci_tests provides conditional independence tests for discrete, continuous, and multivariate data used in structure learning.
pgm/factors
Package factors provides discrete and continuous factor representations for probabilistic graphical models.
Package factors provides discrete and continuous factor representations for probabilistic graphical models.
pgm/identification
Package identification provides causal effect identification algorithms including back-door adjustment and front-door criterion.
Package identification provides causal effect identification algorithms including back-door adjustment and front-door criterion.
pgm/independencies
Package independencies provides representations for conditional independence assertions and independence relations.
Package independencies provides representations for conditional independence assertions and independence relations.
pgm/inference
Package inference provides exact and approximate inference algorithms including variable elimination and belief propagation.
Package inference provides exact and approximate inference algorithms including variable elimination and belief propagation.
pgm/learning
Package learning provides parameter estimation and structure learning algorithms for probabilistic graphical models.
Package learning provides parameter estimation and structure learning algorithms for probabilistic graphical models.
pgm/metrics
Package metrics provides model evaluation functions including structural Hamming distance, confusion matrices, correlation scores, and Fisher's C.
Package metrics provides model evaluation functions including structural Hamming distance, confusion matrices, correlation scores, and Fisher's C.
pgm/models
Package models provides graphical model structures including Bayesian networks, Markov networks, and factor graphs.
Package models provides graphical model structures including Bayesian networks, Markov networks, and factor graphs.
pgm/prediction
Package prediction provides causal prediction methods including DoubleML, naive adjustment regression, and instrumental variable regression.
Package prediction provides causal prediction methods including DoubleML, naive adjustment regression, and instrumental variable regression.
pgm/readwrite
Package readwrite provides readers and writers for probabilistic model file formats: BIF, XMLBIF, NET, UAI, XDSL, PomdpX, XBN, CSV, JSON, and datascience-native XML.
Package readwrite provides readers and writers for probabilistic model file formats: BIF, XMLBIF, NET, UAI, XDSL, PomdpX, XBN, CSV, JSON, and datascience-native XML.
pgm/sampling
Package sampling provides MCMC and other sampling-based methods for approximate inference.
Package sampling provides MCMC and other sampling-based methods for approximate inference.
pgm/structure_score
Package structure_score provides scoring functions for structure learning including BIC, AIC, BDeu, BDs, K2, and log-likelihood variants for discrete, Gaussian, and conditional Gaussian data.
Package structure_score provides scoring functions for structure learning including BIC, AIC, BDeu, BDs, K2, and log-likelihood variants for discrete, Gaussian, and conditional Gaussian data.
pgm/utils
Package utils provides shared utilities for datascience including parsing, optimization helpers, and compatibility functions.
Package utils provides shared utilities for datascience including parsing, optimization helpers, and compatibility functions.
scigo
Package scigo provides scientific computing primitives including statistical distributions, optimization, and special functions.
Package scigo provides scientific computing primitives including statistical distributions, optimization, and special functions.
tabgo
Package tabgo provides tabular data structures and operations for loading, filtering, grouping, and transforming columnar data.
Package tabgo provides tabular data structures and operations for loading, filtering, grouping, and transforming columnar data.
tensorflow/data
Package data provides a data pipeline for feeding arrays to models, analogous to tf.data.Dataset.
Package data provides a data pipeline for feeding arrays to models, analogous to tf.data.Dataset.
tensorflow/gradtape
Package gradtape implements reverse-mode automatic differentiation, analogous to tf.GradientTape.
Package gradtape implements reverse-mode automatic differentiation, analogous to tf.GradientTape.
tensorflow/image
Package image provides image manipulation operations on NDArrays, analogous to tf.image.
Package image provides image manipulation operations on NDArrays, analogous to tf.image.
tensorflow/initializer
Package initializer provides weight initialization strategies, analogous to tf.initializers / tf.keras.initializers.
Package initializer provides weight initialization strategies, analogous to tf.initializers / tf.keras.initializers.
tensorflow/io/model
Package model provides model serialization (save/load) for go-tensorflow, analogous to tf.keras.models.save_model / load_model.
Package model provides model serialization (save/load) for go-tensorflow, analogous to tf.keras.models.save_model / load_model.
tensorflow/keras
Package keras provides high-level model building and training APIs, analogous to tf.keras.
Package keras provides high-level model building and training APIs, analogous to tf.keras.
tensorflow/keras/callbacks
Package callbacks provides training callbacks, analogous to tf.keras.callbacks.
Package callbacks provides training callbacks, analogous to tf.keras.callbacks.
tensorflow/keras/metrics
Package metrics provides evaluation metrics for model performance, analogous to tf.keras.metrics.
Package metrics provides evaluation metrics for model performance, analogous to tf.keras.metrics.
tensorflow/keras/regularizers
Package regularizers provides weight regularization functions, analogous to tf.keras.regularizers.
Package regularizers provides weight regularization functions, analogous to tf.keras.regularizers.
tensorflow/keras/schedule
Package schedule provides learning rate schedule functions, analogous to tf.keras.optimizers.schedules.
Package schedule provides learning rate schedule functions, analogous to tf.keras.optimizers.schedules.
tensorflow/nn/activation
Package activation provides activation functions for neural network layers, analogous to tf.nn.relu, tf.nn.sigmoid, tf.nn.softmax, tf.nn.tanh.
Package activation provides activation functions for neural network layers, analogous to tf.nn.relu, tf.nn.sigmoid, tf.nn.softmax, tf.nn.tanh.
tensorflow/nn/layer
Package layer provides neural network layers, analogous to tf.keras.layers.
Package layer provides neural network layers, analogous to tf.keras.layers.
tensorflow/nn/loss
Package loss provides loss functions for training neural networks, analogous to tf.keras.losses.
Package loss provides loss functions for training neural networks, analogous to tf.keras.losses.
tensorflow/nn/optimizer
Package optimizer provides optimization algorithms for training neural networks, analogous to tf.keras.optimizers.
Package optimizer provides optimization algorithms for training neural networks, analogous to tf.keras.optimizers.
tensorflow/variable
Package variable provides a trainable variable type, analogous to tf.Variable.
Package variable provides a trainable variable type, analogous to tf.Variable.
tests
testutil
Package testutil provides helpers for loading and using test fixtures generated by the Python cross-validation harness.
Package testutil provides helpers for loading and using test fixtures generated by the Python cross-validation harness.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL