lowerDifference.setEntry(j, lowerBound[j] - currentBest.getEntry(j)); upperDifference.setEntry(j, upperBound[j] - currentBest.getEntry(j)); if (lowerDifference.getEntry(j) >= -initialTrustRegionRadius) { if (lowerDifference.getEntry(j) >= ZERO) { currentBest.setEntry(j, lowerBound[j]); lowerDifference.setEntry(j, ZERO); upperDifference.setEntry(j, boundDiff); } else { currentBest.setEntry(j, lowerBound[j] + initialTrustRegionRadius); lowerDifference.setEntry(j, -initialTrustRegionRadius); upperDifference.setEntry(j, FastMath.max(deltaOne, initialTrustRegionRadius)); currentBest.setEntry(j, upperBound[j]); lowerDifference.setEntry(j, -boundDiff); upperDifference.setEntry(j, ZERO); } else { currentBest.setEntry(j, upperBound[j] - initialTrustRegionRadius); lowerDifference.setEntry(j, FastMath.min(deltaOne, deltaTwo)); upperDifference.setEntry(j, initialTrustRegionRadius);
lowerDifference.setEntry(j, lowerBound[j] - currentBest.getEntry(j)); upperDifference.setEntry(j, upperBound[j] - currentBest.getEntry(j)); if (lowerDifference.getEntry(j) >= -initialTrustRegionRadius) { if (lowerDifference.getEntry(j) >= ZERO) { currentBest.setEntry(j, lowerBound[j]); lowerDifference.setEntry(j, ZERO); upperDifference.setEntry(j, boundDiff); } else { currentBest.setEntry(j, lowerBound[j] + initialTrustRegionRadius); lowerDifference.setEntry(j, -initialTrustRegionRadius); upperDifference.setEntry(j, FastMath.max(deltaOne, initialTrustRegionRadius)); currentBest.setEntry(j, upperBound[j]); lowerDifference.setEntry(j, -boundDiff); upperDifference.setEntry(j, ZERO); } else { currentBest.setEntry(j, upperBound[j] - initialTrustRegionRadius); lowerDifference.setEntry(j, FastMath.min(deltaOne, deltaTwo)); upperDifference.setEntry(j, initialTrustRegionRadius);
nact = 0; for (int i = 0; i < n; i++) { xbdi.setEntry(i, ZERO); if (trustRegionCenterOffset.getEntry(i) <= lowerDifference.getEntry(i)) { if (gradientAtTrustRegionCenter.getEntry(i) >= ZERO) { xbdi.setEntry(i, MINUS_ONE); xbdi.setEntry(i, ONE); trialStepPoint.setEntry(i, ZERO); gnew.setEntry(i, gradientAtTrustRegionCenter.getEntry(i)); for (int i = 0; i < n; i++) { if (xbdi.getEntry(i) != ZERO) { s.setEntry(i, ZERO); } else if (beta == ZERO) { s.setEntry(i, -gnew.getEntry(i)); } else { s.setEntry(i, beta * s.getEntry(i) - gnew.getEntry(i)); gredsq = ZERO; for (int i = 0; i < n; i++) { gnew.setEntry(i, gnew.getEntry(i) + stplen * hs.getEntry(i)); if (xbdi.getEntry(i) == ZERO) { trialStepPoint.setEntry(i, trialStepPoint.getEntry(i) + stplen * s.getEntry(i)); xbdi.setEntry(iact, ONE); if (s.getEntry(iact) < ZERO) {
nact = 0; for (int i = 0; i < n; i++) { xbdi.setEntry(i, ZERO); if (trustRegionCenterOffset.getEntry(i) <= lowerDifference.getEntry(i)) { if (gradientAtTrustRegionCenter.getEntry(i) >= ZERO) { xbdi.setEntry(i, MINUS_ONE); xbdi.setEntry(i, ONE); trialStepPoint.setEntry(i, ZERO); gnew.setEntry(i, gradientAtTrustRegionCenter.getEntry(i)); for (int i = 0; i < n; i++) { if (xbdi.getEntry(i) != ZERO) { s.setEntry(i, ZERO); } else if (beta == ZERO) { s.setEntry(i, -gnew.getEntry(i)); } else { s.setEntry(i, beta * s.getEntry(i) - gnew.getEntry(i)); gredsq = ZERO; for (int i = 0; i < n; i++) { gnew.setEntry(i, gnew.getEntry(i) + stplen * hs.getEntry(i)); if (xbdi.getEntry(i) == ZERO) { trialStepPoint.setEntry(i, trialStepPoint.getEntry(i) + stplen * s.getEntry(i)); xbdi.setEntry(iact, ONE); if (s.getEntry(iact) < ZERO) {
originShift.setEntry(j, currentBest.getEntry(j)); for (int k = 0; k < npt; k++) { interpolationPoints.setEntry(k, j, ZERO); modelSecondDerivativesValues.setEntry(i, ZERO); modelSecondDerivativesParameters.setEntry(k, ZERO); for (int j = 0, max = npt - np; j < max; j++) { zMatrix.setEntry(k, j, ZERO); currentBest.setEntry(j, FastMath.min(FastMath.max(lowerBound[j], originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { currentBest.setEntry(j, lowerBound[j]); currentBest.setEntry(j, upperBound[j]); final double f = isMinimize ? objectiveValue : -objectiveValue; final int numEval = getEvaluations(); // nfm + 1 fAtInterpolationPoints.setEntry(nfm, f); if (numEval >= 2 && numEval <= n + 1) { gradientAtTrustRegionCenter.setEntry(nfmm, (f - fbeg) / stepa); if (npt < numEval + n) { final double oneOverStepA = ONE / stepa; final double tmp = (f - fbeg) / stepb;
originShift.setEntry(j, currentBest.getEntry(j)); for (int k = 0; k < npt; k++) { interpolationPoints.setEntry(k, j, ZERO); modelSecondDerivativesValues.setEntry(i, ZERO); modelSecondDerivativesParameters.setEntry(k, ZERO); for (int j = 0, max = npt - np; j < max; j++) { zMatrix.setEntry(k, j, ZERO); currentBest.setEntry(j, FastMath.min(FastMath.max(lowerBound[j], originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { currentBest.setEntry(j, lowerBound[j]); currentBest.setEntry(j, upperBound[j]); final double f = isMinimize ? objectiveValue : -objectiveValue; final int numEval = getEvaluations(); // nfm + 1 fAtInterpolationPoints.setEntry(nfm, f); if (numEval >= 2 && numEval <= n + 1) { gradientAtTrustRegionCenter.setEntry(nfmm, (f - fbeg) / stepa); if (npt < numEval + n) { final double oneOverStepA = ONE / stepa; final double tmp = (f - fbeg) / stepb;
hcol.setEntry(k, ZERO); hcol.setEntry(k, hcol.getEntry(k) + tmp * zMatrix.getEntry(k, j)); glag.setEntry(i, bMatrix.getEntry(knew, i)); glag.setEntry(i, glag.getEntry(i) + tmp * interpolationPoints.getEntry(k, i)); newPoint.setEntry(i, FastMath.max(lowerDifference.getEntry(i), FastMath.min(upperDifference.getEntry(i), tmp))); newPoint.setEntry(-ibdsav - 1, lowerDifference.getEntry(-ibdsav - 1)); newPoint.setEntry(ibdsav - 1, upperDifference.getEntry(ibdsav - 1)); for (int i = 0; i < n; i++) { final double glagValue = glag.getEntry(i); work1.setEntry(i, ZERO); if (FastMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || FastMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { work1.setEntry(i, bigstp); final double tmp2 = trustRegionCenterOffset.getEntry(i) - step * glag.getEntry(i); if (tmp2 <= lowerDifference.getEntry(i)) { work1.setEntry(i, lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)); work1.setEntry(i, upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)); final double glagValue = glag.getEntry(i);
hcol.setEntry(k, ZERO); hcol.setEntry(k, hcol.getEntry(k) + tmp * zMatrix.getEntry(k, j)); glag.setEntry(i, bMatrix.getEntry(knew, i)); glag.setEntry(i, glag.getEntry(i) + tmp * interpolationPoints.getEntry(k, i)); newPoint.setEntry(i, FastMath.max(lowerDifference.getEntry(i), FastMath.min(upperDifference.getEntry(i), tmp))); newPoint.setEntry(-ibdsav - 1, lowerDifference.getEntry(-ibdsav - 1)); newPoint.setEntry(ibdsav - 1, upperDifference.getEntry(ibdsav - 1)); for (int i = 0; i < n; i++) { final double glagValue = glag.getEntry(i); work1.setEntry(i, ZERO); if (FastMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || FastMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { work1.setEntry(i, bigstp); final double tmp2 = trustRegionCenterOffset.getEntry(i) - step * glag.getEntry(i); if (tmp2 <= lowerDifference.getEntry(i)) { work1.setEntry(i, lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)); work1.setEntry(i, upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)); final double glagValue = glag.getEntry(i);
for (int i = 0; i < n; i++) { x.set(0.); x.setEntry(i, 1.); diag[i] = a.operate(x).getEntry(i);
double xoptsq = ZERO; for (int i = 0; i < n; i++) { trustRegionCenterOffset.setEntry(i, interpolationPoints.getEntry(trustRegionCenterInterpolationPointIndex, i)); for (int i = 0; i <= j; i++) { if (i < j) { gradientAtTrustRegionCenter.setEntry(j, gradientAtTrustRegionCenter.getEntry(j) + modelSecondDerivativesValues.getEntry(ih) * trustRegionCenterOffset.getEntry(i)); gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + modelSecondDerivativesValues.getEntry(ih) * trustRegionCenterOffset.getEntry(j)); ih++; gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + temp * interpolationPoints.getEntry(k, i)); work2.setEntry(k, sum); final double temp = fracsq - HALF * sum; for (int i = 0; i < n; i++) { work1.setEntry(i, bMatrix.getEntry(k, i)); lagrangeValuesAtNewPoint.setEntry(i, sum * interpolationPoints.getEntry(k, i) + temp * trustRegionCenterOffset.getEntry(i)); final int ip = npt + i; for (int j = 0; j <= i; j++) { for (int k = 0; k < npt; k++) { sumz += zMatrix.getEntry(k, m); lagrangeValuesAtNewPoint.setEntry(k, work2.getEntry(k) * zMatrix.getEntry(k, m)); sumw += lagrangeValuesAtNewPoint.getEntry(k); work1.setEntry(j, sum); for (int k = 0; k < npt; k++) { bMatrix.setEntry(k, j,
double xoptsq = ZERO; for (int i = 0; i < n; i++) { trustRegionCenterOffset.setEntry(i, interpolationPoints.getEntry(trustRegionCenterInterpolationPointIndex, i)); for (int i = 0; i <= j; i++) { if (i < j) { gradientAtTrustRegionCenter.setEntry(j, gradientAtTrustRegionCenter.getEntry(j) + modelSecondDerivativesValues.getEntry(ih) * trustRegionCenterOffset.getEntry(i)); gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + modelSecondDerivativesValues.getEntry(ih) * trustRegionCenterOffset.getEntry(j)); ih++; gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + temp * interpolationPoints.getEntry(k, i)); work2.setEntry(k, sum); final double temp = fracsq - HALF * sum; for (int i = 0; i < n; i++) { work1.setEntry(i, bMatrix.getEntry(k, i)); lagrangeValuesAtNewPoint.setEntry(i, sum * interpolationPoints.getEntry(k, i) + temp * trustRegionCenterOffset.getEntry(i)); final int ip = npt + i; for (int j = 0; j <= i; j++) { for (int k = 0; k < npt; k++) { sumz += zMatrix.getEntry(k, m); lagrangeValuesAtNewPoint.setEntry(k, work2.getEntry(k) * zMatrix.getEntry(k, m)); sumw += lagrangeValuesAtNewPoint.getEntry(k); work1.setEntry(j, sum); for (int k = 0; k < npt; k++) { bMatrix.setEntry(k, j,
work.setEntry(i, zMatrix.getEntry(knew, 0) * zMatrix.getEntry(i, 0)); lagrangeValuesAtNewPoint.setEntry(knew, lagrangeValuesAtNewPoint.getEntry(knew) - ONE); work.setEntry(jp, bMatrix.getEntry(knew, j)); final double d3 = (alpha * lagrangeValuesAtNewPoint.getEntry(jp) - tau * work.getEntry(jp)) / denom; final double d4 = (-beta * work.getEntry(jp) - tau * lagrangeValuesAtNewPoint.getEntry(jp)) / denom;
work.setEntry(i, zMatrix.getEntry(knew, 0) * zMatrix.getEntry(i, 0)); lagrangeValuesAtNewPoint.setEntry(knew, lagrangeValuesAtNewPoint.getEntry(knew) - ONE); work.setEntry(jp, bMatrix.getEntry(knew, j)); final double d3 = (alpha * lagrangeValuesAtNewPoint.getEntry(jp) - tau * work.getEntry(jp)) / denom; final double d4 = (-beta * work.getEntry(jp) - tau * lagrangeValuesAtNewPoint.getEntry(jp)) / denom;
/** * The constructor of OrdRecParameter. * It use the quantized values of rating to initialize t1 and beta. * Each threshold is initialized as the mean of two contiguous rating values. * Since the index of quantizer is always an successive non-negative integer * begin from 0, so t1 will initialize as 0.5, and the interval between two * thresholds will be 1. * @param qtz The quantizer for ratings */ OrdRecModel(Quantizer qtz) { qtzValues = qtz.getValues(); levelCount = qtzValues.getDimension(); t1 = (qtzValues.getEntry(0) + qtzValues.getEntry(1))/2; beta = new ArrayRealVector(levelCount - 2); double tr = t1; for (int i = 1; i <= beta.getDimension(); i++) { double trnext = (qtzValues.getEntry(i) + qtzValues.getEntry(i + 1)) * 0.5; beta.setEntry(i - 1, Math.log(trnext - tr)); tr = trnext; } }
lowerDifference.setEntry(j, lowerBound[j] - currentBest.getEntry(j)); upperDifference.setEntry(j, upperBound[j] - currentBest.getEntry(j)); if (lowerDifference.getEntry(j) >= -initialTrustRegionRadius) { if (lowerDifference.getEntry(j) >= ZERO) { currentBest.setEntry(j, lowerBound[j]); lowerDifference.setEntry(j, ZERO); upperDifference.setEntry(j, boundDiff); } else { currentBest.setEntry(j, lowerBound[j] + initialTrustRegionRadius); lowerDifference.setEntry(j, -initialTrustRegionRadius); upperDifference.setEntry(j, Math.max(deltaOne, initialTrustRegionRadius)); currentBest.setEntry(j, upperBound[j]); lowerDifference.setEntry(j, -boundDiff); upperDifference.setEntry(j, ZERO); } else { currentBest.setEntry(j, upperBound[j] - initialTrustRegionRadius); lowerDifference.setEntry(j, Math.min(deltaOne, deltaTwo)); upperDifference.setEntry(j, initialTrustRegionRadius);
@Override public double[] solveFToD(float[] b) { ArrayRealVector bVec = new ArrayRealVector(b.length); for (int i = 0; i < b.length; i++) { bVec.setEntry(i, b[i]); } RealVector vec = solver.solve(bVec); double[] result = new double[b.length]; for (int i = 0; i < result.length; i++) { result[i] = vec.getEntry(i); } return result; }
/** * The constructor of OrdRecParameter. * It use the quantized values of rating to initialize t1 and beta. * Each threshold is initialized as the mean of two contiguous rating values. * Since the index of quantizer is always an successive non-negative integer * begin from 0, so t1 will initialize as 0.5, and the interval between two * thresholds will be 1. * @param qtz The quantizer for ratings */ OrdRecModel(Quantizer qtz) { qtzValues = qtz.getValues(); levelCount = qtzValues.getDimension(); t1 = (qtzValues.getEntry(0) + qtzValues.getEntry(1))/2; beta = new ArrayRealVector(levelCount - 2); double tr = t1; for (int i = 1; i <= beta.getDimension(); i++) { double trnext = (qtzValues.getEntry(i) + qtzValues.getEntry(i + 1)) * 0.5; beta.setEntry(i - 1, Math.log(trnext - tr)); tr = trnext; } }
work.setEntry(i, zMatrix.getEntry(knew, 0) * zMatrix.getEntry(i, 0)); lagrangeValuesAtNewPoint.setEntry(knew, lagrangeValuesAtNewPoint.getEntry(knew) - ONE); work.setEntry(jp, bMatrix.getEntry(knew, j)); final double d3 = (alpha * lagrangeValuesAtNewPoint.getEntry(jp) - tau * work.getEntry(jp)) / denom; final double d4 = (-beta * work.getEntry(jp) - tau * lagrangeValuesAtNewPoint.getEntry(jp)) / denom;
for (int i = 0; i < n; i++) { x.set(0.); x.setEntry(i, 1.); diag[i] = a.operate(x).getEntry(i);
for (int i = 0; i < n; i++) { x.set(0.); x.setEntry(i, 1.); diag[i] = a.operate(x).getEntry(i);