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); } else if (trustRegionCenterOffset.getEntry(i) >= upperDifference.getEntry(i) && gradientAtTrustRegionCenter.getEntry(i) <= ZERO) { xbdi.setEntry(i, ONE); if (xbdi.getEntry(i) != ZERO) { ++nact; gnew.setEntry(i, gradientAtTrustRegionCenter.getEntry(i)); stepsq = ZERO; 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)); final double d1 = s.getEntry(i); stepsq += d1 * d1; shs = ZERO; for (int i = 0; i < n; i++) {
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); } else if (trustRegionCenterOffset.getEntry(i) >= upperDifference.getEntry(i) && gradientAtTrustRegionCenter.getEntry(i) <= ZERO) { xbdi.setEntry(i, ONE); if (xbdi.getEntry(i) != ZERO) { ++nact; gnew.setEntry(i, gradientAtTrustRegionCenter.getEntry(i)); stepsq = ZERO; 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)); final double d1 = s.getEntry(i); stepsq += d1 * d1; shs = ZERO; for (int i = 0; i < n; i++) {
final double tmp = zMatrix.getEntry(knew, j); for (int k = 0; k < npt; k++) { hcol.setEntry(k, hcol.getEntry(k) + tmp * zMatrix.getEntry(k, j)); final double alpha = hcol.getEntry(knew); final double ha = HALF * alpha; double tmp = ZERO; for (int j = 0; j < n; j++) { tmp += interpolationPoints.getEntry(k, j) * trustRegionCenterOffset.getEntry(j); tmp *= hcol.getEntry(k); for (int i = 0; i < n; i++) { glag.setEntry(i, glag.getEntry(i) + tmp * interpolationPoints.getEntry(k, i)); double distsq = ZERO; for (int i = 0; i < n; i++) { final double tmp = interpolationPoints.getEntry(k, i) - trustRegionCenterOffset.getEntry(i); dderiv += glag.getEntry(i) * tmp; distsq += tmp * tmp; final double tmp = interpolationPoints.getEntry(k, i) - trustRegionCenterOffset.getEntry(i); if (tmp > ZERO) { if (slbd * tmp < lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { slbd = (lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp; ilbd = -i - 1; if (subd * tmp > upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) {
final double tmp = zMatrix.getEntry(knew, j); for (int k = 0; k < npt; k++) { hcol.setEntry(k, hcol.getEntry(k) + tmp * zMatrix.getEntry(k, j)); final double alpha = hcol.getEntry(knew); final double ha = HALF * alpha; double tmp = ZERO; for (int j = 0; j < n; j++) { tmp += interpolationPoints.getEntry(k, j) * trustRegionCenterOffset.getEntry(j); tmp *= hcol.getEntry(k); for (int i = 0; i < n; i++) { glag.setEntry(i, glag.getEntry(i) + tmp * interpolationPoints.getEntry(k, i)); double distsq = ZERO; for (int i = 0; i < n; i++) { final double tmp = interpolationPoints.getEntry(k, i) - trustRegionCenterOffset.getEntry(i); dderiv += glag.getEntry(i) * tmp; distsq += tmp * tmp; final double tmp = interpolationPoints.getEntry(k, i) - trustRegionCenterOffset.getEntry(i); if (tmp > ZERO) { if (slbd * tmp < lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { slbd = (lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp; ilbd = -i - 1; if (subd * tmp > upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) {
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); lowerDifference.setEntry(j, -initialTrustRegionRadius); final double deltaOne = upperBound[j] - currentBest.getEntry(j); upperDifference.setEntry(j, FastMath.max(deltaOne, initialTrustRegionRadius)); } else if (upperDifference.getEntry(j) <= initialTrustRegionRadius) { if (upperDifference.getEntry(j) <= ZERO) { currentBest.setEntry(j, upperBound[j]); lowerDifference.setEntry(j, -boundDiff); currentBest.setEntry(j, upperBound[j] - initialTrustRegionRadius); final double deltaOne = lowerBound[j] - currentBest.getEntry(j); final double deltaTwo = -initialTrustRegionRadius; lowerDifference.setEntry(j, FastMath.min(deltaOne, deltaTwo));
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); lowerDifference.setEntry(j, -initialTrustRegionRadius); final double deltaOne = upperBound[j] - currentBest.getEntry(j); upperDifference.setEntry(j, FastMath.max(deltaOne, initialTrustRegionRadius)); } else if (upperDifference.getEntry(j) <= initialTrustRegionRadius) { if (upperDifference.getEntry(j) <= ZERO) { currentBest.setEntry(j, upperBound[j]); lowerDifference.setEntry(j, -boundDiff); currentBest.setEntry(j, upperBound[j] - initialTrustRegionRadius); final double deltaOne = lowerBound[j] - currentBest.getEntry(j); final double deltaTwo = -initialTrustRegionRadius; lowerDifference.setEntry(j, FastMath.min(deltaOne, deltaTwo));
final double deltaOne = trustRegionCenterOffset.getEntry(i); xoptsq += deltaOne * deltaOne; double fsave = fAtInterpolationPoints.getEntry(0); final int kbase = 0; 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++; double temp = ZERO; for (int j = 0; j < n; j++) { temp += interpolationPoints.getEntry(k, j) * trustRegionCenterOffset.getEntry(j); temp *= modelSecondDerivativesParameters.getEntry(k); for (int i = 0; i < n; i++) { gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + temp * interpolationPoints.getEntry(k, i)); for (int j = 0; j < n; j++) { double bdtest = bdtol; if (newPoint.getEntry(j) == lowerDifference.getEntry(j)) { bdtest = work1.getEntry(j); if (newPoint.getEntry(j) == upperDifference.getEntry(j)) { bdtest = -work1.getEntry(j);
final double deltaOne = trustRegionCenterOffset.getEntry(i); xoptsq += deltaOne * deltaOne; double fsave = fAtInterpolationPoints.getEntry(0); final int kbase = 0; 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++; double temp = ZERO; for (int j = 0; j < n; j++) { temp += interpolationPoints.getEntry(k, j) * trustRegionCenterOffset.getEntry(j); temp *= modelSecondDerivativesParameters.getEntry(k); for (int i = 0; i < n; i++) { gradientAtTrustRegionCenter.setEntry(i, gradientAtTrustRegionCenter.getEntry(i) + temp * interpolationPoints.getEntry(k, i)); for (int j = 0; j < n; j++) { double bdtest = bdtol; if (newPoint.getEntry(j) == lowerDifference.getEntry(j)) { bdtest = work1.getEntry(j); if (newPoint.getEntry(j) == upperDifference.getEntry(j)) { bdtest = -work1.getEntry(j);
work.setEntry(i, zMatrix.getEntry(knew, 0) * zMatrix.getEntry(i, 0)); final double alpha = work.getEntry(knew); final double tau = lagrangeValuesAtNewPoint.getEntry(knew); lagrangeValuesAtNewPoint.setEntry(knew, lagrangeValuesAtNewPoint.getEntry(knew) - ONE); for (int i = 0; i < npt; i++) { zMatrix.setEntry(i, 0, d1 * zMatrix.getEntry(i, 0) - d2 * lagrangeValuesAtNewPoint.getEntry(i)); final int jp = npt + j; 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 <= jp; i++) { bMatrix.setEntry(i, j, bMatrix.getEntry(i, j) + d3 * lagrangeValuesAtNewPoint.getEntry(i) + d4 * work.getEntry(i)); if (i >= npt) { bMatrix.setEntry(jp, (i - npt), bMatrix.getEntry(i, j));
work.setEntry(i, zMatrix.getEntry(knew, 0) * zMatrix.getEntry(i, 0)); final double alpha = work.getEntry(knew); final double tau = lagrangeValuesAtNewPoint.getEntry(knew); lagrangeValuesAtNewPoint.setEntry(knew, lagrangeValuesAtNewPoint.getEntry(knew) - ONE); for (int i = 0; i < npt; i++) { zMatrix.setEntry(i, 0, d1 * zMatrix.getEntry(i, 0) - d2 * lagrangeValuesAtNewPoint.getEntry(i)); final int jp = npt + j; 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 <= jp; i++) { bMatrix.setEntry(i, j, bMatrix.getEntry(i, j) + d3 * lagrangeValuesAtNewPoint.getEntry(i) + d4 * work.getEntry(i)); if (i >= npt) { bMatrix.setEntry(jp, (i - npt), bMatrix.getEntry(i, j));
originShift.setEntry(j, currentBest.getEntry(j)); for (int k = 0; k < npt; k++) { interpolationPoints.setEntry(k, j, ZERO); nfm <= n) { stepa = initialTrustRegionRadius; if (upperDifference.getEntry(nfmm) == ZERO) { stepa = -stepa; stepa = interpolationPoints.getEntry(nfx, nfxm); stepb = -initialTrustRegionRadius; if (lowerDifference.getEntry(nfxm) == ZERO) { stepb = FastMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); if (upperDifference.getEntry(nfxm) == ZERO) { stepb = FastMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { currentBest.setEntry(j, lowerBound[j]); if (interpolationPoints.getEntry(nfm, j) == upperDifference.getEntry(j)) { currentBest.setEntry(j, upperBound[j]); fbeg = f; trustRegionCenterInterpolationPointIndex = 0; } else if (f < fAtInterpolationPoints.getEntry(trustRegionCenterInterpolationPointIndex)) { trustRegionCenterInterpolationPointIndex = nfm;
originShift.setEntry(j, currentBest.getEntry(j)); for (int k = 0; k < npt; k++) { interpolationPoints.setEntry(k, j, ZERO); nfm <= n) { stepa = initialTrustRegionRadius; if (upperDifference.getEntry(nfmm) == ZERO) { stepa = -stepa; stepa = interpolationPoints.getEntry(nfx, nfxm); stepb = -initialTrustRegionRadius; if (lowerDifference.getEntry(nfxm) == ZERO) { stepb = FastMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); if (upperDifference.getEntry(nfxm) == ZERO) { stepb = FastMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { currentBest.setEntry(j, lowerBound[j]); if (interpolationPoints.getEntry(nfm, j) == upperDifference.getEntry(j)) { currentBest.setEntry(j, upperBound[j]); fbeg = f; trustRegionCenterInterpolationPointIndex = 0; } else if (f < fAtInterpolationPoints.getEntry(trustRegionCenterInterpolationPointIndex)) { trustRegionCenterInterpolationPointIndex = nfm;
@Override public double getIndexValue(int i) { try { return values.getEntry(i); } catch (IndexOutOfBoundsException e) { // have to catch and rethrow to avoid RuntimeException throw new IllegalArgumentException("invalid discrete value", e); } }
double s = 0; for (int j = 0; j < m; ++j) { s += v.getEntry(j) * tmpCol[j];
/** * Get the rth threshold. * * @param thresholdIndex The index of the threshold * @return the rth threshold. */ public double getThreshold(int thresholdIndex) { double tr = t1; if(thresholdIndex < 0) { return Double.NEGATIVE_INFINITY; } else if(thresholdIndex == 0){ return tr; } else if(thresholdIndex > beta.getDimension()) { return Double.POSITIVE_INFINITY; } else { for(int k = 0; k < thresholdIndex; k++) { tr += Math.exp(beta.getEntry(k)); } return tr; } }
@Override public int index(double val) { final int n = values.getDimension(); assert n > 0; int closest = -1; double closev = Double.MAX_VALUE; for (int i = 0; i < n; i++) { double diff = Math.abs(val - values.getEntry(i)); if (diff <= closev) { // <= to round up closev = diff; closest = i; } } if (closest < 0) { throw new IllegalArgumentException("could not quantize value"); } else { return closest; } }
@Override public double getIndexValue(int i) { try { return values.getEntry(i); } catch (IndexOutOfBoundsException e) { // have to catch and rethrow to avoid RuntimeException throw new IllegalArgumentException("invalid discrete value", e); } }
/** * Get the rth threshold. * * @param thresholdIndex The index of the threshold * @return the rth threshold. */ public double getThreshold(int thresholdIndex) { double tr = t1; if(thresholdIndex < 0) { return Double.NEGATIVE_INFINITY; } else if(thresholdIndex == 0){ return tr; } else if(thresholdIndex > beta.getDimension()) { return Double.POSITIVE_INFINITY; } else { for(int k = 0; k < thresholdIndex; k++) { tr += Math.exp(beta.getEntry(k)); } return tr; } }
@Override public int index(double val) { final int n = values.getDimension(); assert n > 0; int closest = -1; double closev = Double.MAX_VALUE; for (int i = 0; i < n; i++) { double diff = Math.abs(val - values.getEntry(i)); if (diff <= closev) { // <= to round up closev = diff; closest = i; } } if (closest < 0) { throw new IllegalArgumentException("could not quantize value"); } else { return closest; } }
double s = 0; for (int j = 0; j < m; ++j) { s += v.getEntry(j) * tmpCol[j];