private double[] calcVisibleFromHidden(double[] hiddens, RbmLayer layer) { double[] result = new double[layer.NumVisible]; for (int v = 0; v < layer.NumVisible; ++v) { double sum = 0.0; for (int h = 0; h < layer.NumHidden; ++h) { sum += hiddens[h] * layer.VHWeights[v][h]; } // sum up visible bias sum += layer.VisBiases[v]; double probActiv = m_ActivationFunction(sum); double pr = m_Rnd.NextDouble(); if (probActiv > 0.5) { result[v] = 1; } else { result[v] = 0; } } return(result); }
private double[] computeVFromH(RbmLayer layer) { // reconstruct visual Nodes as v' double[] vPrime = new double[layer.NumVisible]; // v' in Wikipedia for (int v = 0; v < layer.NumVisible; ++v) { double sum = 0.0; for (int h = 0; h < layer.NumHidden; ++h) { sum += layer.HidValues[h] * layer.VHWeights[v][h]; } sum += layer.VisBiases[v]; // add visible bias double probActiv = m_ActivationFunction(sum); double pr = m_Rnd.NextDouble(); if (probActiv > 0.5) { vPrime[v] = 1; } else { vPrime[v] = 0; } } return(vPrime); }
private double[] computeHPrimeFromVPrime(double[] vPrime, RbmLayer layer) { // // Compute new hidden Nodes as h', using v' double[] hPrime = new double[layer.NumHidden]; for (int hiddenValIndx = 0; hiddenValIndx < layer.NumHidden; ++hiddenValIndx) { double sum = 0.0; for (int v = 0; v < layer.NumVisible; ++v) { sum += vPrime[v] * layer.VHWeights[v][hiddenValIndx]; } sum += layer.HidBiases[hiddenValIndx]; // add the hidden bias double probActiv = m_ActivationFunction(sum); // apply activation double pr = m_Rnd.NextDouble(); // determine 0/1 node value if (probActiv > 0.5) { hPrime[hiddenValIndx] = 1; } else { hPrime[hiddenValIndx] = 0; } } return(hPrime); }
/// <summary> /// Computes hidden values: H = V * W /// </summary> private void computeHiddenValues(RbmLayer layer) { // // Compute hidden node values for current input vector. for (int hiddenIndx = 0; hiddenIndx < layer.NumHidden; ++hiddenIndx) { double sum = 0.0; for (int visibleIndx = 0; visibleIndx < layer.NumVisible; ++visibleIndx) { sum += layer.VisibleValues[visibleIndx] * layer.VHWeights[visibleIndx][hiddenIndx]; } sum += layer.HidBiases[hiddenIndx]; // add the hidden bias //hidProbs[hiddenIndx] = m_ActivationFunction(sum); // compute prob of h activation //double pr = m_Rnd.NextDouble(); // determine 0/1 h node value //if (hidProbs[hiddenIndx] > pr) // hidValues[hiddenIndx] = 1; //else // hidValues[hiddenIndx] = 0; var sumPrime = m_ActivationFunction(sum); //if (sumPrime > 0.5) // hidValues[hiddenIndx] = 1; //else // hidValues[hiddenIndx] = 0; double pr = m_Rnd.NextDouble(); // determine 0/1 h node value if (sumPrime > 0.5) { layer.HidValues[hiddenIndx] = 1; } else { layer.HidValues[hiddenIndx] = 0; } } }