Java Code Examples for org.apache.commons.math3.stat.StatUtils#sum()

The following examples show how to use org.apache.commons.math3.stat.StatUtils#sum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KMeansUtil.java    From Alink with Apache License 2.0 5 votes vote down vote up
public static double[] getProbArrayFromDistanceArray(double[] distances){
    double sum = StatUtils.sum(distances);
    double ratio = 1.0 / sum / (distances.length - 1);
    double[] probs = new double[distances.length];
    Arrays.fill(probs, 1.0 / (distances.length - 1));
    BLAS.axpy(-ratio, distances, probs);
    return probs;
}
 
Example 2
Source File: ClusterMetricsSummary.java    From Alink with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMetrics toMetrics() {
	Params params = new Params();

	DenseVector meanVector = sumVector.scale(1.0 / total);
	String[] clusters = new String[k];
	double[] countArray = new double[k];
	double ssb = 0.0;
	double ssw = 0.0;
	double compactness = 0.0;
	double seperation = 0.0;

	for(int i = 0; i < this.k; i++){
		clusters[i] = clusterId.get(i);
		countArray[i] = clusterCnt.get(i);
		ssb += Math.pow(distance.calc(this.meanVector.get(i), meanVector), 2) * clusterCnt.get(i);
		ssw += distanceSquareSum.get(i);
		compactness += this.compactness.get(i);
	}

	double[] DBIndexArray = new double[k];
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			double d = distance.calc(this.meanVector.get(i), this.meanVector.get(j));
			seperation += d;
			double tmp = (this.compactness.get(i) + this.compactness.get(j)) / d;
			DBIndexArray[i] = Math.max(DBIndexArray[i], tmp);
			DBIndexArray[j] = Math.max(DBIndexArray[j], tmp);
		}
	}

	double DBIndex = StatUtils.sum(DBIndexArray) / k;
	params.set(ClusterMetrics.SSB, ssb);
	params.set(ClusterMetrics.SSW, ssw);
	params.set(ClusterMetrics.COMPACTNESS, compactness / k);
	params.set(ClusterMetrics.K, k);
	params.set(ClusterMetrics.COUNT, total);
	params.set(ClusterMetrics.SEPERATION, 2 * seperation / (k * k - k));
	params.set(ClusterMetrics.DAVIES_BOULDIN, DBIndex);
	params.set(ClusterMetrics.CALINSKI_HARABAZ, ssb * (total - k) / ssw / (k - 1));
	params.set(ClusterMetrics.CLUSTER_ARRAY, clusters);
	params.set(ClusterMetrics.COUNT_ARRAY, countArray);

	return new ClusterMetrics(params);
}
 
Example 3
Source File: AggregateFunctions.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Override
public Double summarize(NumericColumn<?> column) {
  return StatUtils.sum(removeMissing(column));
}
 
Example 4
Source File: Sum.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public double compute(double... values) {
	return StatUtils.sum(values);
}
 
Example 5
Source File: AggregateFunctions.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Override
public Double summarize(NumericColumn<?> column) {
  return StatUtils.sum(removeMissing(column));
}
 
Example 6
Source File: SumValuesInArray.java    From levelup-java-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void sum_values_in_array_with_apache_commons () {
	
	double total = StatUtils.sum(numbers);
	assertEquals(389, total, 0);
}
 
Example 7
Source File: SumValueInList.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void sum_values_in_list_apache() {

	double[] arrayToSume = ArrayUtils.toPrimitive(NUMBERS_FOR_SUM
			.toArray(new Double[NUMBERS_FOR_SUM.size()]));

	double sum = StatUtils.sum(arrayToSume);

	assertEquals(100, sum, 0);
}
 
Example 8
Source File: KnoxShellTable.java    From knox with Apache License 2.0 2 votes vote down vote up
/**
 * Calculates the sum of specified column
 * @param colName the column for which the sum will be calculated
 * @return sum
 */
public double sum(String colName) {
  return StatUtils.sum(toDoubleArray(colName));
}