示例#1
0
  public double getProbabilitySoftRuleAllFalseExceptOne(
      UGroundedSoftRule softRule, UGroundedHardRule hardRule, UFact fact) {

    double q_c = 1;
    for (USoftRulePartition partition : softRule.partitions) {
      if (partition.n > 1) {
        System.err.println("CLAUSE ALREADY SATISFIED!");
        return 1;
      }
      for (USignedFact literal : partition) {
        steps++;
        if ((literal.equals(fact) && literal.sign)
            || (!literal.equals(fact) && !literal.sign && hardRule.contains(literal.fact))) {
          return 1;
        }
      }
      if (partition.n == 1) partition.q_r = (1 - partition.p_i);
      else partition.q_r = partition.p_i;
      q_c *= (1 - partition.q_r);
      steps++;
    }

    // System.out.println("SOFTRULE-1: " + softRule + " -> " + (1 - q_c));
    return 1 - q_c;
  }
示例#2
0
  public double getProbabilitySoftRule(UGroundedSoftRule softRule) {
    if (softRule.partitions == null) softRule.partitions = getPartitions(softRule);

    double q_c = 1;
    for (USoftRulePartition partition : softRule.partitions) {
      steps++;
      if (partition.n > 1) {
        q_c = 0;
        break;
      } else if (partition.n == 1) partition.q_r = (1 - partition.p_i);
      else partition.q_r = partition.p_i;
      // System.out.println("  PART: " + partition + "  " + partition.p_i + "  " + partition.q_r);
      q_c *= (1 - partition.q_r);
      steps++;
    }

    // System.out.println("SOFTRULE: " + softRule + " -> " + (1 - q_c));
    return 1 - q_c;
  }
示例#3
0
  public Collection<USoftRulePartition> getPartitions(UGroundedSoftRule softRule) {
    Map<UGroundedHardRule, USoftRulePartition> partitions =
        new HashMap<UGroundedHardRule, USoftRulePartition>();

    UFact head = softRule.getHead();
    USoftRulePartition partition = new USoftRulePartition();
    partition.add(new USignedFact(head, true));
    partition.p_i = head.p_i;
    partition.n = 0;
    partitions.put(head.getGroundedHardRule(), partition);
    steps++;

    for (UFact fact : softRule) {
      steps++;
      if ((partition = partitions.get(fact.getGroundedHardRule())) == null) {
        partition = new USoftRulePartition();
        partitions.put(fact.getGroundedHardRule(), partition);
      }
      partition.add(new USignedFact(fact, false));
      partition.p_i += fact.p_i;
      partition.n++;
    }

    return partitions.values();
  }