MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / sum

Method sum

JSAT/src/jsat/linear/Vec.java:479–501  ·  view source on GitHub ↗

Computes the sum of the values in this vector @return the sum of this vector's values

()

Source from the content-addressed store, hash-verified

477 * @return the sum of this vector's values
478 */
479 public double sum()
480 {
481 /*
482 * Uses Kahan summation algorithm, which is more accurate then
483 * naively summing the values in floating point. Though it
484 * does not guarenty the best possible accuracy
485 *
486 * See: http://en.wikipedia.org/wiki/Kahan_summation_algorithm
487 */
488
489 double sum = 0;
490 double c = 0;
491 for(IndexValue iv : this)
492 {
493 double d = iv.getValue();
494 double y = d - c;
495 double t = sum+y;
496 c = (t - sum) - y;
497 sum = t;
498 }
499
500 return sum;
501 }
502
503 /**
504 * Computes the mean value of all values stored in this vector

Callers 15

meanMethod · 0.95
testSumMethod · 0.45
testCluster_WeightedMethod · 0.45
testCluster_WeightedMethod · 0.45
testCluster_WeightedMethod · 0.45
dotMethod · 0.45
correlationMethod · 0.45
getM_Bar_for_w0Method · 0.45
getScoreMethod · 0.45
logPdfMethod · 0.45
fMethod · 0.45
logPdfMethod · 0.45

Calls 1

getValueMethod · 0.45

Tested by 4

testSumMethod · 0.36
testCluster_WeightedMethod · 0.36
testCluster_WeightedMethod · 0.36
testCluster_WeightedMethod · 0.36