Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

In this page you can find the example usage for java.util TreeMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyMulticurveSensitivity.java

/**
 * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency.
 * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry.
 * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other
 * existing entries and the entry with the currency and the sum sensitivity.
 * @param ccy The currency. Not null./*from  w  w w. ja va2 s .  co m*/
 * @param sensitivity The sensitivity associated to the currency. Not null.
 * @return The new multiple currency sensitivity.
 */
public MultipleCurrencyMulticurveSensitivity plus(final Currency ccy, final MulticurveSensitivity sensitivity) {
    ArgumentChecker.notNull(ccy, "Currency");
    ArgumentChecker.notNull(sensitivity, "Sensitivity");
    final TreeMap<Currency, MulticurveSensitivity> map = new TreeMap<>();
    if (_sensitivity.containsKey(ccy)) {
        map.put(ccy, sensitivity.plus(_sensitivity.get(ccy)));
        for (final Currency loopccy : _sensitivity.keySet()) {
            if (loopccy != ccy) {
                map.put(loopccy, _sensitivity.get(loopccy));
            }
        }
    } else {
        map.putAll(_sensitivity);
        map.put(ccy, sensitivity);
    }
    return new MultipleCurrencyMulticurveSensitivity(map);
}

From source file:hivemall.anomaly.SingularSpectrumTransform.java

/**
 * Implicit Krylov Approximation (IKA) based naive scoring.
 *
 * Number of iterations for the Power method and QR method is fixed to 1 for efficiency. This
 * may cause failure (i.e. meaningless scores) depending on datasets and initial values.
 *
 *///from   w ww  .j  av a2 s.c o  m
private double computeScoreIKA(@Nonnull final RealMatrix H, @Nonnull final RealMatrix G) {
    // assuming n = m = window, and keep track the left singular vector as `q`
    MatrixUtils.power1(G, q, 1, q, new double[window]);

    RealMatrix T = new Array2DRowRealMatrix(k, k);
    MatrixUtils.lanczosTridiagonalization(H.multiply(H.transpose()), q, T);

    double[] eigvals = new double[k];
    RealMatrix eigvecs = new Array2DRowRealMatrix(k, k);
    MatrixUtils.tridiagonalEigen(T, 1, eigvals, eigvecs);

    // tridiagonalEigen() returns unordered eigenvalues,
    // so the top-r eigenvectors should be picked carefully
    TreeMap<Double, Integer> map = new TreeMap<Double, Integer>(Collections.reverseOrder());
    for (int i = 0; i < k; i++) {
        map.put(eigvals[i], i);
    }
    Iterator<Integer> indices = map.values().iterator();

    double s = 0.d;
    for (int i = 0; i < r; i++) {
        if (!indices.hasNext()) {
            throw new IllegalStateException("Should not happen");
        }
        double v = eigvecs.getEntry(0, indices.next().intValue());
        s += v * v;
    }
    return 1.d - Math.sqrt(s);
}

From source file:org.powertac.genco.CpGencoTest.java

@Test
public void configTest() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("genco.cpGenco.coefficients", "1.0, 2.0, 3.0");
    map.put("genco.cpGenco.pSigma", "0.22");
    init();/*  www.  jav  a  2  s  .c om*/
    Configuration conf = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(conf);
    configurator.configureSingleton(genco);
    assertEquals("3-element list", 3, genco.getCoefficients().size());
    assertEquals("correct 1st", "1.0", genco.getCoefficients().get(0));
    assertEquals("correct last", "3.0", genco.getCoefficients().get(2));
    assertEquals("correct pSigma", 0.22, genco.getPSigma(), 1e-6);
}

From source file:org.wso2.carbon.metrics.jdbc.reporter.JdbcReporterTest.java

