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

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#NO_REGRESSORS . 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 5 votes vote down vote up
/**
 * This is the augmented constructor for the MillerUpdatingRegression class
 *
 * @param numberOfVariables number of regressors to expect, not including constant
 * @param includeConstant include a constant automatically
 * @param errorTolerance  zero tolerance, how machine zero is determined
 */
public MillerUpdatingRegression(int numberOfVariables, boolean includeConstant, double errorTolerance) {
    if (numberOfVariables < 1) {
        throw new ModelSpecificationException(LocalizedFormats.NO_REGRESSORS);
    }
    if (includeConstant) {
        this.nvars = numberOfVariables + 1;
    } else {
        this.nvars = numberOfVariables;
    }
    this.hasIntercept = includeConstant;
    this.nobs = 0;
    this.d = new double[this.nvars];
    this.rhs = new double[this.nvars];
    this.r = new double[this.nvars * (this.nvars - 1) / 2];
    this.tol = new double[this.nvars];
    this.rss = new double[this.nvars];
    this.vorder = new int[this.nvars];
    this.x_sing = new double[this.nvars];
    this.work_sing = new double[this.nvars];
    this.work_tolset = new double[this.nvars];
    this.lindep = new boolean[this.nvars];
    for (int i = 0; i < this.nvars; i++) {
        vorder[i] = i;
    }
    if (errorTolerance > 0) {
        this.epsilon = errorTolerance;
    } else {
        this.epsilon = -errorTolerance;
    }
    return;
}
 
Example 2
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The regcf method conducts the linear regression and extracts the
 * parameter vector. Notice that the algorithm can do subset regression
 * with no alteration.
 *
 * @param nreq how many of the regressors to include (either in canonical
 * order, or in the current reordered state)
 * @return an array with the estimated slope coefficients
 */
private double[] regcf(int nreq) {
    int nextr;
    if (nreq < 1) {
        throw new ModelSpecificationException(LocalizedFormats.NO_REGRESSORS);
    }
    if (nreq > this.nvars) {
        throw new ModelSpecificationException(
                LocalizedFormats.TOO_MANY_REGRESSORS, nreq, this.nvars);
    }
    if (!this.tol_set) {
        tolset();
    }
    double[] ret = new double[nreq];
    boolean rankProblem = false;
    for (int i = nreq - 1; i > -1; i--) {
        if (Math.sqrt(d[i]) < tol[i]) {
            ret[i] = 0.0;
            d[i] = 0.0;
            rankProblem = true;
        } else {
            ret[i] = rhs[i];
            nextr = i * (nvars + nvars - i - 1) / 2;
            for (int j = i + 1; j < nreq; j++) {
                ret[i] = smartAdd(ret[i], -r[nextr] * ret[j]);
                ++nextr;
            }
        }
    }
    if (rankProblem) {
        for (int i = 0; i < nreq; i++) {
            if (this.lindep[i]) {
                ret[i] = Double.NaN;
            }
        }
    }
    return ret;
}
 
Example 3
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is the augmented constructor for the MillerUpdatingRegression class
 *
 * @param numberOfVariables number of regressors to expect, not including constant
 * @param includeConstant include a constant automatically
 * @param errorTolerance  zero tolerance, how machine zero is determined
 */
public MillerUpdatingRegression(int numberOfVariables, boolean includeConstant, double errorTolerance) {
    if (numberOfVariables < 1) {
        throw new ModelSpecificationException(LocalizedFormats.NO_REGRESSORS);
    }
    if (includeConstant) {
        this.nvars = numberOfVariables + 1;
    } else {
        this.nvars = numberOfVariables;
    }
    this.hasIntercept = includeConstant;
    this.nobs = 0;
    this.d = new double[this.nvars];
    this.rhs = new double[this.nvars];
    this.r = new double[this.nvars * (this.nvars - 1) / 2];
    this.tol = new double[this.nvars];
    this.rss = new double[this.nvars];
    this.vorder = new int[this.nvars];
    this.x_sing = new double[this.nvars];
    this.work_sing = new double[this.nvars];
    this.work_tolset = new double[this.nvars];
    this.lindep = new boolean[this.nvars];
    for (int i = 0; i < this.nvars; i++) {
        vorder[i] = i;
    }
    if (errorTolerance > 0) {
        this.epsilon = errorTolerance;
    } else {
        this.epsilon = -errorTolerance;
    }
    return;
}
 
Example 4
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The regcf method conducts the linear regression and extracts the
 * parameter vector. Notice that the algorithm can do subset regression
 * with no alteration.
 *
 * @param nreq how many of the regressors to include (either in canonical
 * order, or in the current reordered state)
 * @return an array with the estimated slope coefficients
 */
private double[] regcf(int nreq) {
    int nextr;
    if (nreq < 1) {
        throw new ModelSpecificationException(LocalizedFormats.NO_REGRESSORS);
    }
    if (nreq > this.nvars) {
        throw new ModelSpecificationException(
                LocalizedFormats.TOO_MANY_REGRESSORS, nreq, this.nvars);
    }
    if (!this.tol_set) {
        tolset();
    }
    double[] ret = new double[nreq];
    boolean rankProblem = false;
    for (int i = nreq - 1; i > -1; i--) {
        if (Math.sqrt(d[i]) < tol[i]) {
            ret[i] = 0.0;
            d[i] = 0.0;
            rankProblem = true;
        } else {
            ret[i] = rhs[i];
            nextr = i * (nvars + nvars - i - 1) / 2;
            for (int j = i + 1; j < nreq; j++) {
                ret[i] = smartAdd(ret[i], -r[nextr] * ret[j]);
                ++nextr;
            }
        }
    }
    if (rankProblem) {
        for (int i = 0; i < nreq; i++) {
            if (this.lindep[i]) {
                ret[i] = Double.NaN;
            }
        }
    }
    return ret;
}