Search in sources :

Example 6 with UAIModel

use of com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel in project aic-praise by aic-sri-international.

the class UAIModelToExpressionFactorNetwork method main.

public static void main(String[] args) {
    try {
        // Importing the file and reading it
        FileReader modelFile = new FileReader(new File("").getAbsolutePath() + "/UAITests/BN_0.uai");
        UAIModel model = UAIModelReader.read(modelFile);
        // Converting the network
        ExpressionFactorNetwork network = convert(model, null);
        // Printing the factors
        for (IdentityWrapper<Factor> fwrapped : network.getAs()) {
            ExpressionFactor f = (ExpressionFactor) fwrapped.getObject();
            println(f);
        }
    /*// This seems to be OK! But when we analyze the connections between the factors:
			
			
			IdentityWrapper<Factor> f = network.getAs().iterator().next();
			
			println("Printing one of the factors of the network:\n\t "+f);
			println("Printing this factor's connections:\n\t" + network.getBsOfA(f));
			println("This shows that there is something wrong\n"
					+ "In fact the connections in the graph are made based on the 'freeVariables' of a factor");
			println("freeVariables of f: "+Expressions.freeVariables((ExpressionFactor)f.getObject(),((ExpressionFactor)f.getObject()).getContext()));
			
			
			println("\nWe can check that those 'abnomalies' are indeed variables on the network:");
			for(Variable v:network.getBs()) {
				System.out.print(v + ", ");
			}*/
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) UAIModel(com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 7 with UAIModel

use of com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel in project aic-praise by aic-sri-international.

the class TestCases method retrieveUAIFile.

private static UAIModel retrieveUAIFile(String folderName, String fileName) {
    if (!fileName.endsWith(".uai")) {
        fileName = fileName + ".uai";
    }
    try {
        FileReader modelFile = new FileReader(new File("").getAbsolutePath() + "/UAITests/" + folderName + "/" + fileName);
        FileReader evidenceFIle = new FileReader(new File("").getAbsolutePath() + "/UAITests/" + folderName + "/" + fileName + ".evid");
        UAIModel model = UAIModelReader.read(modelFile);
        UAIEvidenceReading.read(evidenceFIle, model);
        return model;
    } catch (FileNotFoundException e) {
        FileReader modelFile;
        try {
            modelFile = new FileReader(new File("").getAbsolutePath() + "/UAITests/" + folderName + "/" + fileName);
            return UAIModelReader.read(modelFile);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : UAIModel(com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

UAIModel (com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel)7 File (java.io.File)5 IOException (java.io.IOException)4 FileReader (java.io.FileReader)3 ArrayList (java.util.ArrayList)3 FunctionTable (com.sri.ai.praise.core.representation.classbased.table.core.data.FunctionTable)2 UAIModelReader (com.sri.ai.praise.core.representation.classbased.table.core.uai.parsing.UAIModelReader)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Beta (com.google.common.annotations.Beta)1 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 Expression (com.sri.ai.expresso.api.Expression)1 Expressions (com.sri.ai.expresso.helper.Expressions)1 MultiQuantifierEliminator (com.sri.ai.grinder.api.MultiQuantifierEliminator)1 Theory (com.sri.ai.grinder.api.Theory)1 Equality (com.sri.ai.grinder.library.Equality)1