/** {@inheritDoc} */ @Override public RealVector mapMultiply(double d) { return v.mapMultiply(d); }
/** * Subtract {@code v} from this vector. * Returns a new vector. Does not change instance data. * * @param v Vector to be subtracted. * @return {@code this} - {@code v}. * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} vector. */ public RealVector subtract(RealVector v) throws DimensionMismatchException { checkVectorDimensions(v); RealVector result = v.mapMultiply(-1d); Iterator<Entry> it = iterator(); while (it.hasNext()) { final Entry e = it.next(); final int index = e.getIndex(); result.setEntry(index, e.getValue() + result.getEntry(index)); } return result; }
/** * Find the orthogonal projection of this vector onto another vector. * * @param v vector onto which instance must be projected. * @return projection of the instance onto {@code v}. * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} vector. * @throws MathArithmeticException if {@code this} or {@code v} is the null * vector */ public RealVector projection(final RealVector v) throws DimensionMismatchException, MathArithmeticException { final double norm2 = v.dotProduct(v); if (norm2 == 0.0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } return v.mapMultiply(dotProduct(v) / v.dotProduct(v)); }
/** {@inheritDoc} */ @Override protected void updateClusterParameters() { assertModifiable(); //fetch hyperparameters int kappa_n = kappa0 + size; int nu = nu0 + size; RealVector mu = xi_sum.mapDivide(size); RealVector mu_mu0 = mu.subtract(mu0); RealMatrix C = xi_square_sum.subtract( ( mu.outerProduct(mu) ).scalarMultiply(size) ); RealMatrix psi = psi0.add( C.add( ( mu_mu0.outerProduct(mu_mu0) ).scalarMultiply(kappa0*size/(double)kappa_n) ));// mean = ( mu0.mapMultiply(kappa0) ).add( mu.mapMultiply(size) ).mapDivide(kappa_n); synchronized(this) { covariance = psi.scalarMultiply( (kappa_n+1.0)/(kappa_n*(nu - dimensions + 1.0)) ); cache_covariance_determinant = null; cache_covariance_inverse = null; } meanError = calculateMeanError(psi, kappa_n, nu); meanDf = nu-dimensions+1; } }
/** * Get a new equation equivalent to this one with a positive right hand side. * @param constraint reference constraint * @return new equation */ private LinearConstraint normalize(final LinearConstraint constraint) { if (constraint.getValue() < 0) { return new LinearConstraint(constraint.getCoefficients().mapMultiply(-1), constraint.getRelationship().oppositeRelationship(), -1 * constraint.getValue()); } return new LinearConstraint(constraint.getCoefficients(), constraint.getRelationship(), constraint.getValue()); }
/** * Get a new equation equivalent to this one with a positive right hand side. * @param constraint reference constraint * @return new equation */ private LinearConstraint normalize(final LinearConstraint constraint) { if (constraint.getValue() < 0) { return new LinearConstraint(constraint.getCoefficients().mapMultiply(-1), constraint.getRelationship().oppositeRelationship(), -1 * constraint.getValue()); } return new LinearConstraint(constraint.getCoefficients(), constraint.getRelationship(), constraint.getValue()); }
RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.toArray(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1, maximize ? f.getConstantTerm() : -1 * f.getConstantTerm());
matrix.setEntry(zIndex, zIndex, maximize ? 1 : -1); RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.toArray(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1,
final RealVector v = y.mapMultiply(1. / beta); y = a.operate(v); daxpbypz(-shift, v, -beta / oldb, r1, y);
final RealVector v = this.y.mapMultiply(1. / this.beta1); this.y = this.a.operate(v); if (this.check) {
/** {@inheritDoc} */ @Override public RealVector mapMultiply(double d) { return v.mapMultiply(d); }
/** {@inheritDoc} */ @Override public RealVector mapMultiply(double d) { return v.mapMultiply(d); }
/** * Subtract {@code v} from this vector. * Returns a new vector. Does not change instance data. * * @param v Vector to be subtracted. * @return {@code this} - {@code v}. * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} vector. */ public RealVector subtract(RealVector v) throws DimensionMismatchException { checkVectorDimensions(v); RealVector result = v.mapMultiply(-1d); Iterator<Entry> it = iterator(); while (it.hasNext()) { final Entry e = it.next(); final int index = e.getIndex(); result.setEntry(index, e.getValue() + result.getEntry(index)); } return result; }
/** * Find the orthogonal projection of this vector onto another vector. * * @param v vector onto which instance must be projected. * @return projection of the instance onto {@code v}. * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} vector. * @throws MathArithmeticException if {@code this} or {@code v} is the null * vector */ public RealVector projection(final RealVector v) throws DimensionMismatchException, MathArithmeticException { final double norm2 = v.dotProduct(v); if (norm2 == 0.0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } return v.mapMultiply(dotProduct(v) / v.dotProduct(v)); }
/** * Find the orthogonal projection of this vector onto another vector. * * @param v vector onto which instance must be projected. * @return projection of the instance onto {@code v}. * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} vector. * @throws MathArithmeticException if {@code this} or {@code v} is the null * vector */ public RealVector projection(final RealVector v) throws DimensionMismatchException, MathArithmeticException { final double norm2 = v.dotProduct(v); if (norm2 == 0.0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } return v.mapMultiply(dotProduct(v) / v.dotProduct(v)); }
private RealVector computeMean(int k, double sumGamma){ RealVector res = new ArrayRealVector(data.getColumnDimension()); for (int i=0;i<data.getRowDimension();i++){ res = res.add(data.getRowVector(i).mapMultiply(gammas[i][k])); } return res.mapDivide(sumGamma); }
@Override public double[] gradient(double[] X) { RealVector x = new ArrayRealVector(X); RealVector ret = new ArrayRealVector(dim); for(int i=0; i<socpConstraintParametersList.size(); i++){ SOCPConstraintParameters param = socpConstraintParametersList.get(i); double t = this.buildT(param, x); RealVector u = this.buildU(param, x); double t2uu = t*t - u.dotProduct(u); RealMatrix Jacob = this.buildJ(param, x); int k = u.getDimension(); RealVector G = new ArrayRealVector(k+1); G.setSubVector(0, u); G.setEntry(k, -t); RealVector ret_i = Jacob.operate(G).mapMultiply((2./t2uu)); ret = ret.add(ret_i); } return ret.toArray(); }
/** * Get a new equation equivalent to this one with a positive right hand side. * @param constraint reference constraint * @return new equation */ private LinearConstraint normalize(final LinearConstraint constraint) { if (constraint.getValue() < 0) { return new LinearConstraint(constraint.getCoefficients().mapMultiply(-1), constraint.getRelationship().oppositeRelationship(), -1 * constraint.getValue()); } return new LinearConstraint(constraint.getCoefficients(), constraint.getRelationship(), constraint.getValue()); }
/** * Get a new equation equivalent to this one with a positive right hand side. * @param constraint reference constraint * @return new equation */ private LinearConstraint normalize(final LinearConstraint constraint) { if (constraint.getValue() < 0) { return new LinearConstraint(constraint.getCoefficients().mapMultiply(-1), constraint.getRelationship().oppositeRelationship(), -1 * constraint.getValue()); } return new LinearConstraint(constraint.getCoefficients(), constraint.getRelationship(), constraint.getValue()); }
/** * Get a new equation equivalent to this one with a positive right hand side. * @param constraint reference constraint * @return new equation */ private LinearConstraint normalize(final LinearConstraint constraint) { if (constraint.getValue() < 0) { return new LinearConstraint(constraint.getCoefficients().mapMultiply(-1), constraint.getRelationship().oppositeRelationship(), -1 * constraint.getValue()); } return new LinearConstraint(constraint.getCoefficients(), constraint.getRelationship(), constraint.getValue()); }