示例#1
0
  /** Set a lower-bound estimate inside the rule returns full estimate. */
  public final float estimateRuleCost(List<FeatureFunction> featureFunctions) {
    if (null == featureFunctions) {
      return 0;
    } else {
      float estcost = 0.0f;
      for (FeatureFunction ff : featureFunctions) {
        double mdcost = -ff.estimateLogP(this, -1) * ff.getWeight();
        estcost += mdcost;
      }

      this.est_cost = estcost;
      return estcost;
    }
  }
示例#2
0
  /**
   * This function estimates the cost of a rule, which is used for sorting the rules for cube
   * pruning. The estimated cost is basically the set of precomputable features (features listed
   * along with the rule in the grammar file) along with any other estimates that other features
   * would like to contribute (e.g., a language model estimate). This cost will be a lower bound on
   * the rule's actual cost.
   *
   * <p>The value of this function is used only for sorting the rules. When the rule is later
   * applied in context to particular hypernodes, the rule's actual cost is computed.
   *
   * @param models the list of models available to the decoder
   * @return estimated cost of the rule
   */
  @Override
  public final float estimateRuleCost(List<FeatureFunction> models) {
    if (null == models) return 0.0f;

    if (this.estimatedCost <= Float.NEGATIVE_INFINITY) {
      this.estimatedCost = 0.0f; // weights.innerProduct(computeFeatures());
      // StringBuilder sb = new StringBuilder("estimateRuleCost(" + toString() + ")");

      for (FeatureFunction ff : models) {
        this.estimatedCost -= ff.estimateCost(this, -1);
        // sb.append(String.format(" %s: %.3f", ff.getClass().getSimpleName(),
        // -ff.estimateCost(this, -1)));
      }
      // sb.append(String.format(" ||| total=%.5f",this.estimatedCost));
      // System.err.println(sb.toString());
    }

    return estimatedCost;
  }