Esempio n. 1
0
        void FillTweetInfo()
        {
            Analyser analyser = new Analyser(tweetDatas, labels);

            analyser.Analyse1();

            tweetInfo.Text = "";

            if (analyser.LabelFreq.Count == 0)
            {
                return;
            }

            for (int i = 0; i < labels.Length; i++)
            {
                if (analyser.LabelFreq.ContainsKey(labels[i]) == true)
                {
                    tweetInfo.Text += labels[i] + ": " + analyser.LabelFreq[labels[i]] + "\n";
                }
                else
                {
                    tweetInfo.Text += labels[i] + ": 0" + "\n";
                }
            }

            tweetInfo.Text += "\nTotal: " + analyser.Tweets.Length + "\n";
        }
Esempio n. 2
0
 void SetAnalyser(Analyser _analyser)
 {
     trainingTweets = _analyser.TrainingTweets;
     testingTweets  = _analyser.TestingTweets;
     labels         = _analyser.Labels;
     wordDict       = _analyser.WordDictionary;
     labelDict      = _analyser.LabelDictioanary;
 }
Esempio n. 3
0
        public Trainer(Analyser _analyser, int _hiddenNodes, double _learningRate, TrainingType type)
        {
            analyser = _analyser;
            if (analyser != null)
            {
                trainingTweets = _analyser.TrainingTweets;
                testingTweets  = _analyser.TestingTweets;
                labels         = _analyser.Labels;
                wordDict       = _analyser.WordDictionary;
                labelDict      = _analyser.LabelDictioanary;

                nn = new NeuralNetwork(
                    (type == TrainingType.WORD_TRAINING) ?_analyser.MaxWordPerTweet : 4,
                    _hiddenNodes,
                    _analyser.LabelCount,
                    _learningRate
                    );
            }
        }
Esempio n. 4
0
        private void Test(TrainingType type, Analyser analyser = null)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                MessageBox.Show("you have to choose a file to train....");
                return;
            }
            if (analyser == null)
            {
                analyser = trainer.Analyser;
            }

            TweetData[] twData = analyser.TestingTweets;
            progressBar.Value   = 0;
            progressBar.Maximum = twData.Length;

            List <List <Tuple <int, double> > > list;

            if (type == TrainingType.WORD_TRAINING)
            {
                list = trainer.Test1(progressBar);
            }
            else
            {
                list = trainer.Test2(progressBar);
            }

            confussion = new int[labels.Length, labels.Length];


            richtxtAnnResult.Text = "";
            for (int i = 0; i < analyser.TestingTweets.Length; i++)
            {
                richtxtAnnResult.AppendText("TWEET:\n\n");
                richtxtAnnResult.AppendText(analyser.TestingTweets[i].tweet + "\n\n");
                double max   = double.MinValue;
                int    index = 0;

                richtxtAnnResult.AppendText("PREDICTION:\n\n");
                for (int j = 0; j < list[i].Count; j++)
                {
                    // We may want to percentage of prediction
                    string val        = labels[list[i][j].Item1];
                    double percentage = list[i][j].Item2 * 100;
                    if (percentage > max)
                    {
                        max   = percentage;
                        index = list[i][j].Item1;
                    }


                    richtxtAnnResult.AppendText(val + ": " + percentage.ToString("F2") + "%\n");
                }
                int correct_Index = Array.IndexOf(labels, analyser.TestingTweets[i].users[0].labels[0]);

                confussion[correct_Index, index]++;
                richtxtAnnResult.AppendText("\nANSWER:\t" + analyser.TestingTweets[i].users[0].labels[0]);

                richtxtAnnResult.AppendText("\n\n");
                richtxtAnnResult.AppendText("######################################################n\n");
            }

            ShowAnalyserInfo(trainer);
        }
Esempio n. 5
0
        private void TrainTest(TrainingType type)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                MessageBox.Show("you have to choose a file to train....");
                return;
            }

            btnTest.Enabled   = true;
            progressBar.Value = 0;

            TweetData[] twData = JsonFileController.ReadDataFromJsonFile <TweetData[]>(filePath);
            ParseTweets(ref twData, type);

            Analyser analyser = new Analyser(twData, labels, tbTestCount.Value, chckPickRandomly.Checked);

            if (type == TrainingType.WORD_TRAINING)
            {
                analyser.Analyse1();
            }
            else
            {
                analyser.Analyse2();
            }

            progressBar.Maximum = twData.Length;

            trainer = new Trainer(analyser, tbHiddenNeuronCount.Value, double.Parse(lblLearningRate.Text), type);

            List <List <Tuple <int, double> > > list;

            if (type == TrainingType.WORD_TRAINING)
            {
                trainer.Train1(progressBar);
                list = trainer.Test1(progressBar);
            }
            else
            {
                trainer.Train2(progressBar);
                list = trainer.Test2(progressBar);
            }

            Test(type, analyser);
            //richtxtAnnResult.Text = "";
            //for (int i = 0; i < analyser.TestingTweets.Length; i++)
            //{
            //    richtxtAnnResult.AppendText("TWEET:\n\n");
            //    richtxtAnnResult.AppendText(analyser.TestingTweets[i].tweet + "\n\n");


            //    richtxtAnnResult.AppendText("PREDICTION:\n\n");
            //    for (int j = 0; j < list[i].Count; j++)
            //    {
            //        string val = labels[list[i][j].Item1];
            //        double percentage = list[i][j].Item2 * 100;
            //        richtxtAnnResult.AppendText(val + ":\t" + percentage.ToString("F2") + "%\n");
            //    }

            //    richtxtAnnResult.AppendText("\nANSWER: " + analyser.TestingTweets[i].users[0].labels[0]);

            //    richtxtAnnResult.AppendText("\n\n");
            //    richtxtAnnResult.AppendText("#################################################################\n\n");
            //}

            ShowAnalyserInfo(trainer);
        }