Codota Logo
MathUtils
Code IndexAdd Codota to your IDE (free)

How to use
MathUtils
in
org.canova.api.util

Best Java code snippets using org.canova.api.util.MathUtils (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ArrayList a =
  • Codota Iconnew ArrayList<String>()
  • Codota Iconnew ArrayList()
  • Codota Iconnew ArrayList<Object>()
  • Smart code suggestions by Codota
}
origin: org.nd4j/canova-api

/**
 * 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);
}
origin: org.nd4j/canova-api

/**
 * This returns the sum of products for the given
 * numbers.
 *
 * @param nums the sum of products for the give numbers
 * @return the sum of products for the given numbers
 */
public static double sumOfProducts(double[]... nums) {
 if (nums == null || nums.length < 1) return 0;
 double sum = 0;
 for (int i = 0; i < nums.length; i++) {
     /* The ith column for all of the rows */
  double[] column = column(i, nums);
  sum += times(column);
 }
 return sum;
}//end sumOfProducts
origin: org.nd4j/canova-api

/**
 * 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
origin: org.nd4j/canova-api

/**
 * This returns the minimized loss values for a given vector.
 * It is assumed that  the x, y pairs are at
 * vector[i], vector[i+1]
 *
 * @param vector the vector of numbers to getFromOrigin the weights for
 * @return a double array with w_0 and w_1 are the associated indices.
 */
public static double[] weightsFor(double[] vector) {
   /* split coordinate system */
 List<double[]> coords = coordSplit(vector);
   /* x vals */
 double[] x = coords.get(0);
   /* y vals */
 double[] y = coords.get(1);
 double meanX = sum(x) / x.length;
 double meanY = sum(y) / y.length;
 double sumOfMeanDifferences = sumOfMeanDifferences(x, y);
 double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x);
 double w_1 = sumOfMeanDifferences / xDifferenceOfMean;
 double w_0 = meanY - (w_1) * meanX;
 double[] ret = new double[vector.length];
 ret[0] = w_0;
 ret[1] = w_1;
 return ret;
}//end weightsFor
origin: jpatanooga/Canova

  @Override
  public double tfidf(String word, double frequency) {
    return MathUtils.tfidf(MathUtils.tf((int) frequency),MathUtils.idf(numDocs,idf(word)));
  }
}
origin: org.nd4j/canova-api

/**
 * Returns the log-odds for a given probability.
 *
 * @param prob the probability
 * @return the log-odds after the probability has been mapped to
 * [Utils.SMALL, 1-Utils.SMALL]
 */
public static /*@pure@*/ double probToLogOdds(double prob) {
 if (gr(prob, 1) || (sm(prob, 0))) {
  throw new IllegalArgumentException("probToLogOdds: probability must " +
    "be in [0,1] " + prob);
 }
 double p = SMALL + (1.0 - 2 * SMALL) * prob;
 return Math.log(p / (1 - p));
}
origin: org.nd4j/canova-api

/**
 * Converts an array containing the natural logarithms of
 * probabilities stored in a vector back into probabilities.
 * The probabilities are assumed to sum to one.
 *
 * @param a an array holding the natural logarithms of the probabilities
 * @return the converted array
 */
public static double[] logs2probs(double[] a) {
 double max = a[maxIndex(a)];
 double sum = 0.0;
 double[] result = new double[a.length];
 for (int i = 0; i < a.length; i++) {
  result[i] = Math.exp(a[i] - max);
  sum += result[i];
 }
 normalize(result, sum);
 return result;
}//end logs2probs
origin: org.nd4j/canova-api

/**
 * This returns the determination coefficient of two vectors given a length
 *
 * @param y1 the first vector
 * @param y2 the second vector
 * @param n  the length of both vectors
 * @return the determination coefficient or r^2
 */
public static double determinationCoefficient(double[] y1, double[] y2, int n) {
 return Math.pow(correlation(y1, y2), 2);
}
origin: jpatanooga/Canova

/**
 * 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
origin: org.nd4j/canova-api

/**
 * This will return the bernoulli trial for the given event.
 * A bernoulli trial is a mechanism for detecting the probability
 * of a given event occurring k times in n independent trials
 *
 * @param n           the number of trials
 * @param k           the number of times the target event occurs
 * @param successProb the probability of the event happening
 * @return the probability of the given event occurring k times.
 */
public static double bernoullis(double n, double k, double successProb) {
 double combo = MathUtils.combination(n, k);
 double q = 1 - successProb;
 return combo * Math.pow(successProb, k) * Math.pow(q, n - k);
}//end bernoullis
origin: jpatanooga/Canova

/**
 * This returns the minimized loss values for a given vector.
 * It is assumed that  the x, y pairs are at
 * vector[i], vector[i+1]
 * @param vector the vector of numbers to getFromOrigin the weights for
 * @return a double array with w_0 and w_1 are the associated indices.
 */
public static double[] weightsFor(double[] vector) {
  /* split coordinate system */
  List<double[]> coords=coordSplit(vector);
  /* x vals */
  double[] x=coords.get(0);
  /* y vals */
  double[] y=coords.get(1);
  double meanX=sum(x)/x.length;
  double meanY=sum(y)/y.length;
  double sumOfMeanDifferences=sumOfMeanDifferences(x,y);
  double xDifferenceOfMean=sumOfMeanDifferencesOnePoint(x);
  double w_1=sumOfMeanDifferences/xDifferenceOfMean;
  double w_0=meanY  - (w_1) * meanX;
  double[] ret = new double[vector.length];
  ret[0]=w_0;
  ret[1]=w_1;
  return ret;
}//end weightsFor
origin: org.nd4j/canova-data-nlp

