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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Usage

From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java

/**
  * LWR prediction/*from ww w  . j  a v a  2 s. c  o  m*/
  * 
  * @param X
  * @param Y
  * @param x0
  * @param tau
  * @return
  */
public Double LWRPredict(ArrayRealVector X, ArrayRealVector Y, double x0, final double tau) {
    ArrayRealVector X0 = new ArrayRealVector(X.getDimension(), x0);
    ArrayRealVector delta = X.subtract(X0);
    ArrayRealVector sqDists = delta.ebeMultiply(delta);
    UnivariateFunction expTau = new UnivariateFunction() {
        @Override
        public double value(double arg0) {
            //log.info(" cp univariate tau " + tau);
            return Math.pow(Math.E, -arg0 / (2 * tau));
        }
    };
    ArrayRealVector W = sqDists.map(expTau);
    double Xt_W_X = X.dotProduct(W.ebeMultiply(X));
    if (Xt_W_X == 0.0) {
        log.error(" cp LWR cannot predict - 0 denominator returning NULL");
        log.error("Xcv is " + X.toString());
        log.error("Ycv is " + Y.toString());
        log.error("x0 is " + x0);
        return null; // <==== NOTE: a caller must be prepared for it
    }
    double theta = (1.0 / Xt_W_X) * X.ebeMultiply(W).dotProduct(Y);

    return theta * x0;
}

From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizierTOUFixedMargin.java

private TotalEnergyRecords sumTotalEnergy(HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy,
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, int currentTimeslot) {

    List<TariffSpecification> allSpecs = new ArrayList<TariffSpecification>();
    allSpecs.addAll(tariffSubscriptions.keySet());
    HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy = estimateShiftedPredictions(
            customer2estimatedEnergy, allSpecs, currentTimeslot);

    int predictionRecordLength = customer2estimatedEnergy.values().iterator().next().getDimension();
    ArrayRealVector predictedMyCustomersEnergy = new ArrayRealVector(predictionRecordLength);

    // we currently predict cost by total amount of energy
    ////from   www.  ja  v a2 s  .co  m
    for (Entry<TariffSpecification, HashMap<CustomerInfo, Integer>> entry : tariffSubscriptions.entrySet()) {
        TariffSpecification spec = entry.getKey();
        for (Entry<CustomerInfo, Integer> e : entry.getValue().entrySet()) {
            CustomerInfo customer = e.getKey();
            int subs = e.getValue();
            RealVector customerEnergy = customer2ShiftedEnergy.get(customer).get(spec).getShiftedEnergy()
                    .mapMultiply(subs);
            predictedMyCustomersEnergy = predictedMyCustomersEnergy.add(customerEnergy);
        }
    }
    // competitor energy prediction
    ArrayRealVector predictedCompetitorsEnergyRecord = new ArrayRealVector(predictionRecordLength);
    HashMap<CustomerInfo, HashMap<TariffSpecification, Integer>> predictedCustomerSubscriptions = BrokerUtils
            .revertKeyMapping(tariffSubscriptions);
    for (CustomerInfo cust : predictedCustomerSubscriptions.keySet()) {
        double subsToOthers = cust.getPopulation()
                - BrokerUtils.sumMapValues(predictedCustomerSubscriptions.get(cust));
        RealVector customerNonShiftedEnergy = customer2estimatedEnergy.get(cust).mapMultiply(subsToOthers);
        predictedCompetitorsEnergyRecord = predictedCompetitorsEnergyRecord.add(customerNonShiftedEnergy);
    }

    log.debug("predictedMyCustomersEnergy =" + predictedMyCustomersEnergy.toString());
    log.debug("predictedCompetitorsEnergyRecord =" + predictedCompetitorsEnergyRecord.toString());
    return new TotalEnergyRecords(predictedMyCustomersEnergy, predictedCompetitorsEnergyRecord);
}