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

/**
 * Prints vector values in the console./* w  ww .  j  a va 2  s.  c  om*/
 * @param v - vector to print
 */
public static void vectorPrint(final ArrayRealVector v) {
    for (int i = 0; i < v.getDimension(); i++) {
        System.out.println(v.getEntry(i));
    }
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Sum all vector entries./*from  w  ww.  j  av  a 2s .c  om*/
* @param v - vector
* @return sum of vector entries
*/
public static double sumV(final ArrayRealVector v) {
    double tempD = 0;
    for (int j = 0; j < v.getDimension(); j++) {
        tempD = tempD + v.getEntry(j);
    }
    return tempD;
}

From source file:gamlss.utilities.MatrixFunctions.java

public static double dotProduct(ArrayRealVector v1, ArrayRealVector v2) {
    double out = 0;
    for (int i = 0; i < v1.getDimension(); i++) {
        out = out + v1.getEntry(i) * v2.getEntry(i);
    }/*from  w ww .  j  a va2s .c o  m*/
    return out;
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
*  Calculates inverse of vector values.// w w  w.  j  av  a2s.co m
* @param v - vector
* @return 1/v
*/
public static ArrayRealVector inverse(final ArrayRealVector v) {
    double[] tempArr = new double[v.getDimension()];
    for (int i = 0; i < tempArr.length; i++) {
        tempArr[i] = 1 / v.getEntry(i);
    }
    return new ArrayRealVector(tempArr, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

public static ArrayRealVector multVvsD(ArrayRealVector v, double d) {
    int size = v.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        out[i] = v.getEntry(i) * d;
    }//from  ww w.  j  a  va2 s .  c  o  m
    return new ArrayRealVector(out, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * if the length of the return vector is zero,
 *  then the diff was not completed properly.
 *  @param data - vector//from w w w.  j  a v  a2  s .  co  m
 *  @return - vector
 */
private static ArrayRealVector getDiff(final ArrayRealVector data) {
    double[] newdata = new double[data.getDimension() - 1];

    for (int i = 0; i < newdata.length; i++) {
        newdata[i] = data.getEntry(i + 1) - data.getEntry(i);
    }
    return new ArrayRealVector(newdata, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * Add value to each entry of vector.//from ww w  . java2s.  c  om
 * @param v - vector
 * @param value - value to add
 * @return new vector
 */
public static ArrayRealVector addValueToVector(final ArrayRealVector v, final double value) {
    double[] tempArr = new double[v.getDimension()];
    for (int i = 0; i < tempArr.length; i++) {
        tempArr[i] = v.getEntry(i) + value;
    }
    return new ArrayRealVector(tempArr, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

public static ArrayRealVector addV(ArrayRealVector v1, ArrayRealVector v2) {
    int size = v1.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        out[i] = v1.getEntry(i) + v2.getEntry(i);
    }// w  ww  . j  a va 2 s  .co m
    return new ArrayRealVector(out, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculate log of the the vector entries.
* @param v - vector/*from   w ww .j  av a  2s  . co m*/
* @return log(vector)
*/
public static ArrayRealVector logVec(final ArrayRealVector v) {
    int size = v.getDimension();
    double[] tempArr = new double[size];
    for (int i = 0; i < size; i++) {
        tempArr[i] = FastMath.log(v.getEntry(i));
    }
    return new ArrayRealVector(tempArr, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculate sqrt of the the vector entries.
* @param v - vector/*from  w w  w  .  ja  v  a 2 s  .co  m*/
* @return sqrt(vector)
*/
public static ArrayRealVector sqrtVec(final ArrayRealVector v) {
    int size = v.getDimension();
    double[] tempArr = new double[size];
    for (int i = 0; i < size; i++) {
        tempArr[i] = FastMath.sqrt(v.getEntry(i));
    }
    return new ArrayRealVector(tempArr, false);
}