Source Code Cross Referenced for Mean.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » stat » descriptive » moment » 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.moment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-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.moment;
017:
018:        import java.io.Serializable;
019:
020:        import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
021:        import org.apache.commons.math.stat.descriptive.summary.Sum;
022:
023:        /**
024:         * Returns the arithmetic mean of the available values. Uses the definitional 
025:         * formula:
026:         * <p>
027:         * mean = sum(x_i) / n
028:         * <p>
029:         * where <code>n</code> is the number of observations.
030:         * <p>
031:         * The value of the statistic is computed using the following recursive
032:         * updating algorithm:
033:         * <p>
034:         * <ol>
035:         * <li>Initialize <code>m = </code> the first value</li>
036:         * <li>For each additional value, update using <br>
037:         *   <code>m = m + (new value - m) / (number of observations)</code></li>
038:         * </ol>
039:         * <p>
040:         *  Returns <code>Double.NaN</code> if the dataset is empty.
041:         * <p>
042:         * <strong>Note that this implementation is not synchronized.</strong> If 
043:         * multiple threads access an instance of this class concurrently, and at least
044:         * one of the threads invokes the <code>increment()</code> or 
045:         * <code>clear()</code> method, it must be synchronized externally.
046:         * 
047:         * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
048:         */
049:        public class Mean extends AbstractStorelessUnivariateStatistic
050:                implements  Serializable {
051:
052:            /** Serializable version identifier */
053:            private static final long serialVersionUID = -1296043746617791564L;
054:
055:            /** First moment on which this statistic is based. */
056:            protected FirstMoment moment;
057:
058:            /** 
059:             * Determines whether or not this statistic can be incremented or cleared.
060:             * <p>
061:             * Statistics based on (constructed from) external moments cannot
062:             * be incremented or cleared.
063:             */
064:            protected boolean incMoment;
065:
066:            /** Constructs a Mean. */
067:            public Mean() {
068:                incMoment = true;
069:                moment = new FirstMoment();
070:            }
071:
072:            /**
073:             * Constructs a Mean with an External Moment.
074:             * 
075:             * @param m1 the moment
076:             */
077:            public Mean(final FirstMoment m1) {
078:                this .moment = m1;
079:                incMoment = false;
080:            }
081:
082:            /**
083:             * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#increment(double)
084:             */
085:            public void increment(final double d) {
086:                if (incMoment) {
087:                    moment.increment(d);
088:                }
089:            }
090:
091:            /**
092:             * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#clear()
093:             */
094:            public void clear() {
095:                if (incMoment) {
096:                    moment.clear();
097:                }
098:            }
099:
100:            /**
101:             * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#getResult()
102:             */
103:            public double getResult() {
104:                return moment.m1;
105:            }
106:
107:            /**
108:             * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#getN()
109:             */
110:            public long getN() {
111:                return moment.getN();
112:            }
113:
114:            /**
115:             * Returns the arithmetic mean of the entries in the specified portion of
116:             * the input array, or <code>Double.NaN</code> if the designated subarray
117:             * is empty.
118:             * <p>
119:             * Throws <code>IllegalArgumentException</code> if the array is null.
120:             * <p>
121:             * See {@link Mean} for details on the computing algorithm.
122:             * 
123:             * @param values the input array
124:             * @param begin index of the first array element to include
125:             * @param length the number of elements to include
126:             * @return the mean of the values or Double.NaN if length = 0
127:             * @throws IllegalArgumentException if the array is null or the array index
128:             *  parameters are not valid
129:             */
130:            public double evaluate(final double[] values, final int begin,
131:                    final int length) {
132:                if (test(values, begin, length)) {
133:                    Sum sum = new Sum();
134:                    return sum.evaluate(values, begin, length)
135:                            / ((double) length);
136:                }
137:                return Double.NaN;
138:            }
139:        }
w_w___w_.___j__av_a__2s_.___c_o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.