Search in sources :

Example 1 with ParamsFile

use of edu.cmu.ml.proppr.util.ParamsFile in project ProPPR by TeamCohen.

the class QueryAnswerer method main.

public static void main(String[] args) throws IOException {
    try {
        int inputFiles = Configuration.USE_QUERIES | Configuration.USE_PARAMS;
        int outputFiles = Configuration.USE_ANSWERS;
        int modules = Configuration.USE_PROVER | Configuration.USE_SQUASHFUNCTION;
        int constants = Configuration.USE_WAM | Configuration.USE_THREADS | Configuration.USE_ORDER;
        QueryAnswererConfiguration c = new QueryAnswererConfiguration(args, inputFiles, outputFiles, constants, modules);
        //			c.squashingFunction = new Exp();
        System.out.println(c.toString());
        QueryAnswerer qa = new QueryAnswerer(c.apr, c.program, c.plugins, c.prover, c.normalize, c.nthreads, c.topk);
        if (log.isInfoEnabled())
            log.info("Running queries from " + c.queryFile + "; saving results to " + c.solutionsFile);
        if (c.paramsFile != null) {
            ParamsFile file = new ParamsFile(c.paramsFile);
            qa.addParams(c.prover, new SimpleParamVector<String>(Dictionary.load(file, new ConcurrentHashMap<String, Double>())), c.squashingFunction);
            file.check(c);
        }
        long start = System.currentTimeMillis();
        qa.findSolutions(c.queryFile, c.solutionsFile, c.maintainOrder);
        if (c.prover.getWeighter() instanceof InnerProductWeighter) {
            InnerProductWeighter w = (InnerProductWeighter) c.prover.getWeighter();
            int n = w.getWeights().size();
            int m = w.seenKnownFeatures() + w.seenUnknownFeatures();
            if (((double) w.seenKnownFeatures() / n) < MIN_FEATURE_TRANSFER)
                log.warn("Only saw " + w.seenKnownFeatures() + " of " + n + " known features (" + ((double) w.seenKnownFeatures() / n * 100) + "%) -- test data may be too different from training data");
            if (w.seenUnknownFeatures() > w.seenKnownFeatures())
                log.warn("Saw more unknown features (" + w.seenUnknownFeatures() + ") than known features (" + w.seenKnownFeatures() + ") -- test data may be too different from training data");
        }
        System.out.println("Query-answering time: " + (System.currentTimeMillis() - start));
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(-1);
    }
}
Also used : ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) InnerProductWeighter(edu.cmu.ml.proppr.prove.InnerProductWeighter)

Example 2 with ParamsFile

use of edu.cmu.ml.proppr.util.ParamsFile in project ProPPR by TeamCohen.

the class Grounder method main.

/////////////////////////////////////// Command line ////////////////////////////////
public static void main(String... args) {
    try {
        int inputFiles = Configuration.USE_QUERIES | Configuration.USE_PARAMS;
        int outputFiles = Configuration.USE_GROUNDED;
        int constants = Configuration.USE_WAM | Configuration.USE_THREADS | Configuration.USE_ORDER | Configuration.USE_EMPTYGRAPHS;
        int modules = Configuration.USE_GROUNDER | Configuration.USE_PROVER | Configuration.USE_SQUASHFUNCTION;
        ExampleGrounderConfiguration c = new ExampleGrounderConfiguration(args, inputFiles, outputFiles, constants, modules);
        System.out.println(c.toString());
        if (c.getCustomSetting("graphKey") != null)
            c.grounder.useGraphKeyFile((File) c.getCustomSetting("graphKey"));
        if (c.paramsFile != null) {
            ParamsFile file = new ParamsFile(c.paramsFile);
            c.grounder.addParams(new SimpleParamVector<String>(Dictionary.load(file)), c.squashingFunction);
            file.check(c);
        }
        long start = System.currentTimeMillis();
        c.grounder.groundExamples(c.queryFile, c.groundedFile, c.maintainOrder);
        System.out.println("Grounding time: " + (System.currentTimeMillis() - start));
        System.out.println("Done.");
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(-1);
    }
}
Also used : ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) File(java.io.File)

Example 3 with ParamsFile

use of edu.cmu.ml.proppr.util.ParamsFile in project ProPPR by TeamCohen.

the class ParamsFileTest method test.

@Test
public void test() {
    File paramsFile = new File(PARAMSFILE);
    ParamsFile.save(params, paramsFile, null);
    {
        ParamsFile file = new ParamsFile(paramsFile);
        Map<String, Double> loadedParams = Dictionary.load(file);
        Properties props = file.getHeader();
        assertEquals(0, props.stringPropertyNames().size());
        for (String key : loadedParams.keySet()) {
            assertEquals(key + " mismatch", params.get(key), loadedParams.get(key));
        }
        paramsFile.delete();
    }
    ModuleConfiguration c = new ModuleConfiguration(CMDLINE, 0, 0, Configuration.USE_WAM, Configuration.USE_PROVER);
    ParamsFile.save(params, paramsFile, c);
    {
        ParamsFile file = new ParamsFile(paramsFile);
        Map<String, Double> loadedParams = Dictionary.load(file);
        Properties props = file.getHeader();
        props.list(System.out);
        assertEquals("Should have saved header properties this time", 3, props.stringPropertyNames().size());
        for (String key : loadedParams.keySet()) {
            assertEquals(key + " mismatch", params.get(key), loadedParams.get(key));
        }
        paramsFile.delete();
    }
}
Also used : ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) Properties(java.util.Properties) ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with ParamsFile

use of edu.cmu.ml.proppr.util.ParamsFile in project ProPPR by TeamCohen.

the class ParamsFileTest method testValidation.

@Test
public void testValidation() {
    ModuleConfiguration c = new ModuleConfiguration(CMDLINE, 0, 0, Configuration.USE_WAM, Configuration.USE_PROVER);
    File paramsFile = new File(PARAMSFILE);
    ParamsFile.save(params, paramsFile, c);
    ParamsFile file = new ParamsFile(paramsFile);
    Map<String, Double> loadedParams = Dictionary.load(file);
    file.check(c);
    ModuleConfiguration c2 = new ModuleConfiguration(new String[] { CMDLINE[0], CMDLINE[1], "--prover", "dpr", "--apr", "eps=1e-5:alph=2e-2" }, 0, 0, Configuration.USE_WAM, Configuration.USE_PROVER);
    file.check(c2);
}
Also used : ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) File(java.io.File) Test(org.junit.Test)

Aggregations

ParamsFile (edu.cmu.ml.proppr.util.ParamsFile)4 File (java.io.File)3 Test (org.junit.Test)2 InnerProductWeighter (edu.cmu.ml.proppr.prove.InnerProductWeighter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1