public void getBatchValueGradient(double[] buffer, int batchIndex, int[] batchAssignments) { assert(batchIndex < this.numBatches) : "Incorrect batch index: " + batchIndex + ", range(0, " + this.numBatches + ")"; assert(batchAssignments.length == 2 && batchAssignments[0] <= batchAssignments[1]) : "Invalid batch assignments: " + Arrays.toString(batchAssignments); CRF.Factors batchExpectations = expectations.get(batchIndex); if (batchIndex == numBatches-1) { // crf parameters' check has to be done only once, infinite values are allowed crf.parameters.assertNotNaN(); // factor the constraints and the prior into the expectations of last batch // Gradient = (constraints - expectations + prior) = -(expectations - constraints - prior) // The minus sign is factored in combineGradients method after all gradients are computed batchExpectations.plusEquals(constraints, -1.0); if (usingHyperbolicPrior) batchExpectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else batchExpectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance); batchExpectations.assertNotNaNOrInfinite(); } double[] gradient = cachedGradient.get(batchIndex); // set the cached gradient batchExpectations.getParameters(gradient); System.arraycopy(gradient, 0, buffer, 0, gradient.length); }
public void getBatchValueGradient(double[] buffer, int batchIndex, int[] batchAssignments) { assert(batchIndex < this.numBatches) : "Incorrect batch index: " + batchIndex + ", range(0, " + this.numBatches + ")"; assert(batchAssignments.length == 2 && batchAssignments[0] <= batchAssignments[1]) : "Invalid batch assignments: " + Arrays.toString(batchAssignments); CRF.Factors batchExpectations = expectations.get(batchIndex); if (batchIndex == numBatches-1) { // crf parameters' check has to be done only once, infinite values are allowed crf.parameters.assertNotNaN(); // factor the constraints and the prior into the expectations of last batch // Gradient = (constraints - expectations + prior) = -(expectations - constraints - prior) // The minus sign is factored in combineGradients method after all gradients are computed batchExpectations.plusEquals(constraints, -1.0); if (usingHyperbolicPrior) batchExpectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else batchExpectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance); batchExpectations.assertNotNaNOrInfinite(); } double[] gradient = cachedGradient.get(batchIndex); // set the cached gradient batchExpectations.getParameters(gradient); System.arraycopy(gradient, 0, buffer, 0, gradient.length); }
public void getBatchValueGradient(double[] buffer, int batchIndex, int[] batchAssignments) { assert(batchIndex < this.numBatches) : "Incorrect batch index: " + batchIndex + ", range(0, " + this.numBatches + ")"; assert(batchAssignments.length == 2 && batchAssignments[0] <= batchAssignments[1]) : "Invalid batch assignments: " + Arrays.toString(batchAssignments); CRF.Factors batchExpectations = expectations.get(batchIndex); if (batchIndex == numBatches-1) { // crf parameters' check has to be done only once, infinite values are allowed crf.parameters.assertNotNaN(); // factor the constraints and the prior into the expectations of last batch // Gradient = (constraints - expectations + prior) = -(expectations - constraints - prior) // The minus sign is factored in combineGradients method after all gradients are computed batchExpectations.plusEquals(constraints, -1.0); if (usingHyperbolicPrior) batchExpectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else batchExpectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance); batchExpectations.assertNotNaNOrInfinite(); } double[] gradient = cachedGradient.get(batchIndex); // set the cached gradient batchExpectations.getParameters(gradient); System.arraycopy(gradient, 0, buffer, 0, gradient.length); }
expectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else expectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance);
expectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else expectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance);
expectations.plusEqualsHyperbolicPriorGradient(crf.parameters, -hyperbolicPriorSlope, hyperbolicPriorSharpness); else expectations.plusEqualsGaussianPriorGradient(crf.parameters, -gaussianPriorVariance);