Source Code Cross Referenced for SummaryStatisticsImpl.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » stat » descriptive » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Apache commons math 1.1 » org.apache.commons.math.stat.descriptive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.math.stat.descriptive;
017:
018:        import java.io.Serializable;
019:        import org.apache.commons.math.stat.descriptive.moment.SecondMoment;
020:        import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
021:        import org.apache.commons.math.stat.descriptive.moment.Mean;
022:        import org.apache.commons.math.stat.descriptive.moment.Variance;
023:        import org.apache.commons.math.stat.descriptive.rank.Max;
024:        import org.apache.commons.math.stat.descriptive.rank.Min;
025:        import org.apache.commons.math.stat.descriptive.summary.Sum;
026:        import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
027:        import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
028:
029:        /**
030:         * Provides a default {@link SummaryStatistics} implementation.
031:         *
032:         * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $  
033:         */
034:        public class SummaryStatisticsImpl extends SummaryStatistics implements 
035:                Serializable {
036:
037:            /** Serializable version identifier */
038:            private static final long serialVersionUID = 8787174276883311692L;
039:
040:            /** count of values that have been added */
041:            protected long n = 0;
042:
043:            /** SecondMoment is used to compute the mean and variance */
044:            protected SecondMoment secondMoment = null;
045:
046:            /** sum of values that have been added */
047:            protected Sum sum = null;
048:
049:            /** sum of the square of each value that has been added */
050:            protected SumOfSquares sumsq = null;
051:
052:            /** min of values that have been added */
053:            protected Min min = null;
054:
055:            /** max of values that have been added */
056:            protected Max max = null;
057:
058:            /** sumLog of values that have been added */
059:            protected SumOfLogs sumLog = null;
060:
061:            /** geoMean of values that have been added */
062:            protected GeometricMean geoMean = null;
063:
064:            /** mean of values that have been added */
065:            protected Mean mean = null;
066:
067:            /** variance of values that have been added */
068:            protected Variance variance = null;
069:
070:            /**
071:             * Construct a SummaryStatistics
072:             */
073:            public SummaryStatisticsImpl() {
074:                sum = new Sum();
075:                sumsq = new SumOfSquares();
076:                min = new Min();
077:                max = new Max();
078:                sumLog = new SumOfLogs();
079:                geoMean = new GeometricMean();
080:                secondMoment = new SecondMoment();
081:            }
082:
083:            /**
084:             * Add a value to the data
085:             * 
086:             * @param value  the value to add
087:             */
088:            public void addValue(double value) {
089:                sum.increment(value);
090:                sumsq.increment(value);
091:                min.increment(value);
092:                max.increment(value);
093:                sumLog.increment(value);
094:                geoMean.increment(value);
095:                secondMoment.increment(value);
096:                n++;
097:            }
098:
099:            /** 
100:             * Returns the number of available values
101:             * @return The number of available values
102:             */
103:            public long getN() {
104:                return n;
105:            }
106:
107:            /**
108:             * Returns the sum of the values that have been added to Univariate.
109:             * @return The sum or Double.NaN if no values have been added
110:             */
111:            public double getSum() {
112:                return sum.getResult();
113:            }
114:
115:            /**
116:             * Returns the sum of the squares of the values that have been added.
117:             * <p>
118:             *  Double.NaN is returned if no values have been added.</p>
119:             * 
120:             * @return The sum of squares
121:             */
122:            public double getSumsq() {
123:                return sumsq.getResult();
124:            }
125:
126:            /**
127:             * Returns the mean of the values that have been added.
128:             * <p>
129:             *  Double.NaN is returned if no values have been added.</p>
130:             * 
131:             * @return the mean
132:             */
133:            public double getMean() {
134:                return new Mean(secondMoment).getResult();
135:            }
136:
137:            /**
138:             * Returns the standard deviation of the values that have been added.
139:             * <p>
140:             *  Double.NaN is returned if no values have been added.</p>
141:             * 
142:             * @return the standard deviation
143:             */
144:            public double getStandardDeviation() {
145:                double stdDev = Double.NaN;
146:                if (getN() > 0) {
147:                    if (getN() > 1) {
148:                        stdDev = Math.sqrt(getVariance());
149:                    } else {
150:                        stdDev = 0.0;
151:                    }
152:                }
153:                return (stdDev);
154:            }
155:
156:            /**
157:             * Returns the variance of the values that have been added.
158:             * <p>
159:             *  Double.NaN is returned if no values have been added.</p>
160:             *
161:             * @return the variance 
162:             */
163:            public double getVariance() {
164:                return new Variance(secondMoment).getResult();
165:            }
166:
167:            /**
168:             * Returns the maximum of the values that have been added.
169:             * <p>
170:             *  Double.NaN is returned if no values have been added.</p>
171:             *
172:             * @return the maximum  
173:             */
174:            public double getMax() {
175:                return max.getResult();
176:            }
177:
178:            /**
179:             * Returns the minimum of the values that have been added.
180:             * <p>
181:             *  Double.NaN is returned if no values have been added.</p>
182:             *
183:             * @return the minimum  
184:             */
185:            public double getMin() {
186:                return min.getResult();
187:            }
188:
189:            /**
190:             * Returns the geometric mean of the values that have been added.
191:             * <p>
192:             *  Double.NaN is returned if no values have been added.</p>
193:             *
194:             * @return the geometric mean  
195:             */
196:            public double getGeometricMean() {
197:                return geoMean.getResult();
198:            }
199:
200:            /**
201:             * Generates a text report displaying
202:             * summary statistics from values that
203:             * have been added.
204:             * @return String with line feeds displaying statistics
205:             */
206:            public String toString() {
207:                StringBuffer outBuffer = new StringBuffer();
208:                outBuffer.append("SummaryStatistics:\n");
209:                outBuffer.append("n: " + getN() + "\n");
210:                outBuffer.append("min: " + getMin() + "\n");
211:                outBuffer.append("max: " + getMax() + "\n");
212:                outBuffer.append("mean: " + getMean() + "\n");
213:                outBuffer
214:                        .append("geometric mean: " + getGeometricMean() + "\n");
215:                outBuffer.append("variance: " + getVariance() + "\n");
216:                outBuffer.append("sum of squares: " + getSumsq() + "\n");
217:                outBuffer.append("standard deviation: "
218:                        + getStandardDeviation() + "\n");
219:                return outBuffer.toString();
220:            }
221:
222:            /** 
223:             * Resets all statistics and storage
224:             */
225:            public void clear() {
226:                this .n = 0;
227:                min.clear();
228:                max.clear();
229:                sum.clear();
230:                sumLog.clear();
231:                sumsq.clear();
232:                geoMean.clear();
233:                secondMoment.clear();
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.