outcomeMat = new DenseDoubleMatrix(outcomeSubArray); DenseDoubleVector bias = DenseDoubleVector.ones(featureSubArray.length); DoubleMatrix featureMatrix = sparse ? new SparseDoubleRowMatrix( featureSubArray) : new DenseDoubleMatrix(featureSubArray);
DenseDoubleVector.ones(numHiddenStates));
public static void forwardPropagate(DoubleMatrix[] thetas, DoubleMatrix[] ax, DoubleMatrix[] zx, NetworkConfiguration conf) { for (int i = 1; i < conf.layerSizes.length; i++) { zx[i] = multiply(ax[i - 1], thetas[i - 1], false, true, conf); if (i < (conf.layerSizes.length - 1)) { ax[i] = new DenseDoubleMatrix(DenseDoubleVector.ones(zx[i] .getRowCount()), conf.activations[i].apply(zx[i])); if (conf.hiddenDropoutProbability > 0d) { // compute dropout for ax[i] dropout(conf.rnd, ax[i], conf.hiddenDropoutProbability); } } else { // the output doesn't need a bias ax[i] = conf.activations[i].apply(zx[i]); } } }
@Override public void train(DoubleVector[] features, DoubleVector[] outcome) { Preconditions.checkArgument(features.length == outcome.length, "Features and Outcomes need to match in length!"); DoubleMatrix x = null; DoubleMatrix y = null; // add the bias if (features[0].isSparse()) { x = new SparseDoubleRowMatrix(DenseDoubleVector.ones(features.length), new SparseDoubleRowMatrix(features)); } else { x = new DenseDoubleMatrix(DenseDoubleVector.ones(features.length), new DenseDoubleMatrix(features)); } if (outcome[0].isSparse()) { y = new SparseDoubleRowMatrix(outcome); } else { y = new DenseDoubleMatrix(outcome); } // transpose y to get a faster lookup in the cost function y = y.transpose(); LogisticRegressionCostFunction cnf = new LogisticRegressionCostFunction(x, y, lambda); // random init theta theta = new DenseDoubleVector(x.getColumnCount() * y.getRowCount()); for (int i = 0; i < theta.getDimension(); i++) { theta.set(i, (random.nextDouble() * 2) - 1d); } theta = minimizer.minimize(cnf, theta, numIterations, verbose); }
DenseDoubleVector.ones(positiveHiddenProbs.getRowCount())); DoubleMatrix positiveAssociations = multiply(data, positiveHiddenProbs, true, false); positiveHiddenProbs, theta, false, true)); negativeData.setColumnVector(0, DenseDoubleVector.ones(negativeData.getRowCount())); DoubleMatrix negativeHiddenProbs = activationFunction.apply(multiply( negativeData, theta, false, false)); negativeHiddenProbs.setColumnVector(0, DenseDoubleVector.ones(negativeHiddenProbs.getRowCount())); DoubleMatrix negativeAssociations = multiply(negativeData, negativeHiddenProbs, true, false);