Esempio n. 1
0
        // Methods

        public override bool ExecuteCommand()
        {
            // Initialize the text-to-Id mappers:
            int gold_i = 0;

            featureToFeatureId = new TextIdMapper();
            classToClassId     = new TextIdMapper();
            TextIdMapper[] headerToHeaderIds = new TextIdMapper[] { classToClassId };

            // Workaround: Read everything from STDIN to a file. (Files are used as the text source throughout this application.)
            var svmLight_data = Console.In.ReadToEnd();

            Console.Error.WriteLine("{0} characters of input received.", svmLight_data.Length);
            string tempFile = Path.GetTempFileName();

            int[] goldClasses;
            List <FeatureVector> vectors;

            try
            {
                File.WriteAllText(tempFile, svmLight_data);
                FeatureVectorFile vectorFile = new FeatureVectorFile(path: tempFile, noOfHeaderColumns: 1, featureDelimiter: ' ', isSortRequired: false);

                vectors     = vectorFile.LoadFromSVMLight(featureToFeatureId, headerToHeaderIds, FeatureType.Binary);
                goldClasses = vectorFile.Headers[gold_i];
            }
            finally
            {
                File.Delete(tempFile);
            }
            Debug.Assert(vectors.Count > 0);

            IdValuePair <double>[] chiSquare = new IdValuePair <double> [featureToFeatureId.Count];
            //TODO: Make the implementation less binary dependent (i.e. the hardcoded 2 below).
            double[][,] contingencyTable_f = new double[featureToFeatureId.Count][, ];
            for (int f_i = 0; f_i < featureToFeatureId.Count; f_i++)
            {
                // Create a contingency table for this vector.
                contingencyTable_f[f_i] = new double[classToClassId.Count, 2];
                for (int v_i = 0; v_i < vectors.Count; v_i++)
                {
                    FeatureVector v = vectors[v_i];
                    contingencyTable_f[f_i][v.Headers[gold_i], (int)v.Features[f_i]]++;
                }
                chiSquare[f_i] = new IdValuePair <double>(f_i, StatisticsHelper.CalculateChiSquare(contingencyTable_f[f_i]));
            }
            ReportChiSquareResults(contingencyTable_f, chiSquare);
            return(true);
        }
Esempio n. 2
0
 protected bool Equals(IdValuePair other)
 {
     return(ID == ID);
 }
Esempio n. 3
0
 public void Put([FromBody] IdValuePair idValuePair)
 {
     Trace(HttpMethod.Get, Request.RequestUri.GetLeftPart(System.UriPartial.Path));
     valuesContainer.Add(idValuePair.id, idValuePair.value);
 }
Esempio n. 4
0
 protected bool Equals(IdValuePair other)
 {
     return ID == ID;
 }