//以某个模型的结果为基础,强制只有一个true label static public void GenerateGoldStandardForSnow(int group) { descendLabelsForEachSentence(PaperFunction.NumberOfEachLabel()); foreach (Sentence sentence in Variable.Sentences) { if (sentence.AnnotaitonGroups[group].PDSResult.NumberOfTrueLabel == 1) { sentence.BinaryGold = sentence.AnnotaitonGroups[group].PDSResult; } else { sentence.BinaryGold = new Result(-sentence.AnnotaitonGroups[group].PDSResult.Probability); foreach (KeyValuePair <Label, int> sortedLabel in sentence.SortedLabels) { if (sentence.AnnotaitonGroups[group].PDSResult.Labels[sortedLabel.Key]) { sentence.BinaryGold.Labels[sortedLabel.Key] = true; break; } } } } WriteGoldToFile("Snow"); }
static void Main(string[] args) { #region 初始化 Story CurrentStory = Story.Masatyan; //int[] groupings = new int[] { 30 }; int[] groupsizes = new int[] { 3, 5, 10, 15, 30 }; SimilaritySelector[] SimilaritySelectors = new SimilaritySelector[] { SimilaritySelector.Same, SimilaritySelector.Compare, SimilaritySelector.BinaryResultAndNumericGold }; Variable.GoldType = GoldType.Joint; bool BeepOrTextWhenFinished = false; Variable.Relation = RelationScheme.RenewLower;//与初始化无关,此处控制的是第一次以后的迭代(理论上最合理:RenewLower) Variable.PjDividSentenceCount = true; Variable.SijDividPDataOnI = true; Variable.OutputPdata = false; Variable.OutputResult = true; //Multi-emotion Estimation Model Considering Emotion \textit{Consistency} //Variable.PriorP = new PriorP[] { PriorP.Pj, PriorP.Mcj, PriorP.Sij };//同一个属性,conditional和非conditional不能同时出现 //Multi-emotion Estimation Model Considering Emotion \textit{Consistency} and \textit{Contextual Relationships} Variable.PriorP = new PriorP[] { PriorP.ConditionalPj, PriorP.ConditionalMcj, PriorP.ConditionalSij }; //P:alpha, M:beta, S:gamma Algorithm.DDS.NDDS.NDDSVariable.SmoothBN = Smoothing.None; Variable.SmoothPajl = Smoothing.Laplace; //要平滑(对Personality来说,Laplace更好) Variable.ConvergeValueThreshold = 0; Variable.ConvergeTimeThreshold = 10000; //Boku1次最好,Masa2次最好 SupervisedVariable.NumberOfTraningSentences = 0; #region Personality PersonalityVariable.TransGoldStandard = TransGoldStandard.No; PersonalityVariable.ExchangeLabel = ExchangeLabel.No; #endregion InitializeData(CurrentStory); #endregion #region GoldStandard switch (CurrentStory) { case Story.Bokutati: case Story.BokutatiSample: AnnotatorSelectionForBoku(30, Selector.Most); //筛选人,Variable.Data不变,只变Variable.Annotators break; case Story.Masatyan: AnnotationSelectionForMasa(30, Selector.Most); break; case Story.TwoStories: ConsistencyPaperFunction.LabelpairFrequency(); return; //两个故事时只为统计数据,不计算 } DescendLabelsByNumber(); //label降序排列,生成Variable.LabelArray NumericGold(); //各label被标注的概率作为GS MajorityVoteGold("Reminded"); //被标最多次的多选情况作为GS PersonalityPaperFunction.CevioGold(); if (PersonalityVariable.TransGoldStandard == TransGoldStandard.Yes) { PersonalityVariable.TruePersonality = PersonalityFunction.GetGoldOfPersonality(); PersonalityFunction.TransGoldstandardsForPersonality(); //PersonalityPaperFunction.TransGoldstandardsToCevio(); } #endregion #region 统计 //PaperFunction.CalculateWorkers();//论文用,计算两篇故事共有多少人标过 //PaperFunction.NumberOfEachLabel();//论文用,统计每个label频率 PaperFunction.AverageTrueLabelsPerAnnotation();//论文用,计算平均每次被标了几个label,有输出 //ConsistencyPaperFunction.CalcuateCharacterConsistency(); //ConsistencyPaperFunction.GroupLabels(); #endregion #region Algorithm foreach (int groupsize in groupsizes) { Grouping(GroupingMethod.Seperate, groupsize); IList <Thread> threads = new List <Thread>(); Thread MVThread = new Thread(new ThreadStart(delegate() { Algorithm.MV.MVFunction.RunMV(GoldType.Joint); })); MVThread.Start(); threads.Add(MVThread); MVThread.Name = "MV"; Thread IDSThread = new Thread(new ThreadStart(Algorithm.IDS.IDSFunction.RunIDS)); IDSThread.Start(); threads.Add(IDSThread); IDSThread.Name = "IDS"; Thread PDSThread = new Thread(new ThreadStart(Algorithm.PDS.PDSFunction.RunPDS)); PDSThread.Start(); threads.Add(PDSThread); PDSThread.Name = "PDS"; Thread JDDSThread = new Thread(new ThreadStart(Algorithm.DDS.JDDS.JDDSFunction.RunJDDS)); JDDSThread.Start(); threads.Add(JDDSThread); JDDSThread.Name = "JDDS"; Thread IDDSThread = new Thread(new ThreadStart(Algorithm.DDS.IDDS.IDDSFunction.RunIDDS)); IDDSThread.Start(); threads.Add(IDDSThread); IDDSThread.Name = "IDDS"; Thread NDDSThread = new Thread(delegate() { Algorithm.DDS.NDDS.NDDSFunction.RunNDDS(Math.Pow(10, -1), IndependenceEstimation.MutualInformation); }); NDDSThread.Start(); threads.Add(NDDSThread); NDDSThread.Name = "NDDS"; Thread PeTMThread = new Thread(delegate() { Algorithm.Personality.PeTM.PeTMFunction.RunPeTM(PorSForJointje.S, Smoothing.Laplace, BnOrNot.No); }); PeTMThread.Start(); threads.Add(PeTMThread); PeTMThread.Name = "PeTM"; Thread PeTThread = new Thread(delegate() { Algorithm.Personality.PeT.PeTFunction.RunPeT(PorSForJointje.S, Smoothing.Laplace, BnOrNot.No); }); PeTThread.Start(); threads.Add(PeTThread); PeTThread.Name = "PeT"; foreach (Thread t in threads) { t.Join(); } ObtainAccuracy(threads, SimilaritySelectors);//最后统一计算准确率 } Variable.OutputFile.WriteLine(Variable.ConsoleOutput); Variable.OutputFile.Close(); if (BeepOrTextWhenFinished) { Console.Beep(440, 10000); } else { Console.WriteLine("Press any key to exit..."); } Console.Read(); #endregion }