"Output model (winner) must have at most this number of states; this is taken only as a hint, so if there is no model with that few states, "
+ "the one with the lower number of states will be selected"),
});
final JSAPResult jsapResult = jsap.parse(args);
if (jsap.messagePrinted())
return;
if (jsapResult.getBoolean("verbose")) {
logger.setLevel(Level.DEBUG);
}
File inputFile = new File(jsapResult.getString("input-file"));
File taxoFile = new File(jsapResult.getString("taxonomy-file"));
Taxonomy tree = new Taxonomy(taxoFile);
Candidate initialCandidate;
if (jsapResult.userSpecified("init-explicit")) {
initialCandidate = new Candidate(tree, Util.split(jsapResult.getString("init-explicit")), null, null);
} else if (jsapResult.userSpecified("init-all-level")) {
initialCandidate = Candidate.createFixedLevelCandidate(tree, jsapResult.getInt("init-all-level"));
} else if (jsapResult.getBoolean("init-all-leaves")) {
initialCandidate = Candidate.createLeafCandidate(tree);
} else {
throw new IllegalArgumentException("Either --init-explicit, --init-all-leaves, or --init-all-level should be specified. See --help.");
}
logger.debug("Initial candidate is " + initialCandidate.toBriefString());
Class<SearchStrategy> strategy = (Class<SearchStrategy>) Class.forName(SearchStrategy.class.getPackage().getName() + "." + jsapResult.getString("search-method"));
logger.debug("Search strategy is " + strategy );
double weight1 = jsapResult.getDouble("search-method-weight-1");
if( jsapResult.userSpecified("search-method-weight-1") ) {
logger.info( "Will use weight1=" + weight1 );
}
// Read input file
logger.info("Reading input file");
SymbolTransitionFrequencies symbolTransitions = new SymbolTransitionFrequencies(tree);
symbolTransitions.processFile(inputFile);
// Learning
LearnModel learner = new LearnModel(tree, symbolTransitions, initialCandidate, strategy, weight1);
if (jsapResult.userSpecified("max-iterations")) {
learner.setMaxIterations(jsapResult.getInt("max-iterations"));
}
if (jsapResult.userSpecified("batch-size")) {
learner.setBatchSize(jsapResult.getInt("batch-size"));
}
learner.learn();
if (jsapResult.userSpecified("output-log")) {
String fileName = jsapResult.getString("output-log");
logger.info("Printing logfile to '" + fileName + "'");
PrintWriter reportWriter = outputFile(fileName);
learner.printReport(reportWriter);
reportWriter.close();
}
if (jsapResult.userSpecified("output-model")) {
int maxStates = jsapResult.getInt("winner-model-maxstates");
if( jsapResult.userSpecified("winner-model-maxstates") ) {
logger.info("Will pick the best model only among those having " + maxStates + " states or less" );
}
String fileName = jsapResult.getString("output-model");
logger.info("Printing best model to '" + fileName + "'" );
logger.info("You can use " + GenerateSequences.class.getName() + " to generate sequences");
PrintWriter reportWriter = outputFile(fileName);
learner.printBestModel(maxStates,reportWriter);
reportWriter.close();