Example usage for java.lang System nanoTime

List of usage examples for java.lang System nanoTime

Introduction

In this page you can find the example usage for java.lang System nanoTime.

Prototype

@HotSpotIntrinsicCandidate
public static native long nanoTime();

Source Link

Document

Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.

Usage

From source file:eu.amidst.core.inference.MPEInferenceExperiments.java

/**
 * The class constructor.//from w  w w .  j  a v  a 2 s  .c o  m
 * @param args Array of options: "filename variable a b N useVMP" if variable is continuous or "filename variable w N useVMP" for discrete
 */
public static void main(String[] args) throws Exception {

    int seedNetwork = 61236719 + 123;

    int numberOfGaussians = 20;

    int numberOfMultinomials = numberOfGaussians;
    BayesianNetworkGenerator.setSeed(seedNetwork);
    BayesianNetworkGenerator.setNumberOfGaussianVars(numberOfGaussians);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(numberOfMultinomials, 2);
    BayesianNetworkGenerator.setNumberOfLinks((int) 1.3 * (numberOfGaussians + numberOfMultinomials));

    BayesianNetwork bn = BayesianNetworkGenerator.generateBayesianNetwork();

    int seed = seedNetwork + 231591;

    //if (Main.VERBOSE) System.out.println(bn.getDAG());
    if (Main.VERBOSE)
        System.out.println(bn.toString());

    MPEInference mpeInference = new MPEInference();
    mpeInference.setModel(bn);
    mpeInference.setParallelMode(true);

    if (Main.VERBOSE)
        System.out.println("CausalOrder: "
                + Arrays.toString(Utils.getTopologicalOrder(mpeInference.getOriginalModel().getDAG()).stream()
                        .map(Variable::getName).toArray()));
    List<Variable> modelVariables = Utils.getTopologicalOrder(bn.getDAG());
    if (Main.VERBOSE)
        System.out.println();

    // Including evidence:
    //double observedVariablesRate = 0.00;
    //Assignment evidence = randomEvidence(seed, observedVariablesRate, bn);
    //mpeInference.setEvidence(evidence);

    int parallelSamples = 100;
    int samplingMethodSize = 10000;

    mpeInference.setSampleSize(parallelSamples);

    /***********************************************
     *        SIMULATED ANNEALING
     ************************************************/

    // MPE INFERENCE WITH SIMULATED ANNEALING, ALL VARIABLES
    if (Main.VERBOSE)
        System.out.println();
    long timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SA_GLOBAL);

    Assignment mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (SA.All): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    long timeStop = System.nanoTime();
    double execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
    if (Main.VERBOSE)
        System.out.println();

    // MPE INFERENCE WITH SIMULATED ANNEALING, SOME VARIABLES AT EACH TIME
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SA_LOCAL);

    mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate  (SA.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
    if (Main.VERBOSE)
        System.out.println();

    /***********************************************
     *        HILL CLIMBING
     ************************************************/

    // MPE INFERENCE WITH HILL CLIMBING, ALL VARIABLES
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.HC_GLOBAL);

    mpeEstimate = mpeInference.getEstimate();
    //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (HC.All): " + mpeEstimate.outputString(modelVariables));
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    //  MPE INFERENCE WITH HILL CLIMBING, ONE VARIABLE AT EACH TIME
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.HC_LOCAL);

    mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate  (HC.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    /***********************************************
     *        SAMPLING AND DETERMINISTIC
     ************************************************/

    // MPE INFERENCE WITH SIMULATION AND PICKING MAX

    mpeInference.setSampleSize(samplingMethodSize);

    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SAMPLING);

    mpeEstimate = mpeInference.getEstimate();
    //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (SAMPLING): " + mpeEstimate.outputString(modelVariables));
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    if (bn.getNumberOfVars() <= 50) {

        // MPE INFERENCE, DETERMINISTIC
        timeStart = System.nanoTime();
        mpeInference.runInference(MPEInference.SearchAlgorithm.EXHAUSTIVE);

        mpeEstimate = mpeInference.getEstimate();
        //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
        if (Main.VERBOSE)
            System.out.println("MPE estimate (DETERM.): " + mpeEstimate.outputString(modelVariables));
        if (Main.VERBOSE)
            System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                    + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        if (Main.VERBOSE)
            System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        if (Main.VERBOSE)
            System.out.println();

    }
}