@Override
public double tfidf(String word, double frequency) {
  return MathUtils.tfidf(MathUtils.tf((int) frequency), MathUtils.idf(numDocs, idf(word)));
}
origin: jpatanooga/Canova

/**
 * Returns the log-odds for a given probability.
 *
 * @param prob the probability
 *
 * @return the log-odds after the probability has been mapped to
 * [Utils.SMALL, 1-Utils.SMALL]
 */
public static /*@pure@*/ double probToLogOdds(double prob) {
  if (gr(prob, 1) || (sm(prob, 0))) {
    throw new IllegalArgumentException("probToLogOdds: probability must " +
        "be in [0,1] "+prob);
  }
  double p = SMALL + (1.0 - 2 * SMALL) * prob;
  return Math.log(p / (1 - p));
}
origin: jpatanooga/Canova

/**
 * Converts an array containing the natural logarithms of
 * probabilities stored in a vector back into probabilities.
 * The probabilities are assumed to sum to one.
 *
 * @param a an array holding the natural logarithms of the probabilities
 * @return the converted array
 */
public static double[] logs2probs(double[] a) {
  double max = a[maxIndex(a)];
  double sum = 0.0;
  double[] result = new double[a.length];
  for(int i = 0; i < a.length; i++) {
    result[i] = Math.exp(a[i] - max);
    sum += result[i];
  }
  normalize(result, sum);
  return result;
}//end logs2probs
/**
origin: jpatanooga/Canova

/**
 * This returns the determination coefficient of two vectors given a length
 * @param y1 the first vector
 * @param y2 the second vector
 * @param n the length of both vectors
 * @return the determination coefficient or r^2
 */
public static  double determinationCoefficient(double[] y1, double[] y2, int n) {
  return Math.pow(correlation(y1,y2),2);
}
origin: org.nd4j/canova-api

/**
 * 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
origin: jpatanooga/Canova

/**
 * This will return the bernoulli trial for the given event.
 * A bernoulli trial is a mechanism for detecting the probability
 * of a given event occurring k times in n independent trials
 * @param n the number of trials
 * @param k the number of times the target event occurs
 * @param successProb the probability of the event happening
 * @return the probability of the given event occurring k times.
 */
public static double bernoullis(double n,double k,double successProb) {
  double combo = MathUtils.combination(n, k);
  double p = successProb;
  double q= 1 - successProb;
  return combo * Math.pow(p,k) * Math.pow(q,n-k);
}//end bernoullis
/**
origin: org.nd4j/canova-api

/**
 * This returns the minimized loss values for a given vector.
 * It is assumed that  the x, y pairs are at
 * vector[i], vector[i+1]
 *
 * @param vector the vector of numbers to getFromOrigin the weights for
 * @return a double array with w_0 and w_1 are the associated indices.
 */
public static double[] weightsFor(List<Double> vector) {
 /* split coordinate system */
 List<double[]> coords = coordSplit(vector);
   /* x vals */
 double[] x = coords.get(0);
   /* y vals */
 double[] y = coords.get(1);
 double meanX = sum(x) / x.length;
 double meanY = sum(y) / y.length;
 double sumOfMeanDifferences = sumOfMeanDifferences(x, y);
 double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x);
 double w_1 = sumOfMeanDifferences / xDifferenceOfMean;
 double w_0 = meanY - (w_1) * meanX;
 //double w_1=(n*sumOfProducts(x,y) - sum(x) * sum(y))/(n*sumOfSquares(x) - Math.pow(sum(x),2));
 //	double w_0=(sum(y) - (w_1 * sum(x)))/n;
 double[] ret = new double[vector.size()];
 ret[0] = w_0;
 ret[1] = w_1;
 return ret;
}//end weightsFor
origin: jpatanooga/Canova

/**
 * 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);
}
origin: jpatanooga/Canova

/**
 * This returns the sum of products for the given
 * numbers.
 * @param nums the sum of products for the give numbers
 * @return the sum of products for the given numbers
 */
public static double sumOfProducts(double[]... nums) {
  if(nums==null || nums.length < 1) return 0;
  double sum=0;
  for(int i=0;i<nums.length;i++) {
    /* The ith column for all of the rows */
    double[] column=column(i,nums);
    sum+=times(column);
  }
  return sum;
}//end sumOfProducts
org.canova.api.utilMathUtils

Javadoc

This is a math utils class.

Most used methods

  • clamp
    Clamps the value to a discrete value
  • column
    This returns the given column over an n arrays
  • combination
    This returns the combination of n choose r
  • coordSplit
    This returns the coordinate split in a list of coordinates such that the values for ret[0] are the x
  • correlation
    Returns the correlation coefficient of two double vectors.
  • factorial
    This will return the factorial of the given number n.
  • gr
    Tests if a is greater than b.
  • idf
    Inverse document frequency: the total docs divided by the number of times the word appeared in a doc
  • log2
    Returns the logarithm of a for base 2.
  • maxIndex
    Returns index of maximum element in a given array of doubles. First maximum is returned.
  • normalize
    Normalizes the doubles in the array using the given value.
  • randomNumberBetween
    Generates a random integer between the specified numbers
  • normalize,
  • randomNumberBetween,
  • sm,
  • ssError,
  • ssReg,
  • ssTotal,
  • sum,
  • sumOfMeanDifferences,
  • sumOfMeanDifferencesOnePoint,
  • sumOfProducts

Popular in Java

  • Running tasks concurrently on multiple threads
  • addToBackStack (FragmentTransaction)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • startActivity (Activity)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Collectors (java.util.stream)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now