Exemplo n.º 1
0
        private string[] writeStatics(staticSet newResults)
        {
            // create an array of strings out of static data


            string [] output = new string[16];

            output[0]  = "0";                                     // ID
            output[1]  = DateTime.Now.Date.ToString();            // Today's Date
            output[2]  = DateTime.Now.TimeOfDay.ToString();       // now s time
            output[3]  = datasetFolder.Text;                      // address of dataset
            output[4]  = phraseFile.Text;                         // address of phrase files
            output[5]  = newResults.totalspam.ToString();         // total spams used
            output[6]  = newResults.totalham.ToString();          // total hams used
            output[7]  = phraseNumber.Value.ToString();           // total phrases used
            output[8]  = selectedAlgorithm.ToString();            // algorithm used
            output[9]  = (thresholdValue.Value / 100).ToString(); // value of thrshold
            output[10] = newResults.time.ToString();              // time spent
            output[11] = newResults.accuracy.ToString();          // accuracy
            output[12] = newResults.fpositives.ToString();        // false positives
            output[13] = newResults.fnegatives.ToString();        // false negatives
            output[14] = newResults.spamrecall.ToString();        // spam recall
            output[15] = newResults.spamper.ToString();           // spam precision



            return(output);
        }
Exemplo n.º 2
0
        private void saveLogFile(staticSet newResults)
        {
            // this function writes the new static results to a file

            if (saveAddress == "")
            {
                saveAddress = browseFile();
            }

            loadText.Text = saveAddress;


            bool append = false;

            // headers
            string[] newLine = { "ID",          "Date",            "Time",                  "Data Set", "Phrase File",
                                 "Total Spams", "Total Hams",      "Total Used Phrases",
                                 "Algorithm",   "Threshold",       "Time Spend (seconds) ",
                                 "Accuracy",    "False Positives", "False Negatives",
                                 "Spam Recall", "Spam Precision" };


            append = File.Exists(saveAddress);



            // write the statics into a line in the list


            // write all lines
            try
            {
                StreamWriter writer = new StreamWriter(saveAddress, append);
                if (!append)
                {
                    WriteFile(ref writer, newLine);
                }

                newLine = writeStatics(newResults);
                WriteFile(ref writer, newLine);
                writer.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void runBtm_Click(object sender, EventArgs e)
        {
            // this creates a static structure
            staticSet resultStatic = new staticSet();

            resultStatic = calculateStatics(hamFiles, spamFiles, selectedAlgorithm);

            // write down the result box
            timeBox.Text       = string.Format("Time: {0}", resultStatic.time);
            accurecyBox.Text   = string.Format("Accuracy: {0}", resultStatic.accuracy);
            falseNbox.Text     = string.Format("False Negatives: {0}", resultStatic.fnegatives);
            falsePBox.Text     = string.Format("False Positives: {0}", resultStatic.fpositives);
            spamPrecision.Text = string.Format("Spam Percesion: {0}", resultStatic.spamper);
            spamRecallBox.Text = string.Format("Spam Recall: {0}", resultStatic.spamrecall);

            if (saveFile.Checked)
            {
                saveLogFile(resultStatic);
            }


            fillBox();
        }
Exemplo n.º 4
0
        /// <summary>
        /// this calcuate the shown statics for each algorithm
        /// </summary>
        /// <param name="hams">list of ham files </param>
        /// <param name="spams">list of spam files </param>
        /// <param name="algorithm"></param>
        /// <returns></returns>
        staticSet calculateStatics(string[] hams, string[] spams, AlgorithmBox algorithm)
        {
            staticSet myStatics = new staticSet(0);

            int hamScores  = 0;
            int spamScores = 0;

            myStatics.totalham  = (float)hamNumber.Value;
            myStatics.totalspam = (float)spamNumber.Value;
            progressBar.Value   = 0;
            progressBar.Maximum = (int)(myStatics.totalham + myStatics.totalspam);

            DateTime  tic    = DateTime.Now;
            Algorithm myAlgo = null;

            switch (algorithm)
            {
            case AlgorithmBox.LCS:
                myAlgo = new LCSWord();
                break;


            case AlgorithmBox.Levenshtein:
                myAlgo = new Levenshtien();
                break;

            case AlgorithmBox.Jaro:
                myAlgo = new Jaro();
                break;

            case AlgorithmBox.JaroWinker:
                myAlgo = new JaroWinker();
                break;

            case AlgorithmBox.BiGram:
                myAlgo = new BGram();
                break;

            default:
                break;
            }
            // we need a conditon here
            if (selectedAlgorithm == AlgorithmBox.TFIDF)
            {
                TFIDF myTFI = new TFIDF();
                myTFI.Terms = phrasePower;
                Loop(hams, hamNumber.Value, false, myTFI);
                Loop(spams, spamNumber.Value, true, myTFI);

                // the TFIDF runner
                myTFI.run();
                float threshold = ((float)thresholdValue.Value) / 100F;
                myTFI.claculate(ref hamScores, ref spamScores, threshold);
            }
            else
            {
                // other runners
                hamScores  = Loop(hams, hamNumber.Value, myAlgo);
                spamScores = Loop(spams, spamNumber.Value, myAlgo);
            }



            DateTime toc       = DateTime.Now;
            TimeSpan timeSpent = toc - tic;

            // calculate the spent time , a simple timing mechanism
            myStatics.time = (float)timeSpent.TotalSeconds;

            if (myStatics.totalspam > 0)
            {
                // false negatives
                myStatics.fnegatives = (myStatics.totalspam - spamScores) / myStatics.totalspam;

                // spam recall
                myStatics.spamrecall = spamScores / myStatics.totalspam;

                // spam precision
                myStatics.spamper = spamScores / (spamScores + (myStatics.totalham - hamScores));
            }

            if (myStatics.totalham > 0)
            {
                // false positives
                myStatics.fpositives = (myStatics.totalham - hamScores) / myStatics.totalham;
            }

            if (myStatics.totalham > 0 || myStatics.totalspam > 0)
            {
                // accuracy
                myStatics.accuracy = 1 - (((myStatics.totalspam - spamScores) + (myStatics.totalham - hamScores)) / (myStatics.totalham + myStatics.totalspam));
            }

            // Spam recall



            return(myStatics);
        }