Package org.apache.commons.lang.mutable

Examples of org.apache.commons.lang.mutable.MutableDouble


    public Map<ScoreType, Double> computeNGramScore()
    {
  Map<ScoreType, Double> results = new HashMap<ScoreType, Double>();

  MutableInt gramHit = new MutableInt(0);
  MutableDouble gramScore = new MutableDouble(0);
  // #------------------------------------------------
  // # read model file and create model n-gram maps
  int totalGramHit = 0;
  int totalGramCount = 0;
  double gramScoreBest = -1;
  double gramScoreP = 0; //# precision
  double gramScoreF = 0; //# f-measure
  int totalGramCountP = 0;

  Map<String, Integer> peer_grams = createNGram(peer, this.n);

  if (DEBUG)
  {
      System.out.println(peer.getSourceFile());
      System.out.println(peer.asText());
      int i = 0;
      System.out.print("[");
      for (String key : peer_grams.keySet())
      {
    System.out.print(key + ":" + peer_grams.get(key)
                   .intValue());
    if (i != peer_grams.size() - 1)
    {
        System.out.print("|");
    }
      }
      System.out.println("]");
  }
  for (IRougeSummaryModel model : models)
  {
      Map<String, Integer> model_grams = createNGram(model, this.n);
      if (DEBUG)
      {
    System.out.println(model.getSourceFile());
    System.out.println(model.asText());
    int i = 0;
    System.out.print("[");
    for (String key : model_grams.keySet())
    {
        System.out.print(key + ":" + model_grams.get(key)
                  .intValue());
        if (i != model_grams.size() - 1)
        {
      System.out.print("|");
        }
    }
    System.out.println("]");
      }
      ngramScore(model_grams, peer_grams, gramHit, gramScore);

      switch (scoreMode)
      {
    case 'A':
    case 'a':
    {
        totalGramHit += gramHit.intValue();
        totalGramCount += model_grams.get("_cn_");
        totalGramCountP += peer_grams.get("_cn_");
        break;
    }
    case 'B':
    case 'b':
    {
        if (gramScore.doubleValue() > gramScoreBest)
        {
      //# only take a better score (i.e. better match)
      gramScoreBest = gramScore.doubleValue();
      totalGramHit = gramHit.intValue();
      totalGramCount = model_grams.get("_cn_");
      totalGramCountP = peer_grams.get("_cn_");
        }
        break;
    }
    default:
    {
        System.out.println("Warning: Unknown scoring mode - using average mode");
        totalGramHit += gramHit.intValue();
        totalGramCount += model_grams.get("_cn_");
        totalGramCountP += peer_grams.get("_cn_");
    }
      }
  }

  results.put(ScoreType.TOTAL_GRAM_COUNT, (double) totalGramCount); // total number of ngrams in models
  results.put(ScoreType.TOTAL_GRAM_HIT, (double) totalGramHit);
  if (totalGramCount != 0)
  {
      gramScore.setValue((double) totalGramHit / (double) totalGramCount);
  }
  else
  {
      gramScore.setValue(0);
  }
  results.put(ScoreType.R, gramScore.doubleValue());
  results.put(ScoreType.TOTAL_GRAM_HIT_P, (double) totalGramCountP); // total number of ngrams in peers
  if (totalGramCountP != 0)
  {
      gramScoreP = (double) totalGramHit / (double) totalGramCountP;
  }
  else
  {
      gramScoreP = 0;
  }
  results.put(ScoreType.P, gramScoreP); // precision score
  if (((1 - alpha) * gramScoreP + alpha * gramScoreP) > 0)
  {
      gramScoreF = (gramScoreP * gramScore.doubleValue()) / ((1 - alpha) * gramScoreP + alpha * gramScore.doubleValue());
  }
  else
  {
      gramScoreF = 0;
  }
View Full Code Here


    public Map<ScoreType, Double> computeNGramScore()
    {
  Map<ScoreType, Double> results = new HashMap<ScoreType, Double>();

  MutableInt gramHit = new MutableInt(0);
  MutableDouble gramScore = new MutableDouble(0);
  // #------------------------------------------------
  // # read model file and create model n-gram maps
  int totalGramHit = 0;
  int totalGramCount = 0;
  double gramScoreBest = -1;
  double gramScoreP = 0; //# precision
  double gramScoreF = 0; //# f-measure
  int totalGramCountP = 0;

  Map<String, Integer> peer_grams = createNGram(peer, this.n);

  if (DEBUG)
  {
      System.out.println(peer.getSourceFile());
      System.out.println(peer.asText());
      int i = 0;
      System.out.print("[");
      for (String key : peer_grams.keySet())
      {
    System.out.print(key + ":" + peer_grams.get(key).intValue());
    if (i != peer_grams.size() - 1)
    {
        System.out.print("|");
    }
      }
      System.out.println("]");
  }
  for (IRougeSummaryModel model : models)
  {
      Map<String, Integer> model_grams = createNGram(model, this.n);
      if (DEBUG)
      {
    System.out.println(model.getSourceFile());
    System.out.println(model.asText());
    int i = 0;
    System.out.print("[");
    for (String key : model_grams.keySet())
    {
        System.out.print(key + ":" + model_grams.get(key).intValue());
        if (i != model_grams.size() - 1)
        {
      System.out.print("|");
        }
    }
    System.out.println("]");
      }
      ngramScore(model_grams, peer_grams, gramHit, gramScore);

      switch (scoreMode)
      {
    case 'A':
    case 'a':
    {
        totalGramHit += gramHit.intValue();
        totalGramCount += model_grams.get("_cn_");
        totalGramCountP += peer_grams.get("_cn_");
        break;
    }
    case 'B':
    case 'b':
    {
        if (gramScore.doubleValue() > gramScoreBest)
        {
      //# only take a better score (i.e. better match)
      gramScoreBest = gramScore.doubleValue();
      totalGramHit = gramHit.intValue();
      totalGramCount = model_grams.get("_cn_");
      totalGramCountP = peer_grams.get("_cn_");
        }
        break;
    }
    default:
    {
        System.out.println("Warning: Unknown scoring mode - using average mode");
        totalGramHit += gramHit.intValue();
        totalGramCount += model_grams.get("_cn_");
        totalGramCountP += peer_grams.get("_cn_");
    }
      }
  }

  results.put(ScoreType.TOTAL_GRAM_COUNT, (double) totalGramCount); // total number of ngrams in models
  results.put(ScoreType.TOTAL_GRAM_HIT, (double) totalGramHit);
  if (totalGramCount != 0)
  {
      gramScore.setValue((double) totalGramHit / (double) totalGramCount);
  }
  else
  {
      gramScore.setValue(0);
  }
  results.put(ScoreType.R, gramScore.doubleValue());
  results.put(ScoreType.TOTAL_GRAM_HIT_P, (double) totalGramCountP); // total number of ngrams in peers
  if (totalGramCountP != 0)
  {
      gramScoreP = (double) totalGramHit / (double) totalGramCountP;
  }
  else
  {
      gramScoreP = 0;
  }
  results.put(ScoreType.P, gramScoreP); // precision score
  if (((1 - alpha) * gramScoreP + alpha * gramScoreP) > 0)
  {
      gramScoreF = (gramScoreP * gramScore.doubleValue()) / ((1 - alpha) * gramScoreP + alpha * gramScore.doubleValue());
  }
  else
  {
      gramScoreF = 0;
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.lang.mutable.MutableDouble

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.