From source file:TmlCommandLine.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    long time = System.nanoTime();

    options = new Options();

    // Repository
    options.addOption(OptionBuilder.withDescription(
            "Full path of the repository folder, where TML will retrieve (or insert) documents. (e.g. /home/user/lucene).")
            .hasArg().withArgName("folder").isRequired().create("repo"));

    // Verbosity/*w w  w.  j ava2s .co m*/
    options.addOption(
            OptionBuilder.withDescription("Verbose output in the console (it goes verbose to the log file).")
                    .hasArg(false).isRequired(false).create("v"));

    // Operation on corpus
    options.addOption(OptionBuilder.hasArg(false).withDescription("Performs an operation on a corpus.")
            .isRequired(false).create("O"));

    // The list of operations
    options.addOption(OptionBuilder.withDescription(
            "The list of operations you want to execute on the corpus. (e.g. PassageDistances,PassageSimilarity .")
            .hasArgs().withValueSeparator(',').withArgName("list").isRequired(false).withLongOpt("operations")
            .create());

    // The file to store the results
    options.addOption(OptionBuilder.withDescription("Folder where to store the results. (e.g. results/run01/).")
            .hasArg().withArgName("folder").isRequired(false).withLongOpt("oresults").create());

    // The corpus on which operate
    options.addOption(OptionBuilder.withDescription(
            "Lucene query that defines the corpus to operate with. (e.g. \"type:sentence AND reference:Document01\").")
            .hasArg().withArgName("query").isRequired(false).withLongOpt("ocorpus").create());

    // The corpus on which operate
    options.addOption(OptionBuilder.withDescription(
            "Use all documents in repository as single document corpora, it can be sentence or paragraph based. (e.g. sentence).")
            .hasArgs().withArgName("type").isRequired(false).withLongOpt("oalldocs").create());

    // The properties file for the corpus
    options.addOption(OptionBuilder.withDescription("Properties file with the corpus parameters (optional).")
            .hasArg().withArgName("parameter file").isRequired(false).withLongOpt("ocpar").create());

    // Background knowledge corpus
    options.addOption(OptionBuilder.withDescription(
            "Lucene query that defines a background knowledge on which the corpus will be projected. (e.g. \"type:sentences AND reference:Document*\").")
            .hasArg().withArgName("query").isRequired(false).withLongOpt("obk").create());

    // Background knowledge parameters
    options.addOption(OptionBuilder.withDescription(
            "Properties file with the background knowledge corpus parameters, if not set it will use the same as the corpus.")
            .hasArg().withArgName("parameter file").isRequired(false).withLongOpt("obkpar").create());

    // Term selection
    String criteria = "";
    for (TermSelection tsel : TermSelection.values()) {
        criteria += "," + tsel.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("name")
            .withDescription("Name of the Term selection criteria (" + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otsel").create());

    //   Term selection threshold
    options.addOption(OptionBuilder.hasArgs().withArgName("number")
            .withDescription("Threshold for the tsel criteria option.").withType(Integer.TYPE).isRequired(false)
            .withValueSeparator(',').withLongOpt("otselth").create());

    //   Dimensionality reduction
    criteria = "";
    for (DimensionalityReduction dim : DimensionalityReduction.values()) {
        criteria += "," + dim.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Dimensionality Reduction criteria. (e.g. " + criteria + ").")
            .isRequired(false).withValueSeparator(',').withLongOpt("odim").create());

    //   Dimensionality reduction threshold
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Threshold for the dim options. (e.g. 0,1,2).").isRequired(false)
            .withValueSeparator(',').withLongOpt("odimth").create());

    //   Local weight
    criteria = "";
    for (LocalWeight weight : LocalWeight.values()) {
        criteria += "," + weight.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Local Weight to apply. (e.g." + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otwl").create());

    //   Global weight
    criteria = "";
    for (GlobalWeight weight : GlobalWeight.values()) {
        criteria += "," + weight.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Global Weight to apply. (e.g. " + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otwg").create());

    //   Use Lanczos
    options.addOption(OptionBuilder.hasArg(false).withDescription("Use Lanczos for SVD decomposition.")
            .isRequired(false).withLongOpt("olanczos").create());

    // Inserting documents in repository
    options.addOption(OptionBuilder.hasArg(false).withDescription("Insert documents into repository.")
            .isRequired(false).create("I"));

    // Max documents to insert
    options.addOption(OptionBuilder.hasArg().withArgName("number")
            .withDescription("Maximum number of documents to index or use in an operation.")
            .withType(Integer.TYPE).isRequired(false).withLongOpt("imaxdocs").create());

    // Clean repository
    options.addOption(
            OptionBuilder.hasArg(false).withDescription("Empties the repository before inserting new ones.")
                    .isRequired(false).withLongOpt("iclean").create());

    // Use annotator
    options.addOption(OptionBuilder.hasArgs()
            .withDescription(
                    "List of annotators to use when inserting the documents. (e.g. PennTreeAnnotator).")
            .isRequired(false).withValueSeparator(',').withLongOpt("iannotators").create());

    // Documents folder
    options.addOption(OptionBuilder.hasArg().withArgName("folder")
            .withDescription("The folder that contains the documens to insert.").isRequired(false)
            .withLongOpt("idocs").create());

    // Initializing the line parser
    CommandLineParser parser = new PosixParser();
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp(options);
        return;
    }

    // Validate that either inserting or an operation are given
    if (!line.hasOption("I") && !line.hasOption("O")) {
        System.out.println("One of the options -I or -O must be present.");
        printHelp(options);
        return;
    }

    repositoryFolder = line.getOptionValue("repo");

    try {
        if (line.hasOption("I")) {
            indexing();
        } else if (line.hasOption("O")) {
            operation();
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        printHelp(options);
        return;
    }

    System.out.println("TML finished successfully in " + (System.nanoTime() - time) * 10E-9 + " seconds.");
    return;
}

From source file:PartitionLR.java

