Exemplo n.º 1
0
 /**
  * Compute and return the L1 norm (sum) of the vector.
  *
  * @return the sum of the vector's values
  */
 public double sum() {
   double result = 0;
   DoubleIterator iter = values().iterator();
   while (iter.hasNext()) {
     result += iter.nextDouble();
   }
   return result;
 }
Exemplo n.º 2
0
 /**
  * Compute and return the L2 norm (Euclidian length) of the vector.
  *
  * @return The L2 norm of the vector
  */
 public double norm() {
   double ssq = 0;
   DoubleIterator iter = values().iterator();
   while (iter.hasNext()) {
     double v = iter.nextDouble();
     ssq += v * v;
   }
   return Math.sqrt(ssq);
 }