コード例 #1
0
        // Methods

        public override double ExecuteCommand()
        {
            int instanceName_i = 0;
            int gold_i         = 1;

            featureToFeatureId = new TextIdMapper();
            classToClassId     = new TextIdMapper();
            var instanceNameToId = new TextIdMapper();

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

            FeatureVectorFile vectorFile = new FeatureVectorFile(path: vector_file, noOfHeaderColumns: 2, featureDelimiter: ' ', isSortRequired: false);

            // Read the boundaries:
            int[] sentenceLengths = ReadBoundaryFile(boundary_file);

            // Read the classifier model:
            classifier = MaxEntPOSClassifier.LoadModel(model_file, classToClassId, featureToFeatureId);

            // Read the vectors:
            var testVectors = vectorFile.LoadFromSVMLight(featureToFeatureId, headerToHeaderIds, FeatureType.Continuous);

            // Get the output ready for display.
            int[]    goldClassIds    = vectorFile.Headers[gold_i];
            int[]    instanceNameIds = vectorFile.Headers[instanceName_i];
            string[] instanceNames   = instanceNameToId.GetValues(instanceNameIds);

            // Generate sys_output:
            ConfusionMatrix confusionMatrix;

            File.WriteAllText(sys_output, GenerateSysOutput(instanceNames, testVectors, sentenceLengths, out confusionMatrix, gold_i));
            return(confusionMatrix.CalculateAccuracy());
        }
コード例 #2
0
        // Methods

        public override double ExecuteCommand()
        {
            FeatureVectorFile vectorFile = new FeatureVectorFile(path: vector_file, noOfHeaderColumns: 1, featureDelimiter: ':', isSortRequired: false);

            // Initialize the text-to-Id mappers:
            featureToFeatureId = new TextIdMapper();
            int instanceName_i = 0;
            int gold_i         = 1;

            classToClassId = new TextIdMapper();
            var instanceNameToInstanceNameId = new TextIdMapper();

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

            // Read the boundaries:
            int[] sentenceLengths = ReadBoundaryFile(boundary_file);

            // Read the classifier model:
            classifier = MaxEntPOSClassifier.LoadModel(model_file, classToClassId, featureToFeatureId);

            // Read the vectors:
            var testVectors = vectorFile.LoadFromSVMLight(featureToFeatureId, headerToHeaderIds, FeatureType.Continuous);

            int[] instanceNameIds = vectorFile.Headers[instanceName_i];
            int[] goldClasses     = vectorFile.Headers[gold_i];

            // TODO: Neaten this up a little.
            string[] instanceNames = new string[instanceNameIds.Length];
            for (int i = 0; i < instanceNameIds.Length; i++)
            {
                int instanceNameId = instanceNameIds[i];
                instanceNames[i] = headerToHeaderIds[instanceName_i][i];
            }

            // Generate sys_output:
            var confusionMatrix = GenerateSysOutput(sys_output, instanceNames, testVectors, sentenceLengths, gold_i);

            return(confusionMatrix.CalculateAccuracy());
        }