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

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *//*from  w  ww . jav  a  2  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)
                * dSST(y.getEntry(i), muArr[i], sigmaArr[i], nuArr[i], tauArr[i], Controls.LOG_LIKELIHOOD);
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.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  .com
private ArrayRealVector d2ldmdn(final ArrayRealVector y) {

    ArrayRealVector mu = distributionParameters.get(DistributionSettings.MU);
    ArrayRealVector sigma = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nu = distributionParameters.get(DistributionSettings.NU);
    ArrayRealVector tau = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldmdv = function(mu,sigma,nu,tau) 
        //(2*(tau-1)-(tau+1)*(sigma^2)*(nu^2))/(4*mu),
        out[i] = (2 * (tau.getEntry(i) - 1) - (tau.getEntry(i) + 1) * (sigma.getEntry(i) * sigma.getEntry(i))
                * (nu.getEntry(i) * nu.getEntry(i))) / (4 * mu.getEntry(i));
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.java

/** Second cross derivative of likelihood function 
 * in respect to mu and tau (d2ldmdd = d2l/dmu*dtau).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 *//* w  w w.  j a  v  a  2  s.co  m*/
private ArrayRealVector d2ldmdt(final ArrayRealVector y) {

    ArrayRealVector mu = distributionParameters.get(DistributionSettings.MU);
    ArrayRealVector sigma = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nu = distributionParameters.get(DistributionSettings.NU);
    ArrayRealVector tau = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldmdt = (nu/(mu*tau))*(1+tau+(3/2)
        //*(digamma(1/tau)-digamma(3/tau)))
        out[i] = (nu.getEntry(i) / (mu.getEntry(i) * tau.getEntry(i))) * (1 + tau.getEntry(i)
                + (3 / 2) * (Gamma.digamma(1 / tau.getEntry(i)) - Gamma.digamma(3 / tau.getEntry(i))));

    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.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
 *//*w w  w  .  ja v  a 2s .c  o  m*/
private ArrayRealVector d2ldsdn(final ArrayRealVector y) {

    ArrayRealVector mu = distributionParameters.get(DistributionSettings.MU);
    ArrayRealVector sigma = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nu = distributionParameters.get(DistributionSettings.NU);
    ArrayRealVector tau = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //2ldddv = function(sigma,nu,tau) -(sigma*nu*tau)/2
        out[i] = -(sigma.getEntry(i) * nu.getEntry(i) * tau.getEntry(i)) / 2;

    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.java

/** Second cross derivative of likelihood function
 *  in respect to sigma and tau (d2ldmdd = d2l/dsigma*dtau).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 *//*from www . j  a va2s  .com*/
private ArrayRealVector d2ldsdt(final ArrayRealVector y) {

    ArrayRealVector mu = distributionParameters.get(DistributionSettings.MU);
    ArrayRealVector sigma = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nu = distributionParameters.get(DistributionSettings.NU);
    ArrayRealVector tau = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldddt = (1/(sigma*tau))*(1+tau+(3/2)
        //*(digamma(1/tau)-digamma(3/tau)))
        out[i] = (1 / (sigma.getEntry(i) * tau.getEntry(i))) * (1 + tau.getEntry(i)
                + (3 / 2) * (Gamma.digamma(1 / tau.getEntry(i)) - Gamma.digamma(3 / tau.getEntry(i))));

    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.java

/** Second cross derivative of likelihood function 
 * in respect to nu and tau (d2ldmdd = d2l/dnu*dtau).
 * @param y - vector of values of response variable
 * @return  a vector of Second cross derivative
 */// www .  j  a  v  a2  s .co m
private ArrayRealVector d2ldndt(final ArrayRealVector y) {

    ArrayRealVector mu = distributionParameters.get(DistributionSettings.MU);
    ArrayRealVector sigma = distributionParameters.get(DistributionSettings.SIGMA);
    ArrayRealVector nu = distributionParameters.get(DistributionSettings.NU);
    ArrayRealVector tau = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //d2ldvdt  <- (((sigma^2)*nu)/(2*tau))
        //*(1+(tau/3)+0.5*(digamma(1/tau)-digamma(3/tau)))
        out[i] = (((sigma.getEntry(i) * sigma.getEntry(i)) * nu.getEntry(i)) / (2 * tau.getEntry(i)))
                * (1 + (tau.getEntry(i) / 3)
                        + 0.5 * (Gamma.digamma(1 / tau.getEntry(i)) - Gamma.digamma(3 / tau.getEntry(i))));
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.BCPE.java

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *//*from   w ww. j av  a 2 s .c o  m*/
public final ArrayRealVector globalDevianceIncreament(final ArrayRealVector y) {
    // G.dev.incr  = function(y,mu,sigma,nu,tau,...)
    //-2*dBCPE(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)
                * dBCPE(y.getEntry(i), muArr[i], sigmaArr[i], nuArr[i], tauArr[i], Controls.LOG_LIKELIHOOD);
    }
    return new ArrayRealVector(out, false);
}

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

private RealVector columnToVector(double[][] column) {
    double[] data = new double[column.length];
    for (int i = 0; i < data.length; ++i) {
        data[i] = column[i][0];//  w w w . j av  a  2 s.com
    }
    return new ArrayRealVector(data, false);
}

From source file:org.knowrob.vis.model.util.algorithm.ACCUM.java

/**
 * Calculates curvature for the vertices of a triangle. Based on
 * the trimesh2 (2.12) (Szymon Rusinkiewicz Princeton University)
 * curvature calculation algorithm.//  w  w  w. j av a 2s  . co  m
 * 
 * @see <a href="https://github.com/fcole/qrtsc/tree/master/trimesh2">trimesh2</a>
 * 
 * @param curvatures
 *            vertex curvature mapping
 * @param tri
 *            triangle to calculate curvature for
 */
private static void calculateCurvatureForTriangle(HashMap<Vertex, Curvature> curvatures, Triangle tri) {
    // Edges
    Edge e[] = tri.getEdges();

    // N-T-B coordinate system per face
    Vector3f t = new Vector3f(e[0].getEdgeValue());
    t.normalize();
    Vector3f n = new Vector3f();
    n.cross(e[0].getEdgeValue(), e[1].getEdgeValue());
    //n.normalize();
    Vector3f b = new Vector3f();
    b.cross(n, t);
    b.normalize();

    // Estimate curvature based on variation of normals
    // along edges
    float m[] = { 0.0f, 0.0f, 0.0f };
    double w[][] = { { 0.0d, 0.0d, 0.0d }, { 0.0d, 0.0d, 0.0d }, { 0.0d, 0.0d, 0.0d } };
    for (int j = 0; j < 3; j++) {

        float u = e[j].getEdgeValue().dot(t);
        float v = e[j].getEdgeValue().dot(b);
        w[0][0] += u * u;
        w[0][1] += u * v;
        // w[1][1] += v*v + u*u;
        // w[1][2] += u*v;
        w[2][2] += v * v;
        Vector3f dn = new Vector3f(tri.getPosition()[(j + 2) % 3].getNormalVector());
        Vector3f dnn = new Vector3f(tri.getPosition()[(j + 1) % 3].getNormalVector());
        dn.sub(dnn);
        float dnu = dn.dot(t);
        float dnv = dn.dot(b);
        m[0] += dnu * u;
        m[1] += dnu * v + dnv * u;
        m[2] += dnv * v;
    }
    w[1][1] = w[0][0] + w[2][2];
    w[1][2] = w[0][1];

    RealMatrix coefficients = new Array2DRowRealMatrix(w, false);
    DecompositionSolver solver = new LUDecomposition(coefficients).getSolver();
    if (!solver.isNonSingular()) {
        return;
    }

    RealVector constants = new ArrayRealVector(new double[] { m[0], m[1], m[2] }, false);
    RealVector solution = solver.solve(constants);

    m[0] = (float) solution.getEntry(0);
    m[1] = (float) solution.getEntry(1);
    m[2] = (float) solution.getEntry(2);

    // flag for ill-solutioned system (NaN = no valid info on the curvatures => then consider 
    // the curvatures to be the ones of a simple plane)
    boolean okSolution = true;
    if (isNaN(m[0]) || isNaN(m[1]) || isNaN(m[2])) {
        okSolution = false;
    }

    // Push it back out to the vertices
    for (int j = 0; j < tri.getPosition().length; j++) {
        Vertex vj = tri.getPosition()[j];
        float c1, c12, c2;
        float[] ret;

        // guard against ill-conditioned systems (NaN curvatures are viewed as a simple planar
        // corresponding curves      
        if (okSolution) {
            ret = proj_curv(t, b, m[0], m[1], m[2], curvatures.get(vj).getPrincipleDirectionMax(),
                    curvatures.get(vj).getPrincipleDirectionMin());
            if (isNaN(ret[0]) || isNaN(ret[1]) || isNaN(ret[2])) {
                c1 = 0.0f;
                c12 = 0.0f;
                c2 = 0.0f;
            } else {
                c1 = ret[0];
                c12 = ret[1];
                c2 = ret[2];
            }
        } else {
            c1 = 0.0f;
            c12 = 0.0f;
            c2 = 0.0f;
        }

        Curvature c = curvatures.get(vj);

        double wt = 0.0d;
        if (vj.getPointarea() != 0.0f) {
            if (j == 0)
                wt = tri.getCornerarea().x / vj.getPointarea();
            else if (j == 1)
                wt = tri.getCornerarea().y / vj.getPointarea();
            else
                wt = tri.getCornerarea().z / vj.getPointarea();
        }

        synchronized (c) {
            c.setCurvatureMax((float) (c.getCurvatureMax() + wt * c1));
            c.setCurvatureMinMax((float) (c.getCurvatureMinMax() + wt * c12));
            c.setCurvatureMin((float) (c.getCurvatureMin() + wt * c2));
        }
    }
}

From source file:org.lambda3.indra.core.annoy.AnnoyVectorSpace.java

@Override
protected Map<String, RealVector> collectVectors(Iterable<? extends String> terms) {
    Map<String, RealVector> vectors = new HashMap<>();

    for (String term : terms) {
        double[] v = getVector(term);
        if (v != null) {
            RealVector vector = new ArrayRealVector(v, false);
            vectors.put(term, vector);/*  ww w.java  2s  . c om*/
        }
    }

    return vectors;
}