Esempio n. 1
0
    /**
     * Add a block of features to the buffer.
     *
     * @param features TreeMap with the features for one rule.
     * @return The index of the resulting data block.
     */
    int add(TreeMap<Integer, Float> features) {
      int data_position = buffer.position();

      // Over-estimate how much room this addition will need: for each
      // feature (ID_SIZE for label, "upper bound" of 4 for the value), plus ID_SIZE for
      // the number of features. If this won't fit, reallocate the buffer.
      int size_estimate =
          (4 + EncoderConfiguration.ID_SIZE) * features.size() + EncoderConfiguration.ID_SIZE;
      if (buffer.capacity() - buffer.position() <= size_estimate) reallocate();

      // Write features to buffer.
      idEncoder.write(buffer, features.size());
      for (Integer k : features.descendingKeySet()) {
        float v = features.get(k);
        // Sparse features.
        if (v != 0.0) {
          idEncoder.write(buffer, k);
          encoderConfig.encoder(k).write(buffer, v);
        }
      }
      // Store position the block was written to.
      memoryLookup.add(data_position);
      // Update total size (in bytes).
      totalSize = buffer.position();

      // Return block index.
      return memoryLookup.size() - 1;
    }
Esempio n. 2
0
 /**
  * Handle the '/nocheatplus info' command.
  *
  * @param sender the sender
  * @param playerName the player name
  * @return true, if successful
  */
 private void handleInfoCommand(final CommandSender sender, final String playerName) {
   final Player player = Bukkit.getPlayer(playerName);
   if (player != null) {
     final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
     final TreeMap<Long, ViolationLevel> violations =
         ViolationHistory.getHistory(player).getViolationLevels();
     if (violations.size() > 0) {
       sender.sendMessage(TAG + "Displaying " + playerName + "'s violations...");
       for (final long time : violations.descendingKeySet()) {
         final ViolationLevel violationLevel = violations.get(time);
         final String[] parts = violationLevel.check.split("\\.");
         final String check = parts[parts.length - 1];
         final String parent = parts[parts.length - 2];
         final double VL = Math.round(violationLevel.VL);
         sender.sendMessage(
             TAG
                 + "["
                 + dateFormat.format(new Date(time))
                 + "] ("
                 + parent
                 + ".)"
                 + check
                 + " VL "
                 + VL);
       }
     } else
       sender.sendMessage(
           TAG + "Displaying " + playerName + "'s violations... nothing to display.");
   } else {
     sender.sendMessage(TAG + "404 Not Found");
     sender.sendMessage(TAG + "The requested player was not found on this server.");
   }
 }
  private List<String> getBestCandidate(
      int pos,
      String input,
      List<TreeMap<Integer, String>> wordlist,
      Map<Integer, List<String>> posMap) {

    if (wordlist.size() <= pos) return null;
    if (posMap.get(pos) != null) return posMap.get(pos);

    List<String> results = new ArrayList<String>();

    TreeMap<Integer, String> candidates = wordlist.get(pos);
    Iterator<Integer> indexes = candidates.descendingKeySet().iterator();

    int score = 0;
    List<String> bestcandidate = null;
    String bestterm = null;

    while (indexes.hasNext()) {
      Integer index = indexes.next();
      String term = candidates.get(index);

      int tempscore = 0;
      if (term.length() > 1) tempscore += term.length();

      List<String> terms = null;

      if (pos + term.length() < input.length()) {
        terms = getBestCandidate(pos + term.length(), input, wordlist, posMap);
        tempscore += getScore(terms);
      }

      if (bestterm == null || score < tempscore) {
        bestcandidate = terms;
        bestterm = term;
        score = tempscore;
      } else if (score == tempscore
          && bestcandidate != null
          && terms != null
          && terms.size() == 1
          && terms.get(terms.size() - 1).length()
              > bestcandidate
                  .get(bestcandidate.size() - 1)
                  .length()) { // (정보,법,학회) > (정보,법,학회) / The larger length the last word has, the
                               // better
        bestcandidate = terms;
        bestterm = term;
        score = tempscore;
      }
    }

    if (bestterm != null) results.add(bestterm);
    if (bestcandidate != null) results.addAll(bestcandidate);
    posMap.put(pos, results);

    return results;
  }
