Examples of AssignmentIterator


Examples of cc.mallet.grmm.types.AssignmentIterator

        Factor ptl = unrolled.factorOf (clique);
        double logZ = Math.log (ptl.sum ());

        // for each assigment to the clique
        //  xxx SLOW this will need to be sparsified
        AssignmentIterator assnIt = clique.assignmentIterator ();
        int i = 0;
        while (assnIt.hasNext ()) {
          double marginal = Math.exp (ptl.logValue (assnIt) - logZ);
          expectations [tidx][i].plusEqualsSparse (clique.getFv (), marginal);
          if (defaultExpectations[tidx].location (i) != -1)
            defaultExpectations [tidx].incrementValue (i, marginal);
          assnIt.advance (); i++;
        }

        value += (ptl.logValue (observations) - logZ);
      }
      return value;
View Full Code Here

Examples of org.ggp.base.util.gdl.model.assignments.AssignmentIterator

    Map<GdlVariable, Set<GdlConstant>> varDomains = SentenceDomainModels.getVarDomains(rule, domainModel, VarDomainOpts.INCLUDE_HEAD);
    Map<SentenceForm, ? extends FunctionInfo> functionInfoMap = sentencesSoFar.getFunctionInfo();
    Map<SentenceForm, ? extends Collection<GdlSentence>> completedSentenceFormValues = sentencesSoFar.getSentences().asMap();

    AssignmentsImpl assignments = new AssignmentsImpl(rule, varDomains, functionInfoMap, completedSentenceFormValues);
    AssignmentIterator asnItr = assignments.getIterator();
    GdlSentenceSet sentencesToAdd = GdlSentenceSet.create();
    while (asnItr.hasNext()) {
      Map<GdlVariable, GdlConstant> assignment = asnItr.next();
      boolean allSatisfied = true;
      for (GdlLiteral literal : rule.getBody()) {
        ConcurrencyUtils.checkForInterruption();
        if (!satisfies(assignment, literal, sentencesSoFar.getSentences())) {
          asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
          allSatisfied = false;
          break;
        }
      }
      if (allSatisfied) {
        GdlSentence head = rule.getHead();
        sentencesToAdd.put(headForm, CommonTransforms.replaceVariables(head, assignment));
        asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment);
      }
    }
    return sentencesToAdd;
  }
View Full Code Here

Examples of org.ggp.base.util.gdl.model.assignments.AssignmentIterator

    for (GdlSentence chosenNewSentence : chosenNewSentences) {
      Map<GdlVariable, GdlConstant> preassignments = GdlUtils.getAssignmentMakingLeftIntoRight(chosenLiteral, chosenNewSentence);
      if (preassignments != null) {
        Assignments assignments = new AssignmentsImpl(preassignments, rule, varDomains, functionInfoMap, completedSentenceFormValues);
        AssignmentIterator asnItr = assignments.getIterator();
        while (asnItr.hasNext()) {
          Map<GdlVariable, GdlConstant> assignment = asnItr.next();

          boolean allSatisfied = true;
          for (GdlLiteral literal : rule.getBody()) {
            if (literal == chosenLiteral) {
              //Already satisfied
              continue;
            }
            if (!satisfies(assignment, literal, allSentences.getSentences())) {
              asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
              allSatisfied = false;
              break;
            }
          }
          if (allSatisfied) {
            GdlSentence head = rule.getHead();
            GdlSentence newHead = CommonTransforms.replaceVariables(head, assignment);
            if (!allSentences.containsSentence(headForm, newHead)) {
              sentencesToAdd.put(headForm, newHead);
            }
            asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment);
          }
        }
      }
    }
  }
View Full Code Here

Examples of org.ggp.base.util.gdl.model.assignments.AssignmentIterator

      for(GdlRule rule : model.getRules(curForm)) {
        GdlSentence head = rule.getHead();
        List<GdlVariable> varsInHead = GdlUtils.getVariables(head);
        Assignments assignments = AssignmentsFactory.getAssignmentsForRule(rule, model, functionInfoMap, Collections.EMPTY_MAP);

        AssignmentIterator asnItr = assignments.getIterator();
        while(asnItr.hasNext()) {
          Map<GdlVariable, GdlConstant> assignment = asnItr.next();
          boolean isGoodAssignment = true;

          GdlSentence transformedHead = CommonTransforms.replaceVariables(head, assignment);
          if(trueFlowSentences.contains(transformedHead))
            asnItr.changeOneInNext(varsInHead, assignment);

          //Go through the conjuncts
          for(GdlLiteral literal : rule.getBody()) {
            if(literal instanceof GdlSentence) {
              if(curForm.matches((GdlSentence) literal))
                throw new RuntimeException("Haven't implemented recursion in the game flow");
              GdlSentence transformed = CommonTransforms.replaceVariables((GdlSentence) literal, assignment);
              SentenceForm conjForm = model.getSentenceForm(transformed);
              if(constantForms.contains(conjForm)) {
                if(!constantChecker.isTrueConstant(transformed)) {
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              } else {
                if(!trueFlowSentences.contains(transformed)) {
                  //False sentence
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              }
            } else if(literal instanceof GdlNot) {
              GdlSentence internal = (GdlSentence) ((GdlNot) literal).getBody();
              GdlSentence transformed = CommonTransforms.replaceVariables(internal, assignment);
              SentenceForm conjForm = model.getSentenceForm(transformed);

              if(constantForms.contains(conjForm)) {
                if(constantChecker.isTrueConstant(transformed)) {
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              } else {
                if(trueFlowSentences.contains(transformed)) {
                  //False sentence
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              }

            }
            //Nothing else needs attention, really
          }

          //We've gone through all the conjuncts and are at the
          //end of the rule
          if(isGoodAssignment) {
            trueFlowSentences.add(transformedHead);
            if(varsInHead.isEmpty())
              break; //out of the assignments for this rule
            else
              asnItr.changeOneInNext(varsInHead, assignment);
          }
        }
      }
      //We've gone through all the rules
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.