Killed JavaEvA from comments and ressources, some maths refactored.

This commit is contained in:
Marcel Kronfeld
2008-04-18 14:36:52 +00:00
parent fdbfa5fe85
commit fb20da9657
173 changed files with 918 additions and 2221 deletions

View File

@@ -268,7 +268,7 @@ public class RNG extends Random {
}
/**
* Create a random vector with gaussian random double entries.
* Create a normalized random vector with gaussian random double entries.
*
* @param n
* @return
@@ -278,7 +278,7 @@ public class RNG extends Random {
for (int i = 0; i < result.length; i++) {
result[i] = RNG.gaussianDouble(dev);
}
Mathematics.normalizeVector(result);
Mathematics.normVect(result, result);
return result;
}
}

View File

@@ -14,6 +14,7 @@
package wsi.ra.tool;
/**
* Statistic utils.
*/
@@ -177,25 +178,6 @@ public class StatisticUtils
return maxIndex;
}
/**
* Computes the mean for an array of doubles.
*
* @param vector the array
* @return the mean
*/
public static double mean(double[] vector) {
double sum = 0;
if (vector.length == 0) {
return 0;
}
for (int i = 0; i < vector.length; i++) {
sum += vector[i];
}
return sum / (double) vector.length;
}
/**
* Returns index of minimum element in a given
* array of integers. First minimum is returned.
@@ -240,43 +222,6 @@ public class StatisticUtils
return minIndex;
}
/**
* Normalizes the doubles in the array by their sum.
*
* @param doubles the array of double
* @exception IllegalArgumentException if sum is Zero or NaN
*/
public static void normalize(double[] doubles) {
double sum = 0;
for (int i = 0; i < doubles.length; i++) {
sum += doubles[i];
}
normalize(doubles, sum);
}
/**
* Normalizes the doubles in the array using the given value.
*
* @param doubles the array of double
* @param sum the value by which the doubles are to be normalized
* @exception IllegalArgumentException if sum is zero or NaN
*/
public static void normalize(double[] doubles, double sum) {
if (Double.isNaN(sum)) {
throw new IllegalArgumentException("Can't normalize array. Sum is NaN.");
}
if (sum == 0) {
// Maybe this should just be a return.
throw new IllegalArgumentException("Can't normalize array. Sum is zero.");
}
for (int i = 0; i < doubles.length; i++) {
doubles[i] /= sum;
}
}
/**
* Computes the variance for an array of doubles.
*
@@ -305,54 +250,6 @@ public class StatisticUtils
}
}
/**
* Computes the sum of the elements of an array of doubles.
*
* @param doubles the array of double
* @return the sum of the elements
*/
public static double sum(double[] doubles) {
double sum = 0;
for (int i = 0; i < doubles.length; i++) {
sum += doubles[i];
}
return sum;
}
/**
* Computes the 2-norm of an array of doubles.
*
* @param doubles the array of double
* @return the 2-norm of the elements
*/
public static double norm(double[] doubles) {
double sqSum = 0;
for (int i = 0; i < doubles.length; i++) {
sqSum += doubles[i]*doubles[i];
}
return Math.sqrt(sqSum);
}
/**
* Computes the sum of the elements of an array of integers.
*
* @param ints the array of integers
* @return the sum of the elements
*/
public static int sum(int[] ints) {
int sum = 0;
for (int i = 0; i < ints.length; i++) {
sum += ints[i];
}
return sum;
}
/**
* Returns c*log2(c) for a given integer value c.
*