public static void main(String[] args) {

    if (args.length < 6) {
        System.err.println("Usage: JavaHdfsLR <master> <file> <iters> <L> <D> <use FPGA?> (<testing file>)");
        System.exit(1);//from   w  ww . j  a  v a 2s .co  m
    }
    int ITERATIONS = Integer.parseInt(args[2]);
    System.out.println("iterations: " + ITERATIONS);
    L = Integer.parseInt(args[3]);
    System.out.println("L: " + L);
    D = Integer.parseInt(args[4]);
    System.out.println("D: " + D);
    useFPGA = Integer.parseInt(args[5]);
    System.out.println("use FPGA: " + useFPGA);

    JavaSparkContext sc = new JavaSparkContext(args[0], "PartitionLR", System.getenv("SPARK_HOME"),
            "target/simple-project-1.0.jar");
    JavaRDD<String> lines = sc.textFile(args[1]);
    JavaRDD<DataPoint> points = lines.map(new ParsePoint()).repartition(32).cache();

    float[][] w = new float[L][D];
    for (int i = 0; i < L; i++) {
        for (int j = 0; j < D; j++) {
            w[i][j] = 0.0f;
        }
    }

    System.out.print("Initial w: ");
    printWeights(w);

    for (int k = 1; k <= ITERATIONS; k++) {
        System.out.println("On iteration " + k);

        long tic = System.nanoTime();
        float[][] gradient = points.mapPartitions(new BackwardLR(w)).reduce(new VectorSum());
        System.out.println("elapsed time: " + (System.nanoTime() - tic) / 1e9);

        for (int i = 0; i < L; i++) {
            for (int j = 0; j < D; j++) {
                w[i][j] -= gradient[i][j];
            }
        }

    }

    System.out.print("Final w: ");
    printWeights(w);

    lines = sc.textFile(args.length < 7 ? args[1] : args[6]);
    System.out.println("first prediction");
    System.out.println(Arrays
            .toString(lines.map(new ParsePoint()).repartition(32).mapPartitions(new ForwardLR(w)).first()));

    System.exit(0);
}

From source file:ca.uqac.dim.mapreduce.ltl.ParaLTLValidation.java

