Refine search
final int n = currentBest.getDimension(); final int npt = numberOfInterpolationPoints; final ArrayRealVector glag = new ArrayRealVector(n); final ArrayRealVector hcol = new ArrayRealVector(npt); final ArrayRealVector work1 = new ArrayRealVector(n); final ArrayRealVector work2 = new ArrayRealVector(n); hcol.setEntry(k, ZERO); 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; glag.setEntry(i, bMatrix.getEntry(knew, i)); 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);
if (b.getRowDimension() != m) { throw new DimensionMismatchException(b.getRowDimension(), m); final int nColB = b.getColumnDimension(); final double[][] bp = new double[m][nColB]; final double[] tmpCol = new double[m]; final double[] vData = v.getDataRef(); double s = 0; for (int j = 0; j < m; ++j) { s += v.getEntry(j) * tmpCol[j]; return new Array2DRowRealMatrix(bp, false);
/** * Computes the new value of the features set. * * @param current Current values of the features. * @param sample Training data. * @param learningRate Learning factor. * @return the new values for the features. */ private double[] computeFeatures(double[] current, double[] sample, double learningRate) { final ArrayRealVector c = new ArrayRealVector(current, false); final ArrayRealVector s = new ArrayRealVector(sample, false); // c + learningRate * (s - c) return s.subtract(c).mapMultiplyToSelf(learningRate).add(c).toArray(); } }
/** {@inheritDoc} */ @Override public RealVector operate(final RealVector x) { // Dimension check is carried out by ebeDivide return new ArrayRealVector(MathArrays.ebeDivide(x.toArray(), diag.toArray()), false); }
/** {@inheritDoc} */ public double getCost() { final ArrayRealVector r = new ArrayRealVector(this.getResiduals()); return FastMath.sqrt(r.dotProduct(r)); }
double mean = 0.0; for(int row=0;row<n;row++) { mean += X.getEntry(row, columnId); X.addToEntry(row, columnId, -mean); meanValues.setEntry(columnId, mean); RealMatrix covarianceDD = (X.transpose().multiply(X)).scalarMultiply(1.0/(n-1.0)); RealVector eigenValues = new ArrayRealVector(decomposition.getRealEigenvalues(), false); sqrtEigenValues.setEntry(i, i, FastMath.sqrt(eigenValues.getEntry(i))); double totalVariance = 0.0; for(int i=0;i<d;i++) { totalVariance += eigenValues.getEntry(i);
final int n = currentBest.getDimension(); final int npt = numberOfInterpolationPoints; 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); } else if (trustRegionCenterOffset.getEntry(i) >= upperDifference.getEntry(i) && gradientAtTrustRegionCenter.getEntry(i) <= ZERO) { xbdi.setEntry(i, ONE); if (xbdi.getEntry(i) != ZERO) { ++nact; trialStepPoint.setEntry(i, ZERO); 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));
/** {@inheritDoc} */ public RealVector getSigma(double covarianceSingularityThreshold) { final RealMatrix cov = this.getCovariances(covarianceSingularityThreshold); final int nC = cov.getColumnDimension(); final RealVector sig = new ArrayRealVector(nC); for (int i = 0; i < nC; ++i) { sig.setEntry(i, FastMath.sqrt(cov.getEntry(i,i))); } return sig; }
final RealVector residuals) { final int nR = jacobian.getRowDimension(); final int nC = jacobian.getColumnDimension(); final RealVector jTr = new ArrayRealVector(nC); jTr.setEntry(j, jTr.getEntry(j) + residuals.getEntry(i) * jacobian.getEntry(i, j));
final int solvedCols = FastMath.min(nR, nC); double[] currentResiduals = current.getResiduals().toArray(); double currentCost = current.getCost(); double[] currentPoint = current.getPoint().toArray(); diag[k] = dk; xNorm = FastMath.sqrt(xNorm); sum += weightedJacobian[i][pj] * qtf[i]; maxCosine = FastMath.max(maxCosine, FastMath.abs(sum) / (s * currentCost)); current = problem.evaluate(new ArrayRealVector(currentPoint)); currentResiduals = current.getResiduals().toArray(); currentCost = current.getCost(); currentPoint = current.getPoint().toArray();
transitionMatrixT = transitionMatrix.transpose(); controlMatrix = new Array2DRowRealMatrix(); } else { controlMatrix = processModel.getControlMatrix(); measurementMatrixT = measurementMatrix.transpose(); stateEstimation = new ArrayRealVector(transitionMatrix.getColumnDimension()); } else { stateEstimation = processModel.getInitialStateEstimate(); if (transitionMatrix.getColumnDimension() != stateEstimation.getDimension()) { throw new DimensionMismatchException(transitionMatrix.getColumnDimension(), stateEstimation.getDimension());
this.xL.set(0.); this.r1 = this.b.copy(); this.y = this.m == null ? this.b.copy() : this.m.operate(this.r1); if ((this.m != null) && this.check) { checkSymmetry(this.m, this.r1, this.y, this.m.operate(this.y)); this.beta1 = FastMath.sqrt(this.beta1); throwNPDLOException(this.m, this.y); this.beta = FastMath.sqrt(this.beta); this.tnorm = alpha * alpha + this.beta * this.beta; this.ynorm2 = 0.; this.gmax = FastMath.abs(alpha) + MACH_PREC; this.gmin = this.gmax; this.wbar = new ArrayRealVector(this.a.getRowDimension()); this.wbar.set(0.); } else {
final int n = currentBest.getDimension(); final int npt = numberOfInterpolationPoints; final int ndim = bMatrix.getRowDimension(); 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); nfm <= n) { stepa = initialTrustRegionRadius; if (upperDifference.getEntry(nfmm) == ZERO) { stepa = -stepa; 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)); 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]);
/** * Computes the cost. * * @param residuals Residuals. * @return the cost. * @see #computeResiduals(double[]) * @since 3.1 */ protected double computeCost(double[] residuals) { final ArrayRealVector r = new ArrayRealVector(residuals); return FastMath.sqrt(r.dotProduct(getWeight().operate(r))); }
residualsWeights[i] = weightMatrix.getEntry(i, i); for (int i = 0; i < nR; ++i) { final double[] grad = weightedJacobian.getRow(i); final double weight = residualsWeights[i]; final double residual = currentResiduals[i]; new LUDecomposition(mA).getSolver() : new QRDecomposition(mA).getSolver(); final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
final int n = qrt.length; final int m = qrt[0].length; if (b.getDimension() != m) { throw new DimensionMismatchException(b.getDimension(), m); final double[] y = b.toArray(); for (int minor = 0; minor < FastMath.min(m, n); minor++) { return new ArrayRealVector(x, false);
throws NullArgumentException, NoDataException, DimensionMismatchException { this(new Array2DRowRealMatrix(stateTransition), new Array2DRowRealMatrix(control), new Array2DRowRealMatrix(processNoise), new ArrayRealVector(initialStateEstimate), new Array2DRowRealMatrix(initialErrorCovariance));
for (int i = 0; i < dimension; i++) { boundDifference[i] = upperBound[i] - lowerBound[i]; minDiff = FastMath.min(minDiff, boundDifference[i]); bMatrix = new Array2DRowRealMatrix(dimension + numberOfInterpolationPoints, dimension); zMatrix = new Array2DRowRealMatrix(numberOfInterpolationPoints, numberOfInterpolationPoints - dimension - 1); interpolationPoints = new Array2DRowRealMatrix(numberOfInterpolationPoints, dimension); originShift = new ArrayRealVector(dimension); fAtInterpolationPoints = new ArrayRealVector(numberOfInterpolationPoints); trustRegionCenterOffset = new ArrayRealVector(dimension); gradientAtTrustRegionCenter = new ArrayRealVector(dimension); lowerDifference = new ArrayRealVector(dimension); upperDifference = new ArrayRealVector(dimension); modelSecondDerivativesParameters = new ArrayRealVector(numberOfInterpolationPoints); newPoint = new ArrayRealVector(dimension); alternativeNewPoint = new ArrayRealVector(dimension); trialStepPoint = new ArrayRealVector(dimension); lagrangeValuesAtNewPoint = new ArrayRealVector(dimension + numberOfInterpolationPoints); modelSecondDerivativesValues = new ArrayRealVector(dimension * (dimension + 1) / 2);
/** * 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; } }