Example #1
0
 //Cij从每句话对每个人的标注取并后的结果中统计(更精确) TODO 不应这么算,C应为所有人对所有句的标注,N应为句数x人数
 static public void Mi3OfAllAnnotators()
 {
     foreach (Sentence sentence in Variable.Sentences)
     {
         foreach (Annotator annotator in sentence.Annotators)
         {
             foreach (Affect affect in Variable.AffectAndMuArray)
             {
                 if (annotator.Affects[affect])
                 {
                     sentence.SynthesizedResult.Affects[affect] = true;
                 }
             }
         }
     }
     #region 统计单一的频率
     Dictionary <Affect, double> CountOfAffect = new Dictionary <Affect, double>();
     foreach (Affect affect in Variable.AffectArray)
     {
         CountOfAffect.Add(affect, 0);
     }
     foreach (Sentence sentence in Variable.Sentences)
     {
         if (sentence.SynthesizedResult.Affects[Affect.yorokobi])
         {
             ++CountOfAffect[Affect.yorokobi];
         }
         if (sentence.SynthesizedResult.Affects[Affect.suki])
         {
             ++CountOfAffect[Affect.suki];
         }
         if (sentence.SynthesizedResult.Affects[Affect.yasu])
         {
             ++CountOfAffect[Affect.yasu];
         }
         if (sentence.SynthesizedResult.Affects[Affect.ikari])
         {
             ++CountOfAffect[Affect.ikari];
         }
         if (sentence.SynthesizedResult.Affects[Affect.aware])
         {
             ++CountOfAffect[Affect.aware];
         }
         if (sentence.SynthesizedResult.Affects[Affect.kowa])
         {
             ++CountOfAffect[Affect.kowa];
         }
         if (sentence.SynthesizedResult.Affects[Affect.haji])
         {
             ++CountOfAffect[Affect.haji];
         }
         if (sentence.SynthesizedResult.Affects[Affect.iya])
         {
             ++CountOfAffect[Affect.iya];
         }
         if (sentence.SynthesizedResult.Affects[Affect.takaburi])
         {
             ++CountOfAffect[Affect.takaburi];
         }
         if (sentence.SynthesizedResult.Affects[Affect.odoroki])
         {
             ++CountOfAffect[Affect.odoroki];
         }
     }
     double all = CountOfAffect[Affect.yorokobi] + CountOfAffect[Affect.suki] + CountOfAffect[Affect.yasu] + CountOfAffect[Affect.ikari] + CountOfAffect[Affect.aware] + CountOfAffect[Affect.kowa] + CountOfAffect[Affect.haji] + CountOfAffect[Affect.iya] + CountOfAffect[Affect.takaburi] + CountOfAffect[Affect.odoroki];
     #endregion
     #region 统计二元频率
     Dictionary <BiAffect, double> CountOfBiAffect = new Dictionary <BiAffect, double>();
     for (int i = 0; i < Variable.KindsOfLabel - 1; ++i)
     {
         for (int j = i + 1; j < Variable.KindsOfLabel - 1; ++j)
         {
             foreach (Sentence sentence in Variable.Sentences)
             {
                 BiAffect bi = new BiAffect(Variable.AffectArray[i], Variable.AffectArray[j]);
                 if (sentence.SynthesizedResult.Affects[bi.Affect1] && sentence.SynthesizedResult.Affects[bi.Affect2])
                 {
                     if (CountOfBiAffect.ContainsKey(bi))
                     {
                         ++CountOfBiAffect[bi];
                     }
                     else
                     {
                         CountOfBiAffect.Add(bi, 1);
                     }
                 }
             }
         }
     }
     #endregion
     Dictionary <BiAffect, double> Mi3Dic = new Dictionary <BiAffect, double>();
     foreach (KeyValuePair <BiAffect, double> biAffect in CountOfBiAffect)
     {
         //Mi3Dic.Add(biAffect.Key, (32 / 2.99575052699864) * Math.Log(Math.Pow(biAffect.Value, 1) * all / (CountOfAffect[biAffect.Key.Affect1] * CountOfAffect[biAffect.Key.Affect2]), 2));//扩大的互信息
         Mi3Dic.Add(biAffect.Key, (32 / 12.7612852733616) * Math.Log(Math.Pow(biAffect.Value, 3) * all / (CountOfAffect[biAffect.Key.Affect1] * CountOfAffect[biAffect.Key.Affect2]), 2));//扩大的三次互信息
         //Mi3Dic.Add(biAffect.Key, Math.Pow(biAffect.Value, 3) / (CountOfAffect[biAffect.Key.Affect1] * CountOfAffect[biAffect.Key.Affect2]));
     }
     List <KeyValuePair <BiAffect, double> > sortedMi3 = new List <KeyValuePair <BiAffect, double> >(Mi3Dic);
     sortedMi3.Sort(delegate(KeyValuePair <BiAffect, double> s1, KeyValuePair <BiAffect, double> s2)
     {
         return(s1.Value.CompareTo(s2.Value));
     });
     foreach (KeyValuePair <BiAffect, double> biAffect in sortedMi3)
     {
         Variable.ResultFile.WriteLine(affectToEnglish(biAffect.Key.Affect1) + "," + affectToEnglish(biAffect.Key.Affect2) + "," + biAffect.Value + "," + CountOfBiAffect[biAffect.Key]);
     }
 }
