001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.stat.regression;
018
019import org.apache.commons.math4.exception.MathIllegalArgumentException;
020import org.apache.commons.math4.exception.NoDataException;
021
022/**
023 * An interface for regression models allowing for dynamic updating of the data.
024 * That is, the entire data set need not be loaded into memory. As observations
025 * become available, they can be added to the regression  model and an updated
026 * estimate regression statistics can be calculated.
027 *
028 * @since 3.0
029 */
030public interface UpdatingMultipleLinearRegression {
031
032    /**
033     * Returns true if a constant has been included false otherwise.
034     *
035     * @return true if constant exists, false otherwise
036     */
037    boolean hasIntercept();
038
039    /**
040     * Returns the number of observations added to the regression model.
041     *
042     * @return Number of observations
043     */
044    long getN();
045
046    /**
047     * Adds one observation to the regression model.
048     *
049     * @param x the independent variables which form the design matrix
050     * @param y the dependent or response variable
051     * @throws ModelSpecificationException if the length of {@code x} does not equal
052     * the number of independent variables in the model
053     */
054    void addObservation(double[] x, double y) throws ModelSpecificationException;
055
056    /**
057     * Adds a series of observations to the regression model. The lengths of
058     * x and y must be the same and x must be rectangular.
059     *
060     * @param x a series of observations on the independent variables
061     * @param y a series of observations on the dependent variable
062     * The length of x and y must be the same
063     * @throws ModelSpecificationException if {@code x} is not rectangular, does not match
064     * the length of {@code y} or does not contain sufficient data to estimate the model
065     */
066    void addObservations(double[][] x, double[] y) throws ModelSpecificationException;
067
068    /**
069     * Clears internal buffers and resets the regression model. This means all
070     * data and derived values are initialized
071     */
072    void clear();
073
074
075    /**
076     * Performs a regression on data present in buffers and outputs a RegressionResults object
077     * @return RegressionResults acts as a container of regression output
078     * @throws ModelSpecificationException if the model is not correctly specified
079     * @throws NoDataException if there is not sufficient data in the model to
080     * estimate the regression parameters
081     */
082    RegressionResults regress() throws ModelSpecificationException, NoDataException;
083
084    /**
085     * Performs a regression on data present in buffers including only regressors
086     * indexed in variablesToInclude and outputs a RegressionResults object
087     * @param variablesToInclude an array of indices of regressors to include
088     * @return RegressionResults acts as a container of regression output
089     * @throws ModelSpecificationException if the model is not correctly specified
090     * @throws MathIllegalArgumentException if the variablesToInclude array is null or zero length
091     */
092    RegressionResults regress(int[] variablesToInclude) throws ModelSpecificationException, MathIllegalArgumentException;
093}