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:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizierTOUFixedMargin.java

/**
 * returns positive margin between selling unit-price and buying unit-cost 
 * @param energyUnitCosts//  ww  w  .ja v  a 2s  . c  o m
 * @param fixedRateSeed
 * @return
 */
private double computeAvgMargin(ArrayRealVector energyUnitCosts, TariffSpecification fixedRateSeed) {
    double totalMargin = 0;
    // next: '-' to adjust sign to broker perspective (i.e. make it positive)
    double sellingPricePerKwh = -(fixedRateSeed.getRates().get(0).getValue());
    for (int i = 0; i < energyUnitCosts.getDimension(); ++i) {
        double buyingPricePerKwh = energyUnitCosts.getEntry(i);
        // next: '+' since buyingPricePerKwh is signed (i.e. negative)
        double margin = sellingPricePerKwh + buyingPricePerKwh;
        totalMargin += margin;
        log.debug("computeAvgMargin(): sellingPricePerKwh=" + sellingPricePerKwh + " buyingPricePerKwh="
                + buyingPricePerKwh + "margin =" + margin + " totalMargin=" + totalMargin);
    }
    double avgMargin = totalMargin / energyUnitCosts.getDimension();
    log.debug("avgMargin=" + avgMargin);
    return avgMargin;
}

From source file:gamlss.algorithm.AdditiveFit.java

/**
 * Calculates rss = weighted.mean(residuals^2, w).
 * @param resid - residuals/*from  w  w  w .  j av a2 s.  c  o m*/
 * @param weights - vector of weights
 * @return weighted.mean(residuals^2, w)
 */
private double calculateRss(final ArrayRealVector resid, final ArrayRealVector weights) {
    //rss <- weighted.mean(residuals^2, w)
    size = resid.getDimension();
    tempArr = new double[size];
    for (int i = 0; i < size; i++) {
        tempArr[i] = resid.getEntry(i) * resid.getEntry(i);
    }
    size = 0;
    return mean.evaluate(new ArrayRealVector(tempArr, false).getDataRef(), weights.toArray());
}

From source file:gamlss.algorithm.GlimFit.java

/** Check whether vector wv has some NaN values 
 * and if it does sets NaNs to zero./* www  .j a v a2 s .  c o  m*/
 * @param v = (eta-os)+dldp/(dr*wt)
 * @return v = (eta-os)+dldp/(dr*wt) or zeros*/
private ArrayRealVector wvCheck(final ArrayRealVector v) {
    if (v.isNaN()) {
        double[] tempA = new double[v.getDimension()];
        for (int i = 0; i < tempA.length; i++) {
            Double vD = v.getEntry(i);
            if (vD.isNaN()) {
                tempA[i] = 0.0;
            } else {
                tempA[i] = vD;
            }
        }
        return new ArrayRealVector(tempA, false);
    }
    return v;
}

From source file:gamlss.distributions.GA.java

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *///from  w ww  . j a v  a2  s .c o m
public final ArrayRealVector globalDevianceIncreament(final ArrayRealVector y) {

    size = y.getDimension();
    double[] out = new double[size];

    double[] muArr = distributionParameters.get(DistributionSettings.MU).getDataRef();
    double[] sigmaArr = distributionParameters.get(DistributionSettings.SIGMA).getDataRef();
    for (int i = 0; i < size; i++) {

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

From source file:gamlss.distributions.NO.java

/**  Calculates initial value of mu, by assumption these values lie
between observed data and the trend line.
 * @param y - vector of values of response variable
 * @return vector of initial values of mu
 *///from  www.jav  a  2  s  .c  o m
private ArrayRealVector setMuInitial(final ArrayRealVector y) {
    size = y.getDimension();
    double[] out = new double[size];
    final double yMean = new Mean().evaluate(y.getDataRef());
    for (int i = 0; i < size; i++) {
        out[i] = (y.getEntry(i) + yMean) / 2;
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.NO.java

/** Computes the global Deviance Increament.
 * @param y - vector of response variable values
 * @return vector of global Deviance Increament values 
 *///from   ww  w.  j a  v  a  2 s  .  c  o m
public final ArrayRealVector globalDevianceIncreament(final ArrayRealVector y) {

    size = y.getDimension();
    double[] out = new double[size];

    double[] muArr = distributionParameters.get(DistributionSettings.MU).getDataRef();
    double[] sigmaArr = distributionParameters.get(DistributionSettings.SIGMA).getDataRef();
    for (int i = 0; i < size; i++) {

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

From source file:gamlss.utilities.MakeLinkFunction.java

/**
 *  Calculates a fitted values of the distribution parameter vector according to the log link function
 * @param eta - vector of linear predictor values
 * @return vector of fitted values/*from   w ww  .j ava2  s.  com*/
 */
public ArrayRealVector logInv(ArrayRealVector eta) {
    int size = eta.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        out[i] = FastMath.exp(eta.getEntry(i));
        if (out[i] < 2.220446e-16) //!!!!    .Machine$double.eps
        {
            out[i] = 2.220446e-16;
        }
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.utilities.MakeLinkFunction.java

/**
 * Calculates the values of  distribution parameter  Eta vector according to log link function
 * @param eta - vector of linear predictor values
 * @return muEta vector/*from  ww  w  .ja  v  a  2  s . c o  m*/
 */
public ArrayRealVector logDistParameterEta(ArrayRealVector eta) {
    int size = eta.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        out[i] = FastMath.exp(eta.getEntry(i));
        if (out[i] < 2.220446e-16) //!!!!    .Machine$double.eps
        {
            out[i] = 2.220446e-16;

        }
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.utilities.MakeLinkFunction.java

/**
 * Calculates the values of distribution parameter Eta vector according to log link function
 * @param eta - vector of linear predictor values
 * @return muEta vector//  w ww .  ja v a 2s .  c o  m
 */
public ArrayRealVector logShiftTo2DistParameterEta(ArrayRealVector eta) {
    int size = eta.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //mu.eta <- function(eta) pmax(.Machine$double.eps, exp(eta))
        out[i] = FastMath.exp(eta.getEntry(i));
        if (out[i] < Double.MIN_VALUE) //!!!!    .Machine$double.eps
        {
            out[i] = Double.MIN_VALUE;
        }
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.utilities.MakeLinkFunction.java

/**
 *  Calculates a fitted values of the distribution parameter vector according to the log link function
 * @param eta - vector of linear predictor values
 * @return vector of fitted values/*  w  w  w  .  ja  va  2 s  .c o m*/
 */
public ArrayRealVector logShiftTo2Inv(ArrayRealVector eta) {
    int size = eta.getDimension();
    double[] out = new double[size];
    for (int i = 0; i < size; i++) {
        //linkinv <- function(eta) 2+pmax(.Machine$double.eps, exp(eta)) 
        out[i] = FastMath.exp(eta.getEntry(i));
        if (out[i] < 2.220446e-16) //!!!!    .Machine$double.eps
        {
            out[i] = 2.220446e-16;
        }
        out[i] = out[i] + 2;
    }
    return new ArrayRealVector(out, false);
}