當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。