View Javadoc
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    *      https://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  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.stat.descriptive;
23  
24  import org.hipparchus.exception.LocalizedCoreFormats;
25  import org.hipparchus.exception.MathIllegalArgumentException;
26  import org.hipparchus.util.MathArrays;
27  import org.hipparchus.util.MathUtils;
28  
29  
30  /**
31   * Base interface implemented by all statistics.
32   */
33  public interface UnivariateStatistic extends MathArrays.Function {
34      /**
35       * Returns the result of evaluating the statistic over the input array.
36       * <p>
37       * The default implementation delegates to
38       * <code>evaluate(double[], int, int)</code> in the natural way.
39       *
40       * @param values input array
41       * @return the value of the statistic applied to the input array
42       * @throws MathIllegalArgumentException  if values is null
43       */
44      @Override
45      default double evaluate(double[] values) throws MathIllegalArgumentException {
46          MathUtils.checkNotNull(values, LocalizedCoreFormats.INPUT_ARRAY);
47          return evaluate(values, 0, values.length);
48      }
49  
50      /**
51       * Returns the result of evaluating the statistic over the specified entries
52       * in the input array.
53       *
54       * @param values the input array
55       * @param begin the index of the first element to include
56       * @param length the number of elements to include
57       * @return the value of the statistic applied to the included array entries
58       * @throws MathIllegalArgumentException if values is null or the indices are invalid
59       */
60      @Override
61      double evaluate(double[] values, int begin, int length) throws MathIllegalArgumentException;
62  
63      /**
64       * Returns a copy of the statistic with the same internal state.
65       *
66       * @return a copy of the statistic
67       */
68      UnivariateStatistic copy();
69  }