Java Collections.max Examples

Java Collections.max - 30 examples found. These are the top rated real world Java examples of java.util.Collections.max extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private void getDataToPlot() {
    switch (position) {
      case 0: // Humidity
        dataToPlot = humidityData;
        min = Collections.min(humidityData);
        max = Collections.max(humidityData);
        break;

      case 1: // Light
        dataToPlot = lightData;
        min = Collections.min(lightData);
        max = Collections.max(lightData);
        break;

      case 2: // Moisture
        dataToPlot = moistureData;
        min = Collections.min(moistureData);
        max = Collections.max(moistureData);
        break;

      case 3: // Temperature
        dataToPlot = temperatureData;
        min = Collections.min(temperatureData);
        max = Collections.max(temperatureData);
        break;
    }
  }
  static void displayStats() {
    if (training_time_stats.size() > 0)
      // TODO format floating point
      System.out.println(
          "Iteration time: min="
              + Collections.min(training_time_stats)
              + ", max="
              + Collections.max(training_time_stats)
              + ", avg="
              + Utils.average(training_time_stats)
              + " seconds");

    if (eval_time_stats.size() > 0)
      System.out.println(
          "Evaluation time: min="
              + Collections.min(eval_time_stats)
              + ", max="
              + Collections.max(eval_time_stats)
              + ", avg="
              + Utils.average(eval_time_stats)
              + " seconds");

    if (compute_fit && fit_time_stats.size() > 0)
      System.out.println(
          "fit_time: min="
              + Collections.min(fit_time_stats)
              + ", max="
              + Collections.max(fit_time_stats)
              + ", avg="
              + Utils.average(fit_time_stats)
              + " seconds");

    System.out.println("Memory: " + Memory.getUsage() + " MB");
  }
  public final String correct(String word) {
    if (nWords.containsKey(word)) return word;
    ArrayList<String> list = edits(word);
    HashMap<Integer, String> candidates = new HashMap<Integer, String>();
    for (String s : list) if (nWords.containsKey(s)) candidates.put(nWords.get(s), s);

    if (candidates.size() > 0) return candidates.get(Collections.max(candidates.keySet()));
    return candidates.size() > 0 ? candidates.get(Collections.max(candidates.keySet())) : word;
  }
  public void writeResults(String outputFile) {

    try {
      // Create file
      FileWriter fStream = new FileWriter(outputFile);
      BufferedWriter out = new BufferedWriter(fStream);

      out.write(
          "Attribute Type"
              + SEPARATOR
              + "numberOfDiffValues"
              + SEPARATOR
              + "min"
              + SEPARATOR
              + "max"
              + SEPARATOR
              + "Example\n");
      for (Map.Entry<String, Set<String>> entry : attrByValue.entrySet()) {
        Set<String> attrValues = entry.getValue();
        String lineToWrite = entry.getKey();

        Collections.max(attrValues);

        String sampleValues = "";
        int maxNumberOfSampleValues = 0;

        for (String s : attrValues) {
          sampleValues = sampleValues + " " + s;
          if (maxNumberOfSampleValues > MAX_EXAMPLE_COUNT) break;
          maxNumberOfSampleValues++;
        }

        String max = Collections.max(attrValues);
        String min = Collections.min(attrValues);

        lineToWrite =
            lineToWrite
                + SEPARATOR
                + attrValues.size()
                + SEPARATOR
                + max
                + SEPARATOR
                + min
                + SEPARATOR
                + sampleValues.trim();

        out.write(lineToWrite + "\n");
      }

      out.flush();
      // Close the output stream
      out.close();
    } catch (Exception e) { // Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
  public void findStudentResult(String name) {
    System.out.println("Student name:" + name);

    Map<Subject, Double> subjectDoubleMap = new HashMap<>();
    Map<Subject, Integer> subjectIntegerMap = new HashMap<>();

    /**
     * бежим по группам с типом результатов double и ищем студента если есть, то записываем в
     * subjectDoubleMap
     */
    for (Group<Double> indexDGroup : dGroups) {
      if (indexDGroup.getEvalByName(name) == null) {
        continue;
      } else {
        subjectDoubleMap.put(indexDGroup.getSubject(), indexDGroup.getEvalByName(name));
      }
    }
    /*
     * результируюзщий map не пустой, то выводим на экран
     *
     */
    if (!subjectDoubleMap.isEmpty()) {
      System.out.println(subjectDoubleMap);
      double max1 = Collections.max(subjectDoubleMap.values());

      for (Subject s : subjectDoubleMap.keySet()) {
        if (subjectDoubleMap.get(s) == max1) {
          System.out.println(s + ":" + max1);
        }
      }
    }

    /**
     * бежим по группам с типом результатов integer и ищем студента если есть, то записываем в
     * subjectDoubleMap
     */
    for (Group<Integer> indexIGroup : iGroups) {
      if (indexIGroup.getEvalByName(name) == null) {
        continue;
      } else {
        subjectIntegerMap.put(indexIGroup.getSubject(), indexIGroup.getEvalByName(name));
      }
    }
    if (!subjectIntegerMap.isEmpty()) {
      System.out.println(subjectIntegerMap);
      int max2 = Collections.max(subjectIntegerMap.values());
      for (Subject s : subjectIntegerMap.keySet()) {
        if (subjectIntegerMap.get(s) == max2) {
          System.out.println(s + ":" + max2);
        }
      }
    }
  }
Example #6
0
  public static void evaluateCircuitSNR(LogicCircuit lc, Args options) {

    /*for(Gate g: lc.get_logic_gates()) {
        evaluateGateSNR(g, options);
    }
    for(Gate g: lc.get_output_gates()) {
        evaluateGateSNR(g, options);
    }*/

    ArrayList<Double> input_ons = new ArrayList<>();
    ArrayList<Double> input_offs = new ArrayList<>();

    for (Gate input : lc.get_input_gates()) {
      for (int i = 0; i < input.get_logics().size(); ++i) {
        if (input.get_logics().get(i) == 1) {
          input_ons.add(input.get_outreus().get(i));
        } else if (input.get_logics().get(i) == 0) {
          input_offs.add(input.get_outreus().get(i));
        }
      }
    }

    Double input_on_min = Collections.min(input_ons);
    Double input_off_max = Collections.max(input_offs);

    ArrayList<Double> output_ons = new ArrayList<>();
    ArrayList<Double> output_offs = new ArrayList<>();

    for (Gate output : lc.get_output_gates()) {
      for (int i = 0; i < output.get_logics().size(); ++i) {
        if (output.get_logics().get(i) == 1) {
          output_ons.add(output.get_outreus().get(i));
        } else if (output.get_logics().get(i) == 0) {
          output_offs.add(output.get_outreus().get(i));
        }
      }
    }

    Double output_on_min = Collections.min(output_ons);
    Double output_off_max = Collections.max(output_offs);

    Double out_snr =
        20 * Math.log10((Math.log10(output_on_min / output_off_max)) / (2 * Math.log10(3.2)));

    Double in_snr =
        20 * Math.log10((Math.log10(input_on_min / input_off_max)) / (2 * Math.log10(3.2)));

    Double dsnr = out_snr - in_snr;

    lc.get_scores().set_snr(out_snr);
    lc.get_scores().set_dsnr(dsnr);
  }