本文整理汇总了Java中com.sri.ai.util.Util.mapIntoList方法的典型用法代码示例。如果您正苦于以下问题:Java Util.mapIntoList方法的具体用法?Java Util.mapIntoList怎么用?Java Util.mapIntoList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sri.ai.util.Util
的用法示例。
在下文中一共展示了Util.mapIntoList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeInnerExpressionIfNotContradiction
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Override
protected Expression computeInnerExpressionIfNotContradiction() {
List<Expression> conjuncts = list();
conjuncts.addAll(positiveNormalizedAtoms);
Util.mapIntoList(negativeNormalizedAtoms, n -> fromNormalizedAtomToItsNegationAsLiteral(n), conjuncts);
conjuncts.addAll(externalLiterals);
Expression result = And.make(conjuncts);
return result;
}
示例2: operationOnOperableArguments
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Override
public Expression operationOnOperableArguments(LinkedList<Expression> operableArguments) {
List<Object> operableArgumentValues = Util.mapIntoList(operableArguments.iterator(), GetValue.INSTANCE);
Object resultOnOperableArguments = operationOnOperableValues(operableArgumentValues);
Expression result = Expressions.makeSymbol(resultOnOperableArguments);
return result;
}
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:8,代码来源:CommutativeAssociativeWithOperationOnJavaConstantsOnly.java
示例3: getIndices
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/** Return a list of indexes from a list of index expressions. */
public static List<Expression> getIndices(IndexExpressionsSet indexExpressions) {
List<Expression> indexExpressionsList = ((ExtensionalIndexExpressionsSet) indexExpressions).getList();
List<Expression> result = Util.mapIntoList(indexExpressionsList, new GetIndex());
return result;
}
示例4: makeRandomAtomOn
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* Makes a random atom on variable by summing or subtracting terms from two random atoms generated by super class implementation.
*/
@Override
public Expression makeRandomAtomOn(String mainVariable, Context context) {
String mainVariableName = getVariableName(mainVariable);
Type mainType = getTestingVariableType(mainVariable);
List<String> variableNamesThatAreSubtypesOf = getVariableNamesWhoseTypesAreSubtypesOf(mainType);
int maxNumberOfOtherVariablesInAtom = Math.min(variableNamesThatAreSubtypesOf.size(), 2);
// used to be 3, but if literal has more than two variables, it steps out of difference arithmetic and may lead
// to multiplied variables when literals are propagated.
// For example, X = Y + Z and X = -Y - Z + 3 imply 2Y + 2Z = 3
int numberOfOtherVariablesInAtom = getRandom().nextInt(maxNumberOfOtherVariablesInAtom);
// Note: that otherVariablesForAtom will contain only one or zero elements
ArrayList<String> otherVariablesForAtom = new ArrayList<>();
if (numberOfOtherVariablesInAtom > 0) {
otherVariablesForAtom.add(pickTestingVariableAtRandom(mainType, otherName -> !otherName.equals(mainVariableName)));
}
ArrayList<Expression> constants = new ArrayList<Expression>();
int numberOfConstants = getRandom().nextInt(3);
for (int i = 0; i != numberOfConstants; i++) {
// Note: We know we can safely sample from the Difference Arithmetic Theory Types.
Expression sampledConstant = mainType.sampleUniquelyNamedConstant(getRandom());
Expression constant;
if (getRandom().nextBoolean()) {
constant = sampledConstant;
}
else {
constant = makeSymbol(-sampledConstant.intValue());
}
constants.add(constant);
}
ArrayList<Expression> leftHandSideArguments = new ArrayList<Expression>();
leftHandSideArguments.add(parse(mainVariable));
// needs to be difference, so it's added as negative
Util.mapIntoList(otherVariablesForAtom, otherVariable -> UnaryMinus.make(parse(otherVariable)), leftHandSideArguments);
leftHandSideArguments.addAll(constants);
int numberOfOtherVariablesToBeCanceled = getRandom().nextInt(otherVariablesForAtom.size() + 1);
ArrayList<String> otherVariablesToBeCanceled = Util.pickKElementsWithoutReplacement(otherVariablesForAtom, numberOfOtherVariablesToBeCanceled, getRandom());
// note that this term is positive, so it will cancel the previously negative term with the same "other variable"
Util.mapIntoList(otherVariablesToBeCanceled, v -> parse(v), leftHandSideArguments);
// Note: it may seem odd to generate an "other variable" and add another term that will cancel it later.
// However, this is useful for making sure canceling works properly.
Expression leftHandSide = Plus.make(leftHandSideArguments);
String functor = pickUniformly(getTheoryFunctors(), getRandom());
Expression unsimplifiedResult = apply(functor, leftHandSide, 0);
Expression result = getTheory().simplify(unsimplifiedResult, context);
// System.out.println("Random literal: " + result);
// Note that simplify will eliminate negated variables;
// however, we leave their generation and then elimination here as a sanity check,
// as well as a useful feature for the day when we get assurance that literals will be simplified down the line,
// allowing us to eliminate them here. TODO
return result;
}
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:62,代码来源:DifferenceArithmeticTheoryTestingSupport.java
示例5: InferenceForFactorGraphAndEvidence
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* Constructs a solver for a factor graph and an evidence expression.
* @param factorsAndTypes
* the factors and their type information over which inference is to be performed.
* @param isBayesianNetwork
* indicates if the factor graph is a bayesian network (each potential function in normalized for one of its variables, forms a DAG).
* @param evidence
* an Expression representing the evidence
* @param useFactorization indicates whether to use factorization (as in Variable Elimination)
* @param optionalTheory the theory to be used; if null, a default one is used (as of May 2017, a compound theory with propositional, equalities on categorical types, difference arithmetic, and real linear arithmetic).
*/
public InferenceForFactorGraphAndEvidence(
FactorsAndTypes factorsAndTypes,
boolean isBayesianNetwork,
Expression evidence,
boolean useFactorization,
Theory optionalTheory) {
this.factorGraph = Times.make(factorsAndTypes.getFactors());
this.isBayesianNetwork = isBayesianNetwork;
this.evidence = evidence;
this.mapFromRandomVariableNameToTypeName = new LinkedHashMap<>(factorsAndTypes.getMapFromRandomVariableNameToTypeName());
this.mapFromSymbolNameToTypeName = new LinkedHashMap<>(mapFromRandomVariableNameToTypeName);
this.mapFromSymbolNameToTypeName.putAll(factorsAndTypes.getMapFromNonUniquelyNamedConstantNameToTypeName());
this.mapFromSymbolNameToTypeName.putAll(factorsAndTypes.getMapFromUniquelyNamedConstantNameToTypeName());
allRandomVariables = Util.mapIntoList(this.mapFromRandomVariableNameToTypeName.keySet(), Expressions::parse);
this.mapFromCategoricalTypeNameToSizeString = new LinkedHashMap<>(factorsAndTypes.getMapFromCategoricalTypeNameToSizeString());
Set<Expression> uniquelyNamedConstants = mapIntoSet(factorsAndTypes.getMapFromUniquelyNamedConstantNameToTypeName().keySet(), Expressions::parse);
isUniquelyNamedConstantPredicate = new UniquelyNamedConstantIncludingBooleansAndNumbersPredicate(uniquelyNamedConstants);
if (mapFromRandomVariableNameToTypeName.values().stream().anyMatch(type -> type.contains("->")) ||
factorsAndTypes.getMapFromNonUniquelyNamedConstantNameToTypeName().values().stream().anyMatch(type -> type.contains("->"))) {
}
else {
}
semiRing = new SumProduct(); // for marginalization
if (optionalTheory != null) {
this.theory = optionalTheory;
}
else {
this.theory =
new CompoundTheory(
new EqualityTheory(false, true),
new DifferenceArithmeticTheory(false, true),
new LinearRealArithmeticTheory(false, true),
new PropositionalTheory());
}
this.additionalTypes = new LinkedList<Type>(theory.getNativeTypes()); // add needed types that may not be the type of any variable
this.additionalTypes.addAll(factorsAndTypes.getAdditionalTypes());
if (useFactorization) {
solver = new SGVET();
}
else {
solver = new DefaultMultiQuantifierEliminator();
}
evidenceProbability = null;
}