本文整理汇总了Java中com.sri.ai.util.Util.map方法的典型用法代码示例。如果您正苦于以下问题:Java Util.map方法的具体用法?Java Util.map怎么用?Java Util.map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sri.ai.util.Util
的用法示例。
在下文中一共展示了Util.map方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBurglary
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void testBurglary() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map(
"Boolean", "2");
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"burglary", "Boolean",
"alarm", "Boolean",
"call", "Boolean"
);
// The definitions of non-uniquely named constants
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
// The definitions of non-uniquely named constants
mapFromUniquelyNamedConstantNameToTypeName = Util.map();
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(""
+ "(if alarm then if call then 0.7 else 0.3 else if call then 0 else 1)*"
+ "(if burglary then if alarm then 0.9 else 0.1 else if alarm then 0.01 else 0.99)*"
+ "(if burglary then 0.1 else 0.9)"));
InferenceForFactorGraphAndEvidence inferencer;
inferencer = new InferenceForFactorGraphAndEvidence(
new ExpressionFactorsAndTypes(factors,
mapFromRandomVariableNameToTypeName,
mapFromNonUniquelyNamedConstantNameToTypeName,
mapFromUniquelyNamedConstantNameToTypeName,
mapFromCategoricalTypeNameToSizeString,
list()),
isBayesianNetwork,
evidence,
false, null);
Expression result = inferencer.sum(list(parse("alarm")), Times.make(factors));
System.out.println(result);
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:41,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例2: lucky
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void lucky() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map(
"People", "1000",
"Boolean", "2");
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"lucky", "Boolean",
"winner", "People"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map("rodrigo", "People");
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(""
+ "(if lucky then 1 else 0)*"
+ "(if lucky then if winner = rodrigo then 1 else 0 else 0.5)"));
queryExpression = parse("winner = rodrigo");
evidence = null;
expected = parse("if winner = rodrigo then 1 else 0");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:29,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例3: smartest
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void smartest() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map(
"People", "1000",
"Boolean", "2");
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"boss", "People",
"smartest", "People"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map("bob", "People", "mary", "People", "tom", "People");
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(""
+ "(if (for all P in People : smartest = P => boss = P) then 1 else 0) * " + // same as (if smartest = boss then 1 else 0)
"( if smartest != bob and smartest != mary then 1 else 0)" +
""));
queryExpression = parse("boss = tom");
evidence = null;
expected = parse("if boss = tom then 0.00100200401 else 0.998997996"); // tom is 1 out of 998 people left to be the smartest and boss
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
queryExpression = parse("boss");
evidence = null;
expected = parse("if boss = bob then 0 else if boss = mary then 0 else 0.00100200401"); // gives the distribution to all values of queried variable
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:35,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例4: differenceArithmeticOnIntervalsWithMultipleVariables
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void differenceArithmeticOnIntervalsWithMultipleVariables() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map();
additionalTypes = list(new IntegerInterval(0, 99));
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"I", "0..99",
"J", "0..99",
"K", "0..99"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map();
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"(if J > I then 0.3 else 0.7) *" +
"(if K > J then 0.6 else 0.4)"));
queryExpression = parse("I");
evidence = null;
expected = parse("if I < 98 then (-(0.04 * I ^ 2) + 23.88 * I + 1520.92) / 257164 else if I < 99 then (-(0.06 * I ^ 2) -(0.18 * I) + 4070.88) / 257164 else (0.14 * I ^ 2 + 0.42 * I + 2079.28) / 257164");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:30,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例5: linearRealArithmeticOnPositionSimple
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void linearRealArithmeticOnPositionSimple() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map();
additionalTypes = list(new RealInterval("[0;10]"));
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"position", "[0;10]",
"observedPosition", "Real"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map();
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"(position)*(if observedPosition > 4 and observedPosition < 5 then 1 else 0)"));
queryExpression = parse("position");
evidence = null;
expected = parse("position/50"); // density
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:28,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例6: simplifyTest
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void simplifyTest() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map(
"People", "1000",
"Boolean", "2");
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"lucky", "Boolean",
"winner", "People"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map("rodrigo", "People");
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(""
+ "(if lucky then 1 else 0)*"
+ "(if lucky then if winner = rodrigo then 1 else 0 else 0.5)"));
queryExpression = parse("true or false");
expected = parse("true");
queryExpression = parse("true and false");
expected = parse("false");
queryExpression = parse("1.2 + 1.3 + if rodrigo = rodrigo then 1 else 2");
expected = parse("3.5");
runSimplifyTest();
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:35,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例7: DefaultMultiVariableConstraint
import com.sri.ai.util.Util; //导入方法依赖的package包/类
public DefaultMultiVariableConstraint(Theory theory) {
this(theory, Util.map());
}
示例8: wrapAsMap
import com.sri.ai.util.Util; //导入方法依赖的package包/类
public static Map<Expression, Expression> wrapAsMap(Object... pairs) {
return Util.map(Expressions.wrap(pairs).toArray());
}
示例9: wrapAsMap
import com.sri.ai.util.Util; //导入方法依赖的package包/类
public static Map<SyntaxTree, SyntaxTree> wrapAsMap(Object... pairs) {
return Util.map(Expressions.wrap(pairs).toArray());
}
示例10: testMerge
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void testMerge() {
Switch<String> switch1 =
new Switch<>(
stringMaker,
Util.map(
"1", new Label("11"),
"2", new Label("21")
));
Switch<String> switch2 =
new Switch<>(
stringMaker,
Util.map(
"1", new Label("12"),
"3", new Label("31")
));
Switch<String> switch3 =
new Switch<>(
stringMaker,
Util.map(
));
Switch<String> switch4 =
new Switch<>(
stringMaker,
Util.map(
"4", new Label("41")
));
Switch<String> switch5 =
new Switch<>(
stringMaker,
Util.map(
"3", new Label("32")
));
Switch<String> expected =
new Switch<>(
stringMaker,
Util.map(
"1", new FirstOf(list(new Label("11"), new Label("12"))),
"2", new Label("21"),
"3", new FirstOf(list(new Label("31"), new Label("32"))),
"4", new Label("41")
));
Rewriter merged = Switch.mergeSwitchesWithTheSameKeyMakerIntoASingleOne(list(switch1, switch2, switch3, switch4, switch5));
assertEquals(expected, merged);
}
示例11: relationalConstants
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void relationalConstants() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map(
"Folks", "10",
"Boolean", "2");
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"happy", "Boolean",
"boss", "Folks"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map("tom", "Folks");
isBayesianNetwork = true;
factors = Times.getMultiplicands(parse(""
+ "(1/|Folks|) *" // uniform prior for 'boss' does not depend on the actual value of 'boss'
+ "(if boss = tom then if happy then 1 else 0 else if happy then 0 else 1)"));
queryExpression = parse("happy");
evidence = null; // no evidence
expected = parse("if happy then 0.1 else 0.9");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
queryExpression = parse("happy");
evidence = parse("boss = tom");
expected = parse("if happy then 1 else 0");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
// Now 'boss' is a constant:
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"happy", "Boolean"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map(
"boss", "Folks"
);
isBayesianNetwork = true;
factors = Times.getMultiplicands(parse("" // no need for a prior for 'boss' now
+ "(if boss = tom then if happy then 1 else 0 else if happy then 0 else 1)"));
queryExpression = parse("happy");
evidence = null; // no evidence
expected = parse("if boss = tom then if happy then 1 else 0 else if happy then 0 else 1"); // query is a function of the constant
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
// Ignore: as we implement function-typed theories
// // Now 'boss' is a constant unary predicate:
//
// // The definitions of variables
// mapFromRandomVariableNameToTypeName = Util.map(
// "happy", "Boolean"
// );
//
// mapFromNonUniquelyNamedConstantNameToTypeName = Util.map(
// "boss", "->(x(Folks), Boolean)"
// );
//
// isBayesianNetwork = true;
// factors = Times.getMultiplicands(parse("" // no need for a prior for 'boss' now
// + "(if boss(tom) then if happy then 0.9 else 0.1 else if happy then 0.2 else 0.8)"));
//
// queryExpression = parse("happy");
// evidence = null; // no evidence
// expected = parse("if boss(tom) then if happy then 0.9 else 0.1 else if happy then 0.2 else 0.8"); // query is a function of the constant
// runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
//
// queryExpression = parse("happy");
// evidence = parse("happy");
// expected = parse("if happy then 1 else 0"); // query is NOT a function of the constant in this case
// runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, list());
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:81,代码来源:InferenceForFactorGraphAndEvidenceTest.java
示例12: linearRealArithmeticOnIntervalsWithMultipleVariables
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void linearRealArithmeticOnIntervalsWithMultipleVariables() {
// The definitions of types
mapFromCategoricalTypeNameToSizeString = Util.map();
additionalTypes = list(new RealInterval("[0;100]"));
// The definitions of variables
mapFromRandomVariableNameToTypeName = Util.map(
"X", "[0;100]",
"Y", "[0;100]",
"Z", "[0;100]"
);
mapFromNonUniquelyNamedConstantNameToTypeName = Util.map();
mapFromUniquelyNamedConstantNameToTypeName = Util.map();
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"(if X < 50 then 1 else 2)"));
queryExpression = parse("X");
evidence = null;
expected = parse("if X < 50 then 0.00666666667 else 0.0133333333"); // density
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
queryExpression = parse("X < 50");
evidence = null;
expected = parse("if X < 50 then 0.333333333 else 0.666666667"); // probability of the random event
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"(if Y > X then 0.3 else 0.7) *" +
"(if Z > Y then 0.6 else 0.4)"));
queryExpression = parse("X");
evidence = null;
expected = parse("if X < 100 then (-(0.04 * X ^ 2) + 24 * X + 1500) / 256666.667 else (0.14 * X ^ 2 + 2100) / 256666.667");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"(if Y > X then 0.3*X else 0.7*X) *" +
"(if Z > Y then 0.6*Y else 0.4*Y)"));
queryExpression = parse("X");
evidence = null;
expected = parse("if X < 100 then (-(0.0266666667 * X ^ 4) + 12 * X ^ 3 + 70000 * X) / 596666667 else (0.0933333333 * X ^ 4 + 70000 * X) / 596666667");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
isBayesianNetwork = false;
factors = Times.getMultiplicands(parse(
"if X = 10 then 1 else 2"));
queryExpression = parse("X");
evidence = null;
expected = parse("if X = 10 then 0.005 else 0.01");
runTest(queryExpression, evidence, expected, expected, isBayesianNetwork, factors, mapFromRandomVariableNameToTypeName, mapFromNonUniquelyNamedConstantNameToTypeName, mapFromUniquelyNamedConstantNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes);
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:66,代码来源:InferenceForFactorGraphAndEvidenceTest.java