Search in sources :

Example 1 with TableFactorNetwork

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest2 method importUAIFile.

public static Pair<TableVariable, TableFactorNetwork> importUAIFile(String fileName) {
    Pair<TableVariable, TableFactorNetwork> pairQueryNet = new Pair<>();
    try {
        FileReader modelFile = new FileReader(new File("").getAbsolutePath() + "/UAITests/" + fileName);
        UAIModel model = UAIModelReader.read(modelFile);
        // Converting the network
        pairQueryNet.second = new TableFactorNetwork(model);
        // get one variable and test over the network
        ArrayList<Variable> vars = new ArrayList<>(pairQueryNet.second.getBs());
        // pick any variable
        pairQueryNet.first = (TableVariable) vars.get(0);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return pairQueryNet;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) UAIModel(com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Pair(com.sri.ai.util.base.Pair)

Example 2 with TableFactorNetwork

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest2 method isingModel.

public static Pair<TableVariable, TableFactorNetwork> isingModel(String queryName, int gridSize, double potential) {
    Pair<TableVariable, TableFactorNetwork> pairQueryNet;
    // TestCases.isingModelGridWithRandomWeigthsAndPotetial(gridSize, potential);
    List<TableFactor> factors = null;
    TableVariable query = null;
    for (TableFactor f : factors) {
        for (TableVariable v : f.getVariables()) {
            if (v.getName().equals(queryName)) {
                query = v;
            // Util.println("Query not null");
            }
        }
    // Util.println(f.getVariables());
    }
    TableFactorNetwork tfn = new TableFactorNetwork(factors);
    pairQueryNet = new Pair<>(query, tfn);
    return pairQueryNet;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 3 with TableFactorNetwork

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest3 method testing.

public static void testing(List<TableFactor> factors, int time, TableVariable query, String PGMname) {
    TableFactorNetwork network = new TableFactorNetwork(factors);
    // AEBPTestingDataFrame df  = solveGabrielWithBoxing(query, network, time,PGMname);
    AEBPTestingDataFrame df = solveGabrielWithoutBoxing(query, network, time, PGMname);
    // AEBPTestingDataFrame df3 = solveRodrigoWithoutBoxing(query, network, time, PGMname);
    // df.concatenate(df2);
    // df.concatenate(df3);
    AEBPRPlotting.plottingTheInterval(df, true, PGMname + ".pdf");
    AEBPRPlotting.plottingTheInterval(df, true, PGMname + ".pdf");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)

Example 4 with TableFactorNetwork

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest2 method main.

public static void main(String[] args) {
    String[] fileNames = { // "1a1x.uai",
    "grid40x40.f5.wrap.uai", "or_chain_10.fg.uai", "1a2j.uai", "grid80x80.f10.uai", "1a3c.uai", "grid80x80.f10.wrap.uai", "grid80x80.f15.uai", "or_chain_1.fg.uai", "BN_0.uai", "BN_5.uai", "grid80x80.f15.uai", "BN_101.uai", "BN_6.uai", "grid80x80.f15.wrap.uai", "BN_10.uai", "grid10x10.f10.uai", "grid80x80.f2.uai", "BN_11.uai", "grid10x10.f10.wrap.uai", "grid80x80.f2.wrap.uai", "BN_12.uai", "grid10x10.f15.wrap.uai", "grid80x80.f5.uai", "BN_13.uai", "grid10x10.f5.wrap.uai", "grid80x80.f5.wrap.uai", "BN_14.uai", "grid20x20.f10.uai", "BN_15.uai", "grid20x20.f15.uai", "or_chain_1.fg.uai", "BN_16.uai", "grid20x20.f15.wrap.uai", "pedigree13.uai", "BN_18.uai", "grid20x20.f5.uai", "pedigree18.uai", "BN_1.uai", "grid20x20.f5.wrap.uai", "pedigree19.uai", "BN_2.uai", "grid40x40.f5.uai", "pedigree20.uai" };
    for (String fileName : fileNames) {
        println("----------" + fileName + "----------");
        printPlotToFile(fileName, 20);
    }
    Pair<TableVariable, TableFactorNetwork> pairQueryNet = isingModel("5_5", 10, .2);
    AEBPTestingDataFrame df = solveWithBothMethods(pairQueryNet.first, pairQueryNet.second, 180, "Ising");
    AEBPRPlotting.plottingTheInterval(df, true, "IsingWeightPointTwo");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 5 with TableFactorNetwork

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest2 method printPlotToFile.

public static void printPlotToFile(String fileName, double maxTime) {
    Pair<TableVariable, TableFactorNetwork> pairQueryNet = importUAIFile(fileName);
    AEBPTestingDataFrame df = solveWithBothMethods(pairQueryNet.first, pairQueryNet.second, maxTime, fileName.split(".uai")[0]);
    AEBPRPlotting.plottingTheInterval(df, true, fileName.split(".uai")[0] + ".pdf");
    AEBPRPlotting.plottingTheInterval(df, true, fileName.split(".uai")[0] + ".pdf");
    df.printToCsv(fileName.split(".uai")[0] + ".csv");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Aggregations

TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)8 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)5 AEBPTestingDataFrame (com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)4 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)3 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)2 ExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP)1 UAIModel (com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel)1 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)1 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)1 Pair (com.sri.ai.util.base.Pair)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1