当前位置: 首页>>代码示例>>Java>>正文


Java Expressions.makeSymbol方法代码示例

本文整理汇总了Java中com.sri.ai.expresso.helper.Expressions.makeSymbol方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.makeSymbol方法的具体用法?Java Expressions.makeSymbol怎么用?Java Expressions.makeSymbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sri.ai.expresso.helper.Expressions的用法示例。


在下文中一共展示了Expressions.makeSymbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: solve

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public SolverResult solve(String solveRequestId, ModelLanguage modelLanguage, String model, String evidenceQuery) 
	throws Exception {
	
	if (modelLanguage != ModelLanguage.HOGMv1) {
		throw new UnsupportedOperationException(modelLanguage.name() + " is currently not supported by this solver.");
	}
	
	Translator inputToUAITranslator = TranslatorFactory.newTranslator(modelLanguage, ModelLanguage.UAI);
	
	// NOTE: This trick is dependent on the input model being HOGMv1
	String hogmv1Model = model + "\nrandom UAIQuery : Boolean;\nif "+evidenceQuery+" then UAIQuery else not UAIQuery;\n";

	VECCallResult partitionResult = callVECPR("Partition Function "+solveRequestId, inputToUAITranslator, hogmv1Model, new Reader[] {new StringReader(hogmv1Model)});
	VECCallResult evidenceResult  = callVECPR("Evidence "+solveRequestId, inputToUAITranslator, hogmv1Model+"\nUAIQuery;", new Reader[] {new StringReader(hogmv1Model), new StringReader("UAIQuery")});
	
	Double probabilityResult = Math.pow(10, evidenceResult.resultLog10) / Math.pow(10, partitionResult.resultLog10);
	SolverResult result = new SolverResult(
				Math.max(partitionResult.translationTookMS, evidenceResult.translationTookMS),
				Math.max(partitionResult.vecProcessTookMS, evidenceResult.vecProcessTookMS),
				probabilityResult.isNaN() ? null : Expressions.makeSymbol(probabilityResult)
			);
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:26,代码来源:VECSolver.java

示例2: visitRelationalRandomVariableDeclaration

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override 
public Expression visitRelationalRandomVariableDeclaration(HOGMParser.RelationalRandomVariableDeclarationContext ctx) { 
	Expression name = newSymbol(ctx.name.getText());
	List<Expression> parameters = expressionsList(ctx.parameters);
	Expression arity = Expressions.makeSymbol(parameters.size());
	Expression range = visit(ctx.range);

	List<Expression> declarationArgs = new ArrayList<Expression>();
	declarationArgs.add(name);
	declarationArgs.add(arity);
	declarationArgs.addAll(parameters);
	declarationArgs.add(range);

	Expression result = Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(
			HOGMRandomVariableDeclaration.FUNCTOR_RANDOM_VARIABLE_DECLARATION,
			declarationArgs.toArray());
	
	randomVariableDeclarations.add(newStatementInfo(result, ctx));

	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:22,代码来源:HOGModelVisitor.java

示例3: simplifyExponentIfPossible

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static Expression simplifyExponentIfPossible(Expression exponent) {
	Expression result = exponent;
	
	if (exponent.hasFunctor(Exponentiation.EXPONENTIATION_FUNCTOR)) {
		Expression base  = exponent.get(0);
		Expression power = exponent.get(1);
		
		Expression simplifiedPower = simplifyExponentIfPossible(power);
		if (Expressions.isNumber(base) && isLegalExponent(simplifiedPower)) {
			result = Expressions.makeSymbol(base.rationalValue().pow(simplifiedPower.intValueExact()));
		}
		else if (!power.equals(simplifiedPower)) {
			result = new DefaultFunctionApplication(Exponentiation.EXPONENTIATION_FUNCTOR, Arrays.asList(base, simplifiedPower));
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:19,代码来源:DefaultMonomial.java

示例4: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * Simplify a unary minus application if possible.
 * @param expression
 * @return
 */
public static Expression simplify(Expression expression) {
	if (expression.get(0).hasFunctor(MINUS) && expression.get(0).numberOfArguments() == 1) { // double minus
		Expression argumentsArgument = expression.get(0).get(0);
		if (argumentsArgument.hasFunctor(MINUS) && argumentsArgument.numberOfArguments() == 1) {
			return simplify(expression);
		}
		else {
			return argumentsArgument;
		}
	}
	else if (expression.get(0).getValue() instanceof Number) {
		return Expressions.makeSymbol(expression.get(0).rationalValue().negate());
	}
	return expression;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:21,代码来源:UnaryMinus.java

示例5: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static public Expression simplify(Expression expression) {
	Expression result = expression;
	
	Expression first = expression.get(0);
	Expression second = expression.get(1);

	if (Expressions.isNumber(first)) {
		Rational firstValue = first.rationalValue();
		if (Expressions.isNumber(second)) {
			Rational secondValue = second.rationalValue();
			result = Expressions.makeSymbol(firstValue.subtract(secondValue));
		} 
		else if (firstValue.isZero()) {
			result = Expressions.apply("-", second);
		}
	} 
	else if (Expressions.isNumber(second) && second.rationalValue().isZero()) {
		result = first;
	}
		
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:BinaryMinus.java

示例6: createTuplesOfVarsForTupleTypes

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private static Map<Expression, Expression> createTuplesOfVarsForTupleTypes(QuantifiedExpression quantifiedExpression, List<Map.Entry<Expression, Expression>> indexesOfTupleType) {
	Map<Expression, Expression> result = new HashMap<>();
	
	Set<Expression> allSubExpressions = Util.addAllToSet(new SubExpressionsDepthFirstIterator(quantifiedExpression));
	for (Map.Entry<Expression, Expression> entry : indexesOfTupleType) {
		List<Expression> tupleVars = new ArrayList<>();
		for (int i = 1; i <= entry.getValue().numberOfArguments(); i++) {
			Expression proposedVar = Expressions.makeSymbol(entry.getKey().toString()+"_"+i);
			Expression actualVar   = Expressions.primedUntilUnique(proposedVar, expr -> !allSubExpressions.contains(expr));
			tupleVars.add(actualVar);
		}
		result.put(entry.getKey(), Expressions.makeTuple(tupleVars));
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:17,代码来源:TupleQuantifierSimplifier.java

示例7: visitRelationalConstantDeclaration

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override 
public Expression visitRelationalConstantDeclaration(HOGMParser.RelationalConstantDeclarationContext ctx) { 
	Expression name = newSymbol(ctx.name.getText());
	List<Expression> parameters = expressionsList(ctx.parameters);
	Expression arity = Expressions.makeSymbol(parameters.size());
	Expression range = visit(ctx.range);

	List<Expression> declarationArgs = new ArrayList<Expression>();
	declarationArgs.add(name);
	declarationArgs.add(arity);
	declarationArgs.addAll(parameters);
	declarationArgs.add(range);

	Expression result = Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(
			ConstantDeclaration.FUNCTOR_CONSTANT_DECLARATION,
			declarationArgs.toArray());
	
	constantDeclarations.add(newStatementInfo(result, ctx));

	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:22,代码来源:HOGModelVisitor.java

示例8: convertGenericTableToInstance

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression convertGenericTableToInstance(FunctionTable functionTable, Expression genericFunctionTableExpr, List<Integer> instanceVarIdxs) {
	Expression result = genericFunctionTableExpr;
	Context context = new TrueContext();
	for (int i = 0; i < functionTable.numberVariables(); i++) {
		// Replace the generic variable name with the correct instance name
		result = SyntacticSubstitute.replace(result, Expressions.makeSymbol(genericVariableName(i)), Expressions.makeSymbol(instanceVariableName(instanceVarIdxs.get(i))), context);
		int varCardinality = functionTable.cardinality(i);
		for (int c = 0; c < varCardinality; c++) {
			// Replace the generic constants with constants for the variable index (if they differ)
			Expression genericConstant  = Expressions.makeSymbol(genericConstantValueForVariable(c, i, varCardinality));
			Expression instanceConstant = Expressions.makeSymbol(instanceConstantValueForVariable(c, instanceVarIdxs.get(i), varCardinality));
			if (!genericConstant.equals(instanceConstant)) {
				result = SyntacticSubstitute.replace(result, genericConstant, instanceConstant, context);
			}
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:20,代码来源:UAIUtil.java

示例9: visitExpressionSymbol

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Expression visitExpressionSymbol(
		AntlrGrinderParser.ExpressionSymbolContext ctx) {
	Expression expr   = visit(ctx.expr());
	Expression result = Expressions.makeSymbol(expr);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:8,代码来源:ExpressionVisitor.java

示例10: visitUnaryMinus

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override 
public Expression visitUnaryMinus(HOGMParser.UnaryMinusContext ctx) { 
Expression argument = visit(ctx.term());
Expression result;
if (argument.getValue() instanceof Number) {
	result = Expressions.makeSymbol(argument.rationalValue().negate());
}
else {
	result = Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(MINUS, argument);
}
return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:13,代码来源:HOGModelVisitor.java

示例11: add

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Expression add(Expression value1, Expression value2, Context context) {
	Expression result;
	if (value1.getValue() instanceof Number && value2.getValue() instanceof Number) { // not necessary, as else clause is generic enough to deal with this case as well, but hopefully this saves time.
		result = Expressions.makeSymbol(value1.rationalValue().add(value2.rationalValue()));
	}
	else {
		Expression sum = Plus.make(arrayList(value1, value2));
		result = tryToNormalizeAsPolynomial(sum);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:13,代码来源:Sum.java

示例12: add

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Expression add(Expression value1, Expression value2, Context context) {
	Expression result;
	if (value1.getValue() instanceof Number && value2.getValue() instanceof Number) { // not necessary, as else clause is generic enough to deal with this case as well, but hopefully this saves time.
		result = Expressions.makeSymbol(value1.rationalValue().multiply(value2.rationalValue()));
	}
	else {
		Expression multiplication = Times.make(arrayList(value1, value2));
		result = numericSimplifier.apply(multiplication, context);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:13,代码来源:Product.java

示例13: DefaultMonomial

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private DefaultMonomial(Rational numericFactor, List<Expression> orderedNonNumericFactors, List<Rational> orderedNonNumericPowers) {
	// NOTE: we use Collections.unmodifiable<...> to ensure Monomials are immutable.
	this.numericFactorExpression  = Expressions.makeSymbol(numericFactor);
	this.orderedNonNumericFactors = Collections.unmodifiableList(orderedNonNumericFactors);
	this.orderedNonNumericFactorPowers  = Collections.unmodifiableList(orderedNonNumericPowers);
	
	this.factorToPower.put(this.numericFactorExpression, Rational.ONE);
	for (int i = 0; i < orderedNonNumericFactors.size(); i++) {
		this.factorToPower.put(orderedNonNumericFactors.get(i), orderedNonNumericPowers.get(i));
	}
	
	this.factorToPower = Collections.unmodifiableMap(this.factorToPower);
	
	this.degree = this.orderedNonNumericFactorPowers.stream().reduce(Rational.ZERO, (r1, r2) -> r1.add(r2)).intValue();
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:16,代码来源:DefaultMonomial.java

示例14: indefiniteIntegral

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * Takes a polynomial:<br>
 * <pre>
 * t_1 * variable ^ n + ... + t_n * variable + t_{n+1}
 * </pre>
 * and returns the polynomial equivalent to:<br>
 * <pre>
 * (t_1/(n + 1)) * variable ^ {n + 1} + ... + (t_n / 2) * variable^2 + t_{n+1}*variable
 * </pre>
 * 
 * @param polynomial
 *        the polynomial the indefinite integral is to be found for.
 * @param variable
 *        the variable integration is with respect to.
 * @return the indefinite integral of the given polynomial.
 */
public static Polynomial indefiniteIntegral(Polynomial polynomial, Expression variable) {				
	List<Expression> variables = new ArrayList<>(polynomial.getVariables());
	if (!variables.contains(variable)) {
		variables.add(variable);
		// Ensure the variable we are integrating with respect to is 
		// recognized by the polynomial as being one (this is implied).
		try {
		polynomial = DefaultPolynomial.make(polynomial, variables);
		}
		catch(IllegalArgumentException exception) {
			throw new IllegalArgumentException("Integrating " + polynomial + " requires it to be an integral in the integral variable " + variable + " but it is not because " + exception);
		}
	}		
	
	// Get the integrals of its terms
	List<Expression> integralsOfTerms = new ArrayList<>();
	for (Monomial term : polynomial.getMonomials()) {
		// indefinite integral of the term is:
		// &#x222b; a*x^n dx = a*(x^(n+1)/(n+1) + C		
		// NOTE: we do not need to worry about the case where n = -1 (i.e. division by zero case)
		// as our support for Polynomials only allows for positive integer exponents.
		List<Expression> factorsOfIntegral = new ArrayList<>();
		boolean variableFactorAdded = false;
		for (Expression factor : term.getFactors()) {
			Rational powerOfFactor = term.getPowerOfFactor(factor);
			if (factor.equals(variable)) {					
				Expression nPlusOne = Expressions.makeSymbol(powerOfFactor.add(1));
				factorsOfIntegral.add(Division.make(Exponentiation.make(variable, nPlusOne), nPlusOne));
				variableFactorAdded = true;
			}
			else {
				factorsOfIntegral.add(Exponentiation.make(factor, powerOfFactor));
			}
		}
		// Handle the case where the variable is not in the term, i.e.:
		// &#x222b; a dx = a*x + C	
		if (!variableFactorAdded) {				
			factorsOfIntegral.add(variable);
		}
		
		integralsOfTerms.add(DefaultMonomial.make(Times.make(factorsOfIntegral)));
	}
	
	// The integral of any polynomial is the sum of the integrals of its terms.
	Polynomial result = DefaultPolynomial.make(Plus.make(integralsOfTerms), variables);
			
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:65,代码来源:PolynomialIntegration.java

示例15: negate

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public Monomial negate() {
	DefaultMonomial result = clone();
	result.numericFactorExpression = Expressions.makeSymbol(getNumericFactor().negate());
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:6,代码来源:DefaultMonomial.java


注:本文中的com.sri.ai.expresso.helper.Expressions.makeSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。