private <T> SortedMap<String, T> map(String name, T metric) {
    final TreeMap<String, T> map = new TreeMap<>();
    map.put(name, metric);
    return map;/* w  ww .  java  2  s . co m*/
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyMulticurveSensitivity.java

/**
 * Create a new multiple currency sensitivity by multiplying all the sensitivities in a multiple currency sensitivity by a common factor.
 * @param factor The multiplicative factor.
 * @return The new multiple currency sensitivity.
 *//*w w w.j  av a2 s.  c  om*/
public MultipleCurrencyMulticurveSensitivity multipliedBy(final double factor) {
    final TreeMap<Currency, MulticurveSensitivity> map = new TreeMap<>();
    for (final Currency loopccy : _sensitivity.keySet()) {
        map.put(loopccy, _sensitivity.get(loopccy).multipliedBy(factor));
    }
    return new MultipleCurrencyMulticurveSensitivity(map);
}

From source file:io.mapzone.arena.analytics.graph.ui.FeaturePropertySelectorUI.java

private void fill() {
    if (combo != null && !combo.isDisposed() && featureSource != null) {

        final Collection<PropertyDescriptor> schemaDescriptors = featureSource.getSchema().getDescriptors();
        final GeometryDescriptor geometryDescriptor = featureSource.getSchema().getGeometryDescriptor();
        final TreeMap<String, PropertyDescriptor> properties = Maps.newTreeMap();
        for (PropertyDescriptor descriptor : schemaDescriptors) {
            if (geometryDescriptor == null || !geometryDescriptor.equals(descriptor)) {
                properties.put(descriptor.getName().getLocalPart(), descriptor);
            }//from   w ww  .  j  av  a  2s.co m
        }
        final List<String> columns = Lists.newArrayList();
        columns.addAll(properties.keySet());
        combo.setItems(columns.toArray(new String[properties.size()]));

        combo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onSelect.accept(properties.get(columns.get(combo.getSelectionIndex())));
            }
        });
        combo.getParent().layout();
    }
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyMulticurveSensitivity.java

/**
 * Returns a new multiple currency sensitivity by creating clean sensitivity for each currency (see {@link InterestRateCurveSensitivity} clean() method).
 * @return The cleaned sensitivity./*  w  ww .  j a v a2  s  .  c  om*/
 */
public MultipleCurrencyMulticurveSensitivity cleaned() {
    final TreeMap<Currency, MulticurveSensitivity> map = new TreeMap<>();
    for (final Currency loopccy : _sensitivity.keySet()) {
        map.put(loopccy, _sensitivity.get(loopccy).cleaned());
    }
    final MultipleCurrencyMulticurveSensitivity result = new MultipleCurrencyMulticurveSensitivity(map);
    return result;
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyMulticurveSensitivity.java

/**
 * Returns a new multiple currency sensitivity by creating clean sensitivity for each currency (see {@link InterestRateCurveSensitivity} clean() method).
 * The total value below the tolerance threshold are removed.
 * @param tolerance The tolerance.// w w  w. j av a  2s.co m
 * @return The cleaned sensitivity.
 */
public MultipleCurrencyMulticurveSensitivity cleaned(final double tolerance) {
    final TreeMap<Currency, MulticurveSensitivity> map = new TreeMap<>();
    for (final Currency loopccy : _sensitivity.keySet()) {
        map.put(loopccy, _sensitivity.get(loopccy).cleaned(tolerance));
    }
    final MultipleCurrencyMulticurveSensitivity result = new MultipleCurrencyMulticurveSensitivity(map);
    return result;
}

From source file:herbie.running.analysis.CalcLegTimesKTI.java

public TreeMap<String, Double> getAverageTripDurationsByMode() {
    TreeMap<String, Double> averageTripDurations = new TreeMap<String, Double>();
    for (String mode : this.rawData.keySet()) {
        averageTripDurations.put(mode, StatUtils.mean(this.rawData.get(mode).getElements()));
    }/*from   w w w .  j  a v a 2s.co  m*/
    return averageTripDurations;
}

From source file:net.oremland.rss.reader.fragments.BaseListFragment.java

private TreeMap<String, TModel> getModelMap(List<TModel> models) {
    TreeMap<String, TModel> map = this.createTreeMap();
    for (TModel model : models) {
        map.put(model.getKey(), model);
    }/*from   ww w. j a  va2s. c om*/
    return map;
}