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.SST.java

/** Second derivative d2ldm2= (d^2l)/(dmu^2),
 *  where l - log-likelihood function.//from w w  w  .j a v  a 2s  .  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];
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.PE.java

/** Second cross derivative of likelihood function 
 * in respect to sigma and nu (d2ldmdd = d2l/dsigma*dnu).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 *///  www . ja  va  2 s .  c om
private ArrayRealVector d2ldsdn(final ArrayRealVector y) {

    ArrayRealVector sigmaT = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nuT = distributionParameters.get(DistributionSettings.NU);

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

        //d2ldddv = function(y,mu,sigma,nu) (1/(2*sigma))
        //*((3/nu)*(digamma(1/nu)-digamma(3/nu))+2+(2/nu))
        out[i] = (1 / (2 * sigmaT.getEntry(i))) * ((3 / nuT.getEntry(i))
                * (Gamma.digamma(1 / nuT.getEntry(i)) - Gamma.digamma(3 / nuT.getEntry(i))) + 2
                + (2 / nuT.getEntry(i)));
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.SST.java

/** Second derivative d2lds2= (d^2l)/(dsigma^2), 
 * where l - log-likelihood function./*from  w w w. ja va2  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 <- -dldd*dldd
        out[i] = -dlds[i] * dlds[i];
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);

}

From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java

/**
 * test examples in user guide/*from   w ww .j  av a2  s.c  o m*/
 */
@Test
public void testExamples() {
    // Create a real matrix with two rows and three columns
    double[][] matrixData = { { 1d, 2d, 3d }, { 2d, 5d, 3d } };
    RealMatrix m = new BigSparseRealMatrix(matrixData);
    // One more with three rows, two columns
    double[][] matrixData2 = { { 1d, 2d }, { 2d, 5d }, { 1d, 7d } };
    RealMatrix n = new BigSparseRealMatrix(matrixData2);
    // Now specialOperation m by n
    RealMatrix p = m.multiply(n);
    Assert.assertEquals(2, p.getRowDimension());
    Assert.assertEquals(2, p.getColumnDimension());
    // Invert p
    RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();
    Assert.assertEquals(2, pInverse.getRowDimension());
    Assert.assertEquals(2, pInverse.getColumnDimension());

    // Solve example
    double[][] coefficientsData = { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } };
    RealMatrix coefficients = new BigSparseRealMatrix(coefficientsData);
    RealVector constants = new ArrayRealVector(new double[] { 1, -2, 1 }, false);
    RealVector solution = new LUDecomposition(coefficients).getSolver().solve(constants);
    final double cst0 = constants.getEntry(0);
    final double cst1 = constants.getEntry(1);
    final double cst2 = constants.getEntry(2);
    final double sol0 = solution.getEntry(0);
    final double sol1 = solution.getEntry(1);
    final double sol2 = solution.getEntry(2);
    Assert.assertEquals(2 * sol0 + 3 * sol1 - 2 * sol2, cst0, 1E-12);
    Assert.assertEquals(-1 * sol0 + 7 * sol1 + 6 * sol2, cst1, 1E-12);
    Assert.assertEquals(4 * sol0 - 3 * sol1 - 5 * sol2, cst2, 1E-12);
}

From source file:gamlss.distributions.TF2.java

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *//*  w w  w .j av  a2 s  . co m*/
public final ArrayRealVector globalDevianceIncreament(final ArrayRealVector y) {
    //G.dev.incr  = function(y,mu,sigma,nu,tau,...)  
    size = y.getDimension();
    double[] out = new double[size];

    double[] muArr = distributionParameters.get(DistributionSettings.MU).getDataRef();
    double[] sigmaArr = distributionParameters.get(DistributionSettings.SIGMA).getDataRef();
    double[] nuArr = distributionParameters.get(DistributionSettings.NU).getDataRef();

    for (int i = 0; i < size; i++) {

        out[i] = (-2) * dTF2(y.getEntry(i), muArr[i], sigmaArr[i], nuArr[i], Controls.LOG_LIKELIHOOD);
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.GT.java

/** Second cross derivative of likelihood function in 
 * respect to mu and sigma (d2ldmdd = d2l/dmu*dsigma).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 *//* w  w w.  ja  v a 2  s .com*/
private ArrayRealVector d2ldmds(final ArrayRealVector y) {
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        // d2ldmdd <- -(dldm*dldd)
        out[i] = -dldm[i] * dlds[i];
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.java

/** Second derivative d2ldm2= (d^2l)/(dmu^2), 
 * where l - log-likelihood function./*from   www  .j a v a2s  . c  o  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 <- if (any(tau<1.05)) -dldm*dldm else d2ldm2
        if (tauV.getEntry(i) < 1.05) {
            out[i] = -dldm[i] * dldm[i];
        } else {

            //d2ldm2 <- -((tau*tau)*gamma(2-(1/tau))*gamma(3/tau))
            ///(mu^2*sigma^2*(gamma(1/tau))^2)
            //d2ldm2 <- d2ldm2-(tau*nu^2)/mu^2
            out[i] = -((tauV.getEntry(i) * tauV.getEntry(i))
                    * FastMath.exp(Gamma.logGamma(2 - (1 / tauV.getEntry(i))))
                    * FastMath.exp(Gamma.logGamma(3 / tauV.getEntry(i))))
                    / (muV.getEntry(i) * muV.getEntry(i) * sigmaV.getEntry(i) * sigmaV.getEntry(i)
                            * (FastMath.exp(Gamma.logGamma(1 / tauV.getEntry(i))))
                            * (FastMath.exp(Gamma.logGamma(1 / tauV.getEntry(i)))));
            out[i] = out[i] - (tauV.getEntry(i) * nuV.getEntry(i) * nuV.getEntry(i))
                    / (muV.getEntry(i) * muV.getEntry(i));
        }
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.PE.java

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *//*  ww w. java  2 s.co m*/
public final ArrayRealVector globalDevianceIncreament(final ArrayRealVector y) {
    //G.dev.incr  = function(y,mu,sigma,nu,tau,...)  
    //-2*dST3(y,mu,sigma,nu,tau,log=TRUE),
    size = y.getDimension();
    double[] out = new double[size];

    double[] muArr = distributionParameters.get(DistributionSettings.MU).getDataRef();
    double[] sigmaArr = distributionParameters.get(DistributionSettings.SIGMA).getDataRef();
    double[] nuArr = distributionParameters.get(DistributionSettings.NU).getDataRef();

    for (int i = 0; i < size; i++) {

        out[i] = (-2) * dPE(y.getEntry(i), muArr[i], sigmaArr[i], nuArr[i], Controls.LOG_LIKELIHOOD);
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.SST.java

/** Second derivative d2ldn2= (d^2l)/(dnu^2), 
 * where l - log-likelihood function./*  w w  w .  jav a 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 <- -dldv*dldv
        out[i] = -dldn[i] * dldn[i];
    }
    muV = null;
    sigmaV = null;
    nuV = null;
    tauV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.GT.java

/** Second cross derivative of likelihood function
  * in respect to mu and nu (d2ldmdd = d2l/dmu*dnu).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 *//* w  w w.j av a 2  s  .  c  o m*/
private ArrayRealVector d2ldmdn(final ArrayRealVector y) {
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldmdv <- -(dldm*dldv)
        out[i] = -dldm[i] * dldn[i];
    }
    return new ArrayRealVector(out, false);
}