Skip to main content

Learnergy: Energy-based Machine Learners

Latest release CI DOI License

Learnergy provides PyTorch implementations of Restricted Boltzmann Machines (RBMs) and Deep Belief Networks (DBNs) for unsupervised feature learning, generative modeling, and classification. It also includes dataset adapters, image-quality metrics, and visualization helpers.

Installation

Learnergy requires Python 3.11 or newer. Add it to a project managed by uv with:

uv add learnergy

Add the optional torchvision dependency to run the examples:

uv add "learnergy[examples]"

For a consumer installation in an existing Python environment, pip is also supported:

pip install learnergy
pip install "learnergy[examples]"

Quick start

import torch
from torch.utils.data import TensorDataset

from learnergy.models.bernoulli import RBM

samples = torch.bernoulli(torch.rand(1_024, 784))
targets = torch.zeros(1_024)
dataset = TensorDataset(samples, targets)

model = RBM(n_visible=784, n_hidden=128, learning_rate=0.1)
mse, pseudo_likelihood = model.fit(dataset, batch_size=128, epochs=5)
reconstruction_mse, reconstructed = model.reconstruct(dataset)

Stack RBMs into a DBN:

from learnergy.models.deep import DBN

model = DBN(
    model=("gaussian", "sigmoid"),
    n_visible=784,
    n_hidden=(256, 128),
    steps=(1, 1),
    learning_rate=(0.01, 0.01),
    momentum=(0, 0),
    decay=(0, 0),
    temperature=(1, 1),
)
model.fit(dataset, batch_size=128, epochs=(5, 5))

Available models

Family Models
Bernoulli RBM, ConvRBM, DiscriminativeRBM, HybridDiscriminativeRBM, DropoutRBM, DropConnectRBM, EDropoutRBM
Gaussian GaussianRBM, GaussianReluRBM, GaussianSeluRBM, VarianceGaussianRBM, GaussianConvRBM
Extra SigmoidRBM
Deep DBN, ConvDBN, ResidualDBN

The learnergy.core.Dataset, learnergy.math, and learnergy.visual modules remain available for array-backed datasets, SSIM/scaling helpers, convergence plots, image mosaics, and tensor rendering.

See examples/applications for complete training and classification programs.

Numerical behavior

When enabled, Gaussian normalization uses statistics from the current batch, not stored training statistics. Batches of two or more samples use sample standard deviation; a singleton batch is centered to zero. Representations therefore depend on batch composition. Disable the corresponding normalization flags when supplying externally standardized features.

VarianceGaussianRBM.sigma is a learnable scale: the effective visible variance is sigma**2 plus a dtype-dependent epsilon. Its visible_sampling method returns conditional means followed by sampled states, and Gibbs sampling uses those states.

Gaussian convolutional representations support gradient-based fine-tuning. Use torch.no_grad() when extracting frozen features without an autograd graph.

The corrected variance-Gaussian sampling and stabilized likelihood calculations can change training trajectories, including with a fixed random seed.

Development

The repository uses uv for reproducible environments and packaging:

uv sync --locked
uv run pytest
uv build

Citation

@misc{roder2020learnergy,
    title={Learnergy: Energy-based Machine Learners},
    author={Mateus Roder and Gustavo Henrique de Rosa and João Paulo Papa},
    year={2020},
    eprint={2003.07443},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}

Support

Open an issue for bug reports and questions.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

learnergy-2.0.1.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

learnergy-2.0.1-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file learnergy-2.0.1.tar.gz.

File metadata

  • Download URL: learnergy-2.0.1.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for learnergy-2.0.1.tar.gz
Algorithm Hash digest
SHA256 c5e211417b0af8a2f1f199907421d60619cd49be755f6522683031d1ceb105b7
MD5 e930337aaf63c4bb8571ebea81cbb98b
BLAKE2b-256 177945c43fcafa2433ea53f3f45fcc1699f9e8af5030587d3a7637278702d25f

See more details on using hashes here.

File details

Details for the file learnergy-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: learnergy-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for learnergy-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64284659ff04c9ebe3d71684aed58fdbd1a21d6ddaea90d147d10157f6390d86
MD5 e23a3b81dbce08e72ddc09accb562928
BLAKE2b-256 ee0967dfe422615bd63025ffdac1bd0a5da27becbb6e5c6f57ae2126011da736

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.2

2 files

This release

2.0.1 This release

2 files

2.0.0

2 files

1.2.0

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page