Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#INVALID_REGRESSION_OBSERVATION

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#INVALID_REGRESSION_OBSERVATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds an observation to the regression model
 * @param x the array with regressor values
 * @param y  the value of dependent variable given these regressors
 * @exception ModelSpecificationException if the length of {@code x} does not equal
 * the number of independent variables in the model
 */
public void addObservation(final double[] x, final double y) {

    if ((!this.hasIntercept && x.length != nvars) ||
           (this.hasIntercept && x.length + 1 != nvars)) {
        throw new ModelSpecificationException(LocalizedFormats.INVALID_REGRESSION_OBSERVATION,
                x.length, nvars);
    }
    if (!this.hasIntercept) {
        include(MathUtils.copyOf(x, x.length), 1.0, y);
    } else {
        double[] tmp = new double[x.length + 1];
        System.arraycopy(x, 0, tmp, 1, x.length);
        tmp[0] = 1.0;
        include(tmp, 1.0, y);
    }
    ++nobs;
    return;

}
 
Example 2
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds an observation to the regression model
 * @param x the array with regressor values
 * @param y  the value of dependent variable given these regressors
 * @exception ModelSpecificationException if the length of {@code x} does not equal
 * the number of independent variables in the model
 */
public void addObservation(final double[] x, final double y) {

    if ((!this.hasIntercept && x.length != nvars) ||
           (this.hasIntercept && x.length + 1 != nvars)) {
        throw new ModelSpecificationException(LocalizedFormats.INVALID_REGRESSION_OBSERVATION,
                x.length, nvars);
    }
    if (!this.hasIntercept) {
        include(MathUtils.copyOf(x, x.length), 1.0, y);
    } else {
        double[] tmp = new double[x.length + 1];
        System.arraycopy(x, 0, tmp, 1, x.length);
        tmp[0] = 1.0;
        include(tmp, 1.0, y);
    }
    ++nobs;
    return;

}