Пример #1
0
        //GoldStandard中与其他最接近的一项
        static public void GoldStandardSimilarity(string golds)
        {
            StreamWriter goldSimilarityFile = new StreamWriter("Result/" + golds + "Similarity.csv");

            goldSimilarityFile.WriteLine(golds + ",Similarity");
            double[] goldStandardSimilarity = new double[Variable.NumberOfAnnotationsPerSentenceAfterGrouping + 2];
            switch (golds)
            {
            case "IndependentGold":
                for (int r1 = 0; r1 < Variable.NumberOfAnnotationsPerSentenceAfterGrouping + 2; ++r1)
                {
                    int n = 0;
                    foreach (Sentence sentence in Variable.Sentences)
                    {
                        for (int r2 = 0; r2 < Variable.NumberOfAnnotationsPerSentenceAfterGrouping + 2; ++r2)
                        {
                            if (r1 != r2)
                            {
                                ++n;
                                goldStandardSimilarity[r1] += SimilarityMeasure.JaccardPlusANumber(sentence.IndependentGold[r1], sentence.IndependentGold[r2]);
                            }
                        }
                    }
                    goldStandardSimilarity[r1] /= n;
                    goldSimilarityFile.WriteLine(r1 + "," + goldStandardSimilarity[r1]);
                }
                break;

            case "DependentGold":
                for (int r1 = 0; r1 < Variable.NumberOfAnnotationsPerSentenceAfterGrouping + 2; ++r1)
                {
                    int n = 0;
                    foreach (Sentence sentence in Variable.Sentences)
                    {
                        for (int r2 = 0; r2 < Variable.NumberOfAnnotationsPerSentenceAfterGrouping + 2; ++r2)
                        {
                            if (r1 != r2)
                            {
                                ++n;
                                goldStandardSimilarity[r1] += SimilarityMeasure.JaccardPlusANumber(sentence.DependentGoldStandard[r1], sentence.DependentGoldStandard[r2]);
                            }
                        }
                    }
                    goldStandardSimilarity[r1] /= n;
                    goldSimilarityFile.WriteLine(r1 + "," + goldStandardSimilarity[r1]);
                }
                break;
            }
            goldSimilarityFile.Close();
        }
Пример #2
0
        //计算各结果与最终一项黄金标准的相似度
        static public void GenerateEverySimilarityWithGold()
        {
            double independent = 0;
            double precise     = 0;
            double treeForAll  = 0;
            double treeForSen  = 0;

            foreach (Sentence sentence in Variable.Sentences)
            {
                independent += SimilarityMeasure.JaccardPlusANumber(sentence.IndependentResult, sentence.INVandDNVasGold);
                //precise += SimilarityMeasure.JaccardPlusANumber(sentence.PreciseResult, sentence.INVandDNVasGold);
                //treeForAll += SimilarityMeasure.JaccardPlusANumber(sentence.TreeForAllResult, sentence.INVandDNVasGold);
                //treeForSen += SimilarityMeasure.JaccardPlusANumber(sentence.TreeForSenResult, sentence.INVandDNVasGold);
            }
            independent /= Variable.Sentences.Count;
            precise     /= Variable.Sentences.Count;
            treeForAll  /= Variable.Sentences.Count;
            treeForSen  /= Variable.Sentences.Count;
            //Variable.ResultFile.WriteLine(independent + "," + precise + "," + treeForAll + "," + treeForSen);
        }
Пример #3
0
        static private void ObtainAccuracy(IList <Thread> threads, SimilaritySelector[] SimilaritySelectors)
        {
            foreach (Thread t in threads.ToArray())
            {
                if (t.Name == "PeTM" || t.Name == "PeT")
                {
                    Thread personalityMVThread = new Thread(new ThreadStart(delegate() {}));
                    personalityMVThread.Name = "PeMV";
                    threads.Add(personalityMVThread);//只为计算结果PersonalityMV的准确率
                    break;
                }
            }
            foreach (Thread t in threads)
            {
                IDictionary <SimilaritySelector, double> AverageAccuracy = new Dictionary <SimilaritySelector, double>();
                foreach (SimilaritySelector ss in SimilaritySelectors)
                {
                    AverageAccuracy.Add(ss, 0);
                }
                for (int groupIndex = 0; groupIndex < GroupVariable.AnnotatorGroups.Length; ++groupIndex)
                {
                    IDictionary <SimilaritySelector, double> GroupAccuracy = new Dictionary <SimilaritySelector, double>();
                    foreach (SimilaritySelector ss in SimilaritySelectors)
                    {
                        GroupAccuracy.Add(ss, 0);
                    }
                    foreach (Sentence sentence in Variable.Sentences)
                    {
                        Result result = sentence.AnnotaitonGroups[groupIndex].GetResultFromAlgorithmName(t.Name);
                        foreach (SimilaritySelector ss in SimilaritySelectors)
                        {
                            switch (ss)
                            {
                            case SimilaritySelector.Same:
                                GroupAccuracy[ss] += Convert.ToDouble(result.Equals(sentence.BinaryGold));
                                break;

                            case SimilaritySelector.Compare:
                                GroupAccuracy[ss] += SimilarityMeasure.Compare(result, sentence.BinaryGold);
                                break;

                            case SimilaritySelector.BinaryResultAndNumericGold:
                                GroupAccuracy[ss] += SimilarityMeasure.BinaryAndNumeric(result, sentence.NumericGold);
                                break;

                            case SimilaritySelector.Dice:
                                GroupAccuracy[ss] += SimilarityMeasure.DicePlusANumber(result, sentence.BinaryGold);
                                break;

                            case SimilaritySelector.Jaccard:
                                GroupAccuracy[ss] += SimilarityMeasure.JaccardPlusANumber(result, sentence.BinaryGold);
                                break;
                            }
                        }
                    }
                    foreach (SimilaritySelector ss in SimilaritySelectors)
                    {
                        AverageAccuracy[ss] += GroupAccuracy[ss] / Variable.Sentences.Count;
                    }
                }
                foreach (SimilaritySelector ss in SimilaritySelectors)
                {
                    AverageAccuracy[ss] /= GroupVariable.AnnotatorGroups.Length;
                    switch (ss)
                    {
                    case SimilaritySelector.Same:
                        Function.ConsoleWriteLine(t.Name + "Same: " + AverageAccuracy[ss]);
                        break;

                    case SimilaritySelector.Compare:
                        Function.ConsoleWriteLine(t.Name + "Compare: " + AverageAccuracy[ss]);
                        break;

                    case SimilaritySelector.Jaccard:
                        Function.ConsoleWriteLine(t.Name + "Jaccard: " + AverageAccuracy[ss]);
                        break;

                    case SimilaritySelector.Dice:
                        Function.ConsoleWriteLine(t.Name + "Dice: " + AverageAccuracy[ss]);
                        break;

                    case SimilaritySelector.BinaryResultAndNumericGold:
                        Function.ConsoleWriteLine(t.Name + "Binary&Numeric: " + AverageAccuracy[ss]);
                        break;
                    }
                }
            }
        }