コード例 #1
0
  public Distribution<T> mergeAsNew(Distribution<T> current, Distribution<T> newBit) {
    DiscreteProbabilityDistribution<T> currentDD = (DiscreteProbabilityDistribution<T>) current;
    DiscreteProbabilityDistribution<T> newBitDD = (DiscreteProbabilityDistribution<T>) newBit;
    DiscreteDistribution<T> ret = new DiscreteDistribution<T>();

    Degree denominator = null;
    int i = 0;

    if (newBitDD.getSupport().size() < currentDD.getSupport().size()) {
      for (Iterator<T> newBitIt = newBitDD.getSupport().iterator(); newBitIt.hasNext(); ) {
        T tempT = newBitIt.next();
        if (currentDD.getDistribution().containsKey(tempT)) {
          if (i == 0) {
            denominator = currentDD.getDegree(tempT).mul(newBit.getDegree(tempT));
            i++;
          } else
            denominator = denominator.sum(currentDD.getDegree(tempT).mul(newBit.getDegree(tempT)));
        }
      }

      for (Iterator<T> newBitIt = newBitDD.getSupport().iterator(); newBitIt.hasNext(); ) {
        T tempT = newBitIt.next();
        if (currentDD.getDistribution().containsKey(tempT)) {
          Degree temp = (currentDD.getDegree(tempT).mul(newBit.getDegree(tempT))).div(denominator);
          ret.put(tempT, temp);
        }
      }
    } else {
      i = 0;
      for (Iterator<T> currIt = currentDD.getSupport().iterator(); currIt.hasNext(); ) {
        T tempT = currIt.next();
        if (newBitDD.getDistribution().containsKey(tempT)) {
          if (i == 0) {
            denominator = newBitDD.getDegree(tempT).mul(current.getDegree(tempT));
            i++;
          } else
            denominator = denominator.sum(newBitDD.getDegree(tempT).mul(current.getDegree(tempT)));
        }
      }

      for (Iterator<T> currIt = currentDD.getSupport().iterator(); currIt.hasNext(); ) {
        T tempT = currIt.next();
        if (newBitDD.getDistribution().containsKey(tempT)) {
          Degree temp = (newBitDD.getDegree(tempT).mul(current.getDegree(tempT))).div(denominator);
          ret.put(tempT, temp);
        }
      }
    }

    return ret;
  }
コード例 #2
0
  public Distribution<T> merge(Distribution<T> current, Distribution<T> newBit) {
    // ToDo iterare sull indice piu corto
    DiscreteProbabilityDistribution<T> currentDD = (DiscreteProbabilityDistribution<T>) current;
    DiscreteProbabilityDistribution<T> newBitDD = (DiscreteProbabilityDistribution<T>) newBit;
    Map<T, Degree> map = new HashMap<T, Degree>();

    Degree denominator = null;
    int i = 0;

    for (Iterator<T> currIt = currentDD.getSupport().iterator(); currIt.hasNext(); ) {
      T tempT = currIt.next();
      if (newBitDD.getDistribution().containsKey(tempT)) {

        if (i == 0) {
          denominator = newBitDD.getDegree(tempT).mul(current.getDegree(tempT));
          i++;
        } else
          denominator = denominator.sum(newBitDD.getDegree(tempT).mul(current.getDegree(tempT)));
      }
    }

    for (Iterator<T> currIt = currentDD.getSupport().iterator(); currIt.hasNext(); ) {
      T tempT = currIt.next();
      if (newBitDD.getDistribution().containsKey(tempT)) {
        Degree temp = (newBitDD.getDegree(tempT).mul(current.getDegree(tempT))).div(denominator);
        map.put(tempT, temp);
      }
    }

    currentDD.getDistribution().clear();
    currentDD.getDistribution().putAll(map);
    return currentDD;
  }