Created
October 14, 2018 18:48
-
-
Save NMZivkovic/49d0ece461e80d0ce54abc759195ad31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RBM | |
{ | |
private HiddenLayer _hiddenLayer; | |
private VisibleLayer _visibleLayer; | |
private float _learningRate; | |
public RBM(int hiddenLayerSize, int visibleLayerSize, float learningRate) | |
{ | |
_learningRate = learningRate; | |
_hiddenLayer = new HiddenLayer(hiddenLayerSize); | |
_visibleLayer = new VisibleLayer(visibleLayerSize); | |
_visibleLayer.ConnectLayers(_hiddenLayer); | |
} | |
public void Train(bool[][] input, int numberOfIterations) | |
{ | |
for (int n = 0; n < numberOfIterations; n++) | |
{ | |
for (int i = 0; i < input.GetLength(1); i++) | |
{ | |
_visibleLayer.PushValuesToInput(input[i]); | |
_hiddenLayer.CalculateState(); | |
_visibleLayer.CalculateCDState(); | |
_hiddenLayer.CalculateCDState(); | |
UpdateWeights(); | |
} | |
} | |
} | |
private void UpdateWeights() | |
{ | |
foreach(var inputNeuron in _visibleLayer.Neurons) | |
{ | |
inputNeuron.Outputs.ForEach(x => x.UpdateWeight(_learningRate)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment