Example usage for com.google.common.collect ArrayTable put

List of usage examples for com.google.common.collect ArrayTable put

Introduction

In this page you can find the example usage for com.google.common.collect ArrayTable put.

Prototype

@Override
public V put(R rowKey, C columnKey, @Nullable V value) 

Source Link

Usage

From source file:lu.list.itis.dkd.aig.match.ClusterGenerator.java

/**
 * Helper method used to populate the distance matrix.
 *
 * @param matches/*from   w  w  w . j  a  va  2 s  . co  m*/
 *        The matches used to populate the symmetric distance matrix.
 * @return The populated matrix.
 * @throws SimilarityComputationException
 * @throws InitializationException
 *         Thrown when the initialization of the bridge failed. This is most likely due to
 *         either the connection to the knowledge base failing or the engine not properly
 *         initializing.
 */
public ArrayTable<Match, Match, Float> computeDistances(final List<Match> matches) {
    final ArrayTable<Match, Match, Float> distanceMatrix = ArrayTable.create(matches, matches);
    for (final Match match : matches) {
        for (final Match that : matches) {
            if (distanceMatrix.get(match, that) != null) {
                continue;
            }
            if (match == that) {
                distanceMatrix.put(match, that, 1f);
                distanceMatrix.put(that, match, 1f);
                continue;
            }
            final float similarity = SimilarityProvider.getInstance().compare(match.getAnswerVariable(),
                    that.getAnswerVariable());
            distanceMatrix.put(match, that, similarity);
            distanceMatrix.put(that, match, similarity);
        }
    }
    return distanceMatrix;
}

From source file:eu.itesla_project.mcla.forecast_errors.HistoricalDataCreator.java

private ForecastErrorsHistoricalData loadHistoricalDataFromCsvFile(Path historicalDataCsvFile,
        ArrayList<String> generatorsIds, ArrayList<String> loadsIds,
        ArrayList<StochasticVariable> stochasticVariables) throws IOException {
    ForecastErrorsHistoricalData forecastErrorsHistoricalData = null;

    Integer rowsIndexes[] = getRowsIndexes(historicalDataCsvFile);
    String columnsIndexes[] = getColumnsIndexes(generatorsIds, loadsIds);
    ArrayTable<Integer, String, Float> forecastsData = ArrayTable.create(Arrays.asList(rowsIndexes),
            Arrays.asList(columnsIndexes));
    ArrayTable<Integer, String, Float> snapshotsData = ArrayTable.create(Arrays.asList(rowsIndexes),
            Arrays.asList(columnsIndexes));

    ICsvMapReader csvMapReader = null;//from ww  w  .j  a v a  2s.  com
    int rowcount = 0;
    boolean odd = false;
    try {
        csvMapReader = new CsvMapReader(new FileReader(historicalDataCsvFile.toFile()),
                CsvPreference.STANDARD_PREFERENCE);
        final String[] headers = csvMapReader.getHeader(true);
        final CellProcessor[] rowProcessors = new CellProcessor[headers.length];
        Map<String, Object> componentMap;
        while ((componentMap = csvMapReader.read(headers, rowProcessors)) != null) {
            String datetime = (String) componentMap.get("datetime");
            int forecastTime = (int) Float.parseFloat((String) componentMap.get("forecastTime"));
            if (forecastTime == 0) {
                snapshotsData.put(rowcount, "datetime", Float.valueOf(datetime));
                snapshotsData.put(rowcount, "forecastTime", new Float(forecastTime));
            } else {
                forecastsData.put(rowcount, "datetime", Float.valueOf(datetime));
                forecastsData.put(rowcount, "forecastTime", new Float(forecastTime));
            }
            for (String generatorId : generatorsIds) {
                // generators active power
                String activePowerValue = (String) componentMap.get(generatorId + "_P");
                if (forecastTime == 0)
                    snapshotsData.put(rowcount, generatorId + "_P",
                            (activePowerValue != null) ? Float.valueOf(activePowerValue) : Float.NaN);
                else
                    forecastsData.put(rowcount, generatorId + "_P",
                            (activePowerValue != null) ? Float.valueOf(activePowerValue) : Float.NaN);
                // generators reactive power
                String reactivePowerValue = (String) componentMap.get(generatorId + "_Q");
                if (forecastTime == 0)
                    snapshotsData.put(rowcount, generatorId + "_Q",
                            (reactivePowerValue != null) ? Float.valueOf(reactivePowerValue) : Float.NaN);
                else
                    forecastsData.put(rowcount, generatorId + "_Q",
                            (reactivePowerValue != null) ? Float.valueOf(reactivePowerValue) : Float.NaN);
            }
            for (String loadId : loadsIds) {
                // loads active power
                String activePowerValue = (String) componentMap.get(loadId + "_P");
                if (forecastTime == 0)
                    snapshotsData.put(rowcount, loadId + "_P",
                            (activePowerValue != null) ? Float.valueOf(activePowerValue) : Float.NaN);
                else
                    forecastsData.put(rowcount, loadId + "_P",
                            (activePowerValue != null) ? Float.valueOf(activePowerValue) : Float.NaN);
                // loads reactive power
                String reactivePowerValue = (String) componentMap.get(loadId + "_Q");
                if (forecastTime == 0)
                    snapshotsData.put(rowcount, loadId + "_Q",
                            (reactivePowerValue != null) ? Float.valueOf(reactivePowerValue) : Float.NaN);
                else
                    forecastsData.put(rowcount, loadId + "_Q",
                            (reactivePowerValue != null) ? Float.valueOf(reactivePowerValue) : Float.NaN);
            }
            if (odd) {
                rowcount++;
                odd = false;
            } else {
                odd = true;
            }
        }
        LOGGER.info("Loaded {} records of historical data from csv file {}", rowcount,
                historicalDataCsvFile.toString());
    } catch (IOException e) {
        LOGGER.error("Error loading historical data from cvs file" + historicalDataCsvFile.toString() + ": "
                + e.getMessage());
        throw e;
    } finally {
        if (csvMapReader != null)
            try {
                csvMapReader.close();
            } catch (IOException e) {
                LOGGER.error("Error closing CSV map reader: " + e.getMessage());
            }
    }
    forecastErrorsHistoricalData = new ForecastErrorsHistoricalData(generatorsIds, loadsIds,
            stochasticVariables, forecastsData, snapshotsData);
    return forecastErrorsHistoricalData;
}