/** * Divides all of the given elements of the vector by the 2-norm (the square * root of the sum of the squared values of the elements). If the 2-norm is * zero (which means all the elements are zero), then the vector is not * modified. * * @param vector * The vector to divide the elements by the 2-norm. It is modified by * this method. */ public static void divideByNorm2Equals( final Vector vector) { final double norm2 = vector.norm2(); if (norm2 != 0.0) { vector.scaleEquals(1.0 / norm2); } }
/** * Divides all of the given elements of the vector by the 2-norm (the square * root of the sum of the squared values of the elements). If the 2-norm is * zero (which means all the elements are zero), then the vector is not * modified. * * @param vector * The vector to divide the elements by the 2-norm. It is modified by * this method. */ public static void divideByNorm2Equals( final Vector vector) { final double norm2 = vector.norm2(); if (norm2 != 0.0) { vector.scaleEquals(1.0 / norm2); } }
/** * Divides all of the given elements of the vector by the 2-norm (the square * root of the sum of the squared values of the elements). If the 2-norm is * zero (which means all the elements are zero), then the vector is not * modified. * * @param vector * The vector to divide the elements by the 2-norm. It is modified by * this method. */ public static void divideByNorm2Equals( final Vector vector) { final double norm2 = vector.norm2(); if (norm2 != 0.0) { vector.scaleEquals(1.0 / norm2); } }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
/** * Evaluate the this function on the provided cluster. * * @param cluster The cluster to calculate the function on. * @return The result of applying this function to the cluster. */ public double evaluate(NormalizedCentroidCluster<V> cluster) { double total = 1.0; Vector centroid = cluster.getCentroid().convertToVector(); Vector normalizedCentroid = cluster.getNormalizedCentroid().convertToVector(); //if centroid is 0.0, cosine measure returns 0.0 if (centroid.norm2() != 0.0) { total -= centroid.dotProduct(normalizedCentroid) / centroid.norm2(); } total *= cluster.getMembers().size(); return total; }
/** * Evaluate the this function on the provided cluster. * * @param cluster The cluster to calculate the function on. * @return The result of applying this function to the cluster. */ public double evaluate(NormalizedCentroidCluster<V> cluster) { double total = 1.0; Vector centroid = cluster.getCentroid().convertToVector(); Vector normalizedCentroid = cluster.getNormalizedCentroid().convertToVector(); //if centroid is 0.0, cosine measure returns 0.0 if (centroid.norm2() != 0.0) { total -= centroid.dotProduct(normalizedCentroid) / centroid.norm2(); } total *= cluster.getMembers().size(); return total; }
/** * Evaluate the this function on the provided cluster. * * @param cluster The cluster to calculate the function on. * @return The result of applying this function to the cluster. */ public double evaluate(NormalizedCentroidCluster<V> cluster) { double total = 1.0; Vector centroid = cluster.getCentroid().convertToVector(); Vector normalizedCentroid = cluster.getNormalizedCentroid().convertToVector(); //if centroid is 0.0, cosine measure returns 0.0 if (centroid.norm2() != 0.0) { total -= centroid.dotProduct(normalizedCentroid) / centroid.norm2(); } total *= cluster.getMembers().size(); return total; }
public boolean test_backtrack(Matrix W, Matrix grad, Matrix prox, double eta){ Matrix tmp = prox.clone(); tmp.minusEquals(W); Vector tmpvec = tmp.getColumn(0); return ( eval(prox) <= eval(W) + grad.getColumn(0).dotProduct(tmpvec) + 0.5*eta*tmpvec.norm2()); } }
vectorFactory.createUniformRandom(this.dimensionality, -initializationRange, initializationRange, this.random); if (initialWeights.norm2() < (1.0 / sqrtLambda))
vectorFactory.createUniformRandom(this.dimensionality, -initializationRange, initializationRange, this.random); if (initialWeights.norm2() < (1.0 / sqrtLambda))
vectorFactory.createUniformRandom(this.dimensionality, -initializationRange, initializationRange, this.random); if (initialWeights.norm2() < (1.0 / sqrtLambda))
@Override protected boolean step() { SumSquaredErrorCostFunction.Cache cost = SumSquaredErrorCostFunction.Cache.compute( this.getResult(), this.getData() ); Vector lastParameters = this.lineFunction.getVectorOffset(); Vector direction = cost.JtJ.solve(cost.Jte); double directionNorm = direction.norm2(); if( directionNorm > STEP_MAX ) { direction.scaleEquals( STEP_MAX / directionNorm ); } this.lineFunction.setDirection( direction ); InputOutputPair<Vector,Double> result = this.getLineMinimizer().minimizeAlongDirection( this.lineFunction, cost.parameterCost, cost.Jte ); this.lineFunction.setVectorOffset( result.getInput() ); this.setResultCost( result.getOutput() ); Vector delta = result.getInput().minus( lastParameters ); this.getResult().convertFromVector( result.getInput() ); return !MinimizationStoppingCriterion.convergence( result.getInput(), result.getOutput(), cost.Jte, delta, this.getTolerance() ); }
@Override protected boolean step() { SumSquaredErrorCostFunction.Cache cost = SumSquaredErrorCostFunction.Cache.compute( this.getResult(), this.getData() ); Vector lastParameters = this.lineFunction.getVectorOffset(); Vector direction = cost.JtJ.solve(cost.Jte); double directionNorm = direction.norm2(); if( directionNorm > STEP_MAX ) { direction.scaleEquals( STEP_MAX / directionNorm ); } this.lineFunction.setDirection( direction ); InputOutputPair<Vector,Double> result = this.getLineMinimizer().minimizeAlongDirection( this.lineFunction, cost.parameterCost, cost.Jte ); this.lineFunction.setVectorOffset( result.getInput() ); this.setResultCost( result.getOutput() ); Vector delta = result.getInput().minus( lastParameters ); this.getResult().convertFromVector( result.getInput() ); return !MinimizationStoppingCriterion.convergence( result.getInput(), result.getOutput(), cost.Jte, delta, this.getTolerance() ); }
@Override protected boolean step() { SumSquaredErrorCostFunction.Cache cost = SumSquaredErrorCostFunction.Cache.compute( this.getResult(), this.getData() ); Vector lastParameters = this.lineFunction.getVectorOffset(); Vector direction = cost.JtJ.solve(cost.Jte); double directionNorm = direction.norm2(); if( directionNorm > STEP_MAX ) { direction.scaleEquals( STEP_MAX / directionNorm ); } this.lineFunction.setDirection( direction ); InputOutputPair<Vector,Double> result = this.getLineMinimizer().minimizeAlongDirection( this.lineFunction, cost.parameterCost, cost.Jte ); this.lineFunction.setVectorOffset( result.getInput() ); this.setResultCost( result.getOutput() ); Vector delta = result.getInput().minus( lastParameters ); this.getResult().convertFromVector( result.getInput() ); return !MinimizationStoppingCriterion.convergence( result.getInput(), result.getOutput(), cost.Jte, delta, this.getTolerance() ); }
f.convertFromVector( wnew ); double delta = wnew.minus( w ).norm2(); return delta > this.getTolerance();
f.convertFromVector( wnew ); double delta = wnew.minus( w ).norm2(); return delta > this.getTolerance();
f.convertFromVector( wnew ); double delta = wnew.minus( w ).norm2(); return delta > this.getTolerance();