Example usage for org.apache.commons.math3.linear ArrayRealVector getEntry

List of usage examples for org.apache.commons.math3.linear ArrayRealVector getEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear ArrayRealVector getEntry.

Prototype

@Override
public double getEntry(int index) throws OutOfRangeException 

Source Link

Usage

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculates a difference of two vectors (v1 - v2).
* @param v1 - first vector/*ww  w.j a v  a  2 s . c  om*/
* @param v2 - second vector
* @return vector (v1 - v2)
*/
public static ArrayRealVector vecSub(final ArrayRealVector v1, final ArrayRealVector v2) {
    int size = v1.getDimension();
    double[] tempArr = new double[size];
    for (int i = 0; i < size; i++) {
        tempArr[i] = v1.getEntry(i) - v2.getEntry(i);
    }
    return new ArrayRealVector(tempArr, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculates the sum of two vectors (v1+v2).
* @param v1 - first vector//from   ww w . j  a v a 2 s .  com
* @param v2 - second vector
* @return vector (v1+v2)
*/
public static ArrayRealVector vecSum(final ArrayRealVector v1, final ArrayRealVector v2) {
    int size = v1.getDimension();
    double[] tempArr = new double[size];
    for (int i = 0; i < size; i++) {
        tempArr[i] = v1.getEntry(i) + v2.getEntry(i);
    }
    return new ArrayRealVector(tempArr, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * Calculate this: (x - t) ^ p * (x > t).
 * @param v1 vector 1//from  www.  j  av  a2s.  co m
 * @param v2 vector 2
 * @param p - power
 * @return  matrix C with Cij = v1i * v2j.
 */
//tpower <- function(x, t, p)
public static BlockRealMatrix outertpowerPB(final ArrayRealVector v1, final ArrayRealVector v2, final int p) {

    double[][] newdata = new double[v1.getDimension()][v2.getDimension()];
    for (int j = 0; j < v1.getDimension(); j++) {
        for (int j2 = 0; j2 < v2.getDimension(); j2++) {
            if (v1.getEntry(j) > v2.getEntry(j2)) {
                newdata[j][j2] = FastMath.pow((v1.getEntry(j) - v2.getEntry(j2)), p);
            } else {
                newdata[j][j2] = 0d;
            }
        }
    }
    return new BlockRealMatrix(newdata);
}

From source file:gamlss.algorithm.GlimFitCG.java

private ArrayRealVector setWV(ArrayRealVector in1, ArrayRealVector in2) {

    double[] out = new double[in1.getDimension()];
    for (int i = 0; i < out.length; i++) {
        out[i] = in1.getEntry(i) + in2.getEntry(i);
    }/*from   ww  w  . ja  v  a 2s.  c  om*/
    return new ArrayRealVector(out, false);
}

From source file:gamlss.algorithm.GlimFitCG.java

private ArrayRealVector etaMean(ArrayRealVector etaMU, ArrayRealVector etaOldMU) {

    double[] out = new double[etaMU.getDimension()];
    for (int i = 0; i < out.length; i++) {
        out[i] = (etaMU.getEntry(i) + etaOldMU.getEntry(i)) / 2;
    }//from   ww w  . j  a  v  a2 s  .  c o  m
    return new ArrayRealVector(out, false);
}

From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java

/**
 * Compute the n-fold Cross validation error with LWR and a given Tau
 * /*from ww  w .  jav a  2s . c  o  m*/
 * @param tau
 * @param x
 * @param y
 * @return
 */
private Double CrossValidationError(Double tau, ArrayRealVector x, ArrayRealVector y) {
    int n = x.getDimension();
    double totalError = 0.0;
    for (int i = 0; i < n; ++i) {
        // CV fold for i
        double x_i = x.getEntry(i);
        double y_i = y.getEntry(i);
        ArrayRealVector Xcv = new ArrayRealVector((ArrayRealVector) x.getSubVector(0, i),
                x.getSubVector(i + 1, n - (i + 1)));
        ArrayRealVector Ycv = new ArrayRealVector((ArrayRealVector) y.getSubVector(0, i),
                y.getSubVector(i + 1, n - (i + 1)));
        Double y_predicted = LWRPredict(Xcv, Ycv, x_i, tau);
        if (null == y_predicted) {
            log.error(" cp LWR cannot predict - returning NULL");
            return null;
        }
        double predictionError = y_predicted - y_i;
        totalError += predictionError * predictionError;
    }
    return totalError;
}

From source file:lambertmrev.Lambert.java

public double householder(double T, double x0, int N, double eps, int iter_max, double m_lambda) {
    int it = 0;/*from w ww  .  ja  va2 s . c o m*/
    double err = 1.0;
    double xnew = 0.0;
    double tof = 0.0, delta = 0.0, DT = 0.0, DDT = 0.0, DDDT = 0.0;
    ArrayRealVector out = new ArrayRealVector();
    while ((err > eps) && (it < iter_max)) {
        tof = x2tof(x0, N, m_lambda);
        ArrayRealVector deriv = dTdx(x0, tof, m_lambda);
        DT = deriv.getEntry(0);
        DDT = deriv.getEntry(1);
        DDDT = deriv.getEntry(2);
        delta = tof - T;
        double DT2 = DT * DT;
        xnew = x0 - delta * (DT2 - delta * DDT / 2.0) / (DT * (DT2 - delta * DDT) + DDDT * delta * delta / 6.0);
        err = FastMath.abs(x0 - xnew);
        x0 = xnew;
        it++;
    }

    return x0;
}

From source file:gamlss.algorithm.CGAlgorithm.java

/**
 *  Calculates inverse of dr vector values (1/dr)
 * @param dr - vector of 1/(link function of the linear pridictoor) values
 * @return 1/dr/*from  w w  w .  ja  v  a 2 s  .c  o  m*/
 */
private ArrayRealVector drInverse(ArrayRealVector dr) {
    double[] out = new double[dr.getDimension()];
    for (int i = 0; i < out.length; i++) {
        out[i] = 1 / dr.getEntry(i);
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.algorithm.CGAlgorithm.java

/**
 * Calculates values of wt vector//from www .j av  a  2  s . co  m
 * @param d2ldp2 - vector of second derivative values with respect to the fitted distribution parameter
 * @param dr - vector of 1/(link function of the linear pridictoor) values
 * @return wt = -(d2ldp2/(dr*dr))
 */
private ArrayRealVector wtSet(ArrayRealVector d2ldp2, ArrayRealVector dr) {
    double[] out = new double[d2ldp2.getDimension()];
    for (int i = 0; i < out.length; i++) {
        out[i] = -(d2ldp2.getEntry(i) / (dr.getEntry(i) * dr.getEntry(i)));
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.algorithm.CGAlgorithm.java

/**
 * Calculates values of wt vector/*  w w  w . ja  v a2 s . c o m*/
 * @param d2ldp2 - vector of second derivative values with respect to the fitted distribution parameter
 * @param dr - vector of 1/(link function of the linear pridictoor) values
 * @return wt = -(d2ldp2/(dr*dr))
 */
private ArrayRealVector wMUSIGMAset(ArrayRealVector u2MUSIGMA, ArrayRealVector drMU, ArrayRealVector drSIGMA) {
    double[] out = new double[u2MUSIGMA.getDimension()];
    for (int i = 0; i < out.length; i++) {
        out[i] = -(u2MUSIGMA.getEntry(i) / (drMU.getEntry(i) * drSIGMA.getEntry(i)));
    }
    return new ArrayRealVector(out, false);
}