List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApacheAmoeba.java
@Override public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate, int NUM_RATES, int numEval) { double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset //Arrays.fill(startingVertex, -0.5 * SIMPLEX_EDGE); //Arrays.fill(startingVertex, -1 * SIMPLEX_EDGE); // TODO if there are convergence issues, change these guessed thresholds //SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30); //SimplexOptimizer optimizer = new SimplexOptimizer(1e-4, 1e-4); //SimplexOptimizer optimizer = new SimplexOptimizer(1e-2, 10); SimplexOptimizer optimizer = new SimplexOptimizer(1e-3, 5); //SimplexOptimizer optimizer = new SimplexOptimizer(1e-2, 5); final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval), new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)), GoalType.MAXIMIZE, new InitialGuess(startingVertex), //new NelderMeadSimplex(NUM_RATES, -1 * SIMPLEX_EDGE)); new NelderMeadSimplex(NUM_RATES, SIMPLEX_EDGE));// should be positive since this reflects decrease in (negative) charges TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>(); eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey())); return eval2TOUTariff; }
From source file:io.fabric8.maven.enricher.standard.DefaultControllerEnricherTest.java
protected void enrichAndAssert(int sizeOfObjects, int replicaCount) throws com.fasterxml.jackson.core.JsonProcessingException { // Setup a sample docker build configuration final BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder() .ports(Arrays.asList("8080")).build(); final TreeMap controllerConfig = new TreeMap(); controllerConfig.put("replicaCount", String.valueOf(replicaCount)); setupExpectations(buildConfig, controllerConfig); // Enrich//from w w w. j ava2 s . c o m DefaultControllerEnricher controllerEnricher = new DefaultControllerEnricher(context); KubernetesListBuilder builder = new KubernetesListBuilder(); controllerEnricher.addMissingResources(builder); // Validate that the generated resource contains KubernetesList list = builder.build(); assertEquals(sizeOfObjects, list.getItems().size()); String json = KubernetesResourceUtil.toJson(list.getItems().get(0)); assertThat(json, JsonPathMatchers.isJson()); assertThat(json, JsonPathMatchers.hasJsonPath("$.spec.replicas", Matchers.equalTo(replicaCount))); }
From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApachePowell.java
@Override public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate, int NUM_RATES, int numEval) { double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset Arrays.fill(startingVertex, 0.0); PowellOptimizer optimizer = new PowellOptimizer(1e-3, 5); // needed since one optimization found positive // charges (paying customer to consume...) double[][] boundaries = createBoundaries(NUM_RATES); final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval), //new ObjectiveFunction(new MultivariateFunctionMappingAdapter(tariffUtilityEstimate, boundaries[0], boundaries[1])), new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)), GoalType.MAXIMIZE, new InitialGuess(startingVertex)); TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>(); eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey())); return eval2TOUTariff; }
From source file:com.mg.framework.utils.MiscUtils.java
/** * Returns a List of available locales sorted by display name */// www.j a v a2 s . co m public static List<Locale> availableLocales() { if (availableLocaleList == null) { synchronized (MiscUtils.class) { if (availableLocaleList == null) { TreeMap<String, Locale> localeMap = new TreeMap<String, Locale>(); Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { localeMap.put(locales[i].getDisplayName(), locales[i]); } availableLocaleList = new LinkedList<Locale>(localeMap.values()); } } } return availableLocaleList; }
From source file:net.anthonypoon.ngram.correlation.CorrelationReducer.java
@Override protected void setup(Context context) throws IOException, InterruptedException { threshold = Double.valueOf(context.getConfiguration().get("threshold", "0.7")); lag = Integer.valueOf(context.getConfiguration().get("lag", "0")); lowbound = Integer.valueOf(context.getConfiguration().get("lowbound")); upbound = Integer.valueOf(context.getConfiguration().get("upbound")); String uri = context.getConfiguration().get("target"); Path input = new Path(uri); // Read data from path to be our compare target FileSystem fileSystem = input.getFileSystem(context.getConfiguration()); BufferedReader br = new BufferedReader(new InputStreamReader(fileSystem.open(input))); String line = ""; while ((line = br.readLine()) != null) { String[] strArray = line.split("\t"); if (Integer.valueOf(strArray[1]) <= upbound && Integer.valueOf(strArray[1]) >= lowbound) { if (!corrTargetArray.containsKey(strArray[0])) { corrTargetArray.put(strArray[0], new TreeMap()); }/* w ww . j a v a2 s. co m*/ TreeMap<String, Double> targetElement = corrTargetArray.get(strArray[0]); targetElement.put(strArray[1], Double.valueOf(strArray[2])); } } }
From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApacheBOBYQA.java
@Override public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate, int NUM_RATES, int numEval) { double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset Arrays.fill(startingVertex, 0.0); //Arrays.fill(startingVertex, 0.5 * INITIAL_TRUST_REGION_RADIUS); //Arrays.fill(startingVertex, 1 * INITIAL_TRUST_REGION_RADIUS); final int numIterpolationPoints = 2 * NUM_RATES + 1; // BOBYQA recommends 2n+1 points BOBYQAOptimizer optimizer = new BOBYQAOptimizer(numIterpolationPoints, INITIAL_TRUST_REGION_RADIUS, STOPPING_TRUST_REGION_RADIUS); // needed since one optimization found positive // charges (paying customer to consume...) double[][] boundaries = createBoundaries(NUM_RATES); final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval), new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)), GoalType.MAXIMIZE, new InitialGuess(startingVertex), //new SimpleBounds(boundaries[0], boundaries[1])); SimpleBounds.unbounded(NUM_RATES)); TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>(); eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey())); return eval2TOUTariff; }
From source file:nl.surfnet.coin.api.controller.Oauth1AccessConfirmationController.java
@RequestMapping("/oauth1/confirm_access") public ModelAndView getAccessConfirmation(HttpServletRequest request, HttpServletResponse response) throws Exception { String token = request.getParameter("oauth_token"); if (token == null) { throw new IllegalArgumentException("A request token to authorize must be provided."); }//from w w w .j a v a 2s. c o m OAuthProviderToken providerToken = tokenServices.getToken(token); ConsumerDetails client = clientDetailsService.loadConsumerByConsumerKey(providerToken.getConsumerKey()); String callback = request.getParameter("oauth_callback"); TreeMap<String, Object> model = new TreeMap<String, Object>(); model.put("oauth_token", token); if (callback != null) { model.put("oauth_callback", callback); } model.put("client", client); model.put("locale", RequestContextUtils.getLocale(request).toString()); model.put("staticContentBasePath", staticContentBasePath); Map<String, String> languageLinks = new HashMap<String, String>(); languageLinks.put("en", getUrlWithLanguageParam(request, "en")); languageLinks.put("nl", getUrlWithLanguageParam(request, "nl")); model.put("languageLinks", languageLinks); if (client instanceof OpenConextConsumerDetails) { ClientMetaData clientMetaData = ((OpenConextConsumerDetails) client).getClientMetaData(); if (!clientMetaData.isConsentRequired()) { /* * We skip the consent screen, but to ensure that we hit all the filters and keep * the user flow intact we have implemented this using a javascript POST */ return new ModelAndView("access_confirmation_oauth1_skip_consent", model); } } return new ModelAndView("access_confirmation_oauth1", model); }
From source file:uk.ac.kcl.itemProcessors.DbLineFixerItemProcessor.java
@Override public Document process(final Document doc) throws Exception { LOG.debug("starting " + this.getClass().getSimpleName() + " on doc " + doc.getDocName()); String sql = MessageFormat.format( "SELECT {0}, {1}, {2} FROM {3} WHERE {0} = ''{4}'' " + " ORDER BY {5} DESC ", documentKeyName, lineKeyName, lineContents, srcTableName, doc.getPrimaryKeyFieldValue(), lineKeyName); List<MultilineDocument> docs = template.query(sql, simpleMapper); TreeMap<Integer, String> map = new TreeMap<>(); for (MultilineDocument mldoc : docs) { map.put(Integer.valueOf(mldoc.getLineKey()), mldoc.getLineContents()); }//from w w w . j a v a 2s . com StringBuilder sb2 = new StringBuilder(); for (Map.Entry<Integer, String> entry : map.entrySet()) { sb2.append(entry.getValue()); } addField(doc, sb2.toString()); LOG.debug("finished " + this.getClass().getSimpleName() + " on doc " + doc.getDocName()); return doc; }
From source file:eu.crisis_economics.abm.algorithms.statistics.FloorInterpolator.java
@Override public UnivariateFunction interpolate(final double[] x, final double[] y) throws MathIllegalArgumentException, DimensionMismatchException { Preconditions.checkNotNull(x, y);/*from w ww. ja v a2 s . c o m*/ if (x.length != y.length) throw new DimensionMismatchException(x.length, y.length); final int seriesLength = x.length; if (seriesLength == 0) throw new IllegalArgumentException( "FloorInterpolator.interpolate: input data is empty. Interpolation cannot continue."); final TreeMap<Double, Double> tree = new TreeMap<Double, Double>(); for (int i = 0; i < seriesLength; ++i) tree.put(x[i], y[i]); final UnivariateFunction result = new UnivariateFunction() { @Override public double value(final double t) { if (t < x[0]) return y[0]; else if (t > x[seriesLength - 1]) return y[seriesLength - 1]; else return tree.floorEntry(t).getValue(); } }; return result; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.ClusterCentroidsMain.java
public static TreeMap<Integer, Vector> computeClusterCentroids(String inputVectorsPath, String clusterOutputPath) throws IOException { TreeMap<Integer, Vector> result = new TreeMap<>(); Map<Integer, Integer> counts = new TreeMap<>(); // input for cluto File inputVectors = new File(inputVectorsPath); // resulting clusters File clutoClustersOutput = new File(clusterOutputPath); LineIterator clustersIterator = IOUtils.lineIterator(new FileInputStream(clutoClustersOutput), "utf-8"); LineIterator vectorsIterator = IOUtils.lineIterator(new FileInputStream(inputVectors), "utf-8"); // skip first line (number of clusters and vector size vectorsIterator.next();//from w w w.j av a 2 s . co m while (clustersIterator.hasNext()) { String clusterString = clustersIterator.next(); String vectorString = vectorsIterator.next(); int clusterNumber = Integer.valueOf(clusterString); // now parse the vector DenseVector vector = ClusteringUtils.parseVector(vectorString); // if there is no resulting vector for the particular cluster, add this one if (!result.containsKey(clusterNumber)) { result.put(clusterNumber, vector); } else { // otherwise add this one to the previous one result.put(clusterNumber, result.get(clusterNumber).add(vector)); } // and update counts if (!counts.containsKey(clusterNumber)) { counts.put(clusterNumber, 0); } counts.put(clusterNumber, counts.get(clusterNumber) + 1); } // now compute average for each vector for (Map.Entry<Integer, Vector> entry : result.entrySet()) { // cluster number int clusterNumber = entry.getKey(); // get counts int count = counts.get(clusterNumber); // divide by count of vectors for each cluster (averaging) for (VectorEntry vectorEntry : entry.getValue()) { vectorEntry.set(vectorEntry.get() / (double) count); } } return result; }