Example #2
0
 //Cij从每个人的标注结果中统计
 static public void Mi3OfEachAnnotator()
 {
     #region 统计单一的频率
     Dictionary <Affect, double> CountOfAffect = new Dictionary <Affect, double>();
     foreach (Affect affect in Variable.AffectArray)
     {
         CountOfAffect.Add(affect, 0);
     }
     foreach (Sentence sentence in Variable.Sentences)
     {
         foreach (Annotator annotator in sentence.Annotators)
         {
             if (annotator.Affects[Affect.yorokobi])
             {
                 ++CountOfAffect[Affect.yorokobi];
             }
             if (annotator.Affects[Affect.suki])
             {
                 ++CountOfAffect[Affect.suki];
             }
             if (annotator.Affects[Affect.yasu])
             {
                 ++CountOfAffect[Affect.yasu];
             }
             if (annotator.Affects[Affect.ikari])
             {
                 ++CountOfAffect[Affect.ikari];
             }
             if (annotator.Affects[Affect.aware])
             {
                 ++CountOfAffect[Affect.aware];
             }
             if (annotator.Affects[Affect.kowa])
             {
                 ++CountOfAffect[Affect.kowa];
             }
             if (annotator.Affects[Affect.haji])
             {
                 ++CountOfAffect[Affect.haji];
             }
             if (annotator.Affects[Affect.iya])
             {
                 ++CountOfAffect[Affect.iya];
             }
             if (annotator.Affects[Affect.takaburi])
             {
                 ++CountOfAffect[Affect.takaburi];
             }
             if (annotator.Affects[Affect.odoroki])
             {
                 ++CountOfAffect[Affect.odoroki];
             }
         }
     }
     double all = CountOfAffect[Affect.yorokobi] + CountOfAffect[Affect.suki] + CountOfAffect[Affect.yasu] + CountOfAffect[Affect.ikari] + CountOfAffect[Affect.aware] + CountOfAffect[Affect.kowa] + CountOfAffect[Affect.haji] + CountOfAffect[Affect.iya] + CountOfAffect[Affect.takaburi] + CountOfAffect[Affect.odoroki];
     #endregion
     #region 统计二元频率
     Dictionary <BiAffect, double> CountOfBiAffect = new Dictionary <BiAffect, double>();
     for (int i = 0; i < Variable.KindsOfLabel - 1; ++i)
     {
         for (int j = i + 1; j < Variable.KindsOfLabel - 1; ++j)
         {
             foreach (Sentence sentence in Variable.Sentences)
             {
                 foreach (Annotator annotator in sentence.Annotators)
                 {
                     BiAffect bi = new BiAffect(Variable.AffectArray[i], Variable.AffectArray[j]);
                     if (annotator.Affects[bi.Affect1] && annotator.Affects[bi.Affect2])
                     {
                         if (CountOfBiAffect.ContainsKey(bi))
                         {
                             ++CountOfBiAffect[bi];
                         }
                         else
                         {
                             CountOfBiAffect.Add(bi, 1);
                         }
                     }
                 }
             }
         }
     }
     #endregion
     Dictionary <BiAffect, double> Mi3Dic = new Dictionary <BiAffect, double>();
     foreach (KeyValuePair <BiAffect, double> biAffect in CountOfBiAffect)
     {
         Mi3Dic.Add(biAffect.Key, Math.Log(Math.Pow(biAffect.Value, 3) * all / (CountOfAffect[biAffect.Key.Affect1] * CountOfAffect[biAffect.Key.Affect2]), 2));
     }
     List <KeyValuePair <BiAffect, double> > sortedMi3 = new List <KeyValuePair <BiAffect, double> >(Mi3Dic);
     sortedMi3.Sort(delegate(KeyValuePair <BiAffect, double> s1, KeyValuePair <BiAffect, double> s2)
     {
         return(s2.Value.CompareTo(s1.Value));
     });
     foreach (KeyValuePair <BiAffect, double> biAffect in sortedMi3)
     {
         Variable.ResultFile.WriteLine(biAffect.Key.Affect1 + " + " + biAffect.Key.Affect2 + " " + biAffect.Value);
     }
 }