本文整理匯總了Java中org.apache.commons.math3.linear.ArrayRealVector.getDimension方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayRealVector.getDimension方法的具體用法?Java ArrayRealVector.getDimension怎麽用?Java ArrayRealVector.getDimension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.linear.ArrayRealVector
的用法示例。
在下文中一共展示了ArrayRealVector.getDimension方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: CrossValidationError
import org.apache.commons.math3.linear.ArrayRealVector; //導入方法依賴的package包/類
/**
* Compute the n-fold Cross validation error with LWR and a given Tau
*
* @param tau
* @param x
* @param y
* @return
*/
private Double CrossValidationError(Double tau, ArrayRealVector x,
ArrayRealVector y) {
int n = x.getDimension();
double totalError = 0.0;
for (int i = 0; i < n; ++i) {
// CV fold for i
double x_i = x.getEntry(i);
double y_i = y.getEntry(i);
ArrayRealVector Xcv = new ArrayRealVector( (ArrayRealVector)x.getSubVector(0, i), x.getSubVector(i+1, n - (i+1)) );
ArrayRealVector Ycv = new ArrayRealVector( (ArrayRealVector)y.getSubVector(0, i), y.getSubVector(i+1, n - (i+1)) );
Double y_predicted = LWRPredict(Xcv, Ycv, x_i, tau);
if (null == y_predicted) {
log.error(" cp LWR cannot predict - returning NULL");
return null;
}
double predictionError = y_predicted - y_i;
totalError += predictionError * predictionError;
}
return totalError;
}
示例2: LWRPredict
import org.apache.commons.math3.linear.ArrayRealVector; //導入方法依賴的package包/類
/**
* LWR prediction
*
* @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;
}
示例3: computeAvgMargin
import org.apache.commons.math3.linear.ArrayRealVector; //導入方法依賴的package包/類
/**
* returns positive margin between selling unit-price and buying unit-cost
* @param energyUnitCosts
* @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;
}
示例4: computeEnergyUnitCosts
import org.apache.commons.math3.linear.ArrayRealVector; //導入方法依賴的package包/類
private ArrayRealVector computeEnergyUnitCosts(
CostCurvesPredictor costCurvesPredictor,
ArrayRealVector predictedMyCustomersEnergy,
ArrayRealVector predictedCompetitorsEnergy,
int currentTimeslot) {
ArrayRealVector energyUnitCosts = new ArrayRealVector(predictedMyCustomersEnergy.getDimension());
for (int i = 0; i < energyUnitCosts.getDimension(); ++i) {
int futureTimeslot = currentTimeslot + i + 1; // +1 since energy record starts next timeslot
energyUnitCosts.setEntry(i, costCurvesPredictor.predictUnitCostKwh(currentTimeslot, futureTimeslot, predictedMyCustomersEnergy.getEntry(i), predictedCompetitorsEnergy.getEntry(i))
+ costCurvesPredictor.getFudgeFactorKwh(currentTimeslot));
}
//log.debug("energyUnitCosts =" + energyUnitCosts.toString());
return energyUnitCosts;
}