protected internal override double[] TrainWeights(int[][][][] data, int[][] labels, IEvaluator[] evaluators, int pruneFeatureItr, double[][][][] featureVals) { CRFLogConditionalObjectiveFloatFunction func = new CRFLogConditionalObjectiveFloatFunction(data, labels, windowSize, classIndex, labelIndices, map, flags.backgroundSymbol, flags.sigma); cliquePotentialFunctionHelper = func; QNMinimizer minimizer; if (flags.interimOutputFreq != 0) { IFloatFunction monitor = new ResultStoringFloatMonitor(flags.interimOutputFreq, flags.serializeTo); minimizer = new QNMinimizer(monitor); } else { minimizer = new QNMinimizer(); } if (pruneFeatureItr == 0) { minimizer.SetM(flags.QNsize); } else { minimizer.SetM(flags.QNsize2); } float[] initialWeights; if (flags.initialWeights == null) { initialWeights = func.Initial(); } else { try { log.Info("Reading initial weights from file " + flags.initialWeights); using (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights))))) { initialWeights = ConvertByteArray.ReadFloatArr(dis); } } catch (IOException) { throw new Exception("Could not read from float initial weight file " + flags.initialWeights); } } log.Info("numWeights: " + initialWeights.Length); float[] weightsArray = minimizer.Minimize(func, (float)flags.tolerance, initialWeights); return(ArrayMath.FloatArrayToDoubleArray(weightsArray)); }