Example #1
0
        public ListDHGs Select(string timeSlotID)
        {
            ListDHGs tempDhgs = new ListDHGs();

            foreach (DHGFeatures dhg in DHGs)
            {
                // cross check if it is making shallow copy, because I need shallow copy
                if (dhg.TimeSlotID.Equals(timeSlotID))
                {
                    tempDhgs.DHGs.Add(dhg);
                }
            }

            return(tempDhgs);
        }
Example #2
0
        public static List <KeyValuePair <int, int> > IndexMapper(string line, ListDHGs listDHGs)
        {
            List <KeyValuePair <int, int> > indexMap = new List <KeyValuePair <int, int> >();


            string[] columns = line.Trim().Split(new char[] { ',' }, line.Length);
            int      DHGindex;

            // in condition "i+1" is because of an additional empty column at the end of file.
            for (int i = 0; i + 1 < columns.Length; i += 4)
            {
                //if ( !string.IsNullOrEmpty(columns[i]))
                //{
                //    int dummy = 0;
                //}

                if ((DHGindex = listDHGs.SearchDHGIndex(columns[i], columns[i + 1])) != -1)
                {
                    indexMap.Add(new KeyValuePair <int, int>(i, DHGindex));
                }
            }

            return(indexMap);
        }
        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;
        }
        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);
        }
        public StringBuilder GenerateResults(ListDHGs lstDHG, GroundTruth groundTruth, SlidingWindows slidingWindow, Config _config)
        {
            FinalResult = new Evaluation(_config.TopK);

            return(DetectEventCandidates(lstDHG, groundTruth, slidingWindow, _config));
        }
        private double[] MarkEventCandidates(ListDHGs lstDHGs, double[] threshold, Config _config)
        {
            //Vary bad logic, shame on me :(
            // Just focusing on getting work done, therfore doesn't care for the performance at this point
            // I could have used preprocessor directives for conditional inclusion of the code

            bool isEventCandidate;

            // GF, TP, AC, HB, Total
            double[] totalCandidates = new double[] { 0, 0, 0, 0, 0 };

            foreach (DHGFeatures current in lstDHGs)
            {
                isEventCandidate = false;

                if (!(_config.CandidateSelectionCriteria == CandidateSelection.SELECT_ALL))
                {
                    if (_config.CandidateSelectionCriteria == CandidateSelection.FEATURES_BASED_UNION)
                    {
                        if (_config.IsGF && current.GrowthFactor > threshold[0])
                        {
                            isEventCandidate    = true;
                            totalCandidates[0] += 1;
                        }

                        if (_config.IsTP && current.TrendProbability > threshold[1])
                        {
                            isEventCandidate    = true;
                            totalCandidates[1] += 1;
                        }
                        if (_config.IsDC && current.AggregatedCentrality > threshold[2])
                        {
                            isEventCandidate    = true;
                            totalCandidates[2] += 1;
                        }
                    }
                    else
                    {
                        if (current.HeartbeatScore >= threshold[3])
                        {
                            isEventCandidate    = true;
                            totalCandidates[3] += 1;
                        }
                    }
                }
                else
                {
                    // this block will be reached only if IsSelectAll option is checked.
                    isEventCandidate = true;
                }

                if (isEventCandidate)
                {
                    current.IsEventCandidate = true;
                    current.SortRankingWise(_config.IsDTFRanking, _config.IsDCRanking);
                    current.RemoveBoWBelow(_config.TopK);
                    totalCandidates[4] += 1;
                }
            }
            return(totalCandidates);
        }