// Methods

        public override double ExecuteCommand()
        {
            FeatureVectorFile vectorFile_train = new FeatureVectorFile(path: vector_file, noOfHeaderColumns: 1, featureDelimiter: ':', isSortRequired: false);
            double            accuracy         = Program.ReportOnModel(vectorFile_train, sys_output
                                                                       , classifierFactory: (classToClassId, featureToFeatureId) =>
            {
                return(MaxEntClassifier.LoadModel(model_file, classToClassId, featureToFeatureId));
            }
                                                                       , getDetailsFunc: (classifier, vectors, classToClassId, featureToFeatureId) =>
            {
                return(ProgramOutput.GetDistributionDetails(classifier, vectors, classToClassId));
            }
                                                                       );

            return(accuracy);
        }
Exemple #2
0
        // Methods

        public override bool ExecuteCommand()
        {
            FeatureVectorFile vectorFile_train = new FeatureVectorFile(path: training_data_file, noOfHeaderColumns: 1, featureDelimiter: ' ', isSortRequired: false);

            int          gold_i             = 0;
            TextIdMapper featureToFeatureId = new TextIdMapper();
            TextIdMapper classToClassId     = new TextIdMapper();

            TextIdMapper[] headerToHeaderIds = new TextIdMapper[] { classToClassId };

            var trainingVectors   = vectorFile_train.LoadFromSVMLight(featureToFeatureId, headerToHeaderIds, FeatureType.Binary);
            var goldClasses_train = vectorFile_train.Headers[gold_i];

            // model_file is optional.
            Func <int, FeatureVector, double> calculate_Prob_c_v;

            // If it is not given, p(v|c_i) = 1/|C|, where |C| is the number of class_labels.
            if (string.IsNullOrWhiteSpace(model_file))
            {
                double kProbability = 1D / classToClassId.Count;
                calculate_Prob_c_v = (v, c_i) => { return(kProbability); };
            }
            // If it is given, it is used to calculate p(y|xi).
            else
            {
                MaxEntClassifier classifier = MaxEntClassifier.LoadModel(model_file, classToClassId, featureToFeatureId);
                calculate_Prob_c_v =
                    (c_i, v) =>
                {
                    double[] details;
                    int      sysClass = classifier.Classify(v, out details);
                    return(details[c_i]);
                };
            }

            double[,] expectation = CalculateModelExpectation(trainingVectors, calculate_Prob_c_v);

            OutputEmpiricalCount(expectation, trainingVectors.Count, requiresSort: true);
            return(true);
        }