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.regression;
23
24 import org.hipparchus.exception.MathIllegalArgumentException;
25
26 /**
27 * An interface for regression models allowing for dynamic updating of the data.
28 * That is, the entire data set need not be loaded into memory. As observations
29 * become available, they can be added to the regression model and an updated
30 * estimate regression statistics can be calculated.
31 *
32 */
33 public interface UpdatingMultipleLinearRegression {
34
35 /**
36 * Returns true if a constant has been included false otherwise.
37 *
38 * @return true if constant exists, false otherwise
39 */
40 boolean hasIntercept();
41
42 /**
43 * Returns the number of observations added to the regression model.
44 *
45 * @return Number of observations
46 */
47 long getN();
48
49 /**
50 * Adds one observation to the regression model.
51 *
52 * @param x the independent variables which form the design matrix
53 * @param y the dependent or response variable
54 * @throws MathIllegalArgumentException if the length of {@code x} does not equal
55 * the number of independent variables in the model
56 */
57 void addObservation(double[] x, double y) throws MathIllegalArgumentException;
58
59 /**
60 * Adds a series of observations to the regression model. The lengths of
61 * x and y must be the same and x must be rectangular.
62 *
63 * @param x a series of observations on the independent variables
64 * @param y a series of observations on the dependent variable
65 * The length of x and y must be the same
66 * @throws MathIllegalArgumentException if {@code x} is not rectangular, does not match
67 * the length of {@code y} or does not contain sufficient data to estimate the model
68 */
69 void addObservations(double[][] x, double[] y) throws MathIllegalArgumentException;
70
71 /**
72 * Clears internal buffers and resets the regression model. This means all
73 * data and derived values are initialized
74 */
75 void clear();
76
77
78 /**
79 * Performs a regression on data present in buffers and outputs a RegressionResults object
80 * @return RegressionResults acts as a container of regression output
81 * @throws MathIllegalArgumentException if the model is not correctly specified
82 * @throws MathIllegalArgumentException if there is not sufficient data in the model to
83 * estimate the regression parameters
84 */
85 RegressionResults regress() throws MathIllegalArgumentException;
86
87 /**
88 * Performs a regression on data present in buffers including only regressors
89 * indexed in variablesToInclude and outputs a RegressionResults object
90 * @param variablesToInclude an array of indices of regressors to include
91 * @return RegressionResults acts as a container of regression output
92 * @throws MathIllegalArgumentException if the model is not correctly specified
93 * @throws MathIllegalArgumentException if the variablesToInclude array is null or zero length
94 */
95 RegressionResults regress(int[] variablesToInclude) throws MathIllegalArgumentException;
96 }