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

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

Introduction

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

Prototype

public ArrayRealVector(double[] v1, double[] v2) 

Source Link

Document

Construct a vector by appending one vector to another vector.

Usage

From source file:gamlss.distributions.TF.java

/** Second derivative d2ldn2= (d^2l)/(dnu^2), 
 * where l - log-likelihood function.//  w  ww  .ja  va 2  s. c o m
 * @param y - vector of values of response variable
 * @return  a vector of second derivative d2ldn2= (d^2l)/(dnu^2)
 */
private ArrayRealVector d2ldn2(final ArrayRealVector y) {

    double[] out = new double[size];
    for (int i = 0; i < size; i++) {

        //d2ldv2 <- trigamma(v3)-trigamma(v2)+(2*(nu+5))/(nu*(nu+1)*(nu+3))
        out[i] = Gamma.trigamma(v3[i]) - Gamma.trigamma(v2[i]) + (2.0 * (nuV.getEntry(i) + 5))
                / (nuV.getEntry(i) * (nuV.getEntry(i) + 1) * (nuV.getEntry(i) + 3));

        //d2ldv2 <- d2ldv2/4
        out[i] = out[i] / 4.0;

        //d2ldv2 <- ifelse(d2ldv2 < -1e-15, d2ldv2,-1e-15)
        if (out[i] > -1e-15) {
            out[i] = -1e-15;
        }
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.ST1.java

/** First derivative dldn = dl/dnu, where l - log-likelihood function.
 * @param y - vector of values of response variable
 * @return  a vector of First derivative dldn = dl/dnu
 *//*from   w  w  w . ja v  a  2  s.  c om*/
public final ArrayRealVector dldn(final ArrayRealVector y) {

    dldn = new double[size];
    double temp = 0;
    for (int i = 0; i < size; i++) {

        //dwdv <- w/nu
        //dldv <- (dt(w,df=tau)/pt(w,df=tau))*dwdv
        tdDist.setDegreesOfFreedom(tauV.getEntry(i));
        dldn[i] = (tdDist.density(w[i]) / tdDist.cumulativeProbability(w[i])) * w[i] / nuV.getEntry(i);
    }
    z = null;
    w = null;
    lam = null;
    return new ArrayRealVector(dldn, false);
}

From source file:gamlss.distributions.JSUo.java

/** Second derivative d2lds2= (d^2l)/(dsigma^2), 
 * where l - log-likelihood function.//  ww  w . java 2s  . c om
 * @param y - vector of values of response variable
 * @return  a vector of second derivative d2lds2= (d^2l)/(dsigma^2)
 */
private ArrayRealVector d2lds2(final ArrayRealVector y) {

    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldd2 <- -dldd*dldd
        out[i] = -dlds[i] * dlds[i];
        if (out[i] > -1e-15) {
            out[i] = -1e-15;
        }
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);

}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculate sqrt of the the vector entries.
* @param v - vector/*from  w w  w  .j a v  a  2  s  .c o 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);
}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.RotationKalmanFilter.java

/**
 * Correct the current state estimate with an actual measurement.
 *
 * @param z//ww  w .  ja  v a  2 s . co  m
 *            the measurement vector
 * @throws NullArgumentException
 *             if the measurement vector is {@code null}
 * @throws DimensionMismatchException
 *             if the dimension of the measurement vector does not fit
 * @throws SingularMatrixException
 *             if the covariance matrix could not be inverted
 */
public void correct(final double[] z)
        throws NullArgumentException, DimensionMismatchException, SingularMatrixException {
    correct(new ArrayRealVector(z, false));
}

From source file:gamlss.distributions.PE.java

/** Second derivative d2lds2= (d^2l)/(dsigma^2), 
 * where l - log-likelihood function./*from w ww .j a  v a  2 s .c  o  m*/
 * @param y - vector of values of response variable
 * @return  a vector of second derivative d2lds2= (d^2l)/(dsigma^2)
 */
private ArrayRealVector d2lds2(final ArrayRealVector y) {

    double[] out = new double[size];
    for (int i = 0; i < size; i++) {

        //d2ldd2 <- -nu/(sigma^2)
        out[i] = -nuV.getEntry(i) / (sigmaV.getEntry(i) * sigmaV.getEntry(i));
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.TF2.java

/** Second derivative d2ldn2= (d^2l)/(dnu^2), 
 * where l - log-likelihood function.//from   w  w  w  . j a  va  2 s.  c  o m
 * @param y - vector of values of response variable
 * @return  a vector of second derivative d2ldn2= (d^2l)/(dnu^2)
 */
private ArrayRealVector d2ldn2(final ArrayRealVector y) {

    //d2ldv2 <- d2ldv2 + (ds1dv^2)*TF()$d2ldd2(sigma1, nu)
    tf.setDistributionParameter(DistributionSettings.MU, muV);
    tf.setDistributionParameter(DistributionSettings.SIGMA, sigma1);
    tf.setDistributionParameter(DistributionSettings.NU, nuV);

    tf.firstDerivative(DistributionSettings.SIGMA, y);
    tempV = tf.secondDerivative(DistributionSettings.SIGMA, y);

    double[] out = new double[size];
    for (int i = 0; i < size; i++) {

        //v2 <- nu/2
        //v3 <-(nu+1)/2
        //d2ldv2 <- trigamma(v3)-trigamma(v2)+(2*(nu+5))/(nu*(nu+1)*(nu+3))
        //d2ldv2 <- d2ldv2/4
        out[i] = (Gamma.trigamma((nuV.getEntry(i) + 1) / 2.0) - Gamma.trigamma(nuV.getEntry(i) / 2.0)
                + (2.0 * (nuV.getEntry(i) + 5))
                        / (nuV.getEntry(i) * (nuV.getEntry(i) + 1) * (nuV.getEntry(i) + 3)))
                / 4.0;
        out[i] = out[i] + (ds1dv[i] * ds1dv[i]) * tempV.getEntry(i);
    }
    sigma1 = null;
    ds1dv = null;
    muV = null;
    sigmaV = null;
    nuV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.ST1.java

/** First derivative dldtau = dl/dtau, where l - log-likelihood function.
 * @param y - vector of values of response variable
 * @return  a vector of First derivative dldtau = dl/dtau
 *///  www.ja  v  a 2  s .co  m
public final ArrayRealVector dldt(final ArrayRealVector y) {

    dldt = new double[size];
    for (int i = 0; i < size; i++) {

        //j <- (pt(w,df=tau+0.001,log.p=TRUE)
        //-pt(w,df=tau-0.001,log.p=TRUE))/0.002
        tdDist.setDegreesOfFreedom(tauV.getEntry(i) + 0.001);
        final double part1 = FastMath.log(tdDist.cumulativeProbability(w[i]));

        tdDist.setDegreesOfFreedom(tauV.getEntry(i) - 0.001);
        final double part2 = FastMath.log(tdDist.cumulativeProbability(w[i]));

        final double j = (part1 - part2) / 0.002;

        //dldt <- j + (digamma((tau+1)/2)-digamma(tau/2)
        //-(1/tau)-log(1+(z^2)/tau)+lam*(z^2)/tau)/2
        dldt[i] = j + (Gamma.digamma((tauV.getEntry(i) + 1) / 2) - Gamma.digamma(tauV.getEntry(i) / 2)
                - (1 / tauV.getEntry(i)) - FastMath.log(1 + (z[i] * z[i]) / tauV.getEntry(i))
                + lam[i] * (z[i] * z[i]) / tauV.getEntry(i)) / 2.0;
    }
    z = null;
    w = null;
    lam = null;
    return new ArrayRealVector(dldt, false);
}

From source file:gamlss.utilities.MatrixFunctions.java

/**
* Calculate log of the the vector entries.
* @param v - vector/*  w  ww.  ja  v a 2 s  .  c  o  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.distributions.GT.java

/** Second derivative d2ldm2= (d^2l)/(dmu^2),
 *  where l - log-likelihood function./*from w  w w .j a va 2 s.  co m*/
 * @param y - vector of values of response variable
 * @return  a vector of second derivative d2ldm2= (d^2l)/(dmu^2)
 */
private ArrayRealVector d2ldm2(final ArrayRealVector y) {

    double[] out = new double[size];
    for (int i = 0; i < size; i++) {

        //d2ldm2 <- -dldm*dldm
        out[i] = -dldm[i] * dldm[i];
        //d2ldm2 <- ifelse(d2ldm2 < -1e-15, d2ldm2,-1e-15)
        if (out[i] > -1e-15) {
            out[i] = -1e-15;
        }
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);
}