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

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

Introduction

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

Prototype

@Override
public int getDimension() 

Source Link

Usage

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 
 *//*from   w  w  w .  j  a v a 2s  .  c o 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.JSUo.java

/** Calculate and set initial value of nu.
 * @param y - vector of values of response variable
 * @return vector of initial values of nu
 *///from w  w  w  . j  a v a  2 s. c om
private ArrayRealVector setNuInitial(final ArrayRealVector y) {
    //nu.initial = expression(nu <- rep(0, length(y))),
    return new ArrayRealVector(y.getDimension());
}

From source file:gamlss.distributions.JSUo.java

/** Calculates initial value of tau.
 * @param y - vector of values of response variable
 * @return vector of initial values of tau
 *///from www . j a  va2s .c o  m
private ArrayRealVector setTauInitial(final ArrayRealVector y) {
    //tau.initial = expression(tau <-rep(0.5, length(y))),
    tempV = new ArrayRealVector(y.getDimension());
    tempV.set(0.5);
    return tempV;
}

From source file:gamlss.distributions.JSUo.java

/** Calculate and set initial value of sigma.
    * @param y - vector of values of response variable
    * @return vector of initial values of sigma
    *//*from  w  w  w.  j a va  2  s. co m*/
private ArrayRealVector setSigmaInitial(final ArrayRealVector y) {
    //sigma.initial = expression(sigma<- rep(.1, length(y))),
    tempV = new ArrayRealVector(y.getDimension());
    tempV.set(0.1);
    return tempV;
}

From source file:gamlss.smoothing.PB.java

/**
 *<p>Compute the "hat" matrix.// w  w  w .  j  a v  a  2 s  . c o  m
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * @param xDesign - column of initial smoother matrix
 * @return hat matrix
 */
//function (w, x) 
private ArrayRealVector hatWX(final ArrayRealVector xDesign) {
    //p <- length(x)
    int p = xDesign.getDimension();
    //X <- if (!is.matrix(x)) 
    // matrix(cbind(1, x), ncol = 2)
    //else x
    tempM = new BlockRealMatrix(p, 2);
    tempM.setColumnVector(0, MatrixFunctions.repV(1, p));
    tempM.setColumnVector(1, xDesign);

    //k <- length(w)
    //p <- dim(X)[1]
    //if (p != k)
    if (p != w.getDimension()) {
        System.err.println("`w' and 'x' do not have the same length");
        //stop("`w' and 'x' are not having the same length")
    }

    //Is <- sqrt(w)
    isM = MatrixFunctions.sqrtVec(w);

    //if (any(!is.finite(Is))) 
    if (isM.isInfinite()) {
        //warning("diagonal weights has non-finite entries")
        System.err.println("diagonal weights has non-finite entries");
    }

    //WX <- X
    //wxM = tempM;

    //WX[] <- Is * X
    wxM = MatrixFunctions.multVectorMatrix(isM, tempM);

    //h<-hat(qr(WX))
    return MatrixFunctions.getMainDiagonal(
            (BlockRealMatrix) new BlockRealMatrix(MatrixFunctions.calculateHat(wxM).getData()));
}

From source file:gamlss.distributions.JSUo.java

/** Computes the global Deviance Increament.
    * @param y - vector of response variable values
    * @return vector of global Deviance Increament values 
    *//*from  www .j  a v  a2 s.c  o  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();
    double[] tauArr = distributionParameters.get(DistributionSettings.TAU).getDataRef();

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

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

From source file:gamlss.distributions.TF2.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
 *//*from www .java2 s  .c o  m*/
private ArrayRealVector d2ldsdn(final ArrayRealVector y) {

    sigmaV = distributionParameters.get(DistributionSettings.SIGMA);
    nuV = distributionParameters.get(DistributionSettings.NU);

    size = y.getDimension();
    double[] sigma1T = new double[size];
    double[] ds1ddT = new double[size];
    double[] ds1dvT = new double[size];
    double[] d2ldddvT = new double[size];
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //sigma1 <- (sqrt((nu-2)/nu))*sigma
        sigma1T[i] = FastMath.sqrt((nuV.getEntry(i) - 2.0) / nuV.getEntry(i)) * sigmaV.getEntry(i);

        //ds1dd <-  (sqrt((nu-2)/nu)) 
        ds1ddT[i] = (FastMath.sqrt((nuV.getEntry(i) - 2.0) / nuV.getEntry(i)));

        // ds1dv <-  (sqrt(nu/(nu-2)))*sigma/(nu^2) 
        ds1dvT[i] = (FastMath.sqrt(nuV.getEntry(i) / (nuV.getEntry(i) - 2))) * sigmaV.getEntry(i)
                / (nuV.getEntry(i) * nuV.getEntry(i));

        //d2ldddv <-  ds1dd*2/(sigma1*(nu+3)*(nu+1)) 
        d2ldddvT[i] = ds1ddT[i] * 2 / (sigma1T[i] * (nuV.getEntry(i) + 3) * (nuV.getEntry(i) + 1));
    }

    //d2ldddv <- d2ldddv + ds1dd*ds1dv*TF()$d2ldd2(sigma1, nu)
    tf.setDistributionParameter(DistributionSettings.SIGMA, new ArrayRealVector(sigma1T, false));
    tf.setDistributionParameter(DistributionSettings.NU, nuV);

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

    for (int i = 0; i < size; i++) {
        out[i] = d2ldddvT[i] + ds1ddT[i] * ds1dvT[i] * tempV.getEntry(i);
    }
    tempV = null;
    sigmaV = null;
    nuV = null;
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.TF.java

/** Set logC, c, z arrays.
 * @param y - response variable//from w  w  w.j ava2  s  .  c  o  m
 */
private void setInterimArrays(final ArrayRealVector y) {
    muV = distributionParameters.get(DistributionSettings.MU);
    sigmaV = distributionParameters.get(DistributionSettings.SIGMA);
    nuV = distributionParameters.get(DistributionSettings.NU);

    size = y.getDimension();
    s2 = new double[size];
    dsq = new double[size];
    omega = new double[size];
    ym = new double[size];
    for (int i = 0; i < size; i++) {

        //y-mu
        ym[i] = y.getEntry(i) - muV.getEntry(i);

        //s2 <- sigma^2
        s2[i] = sigmaV.getEntry(i) * sigmaV.getEntry(i);

        //dsq <- ((y-mu)^2)/s2

        dsq[i] = (ym[i] * ym[i]) / s2[i];

        //omega <- (nu+1)/(nu+dsq)
        omega[i] = (nuV.getEntry(i) + 1) / (nuV.getEntry(i) + dsq[i]);
    }
}

From source file:gamlss.distributions.SST.java

/** Calculate and set initial value of nu.
 * @param y - vector of values of response variable
 * @return vector of initial values of nu
 *///w w w. ja  v  a2s  . com
private ArrayRealVector setNuInitial(final ArrayRealVector y) {
    //nu.initial = expression(nu <- rep(1, length(y))),
    tempV = new ArrayRealVector(y.getDimension());
    tempV.set(1.0);
    return tempV;
}

From source file:gamlss.distributions.SST.java

/** Calculates initial value of tau.
 * @param y - vector of values of response variable
 * @return vector of initial values of tau
 *///from   w  w  w.j a  v a2s .co m
private ArrayRealVector setTauInitial(final ArrayRealVector y) {
    //tau.initial = expression(tau <-rep(4, length(y)))
    tempV = new ArrayRealVector(y.getDimension());
    tempV.set(4.0);
    return tempV;
}