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

The following examples show how to use org.apache.commons.math3.stat.StatUtils#sumSq() . 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: SumSqEvaluator.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Object doWork(Object value) throws IOException {
  if(null == value){
    return value;
  }
  else if(!(value instanceof List<?>)){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for value, expecting a List",toExpression(constructingFactory), value.getClass().getSimpleName()));
  }

  @SuppressWarnings({"unchecked"})
  List<Number> list = (List<Number>)value;

  if(0 == list.size()){
    return list;
  }

  double[] vec = new double[list.size()];
  for(int i=0; i< vec.length; i++) {
    vec[i] = list.get(i).doubleValue();
  }

  return StatUtils.sumSq(vec);
}
 
Example 2
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.sumSq(removeMissing(column));
}
 
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.sumSq(removeMissing(column));
}
 
Example 4
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @throws NullPointerException if the sample has not been set
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 5
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 6
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 7
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @throws MathIllegalArgumentException if the sample has not been set or does
 * not contain at least 3 observations
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() throws MathIllegalArgumentException {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 8
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 9
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @throws MathIllegalArgumentException if the sample has not been set or does
 * not contain at least 3 observations
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() throws MathIllegalArgumentException {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 10
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @throws MathIllegalArgumentException if the sample has not been set or does
 * not contain at least 3 observations
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() throws MathIllegalArgumentException {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}
 
Example 11
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the sum of squared deviations of Y from its mean.</p>
 *
 * <p>If the model has no intercept term, <code>0</code> is used for the
 * mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
 *
 * <p>The value returned by this method is the SSTO value used in
 * the {@link #calculateRSquared() R-squared} computation.</p>
 *
 * @return SSTO - the total sum of squares
 * @throws NullPointerException if the sample has not been set
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateTotalSumOfSquares() {
    if (isNoIntercept()) {
        return StatUtils.sumSq(getY().toArray());
    } else {
        return new SecondMoment().evaluate(getY().toArray());
    }
}