~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/site/xdoc/userguide/stat.xml

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  -->
19
19
 
20
20
<?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
21
 
<!-- $Revision: 794492 $ $Date: 2009-07-15 22:06:59 -0400 (Wed, 15 Jul 2009) $ -->
 
21
<!-- $Revision: 925895 $ $Date: 2010-03-21 17:05:20 -0400 (Sun, 21 Mar 2010) $ -->
22
22
<document url="stat.html">
23
23
  <properties>
24
24
    <title>The Commons Math User Guide - Statistics</title>
153
153
          <dd>Using the <code>DescriptiveStatistics</code> aggregate
154
154
          (values are stored in memory):
155
155
        <source>
156
 
// Get a DescriptiveStatistics instance using factory method
157
 
DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
 
156
// Get a DescriptiveStatistics instance
 
157
DescriptiveStatistics stats = new DescriptiveStatistics();
158
158
 
159
159
// Add the data from the array
160
160
for( int i = 0; i &lt; inputArray.length; i++) {
170
170
        <dd>Using the <code>SummaryStatistics</code> aggregate (values are
171
171
        <strong>not</strong> stored in memory):
172
172
       <source>
173
 
// Get a SummaryStatistics instance using factory method
174
 
SummaryStatistics stats = SummaryStatistics.newInstance();
 
173
// Get a SummaryStatistics instance
 
174
SummaryStatistics stats = new SummaryStatistics();
175
175
 
176
176
// Read data from an input stream,
177
177
// adding values and updating sums, counters, etc.
196
196
double median = StatUtils.percentile(50);
197
197
 
198
198
// Compute the mean of the first three values in the array
199
 
mean = StatuUtils.mean(values, 0, 3);
 
199
mean = StatUtils.mean(values, 0, 3);
200
200
        </source>
201
201
        </dd>
202
202
        <dt>Maintain a "rolling mean" of the most recent 100 values from
206
206
        window size set to 100
207
207
        <source>
208
208
// Create a DescriptiveStats instance and set the window size to 100
209
 
DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
 
209
DescriptiveStatistics stats = new DescriptiveStatistics();
210
210
stats.setWindowSize(100);
211
211
 
212
212
// Read data from an input stream,
230
230
        <source>
231
231
// Create a SynchronizedDescriptiveStatistics instance and
232
232
// use as any other DescriptiveStatistics instance
233
 
DescriptiveStatistics stats = DescriptiveStatistics.newInstance(SynchronizedDescriptiveStatistics.class);
 
233
DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();
234
234
        </source>
235
235
        </dd>
236
236
        <dt>Compute statistics for multiple samples and overall statistics concurrently</dt>
263
263
          aggregate</a> method is available, as shown in the following example.
264
264
        This method should be used when aggregation needs to be done across threads.
265
265
        <source>
266
 
// Create a AggregateSummaryStatistics instance to accumulate the overall statistics 
267
 
// and AggregatingSummaryStatistics for the subsamples
268
 
AggregateSummaryStatistics aggregate = new AggregateSummaryStatistics();
269
 
SummaryStatistics setOneStats = aggregate.createContributingStatistics();
270
 
SummaryStatistics setTwoStats = aggregate.createContributingStatistics();
271
 
// Add values to the subsample aggregates
 
266
// Create SummaryStatistics instances for the subsample data
 
267
SummaryStatistics setOneStats = new SummaryStatistics();
 
268
SummaryStatistics setTwoStats = new SummaryStatistics();
 
269
// Add values to the subsample SummaryStatistics instances
272
270
setOneStats.addValue(2);
273
271
setOneStats.addValue(3);
274
272
setTwoStats.addValue(2);
275
273
setTwoStats.addValue(4);
276
274
...
277
 
// Get a <code>StatisticalSummary</code> describing the full set of data
 
275
// Aggregate the subsample statistics
278
276
Collection&lt;SummaryStatistics&gt; aggregate = new ArrayList&lt;SummaryStatistics&gt;();
279
277
aggregate.add(setOneStats);
280
278
aggregate.add(setTwoStats);
281
279
StatisticalSummary aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
 
280
 
 
281
// Full sample data is reported by aggregatedStats
 
282
double totalSampleSum = aggregatedStats.getSum();
282
283
        </source>
283
284
        </dd>
284
285
        </dl>
842
843
          <source>
843
844
double[] observed ={1d, 2d, 3d};
844
845
double mu = 2.5d;
845
 
SummaryStatistics sampleStats = null;
846
 
sampleStats = SummaryStatistics.newInstance();
 
846
SummaryStatistics sampleStats = new SummaryStatistics();
847
847
for (int i = 0; i &lt; observed.length; i++) {
848
848
    sampleStats.addValue(observed[i]);
849
849
}