List of usage examples for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector
public ArrayRealVector(ArrayRealVector v) throws NullArgumentException
From source file:com.github.thorbenlindhauer.factor.CanonicalGaussianFactor.java
@Override public double getValueForAssignment(double[] assignment) { RealVector assignmentVector = new ArrayRealVector(assignment); double exponent = -0.5d * assignmentVector.dotProduct(precisionMatrix.operate(assignmentVector)) + scaledMeanVector.dotProduct(assignmentVector) + normalizationConstant; return Math.exp(exponent); }
From source file:eagle.security.userprofile.model.eigen.UserProfileEigenModeler.java
@Override public List<UserProfileEigenModel> generate(String site, String user, RealMatrix matrix) { LOG.info(String.format("Receive aggregated user activity matrix: %s size: %s x %s", user, matrix.getRowDimension(), matrix.getColumnDimension())); computeStats(matrix);/* w w w . j a v a 2s. c o m*/ RealMatrix normalizedInputMatrix = normalizeData(matrix); int lowVariantColumnCount = 0; for (int j = 0; j < normalizedInputMatrix.getColumnDimension(); j++) { if (statistics[j].isLowVariant()) { lowVariantColumnCount++; } } if (normalizedInputMatrix.getColumnDimension() == lowVariantColumnCount) { LOG.info("found user: " + user + " with all features being low variant. Nothing to do..."); UserProfileEigenModel noopModel = UserProfileEigenModel$.MODULE$.apply(System.currentTimeMillis(), site, user, null, null, 0, null, null, null, null, null, statistics); return Arrays.asList(noopModel); } else { computeCovarianceAndSVD(normalizedInputMatrix, lowVariantColumnCount); computeDimensionWithMaxVariance(); computePrincipalComponents(); maximumL2Norm = new ArrayRealVector(principalComponents.length); minimumL2Norm = new ArrayRealVector(principalComponents.length); for (int i = 0; i < principalComponents.length; i++) { RealMatrix trainingDataTranspose = computeMaxDistanceOnPCs(i); } UserProfileEigenModel userprofileEigenModel = UserProfileEigenModel$.MODULE$.apply( System.currentTimeMillis(), site, user, uMatrix, diagonalMatrix, dimension, minVector, maxVector, principalComponents, maximumL2Norm, minimumL2Norm, statistics); return Arrays.asList(userprofileEigenModel); } }
From source file:edu.utexas.cs.tactex.utilityestimation.UtilityEstimatorDefaultForConsumption.java
/** * Core method for estimating utility//from w w w .j a va2s. co m */ public double estimateUtility(HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, HashMap<TariffSpecification, HashMap<CustomerInfo, Double>> predictedCustomerSubscriptions, HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2estimatedTariffCharges, HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customerTariff2ShiftedEnergy, HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy, MarketPredictionManager marketPredictionManager, CostCurvesPredictor costCurvesPredictor, int currentTimeslot/*, HashMap<CustomerInfo,ArrayRealVector> customer2estimatedEnergy*/) { // <= for print purposes log.debug( "estimateUtility(): currently assuming competing tariffs are not new and that my subscriptions are not going to change as a result of them"); // accumulate the final results //int expectedRecordLength = 7 * 24; // TODO use Timeservice here correctly double estTariffIncome = 0; double estTariffCosts = 0; double wholesaleCosts = 0; double balancingCosts = 0; double distributionCosts = 0; double withdrawCosts = 0; //double totalConsumption = 0; //double totalProduction = 0; final int predictionRecordLength = BrokerUtils.extractPredictionRecordLength(customerTariff2ShiftedEnergy); RealVector predictedEnergyRecord = new ArrayRealVector(predictionRecordLength); RealVector totalConsumptionEnergyRecord = new ArrayRealVector(predictionRecordLength); RealVector totalProductionEnergyRecord = new ArrayRealVector(predictionRecordLength); // for each customer get his usage prediction for (Entry<TariffSpecification, HashMap<CustomerInfo, Double>> entry : predictedCustomerSubscriptions .entrySet()) { TariffSpecification spec = entry.getKey(); HashMap<CustomerInfo, Double> subscriptions = entry.getValue(); for (Entry<CustomerInfo, Double> ce : subscriptions.entrySet()) { CustomerInfo customerInfo = ce.getKey(); Double subscribedPopulation = ce.getValue(); // Predicted total tariff cash flow. Sign is inverted since // evaluatedTariffs was computed from customers' perspective if (spec.getPowerType().isConsumption()) { estTariffIncome += -customer2estimatedTariffCharges.get(customerInfo).get(spec) * subscribedPopulation; } else if (spec.getPowerType().isProduction()) { estTariffCosts += -customer2estimatedTariffCharges.get(customerInfo).get(spec) * subscribedPopulation; } else { log.warn("Ignoring unknown powertype when computing tariffs income/costs: " + spec.getPowerType()); } // Predicted total energy RealVector energyPrediction = customerTariff2ShiftedEnergy.get(customerInfo).get(spec) .getShiftedEnergy().mapMultiply(subscribedPopulation); predictedEnergyRecord = predictedEnergyRecord.add(energyPrediction); // Predicted balancing cost balancingCosts += 0; log.debug("Ignoring balancing costs - assuming they are 0"); // Predicted withdraw costs (currently assuming everyone will pay). // sign is inverted since withdraw payment is from customer's perspective HashMap<CustomerInfo, Integer> cust2subs = tariffSubscriptions.get(spec); if (cust2subs != null) { Integer currentSubs = cust2subs.get(customerInfo); if (currentSubs != null && subscribedPopulation < currentSubs) { double withdraws = currentSubs - subscribedPopulation; withdrawCosts += -(withdraws * spec.getEarlyWithdrawPayment()); } } // Predicted total consumption and total production if (spec.getPowerType().isConsumption()) { totalConsumptionEnergyRecord = totalConsumptionEnergyRecord.add(energyPrediction); } else if (spec.getPowerType().isProduction()) { totalProductionEnergyRecord = totalProductionEnergyRecord.add(energyPrediction); } else { log.warn("Ignoring unknown powertype when computing distribution costs"); } } } // Predicted distribution costs log.debug("Ignoring balancing orders and curtailment when computing distribution costs"); distributionCosts = 0; double distributionFee = contextManager.getDistributionFee(); for (int i = 0; i < totalConsumptionEnergyRecord.getDimension(); ++i) { double totalTimeslotConsumption = Math.abs(totalConsumptionEnergyRecord.getEntry(i)); double totalTimeslotProduction = Math.abs(totalProductionEnergyRecord.getEntry(i)); distributionCosts += Math.max(totalTimeslotConsumption, totalTimeslotProduction) * distributionFee; } // Predicted wholesale costs (in one of the following two methods:) if (configuratorFactoryService.isUseCostCurves()) { // TODO: might not work for non-fixed rate competitor tariffs - // better to send a mapping of competitor tariffs inside // predictedCustomerSubscriptions, compute shifted predictions for them, // and use these predictions here. // compute energy of customers I don't have RealVector predictedCompetitorsEnergyRecord = new ArrayRealVector(predictionRecordLength); HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> map = BrokerUtils .revertKeyMapping(predictedCustomerSubscriptions); for (CustomerInfo cust : map.keySet()) { double subsToOthers = cust.getPopulation() - BrokerUtils.sumMapValues(map.get(cust)); RealVector customerNonShiftedEnergy = customer2NonShiftedEnergy.get(cust).mapMultiply(subsToOthers); predictedCompetitorsEnergyRecord = predictedCompetitorsEnergyRecord.add(customerNonShiftedEnergy); } for (int i = 0; i < predictedEnergyRecord.getDimension(); ++i) { int futureTimeslot = currentTimeslot + i; double neededKwh = predictedEnergyRecord.getEntry(i); double competitorKwh = predictedCompetitorsEnergyRecord.getEntry(i); double unitCost = costCurvesPredictor.predictUnitCostKwh(currentTimeslot, futureTimeslot, neededKwh, competitorKwh); // NOTE: unitCost is signed (typically negative) wholesaleCosts += (unitCost + costCurvesPredictor.getFudgeFactorKwh(currentTimeslot)) * neededKwh; log.debug("cost-curve prediction: current " + currentTimeslot + " futureTimeslot " + futureTimeslot + " neededKwh " + neededKwh + " neededKwh + competitorKwh " + (neededKwh + competitorKwh) + " unitCost " + unitCost); } } else { // compute wholesale costs using this consumption and market manager marketprices prediction ArrayRealVector estimatedMarketPrices = marketPredictionManager.getPricePerKwhPredictionForAbout7Days(); // sanity check if (predictedEnergyRecord.getDimension() != estimatedMarketPrices.getDimension()) { log.error("Cannot compute utility - prediction periods of market and energy differ);"); return 0; } wholesaleCosts = -predictedEnergyRecord.dotProduct(estimatedMarketPrices); } log.info("estTariffIncome " + estTariffIncome); log.info("estTariffCosts " + estTariffCosts); log.info("wholesaleCosts " + wholesaleCosts); log.info("balancingCosts " + balancingCosts); log.info("distributionCosts " + distributionCosts); //log.info("old distributionCosts " + Math.max(totalProduction, totalConsumption) * contextManager.getDistributionFee()); log.info("withdrawCosts " + withdrawCosts); return estTariffIncome + estTariffCosts + wholesaleCosts + balancingCosts + distributionCosts + withdrawCosts; }
From source file:com.itemanalysis.psychometrics.optimization.BOBYQAOptimizer.java
/** {@inheritDoc} */ @Override/* w w w . j av a 2s .c om*/ protected PointValuePair doOptimize() { final double[] lowerBound = getLowerBound(); final double[] upperBound = getUpperBound(); // Validity checks. setup(lowerBound, upperBound); isMinimize = (getGoalType() == GoalType.MINIMIZE); currentBest = new ArrayRealVector(getStartPoint()); final double value = bobyqa(lowerBound, upperBound); return new PointValuePair(currentBest.getDataRef(), isMinimize ? value : -value); }
From source file:gamlss.utilities.MatrixFunctions.java
/** * Create a vector of supplied length with supplied * value at every vector entry./*from w ww .j a va 2 s . com*/ * @param value - value of every vector entry * @param lenght - length of vector * @return new vector */ public static ArrayRealVector repV(final double value, final int lenght) { ArrayRealVector tempV = new ArrayRealVector(lenght); tempV.set(value); return tempV; }
From source file:com.joptimizer.optimizers.LPPrimalDualMethodTest.java
/** * Linear programming in 2D in LP form.//w w w . j a va 2 s .c o m * This is the same problem as {@link JOptimizerTest#testLinearProgramming2D()} solved with LPPrimalDualMethod. */ public void testLPLinearProgramming2D() throws Exception { log.debug("testLPLinearProgramming2D"); // START SNIPPET: LPLinearProgramming-1 //Objective function double[] c = new double[] { -1., -1. }; //Inequalities constraints double[][] G = new double[][] { { 4. / 3., -1 }, { -1. / 2., 1. }, { -2., -1. }, { 1. / 3., 1. } }; double[] h = new double[] { 2., 1. / 2., 2., 1. / 2. }; //Bounds on variables double[] lb = new double[] { 0, 0 }; double[] ub = new double[] { 10, 10 }; //optimization problem LPOptimizationRequest or = new LPOptimizationRequest(); or.setC(c); or.setG(G); or.setH(h); or.setLb(lb); or.setUb(ub); or.setDumpProblem(true); //optimization LPPrimalDualMethod opt = new LPPrimalDualMethod(); opt.setLPOptimizationRequest(or); int returnCode = opt.optimize(); // END SNIPPET: LPLinearProgramming-1 if (returnCode == OptimizationResponse.FAILED) { fail(); } OptimizationResponse response = opt.getOptimizationResponse(); double[] sol = response.getSolution(); RealVector cVector = new ArrayRealVector(c); RealVector solVector = new ArrayRealVector(sol); double value = cVector.dotProduct(solVector); log.debug("sol : " + ArrayUtils.toString(sol)); log.debug("value : " + value); assertEquals(1.5, sol[0], or.getTolerance()); assertEquals(0.0, sol[1], or.getTolerance()); }
From source file:com.yahoo.semsearch.fastlinking.DPSearch.java
/** * * @param forwardPath lattice of forwardPath * @param backwardPath lattice of backwardPath * @param nBestList array of arraylists (of string type) with n-best list for each entity span * @return best forward + best backward path */// w ww. jav a 2 s .co m public String bestMergedPath(double[][] forwardPath, double[][] backwardPath, List<String>[] nBestList) { int length = forwardPath.length; for (int i = 0; i < forwardPath.length; i++) { for (int j = 0; j < nBestList[i].size(); j++) { //System.out.println(forwardPath[i][j] + ", " + backwardPath[length - 1 - i][j] + ": " + nBestList[i].get(j)); forwardPath[i][j] += backwardPath[length - 1 - i][j]; } } StringBuilder bestPath = new StringBuilder(); for (int i = 0; i < forwardPath.length; i++) { RealVector realVector = new ArrayRealVector(forwardPath[i]); int bestPathIndex = realVector.getMaxIndex(); bestPath.append(nBestList[i].get(bestPathIndex)); bestPath.append(CANDIDATE_DELIMITER); } return bestPath.toString(); }
From source file:gamlss.algorithm.TEST.java
private void threeParTest() { String fileName = "Data/distTest.csv"; CSVFileReader readData = new CSVFileReader(fileName); readData.readFile();/*from w w w. jav a 2 s . co m*/ ArrayList<String> data = readData.storeValues; ArrayRealVector y = new ArrayRealVector(data.size()); ArrayRealVector mu = new ArrayRealVector(data.size()); ArrayRealVector sigma = new ArrayRealVector(data.size()); ArrayRealVector nu = new ArrayRealVector(data.size()); ArrayRealVector tau = new ArrayRealVector(data.size()); for (int i = 0; i < data.size(); i++) { String[] line = data.get(i).split(","); y.setEntry(i, Double.parseDouble(line[0])); mu.setEntry(i, Double.parseDouble(line[1])); sigma.setEntry(i, Double.parseDouble(line[2])); nu.setEntry(i, Double.parseDouble(line[3])); tau.setEntry(i, Double.parseDouble(line[4])); } double[] outA = new double[y.getDimension()]; String folder = "C:\\Users\\Daniil\\Desktop\\Gamlss_exp/outDistG.csv"; ArrayRealVector out = null; TF2 dist = new TF2(); dist.setDistributionParameter(DistributionSettings.MU, mu); dist.setDistributionParameter(DistributionSettings.SIGMA, sigma); dist.setDistributionParameter(DistributionSettings.NU, nu); dist.setDistributionParameter(DistributionSettings.TAU, tau); //1 out = dist.firstDerivative(DistributionSettings.MU, y); MatrixFunctions.vectorWriteCSV(folder, out, false); //2 out = dist.secondDerivative(DistributionSettings.MU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //3 out = dist.firstDerivative(DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //4 out = dist.secondDerivative(DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //5 out = dist.secondCrossDerivative(DistributionSettings.MU, DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //6 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.dTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //7 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.dTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //8 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //9 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //10 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //11 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //12 for (int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i),nu.getEntry(i), true, true); } // MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //13 for (int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i),nu.getEntry(i), false, true); } // MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //14 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //15 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //16 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.dTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //17 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.pTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //18 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //19 out = dist.firstDerivative(DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //20 out = dist.secondDerivative(DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //21 out = dist.secondCrossDerivative(DistributionSettings.MU, DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //23 out = dist.secondCrossDerivative(DistributionSettings.SIGMA, DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); // System.out.println("Done !!!"); }
From source file:gamlss.utilities.TestingDistributions.java
private void threeParTest() { String fileName = "Data/distTest.csv"; CSVFileReader readData = new CSVFileReader(fileName); readData.readFile();// w w w. j a v a 2 s .c o m ArrayList<String> data = readData.storeValues; ArrayRealVector y = new ArrayRealVector(data.size()); ArrayRealVector mu = new ArrayRealVector(data.size()); ArrayRealVector sigma = new ArrayRealVector(data.size()); ArrayRealVector nu = new ArrayRealVector(data.size()); ArrayRealVector tau = new ArrayRealVector(data.size()); for (int i = 0; i < data.size(); i++) { String[] line = data.get(i).split(","); y.setEntry(i, Double.parseDouble(line[0])); mu.setEntry(i, Double.parseDouble(line[1])); sigma.setEntry(i, Double.parseDouble(line[2])); nu.setEntry(i, Double.parseDouble(line[3])); tau.setEntry(i, Double.parseDouble(line[4])); } double[] outA = new double[y.getDimension()]; String folder = "C:\\Users\\Daniil\\Desktop\\Gamlss_exp/outDistG.csv"; ArrayRealVector out = null; TF2 dist = new TF2(); dist.setDistributionParameter(DistributionSettings.MU, mu); dist.setDistributionParameter(DistributionSettings.SIGMA, sigma); dist.setDistributionParameter(DistributionSettings.NU, nu); dist.setDistributionParameter(DistributionSettings.TAU, tau); //1 out = dist.firstDerivative(DistributionSettings.MU, y); MatrixFunctions.vectorWriteCSV(folder, out, false); //2 out = dist.secondDerivative(DistributionSettings.MU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //3 out = dist.firstDerivative(DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //4 out = dist.secondDerivative(DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //5 out = dist.secondCrossDerivative(DistributionSettings.MU, DistributionSettings.SIGMA, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //6 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.dTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //7 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.dTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //8 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //9 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, true); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //10 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //11 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.pTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //12 for (int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i),nu.getEntry(i), true, true); } // MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //13 for (int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i),nu.getEntry(i), false, true); } // MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //14 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), true, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //15 for (int i = 0; i < y.getDimension(); i++) { outA[i] = dist.qTF2(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), nu.getEntry(i), false, false); } MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //16 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.dTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //17 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.pTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //18 //for(int i = 0; i < y.getDimension(); i++) { // outA[i] = dist.qTF2(y.getEntry(i)); //} //MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true); //19 out = dist.firstDerivative(DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //20 out = dist.secondDerivative(DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //21 out = dist.secondCrossDerivative(DistributionSettings.MU, DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); //23 out = dist.secondCrossDerivative(DistributionSettings.SIGMA, DistributionSettings.NU, y); MatrixFunctions.vectorWriteCSV(folder, out, true); // System.out.println("Done !!!"); }
From source file:com.datumbox.framework.machinelearning.clustering.GaussianDPMM.java
@Override protected Cluster createNewCluster(Integer clusterId) { ModelParameters modelParameters = knowledgeBase.getModelParameters(); TrainingParameters trainingParameters = knowledgeBase.getTrainingParameters(); Cluster c = new Cluster(clusterId); c.setDimensions(modelParameters.getD()); c.setFeatureIds(modelParameters.getFeatureIds()); c.setKappa0(trainingParameters.getKappa0()); c.setNu0(trainingParameters.getNu0()); double[] mu0 = trainingParameters.getMu0(); if (mu0 != null) { c.setMu0(new ArrayRealVector(mu0)); }/*from ww w.jav a 2s . co m*/ double[][] psi0 = trainingParameters.getPsi0(); if (psi0 != null) { c.setPsi0(new BlockRealMatrix(psi0)); } c.initializeClusterParameters(); return c; }