RestrictedBoltzmannMachine<T>
Models & Types · AiDotNet.NeuralNetworks
Represents a Restricted Boltzmann Machine, which is a type of neural network that learns probability distributions over its inputs.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → VectorModelLayoutBase<T> → RestrictedBoltzmannMachine<T>
For Beginners
A Restricted Boltzmann Machine is like a two-way translator between data and features.
Think of it like this:
- The visible layer is like words in English
- The hidden layer is like words in French
- The network learns how to translate back and forth between the languages
When you train an RBM:
- It learns to recognize patterns in your data (translate English to French)
- It also learns to recreate the original data from those patterns (translate French back to English)
For example, if you train an RBM on images of faces:
- The visible layer represents the pixel values of the images
- The hidden layer might learn to recognize features like “has a mustache” or “is smiling”
- Once trained, you could activate certain hidden units to generate new face images with specific features
RBMs can be used for dimensionality reduction, feature learning, pattern completion, and even generating new data samples similar to the training data.
How It Works
A Restricted Boltzmann Machine (RBM) is a two-layer neural network that learns to reconstruct its input data. Unlike feedforward networks, RBMs are generative models that learn the probability distribution of the training data. They consist of a visible layer (representing the input data) and a hidden layer (representing features), with connections between layers but no connections within a layer (hence “restricted”). RBMs are trained using an algorithm called Contrastive Divergence, which involves both forward and backward passes between layers.
Example
var input = Tensor<float>.CreateRandom(new[] { 1, 784 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new RestrictedBoltzmannMachine<float>())
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
RestrictedBoltzmannMachine() |
|
RestrictedBoltzmannMachine(NeuralNetworkArchitecture<T> architecture, int visibleSize, int hiddenSize, IActivationFunction<T> scalarActivation, ILossFunction<T> lossFunction, RestrictedBoltzmannMachineOptions options) |
Initializes a new instance of the RestrictedBoltzmannMachine class with the specified architecture, sizes, and vector activation function. |
RestrictedBoltzmannMachine(NeuralNetworkArchitecture<T> architecture, int visibleSize, int hiddenSize, IVectorActivationFunction<T> vectorActivation, ILossFunction<T> lossFunction, RestrictedBoltzmannMachineOptions options) |
Initializes a new instance of the RestrictedBoltzmannMachine class with the specified architecture, sizes, and vector activation function. |
Properties
| Property | Summary |
|---|---|
TrainingObjectiveKind TrainingObjectiveKind { get; } |
|
int HiddenSize { get; set; } |
Gets the number of neurons in the hidden layer. |
int VisibleSize { get; set; } |
Gets the number of neurons in the visible layer. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
|
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the RBM model. |
T ComputeReconstructionError(Tensor<T> input) |
|
T EvaluateTrainingObjective(Tensor<T> input, Tensor<T> target) |
|
Tensor<T> ExtractFeatures(Tensor<T> input, bool binarize) |
Extracts features from input data using the trained RBM. |
Tensor<T> GenerateSamples(int numSamples, int numSteps) |
Generates samples from the RBM by starting with a random visible state and performing Gibbs sampling. |
Tensor<T> GetHiddenLayerActivation(Tensor<T> visibleLayer) |
Calculates the activation probabilities of the hidden layer given the visible layer. |
Tensor<T> GetVisibleLayerActivation(Tensor<T> hiddenLayer) |
Calculates the activation probabilities of the visible layer given the hidden layer. |
Tensor<T> ResolveTrainingTarget(Tensor<T> input, Tensor<T> proposedTarget) |
|
void SetTrainingParameters(T learningRate, int cdSteps) |
Serializes the RBM-specific data to a binary writer. |