⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 summarystatistics.java

📁 Apache的common math数学软件包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @return String with line feeds displaying statistics     * @since 1.2     */    public String toString() {        StringBuffer outBuffer = new StringBuffer();        outBuffer.append("SummaryStatistics:\n");        outBuffer.append("n: " + getN() + "\n");        outBuffer.append("min: " + getMin() + "\n");        outBuffer.append("max: " + getMax() + "\n");        outBuffer.append("mean: " + getMean() + "\n");        outBuffer.append("geometric mean: " + getGeometricMean() + "\n");        outBuffer.append("variance: " + getVariance() + "\n");        outBuffer.append("sum of squares: " + getSumsq() + "\n");        outBuffer.append("standard deviation: " + getStandardDeviation() + "\n");        outBuffer.append("sum of logs: " + getSumOfLogs() + "\n");        return outBuffer.toString();    }    /**      * Resets all statistics and storage     */    public void clear() {        this.n = 0;        minImpl.clear();        maxImpl.clear();        sumImpl.clear();        sumLogImpl.clear();        sumsqImpl.clear();        geoMeanImpl.clear();        secondMoment.clear();        if (meanImpl != mean) {            meanImpl.clear();        }        if (varianceImpl != variance) {            varianceImpl.clear();        }    }        /**     * Returns true iff <code>object</code> is a <code>SummaryStatistics</code>     * instance and all statistics have the same values as this.     * @param object the object to test equality against.     * @return true if object equals this     */    public boolean equals(Object object) {        if (object == this ) {            return true;        }        if (object instanceof SummaryStatistics == false) {            return false;        }        SummaryStatistics stat = (SummaryStatistics) object;        return (MathUtils.equals(stat.getGeometricMean(),                 this.getGeometricMean()) &&                MathUtils.equals(stat.getMax(), this.getMax()) &&                 MathUtils.equals(stat.getMean(),this.getMean()) &&                MathUtils.equals(stat.getMin(),this.getMin()) &&                MathUtils.equals(stat.getN(), this.getN()) &&                MathUtils.equals(stat.getSum(), this.getSum()) &&                MathUtils.equals(stat.getSumsq(),this.getSumsq()) &&                MathUtils.equals(stat.getVariance(),this.getVariance()));    }        /**     * Returns hash code based on values of statistics     *      * @return hash code     */    public int hashCode() {        int result = 31 + MathUtils.hash(getGeometricMean());        result = result * 31 + MathUtils.hash(getGeometricMean());        result = result * 31 + MathUtils.hash(getMax());        result = result * 31 + MathUtils.hash(getMean());        result = result * 31 + MathUtils.hash(getMin());        result = result * 31 + MathUtils.hash(getN());        result = result * 31 + MathUtils.hash(getSum());        result = result * 31 + MathUtils.hash(getSumsq());        result = result * 31 + MathUtils.hash(getVariance());        return result;    }    // Getters and setters for statistics implementations    /**     * Returns the currently configured Sum implementation     *      * @return the StorelessUnivariateStatistic implementing the sum     * @since 1.2     */    public StorelessUnivariateStatistic getSumImpl() {        return sumImpl;    }    /**     * <p>Sets the implementation for the Sum.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param sumImpl the StorelessUnivariateStatistic instance to use     * for computing the Sum     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setSumImpl(StorelessUnivariateStatistic sumImpl) {        checkEmpty();        this.sumImpl = sumImpl;    }    /**     * Returns the currently configured sum of squares implementation     *      * @return the StorelessUnivariateStatistic implementing the sum of squares     * @since 1.2     */    public StorelessUnivariateStatistic getSumsqImpl() {        return sumsqImpl;    }    /**     * <p>Sets the implementation for the sum of squares.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param sumsqImpl the StorelessUnivariateStatistic instance to use     * for computing the sum of squares     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setSumsqImpl(            StorelessUnivariateStatistic sumsqImpl) {        checkEmpty();        this.sumsqImpl = sumsqImpl;    }    /**     * Returns the currently configured minimum implementation     *      * @return the StorelessUnivariateStatistic implementing the minimum     * @since 1.2     */    public StorelessUnivariateStatistic getMinImpl() {        return minImpl;    }    /**     * <p>Sets the implementation for the minimum.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param minImpl the StorelessUnivariateStatistic instance to use     * for computing the minimum     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setMinImpl(StorelessUnivariateStatistic minImpl) {        checkEmpty();        this.minImpl = minImpl;    }    /**     * Returns the currently configured maximum implementation     *      * @return the StorelessUnivariateStatistic implementing the maximum     * @since 1.2     */    public StorelessUnivariateStatistic getMaxImpl() {        return maxImpl;    }    /**     * <p>Sets the implementation for the maximum.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param maxImpl the StorelessUnivariateStatistic instance to use     * for computing the maximum     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setMaxImpl(StorelessUnivariateStatistic maxImpl) {        checkEmpty();        this.maxImpl = maxImpl;    }    /**     * Returns the currently configured sum of logs implementation     *      * @return the StorelessUnivariateStatistic implementing the log sum     * @since 1.2     */    public StorelessUnivariateStatistic getSumLogImpl() {        return sumLogImpl;    }    /**     * <p>Sets the implementation for the sum of logs.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param sumLogImpl the StorelessUnivariateStatistic instance to use     * for computing the log sum     * @throws IllegalStateException if data has already been added      *  (i.e if n > 0)     * @since 1.2     */    public void setSumLogImpl(            StorelessUnivariateStatistic sumLogImpl) {        checkEmpty();        this.sumLogImpl = sumLogImpl;        geoMean.setSumLogImpl(sumLogImpl);    }    /**     * Returns the currently configured geometric mean implementation     *      * @return the StorelessUnivariateStatistic implementing the geometric mean     * @since 1.2     */    public StorelessUnivariateStatistic getGeoMeanImpl() {        return geoMeanImpl;    }    /**     * <p>Sets the implementation for the geometric mean.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param geoMeanImpl the StorelessUnivariateStatistic instance to use     * for computing the geometric mean     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setGeoMeanImpl(            StorelessUnivariateStatistic geoMeanImpl) {        checkEmpty();        this.geoMeanImpl = geoMeanImpl;    }    /**     * Returns the currently configured mean implementation     *      * @return the StorelessUnivariateStatistic implementing the mean     * @since 1.2     */    public StorelessUnivariateStatistic getMeanImpl() {        return meanImpl;    }    /**     * <p>Sets the implementation for the mean.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param meanImpl the StorelessUnivariateStatistic instance to use     * for computing the mean     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setMeanImpl(            StorelessUnivariateStatistic meanImpl) {        checkEmpty();        this.meanImpl = meanImpl;    }    /**     * Returns the currently configured variance implementation     *      * @return the StorelessUnivariateStatistic implementing the variance     * @since 1.2     */    public StorelessUnivariateStatistic getVarianceImpl() {        return varianceImpl;    }    /**     * <p>Sets the implementation for the variance.</p>     * <p>This method must be activated before any data has been added - i.e.,     * before {@link #addValue(double) addValue} has been used to add data;      * otherwise an IllegalStateException will be thrown.</p>     *      * @param varianceImpl the StorelessUnivariateStatistic instance to use     * for computing the variance     * @throws IllegalStateException if data has already been added     *  (i.e if n > 0)     * @since 1.2     */    public void setVarianceImpl(            StorelessUnivariateStatistic varianceImpl) {        checkEmpty();        this.varianceImpl = varianceImpl;    }        /**     * Throws IllegalStateException if n > 0.     */    private void checkEmpty() {        if (n > 0) {            throw new IllegalStateException(                "Implementations must be configured before values are added.");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -