Ejemplo n.º 1
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                selectWindowReady   = false;
                progressBar.Visible = true;

                if (MessageBox.Show("Make sure file name contains \n" +
                                    "Dataset name: e.g. FA or ST or US\n" +
                                    "Aggregation: e.g. 1min or 5min or 10min\n" +
                                    "Graph Type: e.g. W for weighted or NW for non-weighted\n" +
                                    "You want to contniue..? (y/n)", "Critical", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (txtResultFileName.Text == "")
                    {
                        throw new Exception("Enter Result File Name...");
                    }
                    if (!chkRankDC.Checked && !chkRankDTF.Checked)
                    {
                        throw new Exception("Select Ranking Criteria");
                    }

                    _gTruth                  = new GroundTruth();
                    _slidingWindows          = new SlidingWindows();
                    _slidingWindowsThreshold = new Hashtable();

                    _listDHGs = new ListDHGs();

                    _config.AdjustmentParameter = (double)numDownParameter.Value;
                    _config.TopK     = (int)numUpDownTopBoW.Value;
                    _config.FileName = txtResultFileName.Text.Trim();

                    _config.IsGF           = chkGF.Checked;
                    _config.IsTP           = chkTP.Checked;
                    _config.IsDC           = chkAC.Checked;
                    _config.IsDTFRanking   = chkRankDTF.Checked;
                    _config.IsDCRanking    = chkRankDC.Checked;
                    _config.IsRankingFused = cmbRanking.SelectedIndex == 0 ? true: false;

                    _config.CandidateSelectionCriteria = (CandidateSelection)cmbCandidateSelection.SelectedIndex;



                    //if ( !_allFilesLoaded)
                    {
                        _gTruth.LoadGroundTruth(groundTruthFiles);


                        string filePath = "";

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblSlidingWindows.Text;
                        }
                        else
                        {
                            filePath = Util.SlidingWindowPath(cmbCaseStudy.SelectedIndex);
                        }

                        _slidingWindows.LoadSlidingWindow(filePath);

                        string[] windows = _slidingWindows.ListOfWindows.Select(x => x.TimeSlotID).ToArray <string>();

                        cmbWin.Clear();

                        cmbWin.Add(new KeyValuePair <string, string>("None", "Select a Sliding Window"));
                        foreach (string winTime in windows)
                        {
                            cmbWin.Add(new KeyValuePair <string, string>(winTime, Util.ConvertToFormatedDate(winTime)));
                        }

                        //cmbSelectWindow.DataSource = null;
                        //cmbSelectWindow.Items.Clear();

                        cmbSelectWindow.DataSource    = cmbWin;
                        cmbSelectWindow.DisplayMember = "Value";
                        cmbSelectWindow.ValueMember   = "Key";
                        cmbSelectWindow.SelectedIndex = 0;

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblSlidingWindowFeatures.Text;
                        }
                        else
                        {
                            filePath = Util.WindowsFeaturesPath(cmbCaseStudy.SelectedIndex);
                        }

                        _listDHGs.LoadDHGsFeatures(filePath, _slidingWindows, _config, out _listChartSeries);

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblDegreeCentrality.Text;
                        }
                        else
                        {
                            filePath = Util.RawDataPath(cmbCaseStudy.SelectedIndex);
                        }

                        LoadDegreeCentralityFile(filePath);

                        //_allFilesLoaded = true;
                    }

                    chart1.Series.Clear();
                    DrawChart(_listChartSeries);

                    pnlChartOptions.Visible = true;
                    //myToolTip.SetToolTip(picBoxDC, Util.RawDataPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxGT, Util.GroundTruthPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxSW, Util.SlidingWindowPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxWF, Util.WindowsFeaturesPath(cmbCaseStudy.SelectedIndex));

                    Results rslt = new Results(txtResultFileName.Text.Trim());
                    //rTxtResults.Text = rslt.GenerateResults(_listDHGs, _gTruth, _slidingWindows, _config).ToString();
                    rslt.GenerateResults(_listDHGs, _gTruth, _slidingWindows, _config).ToString();

                    selectWindowReady = true;


                    rTxtResults.Text = tempTweetText;
                    //myRtb.SelectionStart = s_start;
                    //myRtb.SelectionLength = 0;
                    //myRtb.SelectionColor = color;
                    rTxtResults.Select(0, 1428);
                    //rTxtResults.SelectionStart = 0;
                    //rTxtResults.SelectionLength = 1440;
                    rTxtResults.SelectionBackColor = Color.FromArgb(255, 192, 128);

                    rTxtResults.Select(1428, 1500);
                    //rTxtResults.SelectionStart = 0;
                    //rTxtResults.SelectionLength = 1440;
                    rTxtResults.SelectionBackColor = Color.FromArgb(255, 224, 192);

                    ////myRtb.SelectionStart = s_start;
                    ////myRtb.SelectionLength = 0;
                    ////myRtb.SelectionColor = color;
                    //rTxtResults.Select(0, 1440);
                    ////rTxtResults.SelectionStart = 0;
                    ////rTxtResults.SelectionLength = 1440;
                    //rTxtResults.SelectionBackColor = Color.FromArgb(255, 128, 0);

                    //rTxtResults.Select(1442,500);
                    ////rTxtResults.SelectionStart = 0;
                    ////rTxtResults.SelectionLength = 1440;
                    //rTxtResults.SelectionBackColor = Color.FromArgb(255, 192, 128);


                    MessageBox.Show("Results are successfully generated..");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            int dummy = 0;
        }
Ejemplo n.º 2
0
        public StringBuilder GenerateResults(ListDHGs lstDHG, GroundTruth groundTruth, SlidingWindows slidingWindow, Config _config)
        {
            FinalResult = new Evaluation(_config.TopK);

            return(DetectEventCandidates(lstDHG, groundTruth, slidingWindow, _config));
        }
Ejemplo n.º 3
0
        public StringBuilder DetectEventCandidates(ListDHGs lstDHG, GroundTruth groundTruth, SlidingWindows slidingWindow, Config _config)
        {
            double[] currentWinThreshold = new double[] {
                0,                                        // Threshold against Growth factor
                0,                                        // Threshold against Trend Probability
                0,                                        // Threshold against Aggregated Centrality
                0                                         // Threshold against Fused features as Heartbeat
            };

            //double currentWinThreshold = 0;

            StringBuilder strBuilder = new StringBuilder();

            foreach (SingleWindow win in slidingWindow.ListOfWindows)
            {
                // cross check if following LINQ line creates a shallow copy, because I need a SHALLOW COPY
                // and same reference will be passed on to multiple functions.
                //ListDHGs candidateWindowDHGs = (ListDHGs)lstDHG.DHGs.Where(x => x.TimeSlotID.Equals(win.TimeSlotID));
                ListDHGs candidateWindowDHGs = lstDHG.Select(win.TimeSlotID);

                //candidateWindowDHGs.DHGs[0].IsEventCandidate = true;

                string str = "";
                str += win.TimeSlotID + ",";


                //if ( isGrowthFactor)
                //    currentWinThreshold = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => (double)x.GrowthFactor).ToArray<double>(), parameterOmega);
                //else

                //currentWinThreshold = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.HeartbeatScore).ToArray<double>(), _config.AdjustmentParameter);


                if (_config.CandidateSelectionCriteria == CandidateSelection.HEARTBEAT)
                {
                    currentWinThreshold[3] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.HeartbeatScore).ToArray <double>(), _config.AdjustmentParameter);
                }
                else if (_config.CandidateSelectionCriteria == CandidateSelection.FEATURES_BASED_UNION)
                {
                    if (_config.IsGF)
                    {
                        currentWinThreshold[0] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.GrowthFactor).ToArray <double>(), _config.AdjustmentParameter);
                    }

                    if (_config.IsTP)
                    {
                        currentWinThreshold[1] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => (x.PosTrendProbability - x.NegTrendProbability)).ToArray <double>(), _config.AdjustmentParameter);
                    }

                    if (_config.IsDC)
                    {
                        currentWinThreshold[2] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.AggregatedCentrality).ToArray <double>(), _config.AdjustmentParameter);
                    }
                }

                //////////////////////////////////////////////////////////////////////////////////
                ////////////// CANDIDATE EVENT DETECTION USING ADOPTIVE THRESHOLD /////////////////
                //////////////////////////////////////////////////////////////////////////////////

                // Total Candidates Count = 0=>GF, 1=>TP, 2=>AC, 3=>HB, 4=>Union
                double[] totalCandidates = MarkEventCandidates(candidateWindowDHGs, currentWinThreshold, _config);

                CandidateTopics candTopic = new CandidateTopics();

                /////////////////////////////////////////////////////////////////////
                //////////////////// MERGING CANDIDATE DHGs /////////////////////////
                /////////////////////////////////////////////////////////////////////
                foreach (DHGFeatures dhg in candidateWindowDHGs)
                {
                    if (dhg.IsEventCandidate)
                    {
                        str += dhg.DHG_No + ",";

                        foreach (Term term in dhg.BoW)
                        {
                            int index;
                            if ((index = candTopic.Contains(term.Word)) >= 0)
                            {
                                //if ((float)candTopic.CandidateKeywords[term.Word] < term.Ranking)
                                //    candTopic.CandidateKeywords[term.Word] = term.Ranking;
                                if (candTopic.CandidateKeywords[index].Ranking < term.Ranking)
                                {
                                    candTopic.CandidateKeywords[index] = term;
                                }
                            }
                            else
                            {
                                candTopic.CandidateKeywords.Add(new Term(term));
                            }
                        }
                    }
                } // end of all the DHGs in candidate window

                candTopic.SortRankingWise();
                win.CandidateTopics = candTopic;

                Util.WriteCadidateTopics(candTopic, win.TimeSlotID);

                //candTopic.RemoveBoWBelow(topK);
                ///////////////////////////////////////////////////////////////
                ///// MATCHING RESULTS WITH GROUND TRUTH AND EVALUATING ///////
                ///////////////////////////////////////////////////////////////
                FullDatasetRawResults.Add(
                    new KeyValuePair <string, Evaluation>(
                        win.TimeSlotID,
                        MatchResultWithGroundTruth(
                            (ActualTopics)groundTruth
                            .TimeSlot[win.TimeSlotID],
                            candTopic,
                            _config.TopK
                            )
                        )
                    );

                str += ",,THRESHOLD (GF:" + Math.Round(currentWinThreshold[0], 2).ToString() +
                       " | TP:" + Math.Round(currentWinThreshold[1], 2).ToString() +
                       " | AC:" + Math.Round(currentWinThreshold[2], 2).ToString() +
                       " | HB:" + Math.Round(currentWinThreshold[3], 2).ToString() +
                       "  AND  CANDIDATE COUNT (GF:" + totalCandidates[0].ToString() +
                       " | TP:" + totalCandidates[1].ToString() +
                       " | AC:" + totalCandidates[2].ToString() +
                       " | HB:" + totalCandidates[3].ToString() +
                       " | Union:" + totalCandidates[4].ToString() + ")\n";
                strBuilder.Append(str);
            }

            MicroAveragingResults(_config.TopK);

            Util.WriteFinalResults(FinalResult, _fileName, _config, strBuilder);


            return(strBuilder);
        }