/**
 * Program entry point./*from w  w w.  j av a2 s .  co m*/
 * @param args Command-line arguments
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    // Define and process command line arguments
    Options options = new Options();
    HelpFormatter help_formatter = new HelpFormatter();
    Option opt;
    options.addOption("h", "help", false, "Show help");
    opt = OptionBuilder.withArgName("property").hasArg()
            .withDescription("Property to verify, enclosed in double quotes").create("p");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename").create("i");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg()
            .withDescription("Set verbosity level to x (default: 0 = quiet)").create("v");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("ParserType").hasArg().withDescription("Parser type (Dom or Sax)")
            .create("t");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("redirection").withArgName("x").hasArg()
            .withDescription("Set the redirection file for the System.out").create("r");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("mapper").withArgName("x").hasArg()
            .withDescription("Set the number of mapper").create("m");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("reducer").withArgName("x").hasArg()
            .withDescription("Set the number of reducer").create("n");
    options.addOption(opt);
    CommandLine c_line = parseCommandLine(options, args);

    String redirectionFile = "";

    //Contains a redirection file for the output
    if (c_line.hasOption("redirection")) {
        try {
            redirectionFile = c_line.getOptionValue("redirection");
            PrintStream ps;
            ps = new PrintStream(redirectionFile);
            System.setOut(ps);
        } catch (FileNotFoundException e) {
            System.out.println("Redirection error !!!");
            e.printStackTrace();
        }
    }

    if (!c_line.hasOption("p") || !c_line.hasOption("i") | c_line.hasOption("h")) {
        help_formatter.printHelp(app_name, options);
        System.exit(1);
    }
    assert c_line.hasOption("p");
    assert c_line.hasOption("i");
    String trace_filename = c_line.getOptionValue("i");
    String trace_format = getExtension(trace_filename);
    String property_str = c_line.getOptionValue("p");
    String ParserType = "";
    int MapperNum = 0;
    int ReducerNum = 0;

    //Contains a parser type
    if (c_line.hasOption("t")) {
        ParserType = c_line.getOptionValue("t");
    } else {
        System.err.println("No Parser Type in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a mapper number
    if (c_line.hasOption("m")) {
        MapperNum = Integer.parseInt(c_line.getOptionValue("m"));
    } else {
        System.err.println("No Mapper Number in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a reducer number
    if (c_line.hasOption("n")) {
        ReducerNum = Integer.parseInt(c_line.getOptionValue("n"));
    } else {
        System.err.println("No Reducer Number in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    if (c_line.hasOption("v"))
        m_verbosity = Integer.parseInt(c_line.getOptionValue("v"));

    // Obtain the property to verify and break into subformulas
    Operator property = null;
    try {
        int preset = Integer.parseInt(property_str);
        property = new Edoc2012Presets().property(preset);
    } catch (NumberFormatException e) {
        try {
            property = Operator.parseFromString(property_str);
        } catch (Operator.ParseException pe) {
            System.err.println("ERROR: parsing");
            System.exit(1);
        }
    }
    Set<Operator> subformulas = property.getSubformulas();

    // Initialize first collector depending on input file format
    int max_loops = property.getDepth();
    int max_tuples_total = 0, total_tuples_total = 0;
    long time_begin = System.nanoTime();
    TraceCollector initial_collector = null;
    {
        File in_file = new File(trace_filename);
        if (trace_format.compareToIgnoreCase(".txt") == 0) {
            initial_collector = new CharacterTraceCollector(in_file, subformulas);
        } else if (trace_format.compareToIgnoreCase(".xml") == 0) {
            if (ParserType.equals("Dom")) {
                initial_collector = new XmlDomTraceCollector(in_file, subformulas);
            } else if (ParserType.equals("Sax")) {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            } else {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            }
        }
    }
    if (initial_collector == null) {
        System.err.println("ERROR: unrecognized input format");
        System.exit(1);
    }

    // Start workflow
    int trace_len = initial_collector.getTraceLength();
    InCollector<Operator, LTLTupleValue> loop_collector = initial_collector;
    print(System.out, property.toString(), 2);
    print(System.out, loop_collector.toString(), 3);
    for (int i = 0; i < max_loops; i++) {
        print(System.out, "Loop " + i, 2);
        LTLParallelWorkflow w = new LTLParallelWorkflow(new LTLMapper(subformulas),
                new LTLReducer(subformulas, trace_len), loop_collector,
                new ResourceManager<Operator, LTLTupleValue>(MapperNum),
                new ResourceManager<Operator, LTLTupleValue>(ReducerNum));
        loop_collector = w.run();
        max_tuples_total += w.getMaxTuples();
        total_tuples_total += w.getTotalTuples();

        if (m_verbosity >= 3) {
            print(System.out, loop_collector.toString(), 3);
        }
    }
    boolean result = getVerdict(loop_collector, property);
    long time_end = System.nanoTime();
    if (result)
        print(System.out, "Formula is true", 1);
    else
        print(System.out, "Formula is false", 1);

    long time_total = (time_end - time_begin) / 1000000;
    System.out.println(trace_len + "," + max_tuples_total + "," + total_tuples_total + "," + time_total);
}

From source file:eu.amidst.flinklink.examples.misc.DynamicParallelVMPExtended.java

/**
*
* ./bin/flink run -m yarn-cluster -yn 8 -ys 4 -yjm 1024 -ytm 9000
*              -c eu.amidst.flinklink.examples.misc.DynamicParallelVMPExtended ../flinklink.jar 0 10 1000000 100 100 100 3 0
*
*
* @param args command line arguments/*from w w  w  . j av  a  2s .co  m*/
* @throws Exception
*/
public static void main(String[] args) throws Exception {

    int nCVars = Integer.parseInt(args[0]);
    int nMVars = Integer.parseInt(args[1]);
    int nSamples = Integer.parseInt(args[2]);
    int windowSize = Integer.parseInt(args[3]);
    int globalIter = Integer.parseInt(args[4]);
    int localIter = Integer.parseInt(args[5]);
    int nsets = Integer.parseInt(args[6]);
    int seed = Integer.parseInt(args[7]);
    boolean generateData = Boolean.parseBoolean(args[8]);

    /*
     * Generate dynamic datasets
     */
    if (generateData) {
        String[] argsDatasets = ArrayUtils.addAll(ArrayUtils.subarray(args, 0, 4),
                ArrayUtils.subarray(args, 6, 8));
        DynamicDataSets dynamicDataSets = new DynamicDataSets();
        dynamicDataSets.generateDynamicDataset(argsDatasets);
    }

    /*
     * Logging
     */
    //PropertyConfigurator.configure(args[6]);
    BasicConfigurator.configure();

    logger.info("Starting DynamicVMPExtended experiments");

    //String fileName = "hdfs:///tmp"+nCVars+"_"+nMVars+"_"+nSamples+"_"+nsets+"_"+seed;
    String fileName = "./datasets/tmp" + nCVars + "_" + nMVars + "_" + nSamples + "_" + nsets + "_" + seed;

    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataFlink<DynamicDataInstance> data0 = DataFlinkLoader.loadDynamicDataFromFolder(env,
            fileName + "_iter_" + 0 + ".arff", false);

    DynamicDAG hiddenNB = getHiddenDynamicNaiveBayesStructure(data0.getAttributes(), false);

    System.out.println(hiddenNB.toString());

    //Structure learning is excluded from the test, i.e., we use directly the initial Asia network structure
    // and just learn then test the parameter learning

    long start = System.nanoTime();

    //Parameter Learning
    DynamicParallelVB parallelVB = new DynamicParallelVB();
    parallelVB.setGlobalThreshold(0.1);
    parallelVB.setMaximumGlobalIterations(globalIter);
    parallelVB.setLocalThreshold(0.1);
    parallelVB.setMaximumLocalIterations(localIter);
    parallelVB.setSeed(5);
    parallelVB.setOutput(true);

    //Set the window size
    parallelVB.setBatchSize(windowSize);
    parallelVB.setDAG(hiddenNB);
    parallelVB.initLearning();

    System.out.println("--------------- DATA " + 0 + " --------------------------");
    parallelVB.updateModelWithNewTimeSlice(0, data0);

    for (int i = 1; i < nsets; i++) {
        logger.info("--------------- DATA " + i + " --------------------------");
        DataFlink<DynamicDataInstance> dataNew = DataFlinkLoader.loadDynamicDataFromFolder(env,
                fileName + "_iter_" + i + ".arff", false);
        parallelVB.updateModelWithNewTimeSlice(i, dataNew);
    }

    logger.info(parallelVB.getLearntDynamicBayesianNetwork().toString());

    long duration = (System.nanoTime() - start) / 1;
    double seconds = duration / 1000000000.0;
    logger.info("Running time: {} seconds.", seconds);

}

From source file:de.unisb.cs.st.javaslicer.slicing.DirectSlicer.java

public static void main(String[] args) {
    Options options = createOptions();/*from w w  w .ja  va  2 s  .  co m*/
    CommandLineParser parser = new GnuParser();
    CommandLine cmdLine;

    try {
        cmdLine = parser.parse(options, args, true);
    } catch (ParseException e) {
        System.err.println("Error parsing the command line arguments: " + e.getMessage());
        return;
    }

    if (cmdLine.hasOption('h')) {
        printHelp(options, System.out);
        System.exit(0);
    }

    String[] additionalArgs = cmdLine.getArgs();
    if (additionalArgs.length != 2) {
        printHelp(options, System.err);
        System.exit(-1);
    }
    File traceFile = new File(additionalArgs[0]);
    String slicingCriterionString = additionalArgs[1];

    Long threadId = null;
    if (cmdLine.hasOption('t')) {
        try {
            threadId = Long.parseLong(cmdLine.getOptionValue('t'));
        } catch (NumberFormatException e) {
            System.err.println("Illegal thread id: " + cmdLine.getOptionValue('t'));
            System.exit(-1);
        }
    }

    TraceResult trace;
    try {
        trace = TraceResult.readFrom(traceFile);
    } catch (IOException e) {
        System.err.format("Could not read the trace file \"%s\": %s%n", traceFile, e);
        System.exit(-1);
        return;
    }

    List<SlicingCriterion> sc = null;
    try {
        sc = StaticSlicingCriterion.parseAll(slicingCriterionString, trace.getReadClasses());
    } catch (IllegalArgumentException e) {
        System.err.println("Error parsing slicing criterion: " + e.getMessage());
        System.exit(-1);
        return;
    }

    List<ThreadId> threads = trace.getThreads();
    if (threads.size() == 0) {
        System.err.println("The trace file contains no tracing information.");
        System.exit(-1);
    }

    ThreadId tracing = null;
    for (ThreadId t : threads) {
        if (threadId == null) {
            if ("main".equals(t.getThreadName())
                    && (tracing == null || t.getJavaThreadId() < tracing.getJavaThreadId()))
                tracing = t;
        } else if (t.getJavaThreadId() == threadId.longValue()) {
            tracing = t;
        }
    }

    if (tracing == null) {
        System.err.println(threadId == null ? "Couldn't find the main thread."
                : "The thread you specified was not found.");
        System.exit(-1);
        return;
    }

    long startTime = System.nanoTime();
    DirectSlicer slicer = new DirectSlicer(trace);
    if (cmdLine.hasOption("--progress"))
        slicer.addProgressMonitor(new ConsoleProgressMonitor());
    Set<Instruction> slice = slicer.getDynamicSlice(tracing, sc);
    long endTime = System.nanoTime();

    List<Instruction> sliceList = new ArrayList<Instruction>(slice);
    Collections.sort(sliceList);

    System.out.println("The dynamic slice for criterion " + sc + ":");
    for (Instruction insn : sliceList) {
        System.out.format((Locale) null, "%s.%s:%d %s%n", insn.getMethod().getReadClass().getName(),
                insn.getMethod().getName(), insn.getLineNumber(), insn.toString());
    }
    System.out.format((Locale) null, "%nSlice consists of %d bytecode instructions.%n", sliceList.size());
    System.out.format((Locale) null, "Computation took %.2f seconds.%n", 1e-9 * (endTime - startTime));
}

From source file:edu.cmu.lti.oaqa.apps.Client.java

public static void main(String args[]) {
    BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));

    Options opt = new Options();

    Option o = new Option(PORT_SHORT_PARAM, PORT_LONG_PARAM, true, PORT_DESC);
    o.setRequired(true);/*from w w w.j a v  a2 s  .c o  m*/
    opt.addOption(o);
    o = new Option(HOST_SHORT_PARAM, HOST_LONG_PARAM, true, HOST_DESC);
    o.setRequired(true);
    opt.addOption(o);
    opt.addOption(K_SHORT_PARAM, K_LONG_PARAM, true, K_DESC);
    opt.addOption(R_SHORT_PARAM, R_LONG_PARAM, true, R_DESC);
    opt.addOption(QUERY_TIME_SHORT_PARAM, QUERY_TIME_LONG_PARAM, true, QUERY_TIME_DESC);
    opt.addOption(RET_OBJ_SHORT_PARAM, RET_OBJ_LONG_PARAM, false, RET_OBJ_DESC);
    opt.addOption(RET_EXTERN_ID_SHORT_PARAM, RET_EXTERN_ID_LONG_PARAM, false, RET_EXTERN_ID_DESC);

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    try {
        CommandLine cmd = parser.parse(opt, args);

        String host = cmd.getOptionValue(HOST_SHORT_PARAM);

        String tmp = null;

        tmp = cmd.getOptionValue(PORT_SHORT_PARAM);

        int port = -1;

        try {
            port = Integer.parseInt(tmp);
        } catch (NumberFormatException e) {
            Usage("Port should be integer!");
        }

        boolean retObj = cmd.hasOption(RET_OBJ_SHORT_PARAM);
        boolean retExternId = cmd.hasOption(RET_EXTERN_ID_SHORT_PARAM);

        String queryTimeParams = cmd.getOptionValue(QUERY_TIME_SHORT_PARAM);
        if (null == queryTimeParams)
            queryTimeParams = "";

        SearchType searchType = SearchType.kKNNSearch;
        int k = 0;
        double r = 0;

        if (cmd.hasOption(K_SHORT_PARAM)) {
            if (cmd.hasOption(R_SHORT_PARAM)) {
                Usage("Range search is not allowed if the KNN search is specified!");
            }
            tmp = cmd.getOptionValue(K_SHORT_PARAM);
            try {
                k = Integer.parseInt(tmp);
            } catch (NumberFormatException e) {
                Usage("K should be integer!");
            }
            searchType = SearchType.kKNNSearch;
        } else if (cmd.hasOption(R_SHORT_PARAM)) {
            if (cmd.hasOption(K_SHORT_PARAM)) {
                Usage("KNN search is not allowed if the range search is specified!");
            }
            searchType = SearchType.kRangeSearch;
            tmp = cmd.getOptionValue(R_SHORT_PARAM);
            try {
                r = Double.parseDouble(tmp);
            } catch (NumberFormatException e) {
                Usage("The range value should be numeric!");
            }
        } else {
            Usage("One has to specify either range or KNN-search parameter");
        }

        String separator = System.getProperty("line.separator");

        StringBuffer sb = new StringBuffer();
        String s;

        while ((s = inp.readLine()) != null) {
            sb.append(s);
            sb.append(separator);
        }

        String queryObj = sb.toString();

        try {
            TTransport transport = new TSocket(host, port);
            transport.open();

            TProtocol protocol = new TBinaryProtocol(transport);
            QueryService.Client client = new QueryService.Client(protocol);

            if (!queryTimeParams.isEmpty())
                client.setQueryTimeParams(queryTimeParams);

            List<ReplyEntry> res = null;

            long t1 = System.nanoTime();

            if (searchType == SearchType.kKNNSearch) {
                System.out.println(String.format("Running a %d-NN search", k));
                res = client.knnQuery(k, queryObj, retExternId, retObj);
            } else {
                System.out.println(String.format("Running a range search (r=%g)", r));
                res = client.rangeQuery(r, queryObj, retExternId, retObj);
            }

            long t2 = System.nanoTime();

            System.out.println(String.format("Finished in %g ms", (t2 - t1) / 1e6));

            for (ReplyEntry e : res) {
                System.out.println(String.format("id=%d dist=%g %s", e.getId(), e.getDist(),
                        retExternId ? "externId=" + e.getExternId() : ""));
                if (retObj)
                    System.out.println(e.getObj());
            }

            transport.close(); // Close transport/socket !
        } catch (TException te) {
            System.err.println("Apache Thrift exception: " + te);
            te.printStackTrace();
        }

    } catch (ParseException e) {
        Usage("Cannot parse arguments");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:edu.uiowa.javatm.JavaTM.java

/**
 * @param args First one indicates which topic model to use
 *//*w w w  .j a  v a 2  s.  c  o m*/
public static void main(String[] args) {
    TMGibbsSampler tmGibbsSampler = null;

    Option modelType = Option.builder("model").longOpt("model-type").desc("Type of topic models to use")
            .hasArg().required().build();

    Option dataName = Option.builder("name").longOpt("data-name").desc("Data name: used for saving outputs")
            .hasArg().required().build();

    Option alpha = Option.builder("a").longOpt("alpha")
            .desc("Dirichlet prior for document (author) over topic multinomial").hasArg().required().build();

    Option beta = Option.builder("b").longOpt("beta").desc("Dirichlet prior for topic over word multinomial")
            .hasArg().required().build();

    Option pi = Option.builder("p").longOpt("pi").desc("Dirichlet prior for topic over time multinomial")
            .hasArg().build();

    Option K = Option.builder("K").longOpt("K").desc("The number of timestamp indices").hasArg().build();

    /*Option tau = Option.builder("tau").longOpt("tau")
    .desc("Smoothing constant for topic time")
    .hasArg().build();*/

    Option doc = Option.builder("doc").longOpt("document-file").desc("WD matrix to use").hasArg().required()
            .build();

    Option voc = Option.builder("voc").longOpt("vocabulary-file")
            .desc("Vocabulary file of the corpus of interest").hasArg().required().build();

    Option auth = Option.builder("auth").longOpt("auth-file").desc("Author indices for each token").hasArg()
            .build();

    Option authArray = Option.builder("authArray").longOpt("author-list-file").desc("Author list").hasArg()
            .build();

    Option dkArray = Option.builder("dk").longOpt("document-time-file").desc("Document timestamp file").hasArg()
            .build();

    Option citationMat = Option.builder("cm").longOpt("citation-matrix")
            .desc("Citation overtime for the corpus").hasArg().build();

    Option numTopics = Option.builder("topic").longOpt("num-topics").desc("The total number of topics").hasArg()
            .required().build();

    Option numIters = Option.builder("iter").longOpt("num-iters").desc("The total number of iterations")
            .hasArg().required().build();

    Option outputDir = Option.builder("odir").longOpt("output-dir").desc("Output directory").hasArg().required()
            .build();

    Options options = new Options();
    options.addOption(modelType).addOption(alpha).addOption(beta).addOption(numTopics).addOption(K)
            .addOption(pi).addOption(citationMat).addOption(numIters).addOption(doc).addOption(voc)
            .addOption(dkArray).addOption(outputDir).addOption(auth).addOption(authArray).addOption(dataName);

    CommandLineParser parser = new DefaultParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String model = line.getOptionValue("model");
        String name = line.getOptionValue("name");
        String docFile = line.getOptionValue("doc");
        String vocFile = line.getOptionValue("voc");
        int topics = Integer.parseInt(line.getOptionValue("topic"));
        int iters = Integer.parseInt(line.getOptionValue("iter"));
        double a = Double.parseDouble(line.getOptionValue("a"));
        double b = Double.parseDouble(line.getOptionValue("b"));

        String modelLower = model.toLowerCase();
        if (modelLower.equals("lda")) {
            tmGibbsSampler = new LDAGibbsSampler(topics, iters, a, b, docFile, vocFile);
        } else if (modelLower.equals("at")) {
            String authFile = line.getOptionValue("auth");
            String authArrayFile = line.getOptionValue("authArray");
            //double tau_val = Double.parseDouble(line.getOptionValue("tau"));
            tmGibbsSampler = new ATGibbsSampler(topics, iters, a, b, docFile, vocFile, authFile, authArrayFile);
        } else if (modelLower.equals("tot")) {
            String dkFile = line.getOptionValue("dk");
            //double tau_val = Double.parseDouble(line.getOptionValue("tau"));
            tmGibbsSampler = new ToTGibbsSampler(topics, iters, a, b, docFile, vocFile, dkFile);
        } else if (modelLower.equals("tiot")) {
            String timeFile = line.getOptionValue("dk");
            String citationFile = line.getOptionValue("cm");
            double p = Double.parseDouble(line.getOptionValue("p"));
            //int k = Integer.parseInt(line.getOptionValue("K"));
            tmGibbsSampler = new TIOTGibbsSampler(topics, iters, a, b, p, docFile, vocFile, timeFile,
                    citationFile);
        } else {
            System.err.println("Invalid model type selection. Must be lda, at, tot or atot.");
            System.exit(ExitStatus.ILLEGAL_ARGUMENT);
        }

        long startTime = System.nanoTime();
        tmGibbsSampler.fit();
        TMOutcome outcome = tmGibbsSampler.get_outcome();
        long endTime = System.nanoTime();
        long duration = (endTime - startTime);
        System.out.println("Overall elapsed time: " + duration / 1000000000. + " seconds");

        tmGibbsSampler.showTopics(10);
        outcome.showTopicDistribution();

        String oDir = line.getOptionValue("odir");
        if (!oDir.endsWith("/")) {
            oDir = oDir + "/";
        }
        // append name to `oDir`
        oDir = oDir + name + "-";

        if (modelLower.contains("tot")) {
            // topic over time (tot and atot) has beta distribution parameters to write
            Utils.write2DArray(((ToTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv");
        }

        if (modelLower.contains("tiot")) {
            // topic over time (tot and atot) has beta distribution parameters to write
            Utils.write2DArray(((TIOTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv");
            double[][][] ga = ((TIOTOutcome) outcome).getGa();
            for (int t = 0; t < ga.length; t++) {
                Utils.write2DArray(ga[t], oDir + "gamma-" + t + "-" + modelLower + ".csv");
            }
        }

        Utils.write2DArray(outcome.getPhi(), oDir + "phi-" + modelLower + ".csv");
        Utils.write2DArray(outcome.getTheta(), oDir + "theta-" + modelLower + ".csv");

        System.out.println("Output files saved to " + oDir);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
    }

}

From source file:jsdp.app.control.clqg.univariate.CLQG.java

public static void main(String args[]) {

    /*******************************************************************
     * Problem parameters//from  w  w w .java  2  s . com
     */

    int T = 20; // Horizon length
    double G = 1; // Input transition
    double Phi = 1; // State transition
    double R = 1; // Input cost
    double Q = 1; // State cost
    double Ulb = -1; // Action constraint
    double Uub = 20; // Action constraint
    double noiseStd = 5; // Standard deviation of the noise

    double[] noiseStdArray = new double[T];
    Arrays.fill(noiseStdArray, noiseStd);
    double truncationQuantile = 0.975;

    // Random variables

    Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(noiseStdArray.length)
            .mapToObj(i -> new NormalDist(0, noiseStdArray[i]))

            .toArray(Distribution[]::new);
    double[] supportLB = IntStream.iterate(0, i -> i + 1).limit(T)
            .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], 1 - truncationQuantile)).toArray();

    double[] supportUB = IntStream.iterate(0, i -> i + 1).limit(T)
            .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], truncationQuantile)).toArray();

    double initialX = 0; // Initial state

    /*******************************************************************
     * Model definition
     */

    // State space

    double stepSize = 0.5; //Stepsize must be 1 for discrete distributions
    double minState = -25;
    double maxState = 100;
    StateImpl.setStateBoundaries(stepSize, minState, maxState);

    // Actions

    Function<State, ArrayList<Action>> buildActionList = (Function<State, ArrayList<Action>> & Serializable) s -> {
        StateImpl state = (StateImpl) s;
        ArrayList<Action> feasibleActions = new ArrayList<Action>();
        double maxAction = Math.min(Uub, (StateImpl.getMaxState() - Phi * state.getInitialState()) / G);
        double minAction = Math.max(Ulb, (StateImpl.getMinState() - Phi * state.getInitialState()) / G);
        for (double actionPointer = minAction; actionPointer <= maxAction; actionPointer += StateImpl
                .getStepSize()) {
            feasibleActions.add(new ActionImpl(state, actionPointer));
        }
        return feasibleActions;
    };

    Function<State, Action> idempotentAction = (Function<State, Action> & Serializable) s -> new ActionImpl(s,
            0.0);

    ImmediateValueFunction<State, Action, Double> immediateValueFunction = (initialState, action,
            finalState) -> {
        ActionImpl a = (ActionImpl) action;
        StateImpl fs = (StateImpl) finalState;
        double inputCost = Math.pow(a.getAction(), 2) * R;
        double stateCost = Math.pow(fs.getInitialState(), 2) * Q;
        return inputCost + stateCost;
    };

    // Random Outcome Function

    RandomOutcomeFunction<State, Action, Double> randomOutcomeFunction = (initialState, action, finalState) -> {
        double realizedNoise = ((StateImpl) finalState).getInitialState()
                - ((StateImpl) initialState).getInitialState() * Phi - ((ActionImpl) action).getAction() * G;
        return realizedNoise;
    };

    /*******************************************************************
     * Solve
     */

    // Sampling scheme

    SamplingScheme samplingScheme = SamplingScheme.NONE;
    int maxSampleSize = 50;
    double reductionFactorPerStage = 1;

    // Value Function Processing Method: backward recursion
    double discountFactor = 1.0;
    int stateSpaceLowerBound = 10000000;
    float loadFactor = 0.8F;
    BackwardRecursionImpl recursion = new BackwardRecursionImpl(OptimisationDirection.MIN, distributions,
            supportLB, supportUB, immediateValueFunction, randomOutcomeFunction, buildActionList,
            idempotentAction, discountFactor, samplingScheme, maxSampleSize, reductionFactorPerStage,
            stateSpaceLowerBound, loadFactor, HashType.THASHMAP);

    System.out.println("--------------Backward recursion--------------");
    StopWatch timer = new StopWatch();
    OperatingSystemMXBean osMBean;
    try {
        osMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
                ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
        long nanoBefore = System.nanoTime();
        long cpuBefore = osMBean.getProcessCpuTime();

        timer.start();
        recursion.runBackwardRecursionMonitoring();
        timer.stop();

        long cpuAfter = osMBean.getProcessCpuTime();
        long nanoAfter = System.nanoTime();

        long percent;
        if (nanoAfter > nanoBefore)
            percent = ((cpuAfter - cpuBefore) * 100L) / (nanoAfter - nanoBefore);
        else
            percent = 0;

        System.out.println(
                "Cpu usage: " + percent + "% (" + Runtime.getRuntime().availableProcessors() + " cores)");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println();
    double ETC = recursion.getExpectedCost(initialX);
    StateDescriptorImpl initialState = new StateDescriptorImpl(0, initialX);
    double action = recursion.getOptimalAction(initialState).getAction();
    System.out.println("Expected total cost (assuming an initial state " + initialX + "): " + ETC);
    System.out.println("Optimal initial action: " + action);
    System.out.println("Time elapsed: " + timer);
    System.out.println();
}

From source file:general.Main.java

/**
 * Selects the files to be processed and specifies the files to write to.
 *
 * @param args Arguments to specify runtime behavior.
 *//*from   w  w  w  .j  a  v a2 s.  c om*/
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException,
        InstantiationException, IllegalAccessException {
    Options options = new Options();
    options.addOption("l", "logging", false, "enables file logging");
    options.addOption("j", "jena", false, "uses the Jena SPARQL Parser");
    options.addOption("o", "openrdf", false, "uses the OpenRDF SPARQL Parser");
    options.addOption("f", "file", true, "defines the input file prefix");
    options.addOption("h", "help", false, "displays this help");
    options.addOption("t", "tsv", false, "reads from .tsv-files");
    // options.addOption("p", "parquet", false, "read from .parquet-files");
    options.addOption("n", "numberOfThreads", true, "number of used threads, default 1");
    options.addOption("b", "withBots", false, "enables metric calculation for bot queries+");
    options.addOption("p", "readPreprocessed", false, "enables reading of preprocessed files");

    //some parameters which can be changed through parameters
    //QueryHandler queryHandler = new OpenRDFQueryHandler();
    String inputFilePrefix;
    String inputFileSuffix = ".tsv";
    String queryParserName = "OpenRDF";
    Class inputHandlerClass = null;
    Class queryHandlerClass = null;
    int numberOfThreads = 1;

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("help", options);
            return;
        }
        if (cmd.hasOption("openrdf")) {
            queryHandlerClass = OpenRDFQueryHandler.class;
        }
        if (cmd.hasOption("tsv")) {
            inputFileSuffix = ".tsv";
            inputHandlerClass = InputHandlerTSV.class;
        }
        if (cmd.hasOption("parquet")) {
            inputFileSuffix = ".parquet";
            Logger.getLogger("org").setLevel(Level.WARN);
            Logger.getLogger("akka").setLevel(Level.WARN);
            SparkConf conf = new SparkConf().setAppName("SPARQLQueryAnalyzer").setMaster("local");
            JavaSparkContext sc = new JavaSparkContext(conf);
            inputHandlerClass = InputHandlerParquet.class;
        }
        if (inputHandlerClass == null) {
            System.out.println("Please specify which parser to use, either -t for TSV or -p for parquet.");
        }
        if (cmd.hasOption("file")) {
            inputFilePrefix = cmd.getOptionValue("file").trim();
        } else {
            System.out.println(
                    "Please specify at least the file which we should work on using the option '--file PREFIX' or 'f PREFIX'");
            return;
        }
        if (cmd.hasOption("logging")) {
            LoggingHandler.initFileLog(queryParserName, inputFilePrefix);
        }
        if (cmd.hasOption("numberOfThreads")) {
            numberOfThreads = Integer.parseInt(cmd.getOptionValue("numberOfThreads"));
        }
        if (cmd.hasOption("withBots")) {
            withBots = true;
        }
        if (cmd.hasOption("readPreprocessed")) {
            readPreprocessed = true;
        }
    } catch (UnrecognizedOptionException e) {
        System.out.println("Unrecognized commandline option: " + e.getOption());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        return;
    } catch (ParseException e) {
        System.out.println(
                "There was an error while parsing your command line input. Did you rechecked your syntax before running?");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        return;
    }

    LoggingHandler.initConsoleLog();

    loadPreBuildQueryTypes();

    long startTime = System.nanoTime();

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);

    for (int day = 1; day <= 31; day++) {
        String inputFile = inputFilePrefix + String.format("%02d", day) + inputFileSuffix;
        Runnable parseOneMonthWorker = new ParseOneMonthWorker(inputFile, inputFilePrefix, inputHandlerClass,
                queryParserName, queryHandlerClass, day);
        executor.execute(parseOneMonthWorker);
    }
    executor.shutdown();

    while (!executor.isTerminated()) {
        //wait until all workers are finished
    }

    writeQueryTypes(inputFilePrefix);

    long stopTime = System.nanoTime();
    long millis = TimeUnit.MILLISECONDS.convert(stopTime - startTime, TimeUnit.NANOSECONDS);
    Date date = new Date(millis);
    System.out.println("Finished executing with all threads: "
            + new SimpleDateFormat("mm-dd HH:mm:ss:SSSSSSS").format(date));
}