Exemplo n.º 1
0
 public SemiSupervisedLogConditionalObjectiveFunction(AbstractCachingDiffFunction objFunc, AbstractCachingDiffFunction biasedObjFunc, LogPrior prior, double convexComboFrac)
 {
     this.objFunc         = objFunc;
     this.biasedObjFunc   = biasedObjFunc;
     this.prior           = prior;
     this.convexComboFrac = convexComboFrac;
     if (convexComboFrac < 0 || convexComboFrac > 1.0)
     {
         throw new Exception("convexComboFrac has to lie between 0 and 1 (both inclusive).");
     }
 }
Exemplo n.º 2
0
        private double[] TrainWeightsUsingNonLinearCRF(AbstractCachingDiffFunction func, IEvaluator[] evaluators)
        {
            IMinimizer <IDiffFunction> minimizer = GetMinimizer(0, evaluators);

            double[] initialWeights;
            if (flags.initialWeights == null)
            {
                initialWeights = func.Initial();
            }
            else
            {
                log.Info("Reading initial weights from file " + flags.initialWeights);
                try
                {
                    using (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights)))))
                    {
                        initialWeights = ConvertByteArray.ReadDoubleArr(dis);
                    }
                }
                catch (IOException)
                {
                    throw new Exception("Could not read from double initial weight file " + flags.initialWeights);
                }
            }
            log.Info("numWeights: " + initialWeights.Length);
            if (flags.testObjFunction)
            {
                StochasticDiffFunctionTester tester = new StochasticDiffFunctionTester(func);
                if (tester.TestSumOfBatches(initialWeights, 1e-4))
                {
                    log.Info("Testing complete... exiting");
                    System.Environment.Exit(1);
                }
                else
                {
                    log.Info("Testing failed....exiting");
                    System.Environment.Exit(1);
                }
            }
            //check gradient
            if (flags.checkGradient)
            {
                if (func.GradientCheck())
                {
                    log.Info("gradient check passed");
                }
                else
                {
                    throw new Exception("gradient check failed");
                }
            }
            return(minimizer.Minimize(func, flags.tolerance, initialWeights));
        }
Exemplo n.º 3
0
 public SemiSupervisedLogConditionalObjectiveFunction(AbstractCachingDiffFunction objFunc, AbstractCachingDiffFunction biasedObjFunc, LogPrior prior)
     : this(objFunc, biasedObjFunc, prior, 0.5)
 {
 }