/** * Total variance in target attribute * * @param residuals error * @param targetAttribute data for target attribute * @return Total variance in target attribute */ public static double ssTotal(double[] residuals, double[] targetAttribute) { return ssReg(residuals, targetAttribute) + ssError(residuals, targetAttribute); }
/** * This returns the permutation of n choose r. * * @param n the n to choose * @param r the number of elements to choose * @return the permutation of these numbers */ public static double permutation(double n, double r) { double nFac = MathUtils.factorial(n); double nMinusRFac = MathUtils.factorial((n - r)); return nFac / nMinusRFac; }//end permutation
public static double[] sampleDoublesInInterval(double[][] doubles, int l) { double[] sample = new double[l]; for (int i = 0; i < l; i++) { int rand1 = randomNumberBetween(0, doubles.length - 1); int rand2 = randomNumberBetween(0, doubles[i].length); sample[i] = doubles[rand1][rand2]; } return sample; }
/** * Discretize the given value * @param value the value to discretize * @param min the min of the distribution * @param max the max of the distribution * @param binCount the number of bins * @return the discretized value */ public static int discretize(double value, double min, double max, int binCount) { int discreteValue = (int) (binCount * normalize(value, min, max)); return clamp(discreteValue, 0, binCount - 1); }
/** * Split a string using the default separator * @param str a string that may have escaped separator * @return an array of strings */ public static String[] split(String str) { return split(str, ESCAPE_CHAR, COMMA); }
/** * Escape commas in the string using the default escape char * @param str a string * @return an escaped string */ public static String escapeString(String str) { return escapeString(str, ESCAPE_CHAR, COMMA); }
/** * This returns the entropy for a given vector of probabilities. * @param probabilities the probabilities to getFromOrigin the entropy for * @return the entropy of the given probabilities. */ public static double information(double[] probabilities) { double total = 0.0; for (double d : probabilities) { total += (-1.0 * log2(d) * d); } return total; }//end information
/** * Unescape commas in the string using the default escape char * @param str a string * @return an unescaped string */ public static String unEscapeString(String str) { return unEscapeString(str, ESCAPE_CHAR, COMMA); }
/** * * Given a finish and start time in long milliseconds, returns a * String in the format Xhrs, Ymins, Z sec, for the time difference between two times. * If finish time comes before start time then negative valeus of X, Y and Z wil return. * * @param finishTime finish time * @param startTime start time */ public static String formatTimeDiff(long finishTime, long startTime){ long timeDiff = finishTime - startTime; return formatTime(timeDiff); }
protected synchronized CopyInCopyOutBuffer initialValue() { return new CopyInCopyOutBuffer(); } };
/** * Discretize the given value * * @param value the value to discretize * @param min the min of the distribution * @param max the max of the distribution * @param binCount the number of bins * @return the discretized value */ public static int discretize(double value, double min, double max, int binCount) { int discreteValue = (int) (binCount * normalize(value, min, max)); return clamp(discreteValue, 0, binCount - 1); }
/** * This returns the permutation of n choose r. * @param n the n to choose * @param r the number of elements to choose * @return the permutation of these numbers */ public static double permutation(double n,double r) { double nFac=MathUtils.factorial(n); double nMinusRFac=MathUtils.factorial((n-r)); return nFac/nMinusRFac; }//end permutation
public static double[] sampleDoublesInInterval(double[][] doubles, int l) { double[] sample = new double[l]; for(int i=0;i<l;i++) { int rand1=randomNumberBetween(0, doubles.length-1); int rand2=randomNumberBetween(0,doubles[i].length); sample[i]=doubles[rand1][rand2]; } return sample; }
/** * Split a string using the default separator * @param str a string that may have escaped separator * @return an array of strings */ public static String[] split(String str) { return split(str, ESCAPE_CHAR, COMMA); }
/** * Escape commas in the string using the default escape char * @param str a string * @return an escaped string */ public static String escapeString(String str) { return escapeString(str, ESCAPE_CHAR, COMMA); }
/** * This returns the entropy for a given vector of probabilities. * * @param probabilities the probabilities to getFromOrigin the entropy for * @return the entropy of the given probabilities. */ public static double information(double[] probabilities) { double total = 0.0; for (double d : probabilities) { total += (-1.0 * log2(d) * d); } return total; }//end information
/** * Unescape commas in the string using the default escape char * @param str a string * @return an unescaped string */ public static String unEscapeString(String str) { return unEscapeString(str, ESCAPE_CHAR, COMMA); }
/** * This returns the combination of n choose r * @param n the number of elements overall * @param r the number of elements to choose * @return the amount of possible combinations for this applyTransformToDestination of elements */ public static double combination(double n,double r) { double nFac=MathUtils.factorial(n); double rFac=MathUtils.factorial(r); double nMinusRFac=MathUtils.factorial((n-r)); return nFac/(rFac * nMinusRFac); }//end combination
/** * This returns the combination of n choose r * * @param n the number of elements overall * @param r the number of elements to choose * @return the amount of possible combinations for this applyTransformToDestination of elements */ public static double combination(double n, double r) { double nFac = MathUtils.factorial(n); double rFac = MathUtils.factorial(r); double nMinusRFac = MathUtils.factorial((n - r)); return nFac / (rFac * nMinusRFac); }//end combination