org.apache.commons.math.stat.descriptive.summary.SumOfSquares Java Examples

The following examples show how to use org.apache.commons.math.stat.descriptive.summary.SumOfSquares. 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: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #2
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #3
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #4
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #5
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #6
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #7
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #8
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #9
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #10
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #11
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #12
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #13
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #14
Source File: MultivariateSummaryStatistics.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #15
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #16
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #17
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
Example #18
Source File: SummaryStatisticsImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SummaryStatistics
 */
public SummaryStatisticsImpl() {
    sum = new Sum();
    sumsq = new SumOfSquares();
    min = new Min();
    max = new Max();
    sumLog = new SumOfLogs();
    geoMean = new GeometricMean();
    secondMoment = new SecondMoment();
}
 
Example #19
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.maxImpl = source.maxImpl.copy();
    dest.meanImpl = source.meanImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.varianceImpl = source.varianceImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        // Keep geoMeanImpl, sumLogImpl in synch
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }
    SecondMoment.copy(source.secondMoment, dest.secondMoment);
    dest.n = source.n;

    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    }
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    }
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    }
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    }
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    }
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    }
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    }
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    }
}
 
Example #20
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example #21
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 * 
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;
    
    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() * 
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example #22
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 * 
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullPointerException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest) {
    dest.maxImpl = source.maxImpl.copy();
    dest.meanImpl = source.meanImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.varianceImpl = source.varianceImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        // Keep geoMeanImpl, sumLogImpl in synch
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }
    SecondMoment.copy(source.secondMoment, dest.secondMoment);
    dest.n = source.n;
    
    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    } 
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    } 
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    } 
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    } 
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    } 
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    } 
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    } 
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    } 
}
 
Example #23
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullPointerException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest) {
    dest.maxImpl = source.maxImpl.copy();
    dest.meanImpl = source.meanImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.varianceImpl = source.varianceImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        // Keep geoMeanImpl, sumLogImpl in synch
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }
    SecondMoment.copy(source.secondMoment, dest.secondMoment);
    dest.n = source.n;

    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    }
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    }
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    }
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    }
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    }
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    }
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    }
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    }
}
 
Example #24
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 * 
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;
    
    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() * 
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example #25
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 * 
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullPointerException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest) {
    dest.maxImpl = source.maxImpl.copy();
    dest.meanImpl = source.meanImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.varianceImpl = source.varianceImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        // Keep geoMeanImpl, sumLogImpl in synch
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }
    SecondMoment.copy(source.secondMoment, dest.secondMoment);
    dest.n = source.n;
    
    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    } 
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    } 
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    } 
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    } 
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    } 
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    } 
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    } 
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    } 
}
 
Example #26
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example #27
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 * 
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;
    
    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() * 
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example #28
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 * 
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullPointerException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest) {
    dest.maxImpl = source.maxImpl.copy();
    dest.meanImpl = source.meanImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.varianceImpl = source.varianceImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        // Keep geoMeanImpl, sumLogImpl in synch
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }
    SecondMoment.copy(source.secondMoment, dest.secondMoment);
    dest.n = source.n;
    
    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    } 
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    } 
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    } 
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    } 
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    } 
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    } 
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    } 
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    } 
}
 
Example #29
Source File: Math_43_SummaryStatistics_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.maxImpl = source.maxImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    dest.secondMoment = source.secondMoment.copy();
    dest.n = source.n;

    // Keep commons-math supplied statistics with embedded moments in synch
    if (source.getVarianceImpl() instanceof Variance) {
        dest.varianceImpl = new Variance(dest.secondMoment);
    } else {
        dest.varianceImpl = source.varianceImpl.copy();
    }
    if (source.meanImpl instanceof Mean) {
        dest.meanImpl = new Mean(dest.secondMoment);
    } else {
        dest.meanImpl = source.meanImpl.copy();
    }
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }

    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    }
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    }
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    }
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    }
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    }
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    }
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    }
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    }
}
 
Example #30
Source File: OneWayAnovaImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}