@Test public void testModel() throws IOException { RealValueFileEventStream rvfes1 = new RealValueFileEventStream( "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt"); testDataIndexer.index(rvfes1); QNModel trainedModel = new QNTrainer(15, true).trainModel( ITERATIONS, testDataIndexer); Assert.assertFalse(trainedModel.equals(null)); }
public QNModel trainModel(int iterations, DataIndexer indexer) { Function objectiveFunction; if (threads == 1) { System.out.println("Computing model parameters ..."); objectiveFunction = new NegLogLikelihood(indexer); } else { System.out.println("Computing model parameters in " + threads + " threads ..."); objectiveFunction = new ParallelNegLogLikelihood(indexer, threads); } QNMinimizer minimizer = new QNMinimizer( l1Cost, l2Cost, iterations, m, maxFctEval, printMessages); minimizer.setEvaluator(new ModelEvaluator(indexer)); double[] parameters = minimizer.minimize(objectiveFunction); String[] predLabels = indexer.getPredLabels(); int nPredLabels = predLabels.length; String[] outcomeNames = indexer.getOutcomeLabels(); int nOutcomes = outcomeNames.length; Context[] params = new Context[nPredLabels]; for (int ci = 0; ci < params.length; ci++) { List<Integer> outcomePattern = new ArrayList<>(nOutcomes); List<Double> alpha = new ArrayList<>(nOutcomes); for (int oi = 0; oi < nOutcomes; oi++) { double val = parameters[oi * nPredLabels + ci]; outcomePattern.add(oi); alpha.add(val); } params[ci] = new Context(ArrayMath.toIntArray(outcomePattern), ArrayMath.toDoubleArray(alpha)); } return new QNModel(params, predLabels, outcomeNames); }
QNTrainer extends AbstractEventTrainer { public QNModel trainModel(int iterations, DataIndexer indexer) { Function objectiveFunction; if (threads == 1) { System.out.println("Computing model parameters ..."); objectiveFunction = new NegLogLikelihood(indexer); } else { System.out.println("Computing model parameters in " + threads + " threads ..."); objectiveFunction = new ParallelNegLogLikelihood(indexer, threads); } QNMinimizer minimizer = new QNMinimizer( l1Cost, l2Cost, iterations, m, maxFctEval, printMessages); minimizer.setEvaluator(new ModelEvaluator(indexer)); double[] parameters = minimizer.minimize(objectiveFunction); String[] predLabels = indexer.getPredLabels(); int nPredLabels = predLabels.length; String[] outcomeNames = indexer.getOutcomeLabels(); int nOutcomes = outcomeNames.length; Context[] params = new Context[nPredLabels]; for (int ci = 0; ci < params.length; ci++) { List<Integer> outcomePattern = new ArrayList<>(nOutcomes); List<Double> alpha = new ArrayList<>(nOutcomes); for (int oi = 0; oi < nOutcomes; oi++) { double val = parameters[oi * nPredLabels + ci]; outcomePattern.add(oi); alpha.add(val); } params[ci] = new Context(ArrayMath.toIntArray(outcomePattern), ArrayMath.toDoubleArray(alpha)); } return new QNModel(params, predLabels, outcomeNames); } }
QNTrainer extends AbstractEventTrainer { public QNModel trainModel(int iterations, DataIndexer indexer) { Function objectiveFunction; if (threads == 1) { System.out.println("Computing model parameters ..."); objectiveFunction = new NegLogLikelihood(indexer); } else { System.out.println("Computing model parameters in " + threads + " threads ..."); objectiveFunction = new ParallelNegLogLikelihood(indexer, threads); } QNMinimizer minimizer = new QNMinimizer( l1Cost, l2Cost, iterations, m, maxFctEval, printMessages); minimizer.setEvaluator(new ModelEvaluator(indexer)); double[] parameters = minimizer.minimize(objectiveFunction); String[] predLabels = indexer.getPredLabels(); int nPredLabels = predLabels.length; String[] outcomeNames = indexer.getOutcomeLabels(); int nOutcomes = outcomeNames.length; Context[] params = new Context[nPredLabels]; for (int ci = 0; ci < params.length; ci++) { List<Integer> outcomePattern = new ArrayList<>(nOutcomes); List<Double> alpha = new ArrayList<>(nOutcomes); for (int oi = 0; oi < nOutcomes; oi++) { double val = parameters[oi * nPredLabels + ci]; outcomePattern.add(oi); alpha.add(val); } params[ci] = new Context(ArrayMath.toIntArray(outcomePattern), ArrayMath.toDoubleArray(alpha)); } return new QNModel(params, predLabels, outcomeNames); } QNTrainer(TrainingParameters parameters);  QNTrainer(boolean printMessages);  QNTrainer(int m);  QNTrainer(int m, boolean verbose);  QNTrainer(int m, int maxFctEval, boolean printMessages);  QNTrainer(); }
QNTrainer extends AbstractEventTrainer { public QNModel trainModel(int iterations, DataIndexer indexer) { Function objectiveFunction; if (threads == 1) { System.out.println("Computing model parameters ..."); objectiveFunction = new NegLogLikelihood(indexer); } else { System.out.println("Computing model parameters in " + threads + " threads ..."); objectiveFunction = new ParallelNegLogLikelihood(indexer, threads); } QNMinimizer minimizer = new QNMinimizer( l1Cost, l2Cost, iterations, m, maxFctEval, printMessages); minimizer.setEvaluator(new ModelEvaluator(indexer)); double[] parameters = minimizer.minimize(objectiveFunction); String[] predLabels = indexer.getPredLabels(); int nPredLabels = predLabels.length; String[] outcomeNames = indexer.getOutcomeLabels(); int nOutcomes = outcomeNames.length; Context[] params = new Context[nPredLabels]; for (int ci = 0; ci < params.length; ci++) { List<Integer> outcomePattern = new ArrayList<>(nOutcomes); List<Double> alpha = new ArrayList<>(nOutcomes); for (int oi = 0; oi < nOutcomes; oi++) { double val = parameters[oi * nPredLabels + ci]; outcomePattern.add(oi); alpha.add(val); } params[ci] = new Context(ArrayMath.toIntArray(outcomePattern), ArrayMath.toDoubleArray(alpha)); } return new QNModel(params, predLabels, outcomeNames); } QNTrainer(TrainingParameters parameters);  QNTrainer(boolean printMessages);  QNTrainer(int m);  QNTrainer(int m, boolean verbose);  QNTrainer(int m, int maxFctEval, boolean printMessages);  QNTrainer(); @Override void init(TrainingParameters trainingParameters, Map<String, String> reportMap); @Override @Deprecated void init(Map<String, String> trainParams, Map<String, String> reportMap); @Override void validate(); @Deprecated @Override boolean isValid(); boolean isSortAndMerge(); AbstractModel doTrain(DataIndexer indexer); QNModel trainModel(int iterations, DataIndexer indexer); }
QNTrainer extends AbstractEventTrainer { public QNModel trainModel(int iterations, DataIndexer indexer) { Function objectiveFunction; if (threads == 1) { System.out.println("Computing model parameters ..."); objectiveFunction = new NegLogLikelihood(indexer); } else { System.out.println("Computing model parameters in " + threads + " threads ..."); objectiveFunction = new ParallelNegLogLikelihood(indexer, threads); } QNMinimizer minimizer = new QNMinimizer( l1Cost, l2Cost, iterations, m, maxFctEval, printMessages); minimizer.setEvaluator(new ModelEvaluator(indexer)); double[] parameters = minimizer.minimize(objectiveFunction); String[] predLabels = indexer.getPredLabels(); int nPredLabels = predLabels.length; String[] outcomeNames = indexer.getOutcomeLabels(); int nOutcomes = outcomeNames.length; Context[] params = new Context[nPredLabels]; for (int ci = 0; ci < params.length; ci++) { List<Integer> outcomePattern = new ArrayList<>(nOutcomes); List<Double> alpha = new ArrayList<>(nOutcomes); for (int oi = 0; oi < nOutcomes; oi++) { double val = parameters[oi * nPredLabels + ci]; outcomePattern.add(oi); alpha.add(val); } params[ci] = new Context(ArrayMath.toIntArray(outcomePattern), ArrayMath.toDoubleArray(alpha)); } return new QNModel(params, predLabels, outcomeNames); } QNTrainer(TrainingParameters parameters);  QNTrainer(boolean printMessages);  QNTrainer(int m);  QNTrainer(int m, boolean verbose);  QNTrainer(int m, int maxFctEval, boolean printMessages);  QNTrainer(); @Override void init(TrainingParameters trainingParameters, Map<String, String> reportMap); @Override @Deprecated void init(Map<String, String> trainParams, Map<String, String> reportMap); @Override void validate(); @Deprecated @Override boolean isValid(); boolean isSortAndMerge(); AbstractModel doTrain(DataIndexer indexer); QNModel trainModel(int iterations, DataIndexer indexer); static final String MAXENT_QN_VALUE; static final String THREADS_PARAM; static final int THREADS_DEFAULT; static final String L1COST_PARAM; static final double L1COST_DEFAULT; static final String L2COST_PARAM; static final double L2COST_DEFAULT; static final String M_PARAM; static final int M_DEFAULT; static final String MAX_FCT_EVAL_PARAM; static final int MAX_FCT_EVAL_DEFAULT; }