Ejemplo n.º 4
0
        public void LoadDHGsFeatures(string filePath, SlidingWindows slidingWindows, Config _config, out List <List <KeyValuePair <string, double> > > listChartSeries)
        {
            try
            {
                DHGFeatures tempDHG;

                string[] readLines = File.ReadAllText(filePath).Split(new char[] { '\n' });


                FeatureSet = readLines[0]
                             .Trim()
                             .Split(new char[] { ',' }, readLines.Length, StringSplitOptions.RemoveEmptyEntries)
                             .ToList <string>();

                /////// LIST OF FEATURES IN SEQUENCE ///////
                //0     Window No
                //1     S_Time
                //2     E_Time
                //3     Node Freq
                //4     Neg Prob
                //5     Pos Prob
                //6     Centrality
                //7     Node Count
                //8     Tweet Count
                //9     User Count
                //10    Execution Time
                ////////////////////////////////////////////

                listChartSeries = new List <List <KeyValuePair <string, double> > >();

                List <KeyValuePair <string, double> > HB = new List <KeyValuePair <string, double> >();
                List <KeyValuePair <string, double> > NS = new List <KeyValuePair <string, double> >();
                List <KeyValuePair <string, double> > UP = new List <KeyValuePair <string, double> >();


                for (int i = 1; i < readLines.Length; i++)
                {
                    if (readLines[i].Length > 9)     // number of features
                    {
                        string[] featuresValue = readLines[i].Trim().Split(new char[] { ',' }, readLines.Length, StringSplitOptions.RemoveEmptyEntries);

                        double hbScore = 1;

                        if (_config.IsGF)
                        {
                            hbScore *= int.Parse(featuresValue[3]);
                        }
                        if (_config.IsTP)
                        {
                            hbScore *= (Math.Abs(float.Parse(featuresValue[5]) - float.Parse(featuresValue[4])));
                        }
                        if (_config.IsDC)
                        {
                            hbScore *= float.Parse(featuresValue[6]);
                        }

                        HB.Add(new KeyValuePair <string, double>(featuresValue[1], hbScore));
                        NS.Add(new KeyValuePair <string, double>(featuresValue[1], int.Parse(featuresValue[7])));
                        UP.Add(new KeyValuePair <string, double>(featuresValue[1], int.Parse(featuresValue[9])));



                        tempDHG = new DHGFeatures();
                        //tempDHG.TimeSlotID = slidingWindows.ContainsCandidateDHG(featuresValue[0]);

                        //if (tempDHG.TimeSlotID.Equals("Y"))
                        tempDHG.TimeSlotID = slidingWindows.ContainsCandidateDHG(featuresValue[0]);
                        if (tempDHG.TimeSlotID.StartsWith("Y"))
                        {
                            tempDHG.TimeSlotID           = tempDHG.TimeSlotID.Split(new char[] { '$' }, tempDHG.TimeSlotID.Length, StringSplitOptions.RemoveEmptyEntries)[1];
                            tempDHG.DHG_No               = featuresValue[0];
                            tempDHG.StartingTime         = featuresValue[1];
                            tempDHG.EndingTime           = featuresValue[2];
                            tempDHG.GrowthFactor         = int.Parse(featuresValue[3]);
                            tempDHG.NegTrendProbability  = float.Parse(featuresValue[4]);
                            tempDHG.PosTrendProbability  = float.Parse(featuresValue[5]);
                            tempDHG.AggregatedCentrality = float.Parse(featuresValue[6]);
                            tempDHG.TotalNodes           = int.Parse(featuresValue[7]);
                            tempDHG.TotalTweets          = int.Parse(featuresValue[8]);
                            tempDHG.TotalUsers           = int.Parse(featuresValue[9]);

                            // because some of the result i took long ago does not have this infromation written in the files
                            if (featuresValue.Length == 11)
                            {
                                tempDHG.ExecutionTime = int.Parse(featuresValue[10]);
                            }
                            else
                            {
                                tempDHG.ExecutionTime = 0;
                            }


                            //tempDHG.HeartbeatScore = tempDHG.GrowthFactor * tempDHG.AggregatedCentrality * (tempDHG.PosTrendProbability-tempDHG.NegTrendProbability);
                            //double
                            hbScore = 1;

                            if (_config.IsGF)
                            {
                                hbScore *= tempDHG.GrowthFactor;
                            }
                            if (_config.IsTP)
                            {
                                hbScore *= (Math.Abs(tempDHG.PosTrendProbability - tempDHG.NegTrendProbability));
                            }
                            if (_config.IsDC)
                            {
                                hbScore *= tempDHG.AggregatedCentrality;
                            }

                            tempDHG.HeartbeatScore = hbScore;
                            DHGs.Add(tempDHG);
                        }
                    }
                }

                listChartSeries.Add(HB); // Heartbeat
                listChartSeries.Add(NS); // Network Size
                listChartSeries.Add(UP); // User Participation
            }

            catch (Exception ex)
            {
                throw new Exception("Unable to load Sliding Window Features file\n" + ex);
            }
        }