1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.math4.legacy.stat.descriptive;
18
19 import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
20
21 /**
22 * Extends the definition of {@link UnivariateStatistic} with
23 * {@link #increment} and {@link #incrementAll(double[])} methods for adding
24 * values and updating internal state.
25 * <p>
26 * This interface is designed to be used for calculating statistics that can be
27 * computed in one pass through the data without storing the full array of
28 * sample values.
29 * <p>
30 * Note: unless otherwise stated, the {@link #evaluate(double[])} and
31 * {@link #evaluate(double[], int, int)} methods do <b>NOT</b> alter the internal
32 * state of the respective statistic.
33 */
34 public interface StorelessUnivariateStatistic extends UnivariateStatistic {
35
36 /**
37 * Updates the internal state of the statistic to reflect the addition of the new value.
38 * @param d the new value.
39 */
40 void increment(double d);
41
42 /**
43 * Updates the internal state of the statistic to reflect addition of
44 * all values in the values array. Does not clear the statistic first --
45 * i.e., the values are added <strong>incrementally</strong> to the dataset.
46 *
47 * @param values array holding the new values to add
48 * @throws MathIllegalArgumentException if the array is null
49 */
50 void incrementAll(double[] values) throws MathIllegalArgumentException;
51
52 /**
53 * Updates the internal state of the statistic to reflect addition of
54 * the values in the designated portion of the values array. Does not
55 * clear the statistic first -- i.e., the values are added
56 * <strong>incrementally</strong> to the dataset.
57 *
58 * @param values array holding the new values to add
59 * @param start the array index of the first value to add
60 * @param length the number of elements to add
61 * @throws MathIllegalArgumentException if the array is null or the index
62 */
63 void incrementAll(double[] values, int start, int length) throws MathIllegalArgumentException;
64
65 /**
66 * Returns the current value of the Statistic.
67 * @return value of the statistic, <code>Double.NaN</code> if it
68 * has been cleared or just instantiated.
69 */
70 double getResult();
71
72 /**
73 * Returns the number of values that have been added.
74 * @return the number of values.
75 */
76 long getN();
77
78 /**
79 * Clears the internal state of the Statistic.
80 */
81 void clear();
82
83 /**
84 * Returns a copy of the statistic with the same internal state.
85 *
86 * @return a copy of the statistic
87 */
88 @Override
89 StorelessUnivariateStatistic copy();
90 }