Esempio n. 4
0
 public void PrintWords() {
   System.out.println("Top 20 Common Words");
   System.out.println("-------------------");
   twenty.putAll(commonWords);
   int i = 1;
   for (String str : twenty.descendingKeySet()) {
     System.out.println(i + ". " + str + " " + twenty.get(str));
     ++i;
     if (i == 21) return;
   }
 }
  public void reduce(Text key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {

    // 편차값에 대한 카운트를 저장할 Map 선언 <편차값,aws갯수>
    TreeMap<Double, String> awsCountDev = new TreeMap<Double, String>();

    for (Text val : values) {

      try {

        CsvParser parser = new CsvParser();
        parser.parse(val.toString());

        // Values에 포함된 기상요소 편차 값
        double deviation = Double.parseDouble(parser.get(1));
        // aws 조합
        String awsSet = parser.get(0) + DELIMITER + parser.get(1) + DELIMITER + parser.get(2);

        // 편차 값이 이미 저장되어 있으면 값 1 증가, 저장된 편차 값이 없으면 최초값 1 부여
        if (awsCountDev.containsKey(deviation)) {
          awsCountDev.put(deviation, awsCountDev.get(deviation) + "|" + awsSet);
        } else {
          awsCountDev.put(deviation, awsSet);
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    int writeCnt = 0;

    String awsSetList = "";
    Iterator<Double> iterator = awsCountDev.descendingKeySet().iterator();

    while (iterator.hasNext()) {

      Double valuesDev = iterator.next();

      String[] arr = StringUtil.myToken(awsCountDev.get(valuesDev), "|");

      int awsCount = arr.length;
      for (int i = 0; i < awsCount; i++) {

        awsSetList += DELIMITER + arr[i];
        writeCnt++;
      }

      if (writeCnt >= returnCnt) break;
    }

    context.write(new Text(key + DELIMITER + writeCnt + awsSetList), NullWritable.get());
  }
  // get descending order image file list
  public static ArrayList<String> getFileListDes(String folderPath) {

    ArrayList<String> ret = new ArrayList<String>();

    ArrayList<File> fileList = getFileList(folderPath);

    // descending sort file name
    TreeMap<String, File> map = new TreeMap<String, File>();
    for (File file : fileList) {
      map.put(file.getPath(), file);
    }

    NavigableSet<String> mapDesList = map.descendingKeySet();
    for (String file : mapDesList) {
      ret.add(file);
    }

    return ret;
  }
Esempio n. 7
0
 public NavigableSet<K> descendingKeySet() {
   return realMap.descendingKeySet();
 }
Esempio n. 8
0
  public void newOrder(long orderNumber, double price, String passCode)
      throws IllegalStateValueDataModificationException {
    if (!this.passCode.equals(passCode)) {
      throw new IllegalStateValueDataModificationException();
    }
    correlator.addLiveState(this);

    TreeMap<Integer, Double> neg = new TreeMap<Integer, Double>(collapsedDist.headMap(0));
    SortedMap<Integer, Double> pos = collapsedDist.tailMap(0);

    int shortProfit = 0;
    int shortLoss = 0;

    // System.out.println("Distribution: ");
    for (int returnClass : neg.descendingKeySet()) {
      double weight = neg.get(returnClass);
      if (weight / sumWeights > correlator.confidenceProfit) {
        shortProfit = returnClass;
        break;
      }
    }

    for (int returnClass : neg.descendingKeySet()) {
      double weight = neg.get(returnClass);
      if (weight / sumWeights > correlator.confidenceLoss) {
        shortLoss = returnClass;
        break;
      }
    }

    int longProfit = 0;
    int longLoss = 0;
    for (int returnClass : pos.keySet()) {
      double weight = pos.get(returnClass);
      if (weight / sumWeights > correlator.confidenceProfit) {
        longProfit = returnClass;
        break;
      }
    }

    for (int returnClass : pos.keySet()) {
      double weight = pos.get(returnClass);
      if (weight / sumWeights > correlator.confidenceLoss) {
        longLoss = returnClass;
        break;
      }
    }
    if (longProfit == 0) {
      longProfit = (int) (10 * Math.random());
    }
    if (shortProfit == 0) {
      shortProfit = (int) (-10 * Math.random());
    }

    double takeProfit = price + (longProfit * res);
    // double stopLoss = price - (shortLoss*res);
    double stopLoss = price - (longProfit * res);
    if (Math.abs(shortProfit) > longProfit) {
      takeProfit = price + (shortProfit * res);
      // stopLoss = price + (longLoss*res);
      stopLoss = price - (shortProfit * res);
    }
    openOrders.put(orderNumber, new OpenOrder("" + orderNumber, price, takeProfit, stopLoss));
    // System.out.println("New Order from " + state + ": " + orderNumber + ": " + price + " " +
    // takeProfit + " " + stopLoss);
  }