/// <summary> /// Sample the visible (input), given the hidden neurons (output). Return the mean, and a sample, based on that /// mean probability. /// </summary> /// <param name="rbm">The RBM to use.</param> /// <param name="sampleH0">Hidden (h) samples.</param> /// <param name="mean">Output: Visible (v) mean.</param> /// <param name="sample">Output: Visible (v) sample.</param> public void SampleVH(RestrictedBoltzmannMachine rbm, double[] sampleH0, double[] mean, double[] sample) { for (int i = 0; i < rbm.VisibleCount; i++) { mean[i] = PropDown(rbm, sampleH0, i, rbm.BiasV[i]); sample[i] = rbm.binomial(1, mean[i]); } }
/// <summary> /// Sample the hidden neurons (output), given the visible (input). Return the mean, and a sample, based on that /// mean probability. /// </summary> /// <param name="rbm">The RBM to use.</param> /// <param name="v0Sample">The input to the layer.</param> /// <param name="mean">Output: mean value of each hidden neuron.</param> /// <param name="sample">Output: sample, based on mean.</param> public void SampleHV(RestrictedBoltzmannMachine rbm, double[] v0Sample, double[] mean, double[] sample) { for (int i = 0; i < rbm.HiddenCount; i++) { // Find the mean. mean[i] = PropUp(rbm, v0Sample, rbm.Layer.Weights[i], rbm.BiasH[i]); // Sample, based on that mean. sample[i] = rbm.binomial(1, mean[i]); } }