List of usage examples for org.apache.commons.math3.linear ArrayRealVector mapDivideToSelf
@Override public RealVector mapDivideToSelf(double d)
From source file:info.rmarcus.birkhoffvonneumann.MatrixUtils.java
public static double[] normalize(double[] input) { ArrayRealVector arv = new ArrayRealVector(input); arv.mapDivideToSelf(arv.getNorm()); return NullUtils.orThrow(arv.toArray(), () -> new BVNRuntimeException("Could not normalize array!")); }
From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java
private ArrayRealVector createNormalizedXVector(Set<Double> xValues, double min, double max) { Double[] dummy1 = new Double[1]; // needed to determine the type of toArray? ArrayRealVector xVector = new ArrayRealVector(xValues.toArray(dummy1)); xVector.mapSubtractToSelf(min);//from w w w .j a va 2 s . c o m xVector.mapDivideToSelf(max - min); // translating [0,1]=>[0.1,0.9] xVector.mapMultiplyToSelf(SQUEEZE); xVector.mapAddToSelf(OFFSET); return xVector; }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.DefaultCapacityBundle.java
/** * sum all originator's (scaled) energies (since I believe the broker sees the * sum of them only). /*from w w w . j a va2 s . c om*/ * @param currentTimeslot * @throws Exception * @throws DimensionMismatchException */ @Override public ArrayRealVector getPredictedEnergy(TariffSubscription subscription, int recordLength, int currentTimeslot) throws DimensionMismatchException, Exception { ArrayRealVector result = new ArrayRealVector(recordLength); // sum all originator's energies for (CapacityOriginator originator : capacityOriginators) { ArrayRealVector originatorPredictedEnergy = originator.getPredictedEnergy(subscription, recordLength, currentTimeslot); //log.info("originatorPredictedEnergy " + Arrays.toString(originatorPredictedEnergy.toArray())); result = result.add(originatorPredictedEnergy); //log.info("bundleresult " + Arrays.toString(result.toArray())); } // normalize to 1 population member result.mapDivideToSelf(customerInfo.getPopulation()); //log.info("bundleresultnormalized " + Arrays.toString(result.toArray())); // all predictions are positive and are adjusted in the server in // DefaultUtilityOptimizer.usePower() therefore we adjust the sign here, // the last point before returning to our shifting predictor double usageSign = getPowerType().isConsumption() ? +1 : -1; result.mapMultiplyToSelf(usageSign); return result; }
From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java
public void align() { // refresh all nodes /*/* ww w. jav a2s . c om*/ if (!coordinates.keySet().equals(graph.vertexSet())) { final Map<N, ArrayRealVector> newCoordinates = new HashMap<N, ArrayRealVector>(); for (final N node : graph.vertexSet()) { if (coordinates.containsKey(node)) { newCoordinates.put(node, coordinates.get(node)); } else { newCoordinates.put(node, randomCoordinates(dimensions)); } } coordinates = Collections.synchronizedMap(newCoordinates); } */ totalMovement = DEFAULT_TOTAL_MOVEMENT; maxMovement = DEFAULT_MAX_MOVEMENT; ArrayRealVector center; //if (threadExecutor == null) { center = processLocally(); /*} else { // align all nodes in parallel final List<Future<ArrayRealVector>> futures = submitFutureAligns(); // wait for all nodes to finish aligning and calculate new sum of // all the points try { center = waitAndProcessFutures(futures); } catch (InterruptedException caught) { //LOGGER.warn("waitAndProcessFutures was unexpectedly interrupted", caught); throw new RuntimeException("Unexpected interruption. Get should block indefinitely", caught); } }*/ //LOGGER.debug("maxMove: " + maxMovement + ", Average Move: " + getAverageMovement()); //TODO use normalize max speed parameter, to control the speed it does this so it's not discontinuous and jumpy if (normalize()) { // divide each coordinate of the sum of all the points by the number of // nodes in order to calculate the average point, or center of all the // points center.mapDivideToSelf(vertices.length); recenterNodes(center); } }