Click or drag to resize
Accord.NET (logo)

RestrictedBoltzmannMachine Class

Restricted Boltzmann Machine.
Inheritance Hierarchy
SystemObject
  Accord.NeuroNetwork
    Accord.NeuroActivationNetwork
      Accord.Neuro.NetworksRestrictedBoltzmannMachine

Namespace:  Accord.Neuro.Networks
Assembly:  Accord.Neuro (in Accord.Neuro.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class RestrictedBoltzmannMachine : ActivationNetwork
Request Example View Source

The RestrictedBoltzmannMachine type exposes the following members.

Constructors
  NameDescription
Public methodRestrictedBoltzmannMachine(Int32, Int32)
Creates a new RestrictedBoltzmannMachine.
Public methodRestrictedBoltzmannMachine(StochasticLayer, StochasticLayer)
Creates a new RestrictedBoltzmannMachine.
Public methodRestrictedBoltzmannMachine(IStochasticFunction, Int32, Int32)
Creates a new RestrictedBoltzmannMachine.
Top
Properties
  NameDescription
Public propertyHidden
Gets the hidden layer of the machine.
Public propertyInputsCount
Network's inputs count.
(Inherited from Network.)
Public propertyLayers
Network's layers.
(Inherited from Network.)
Public propertyOutput
Network's output vector.
(Inherited from Network.)
Public propertyVisible
Gets the visible layer of the machine.
Top
Methods
  NameDescription
Public methodCompute
Compute output vector of the network.
(Overrides NetworkCompute(Double).)
Public methodStatic memberCreateGaussianBernoulli
Constructs a Gaussian-Bernoulli network with visible Gaussian units and hidden Bernoulli units.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGenerateInput
Samples an input vector from the network given an output vector.
Public methodGenerateOutput
Samples an output vector from the network given an input vector.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRandomize
Randomize layers of the network.
(Inherited from Network.)
Public methodReconstruct
Reconstructs a input vector for a given output.
Public methodSave(Stream)
Save network to specified file.
(Inherited from Network.)
Public methodSave(String)
Save network to specified file.
(Inherited from Network.)
Public methodSetActivationFunction
Set new activation function for all neurons of the network.
(Inherited from ActivationNetwork.)
Public methodToActivationNetwork(Int32)
Creates a new ActivationNetwork from this instance.
Public methodToActivationNetwork(IActivationFunction, Int32)
Creates a new ActivationNetwork from this instance.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUpdateVisibleWeights
Updates the weights of the visible layer by copying the reverse of the weights in the hidden layer.
Top
Fields
  NameDescription
Protected fieldinputsCount
Network's inputs count.
(Inherited from Network.)
Protected fieldlayers
Network's layers.
(Inherited from Network.)
Protected fieldlayersCount
Network's layers count.
(Inherited from Network.)
Protected fieldoutput
Network's output vector.
(Inherited from Network.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Examples
// Create some sample inputs and outputs. Note that the
// first four vectors belong to one class, and the other
// four belong to another (you should see that the 1s
// accumulate on the beginning for the first four vectors
// and on the end for the second four).

double[][] inputs =
{
    new double[] { 1,1,1, 0,0,0 }, // class a
    new double[] { 1,0,1, 0,0,0 }, // class a
    new double[] { 1,1,1, 0,0,0 }, // class a
    new double[] { 0,0,1, 1,1,0 }, // class b
    new double[] { 0,0,1, 1,0,0 }, // class b
    new double[] { 0,0,1, 1,1,0 }, // class b
};

double[][] outputs =
{
    new double[] { 1, 0 }, // indicates the inputs at this
    new double[] { 1, 0 }, // position belongs to class a
    new double[] { 1, 0 },
    new double[] { 0, 1 }, // indicates the inputs at this
    new double[] { 0, 1 }, // position belongs to class b
    new double[] { 0, 1 },
};

// Create a Bernoulli activation function
var function = new BernoulliFunction(alpha: 0.5);

// Create a Restricted Boltzmann Machine for 6 inputs and with 1 hidden neuron
var rbm = new RestrictedBoltzmannMachine(function, inputsCount: 6, hiddenNeurons: 2);

// Create the learning algorithm for RBMs
var teacher = new ContrastiveDivergenceLearning(rbm)
{
    Momentum = 0,
    LearningRate = 0.1,
    Decay = 0
};

// learn 5000 iterations
for (int i = 0; i < 5000; i++)
    teacher.RunEpoch(inputs);

// Compute the machine answers for the given inputs:
double[] a = rbm.Compute(new double[] { 1, 1, 1, 0, 0, 0 }); // { 0.99, 0.00 }
double[] b = rbm.Compute(new double[] { 0, 0, 0, 1, 1, 1 }); // { 0.00, 0.99 }

// As we can see, the first neuron responds to vectors belonging
// to the first class, firing 0.99 when we feed vectors which 
// have 1s at the beginning. Likewise, the second neuron fires 
// when the vector belongs to the second class.

// We can also generate input vectors given the classes:
double[] xa = rbm.GenerateInput(new double[] { 1, 0 }); // { 1, 1, 1, 0, 0, 0 }
double[] xb = rbm.GenerateInput(new double[] { 0, 1 }); // { 0, 0, 1, 1, 1, 0 }

// As we can see, if we feed an output pattern where the first neuron
// is firing and the second isn't, the network generates an example of
// a vector belonging to the first class. The same goes for the second
// neuron and the second class.
See Also