Пример #1
0
        static private Sije InitializeSijeWithBN(Mce mce, int groupIndex)
        {
            Sije sije = new Sije(1);
            Sij  sij  = NDDSFunction.Initialize(groupIndex, Math.Pow(10, -1), IndependenceEstimation.MutualInformation);

            foreach (Sentence sentence in Variable.Sentences)
            {
                sije.Value.Add(sentence, new Dictionary <Labelset, IDictionary <Will, double> >());
                IDictionary <Will, double> willDenominator = new Dictionary <Will, double>();
                willDenominator.Add(Will.strong, 0);
                willDenominator.Add(Will.weak, 0);
                foreach (Labelset labelset in sij.Value[sentence].Keys.ToArray())
                {
                    double valueOfStrong = sij.Value[sentence][labelset] * labelset.HowStrong;
                    double valueOfWeak   = sij.Value[sentence][labelset] * labelset.HowWeak;
                    if (sije.Value[sentence].ContainsKey(labelset))
                    {
                        sije.Value[sentence][labelset][Will.strong] += valueOfStrong;
                        sije.Value[sentence][labelset][Will.weak]   += valueOfWeak;
                    }
                    else
                    {
                        sije.Value[sentence].Add(labelset, new Dictionary <Will, double>());
                        sije.Value[sentence][labelset].Add(Will.strong, valueOfStrong);
                        sije.Value[sentence][labelset].Add(Will.weak, valueOfWeak);
                    }
                    willDenominator[Will.strong] += valueOfStrong;
                    willDenominator[Will.weak]   += valueOfStrong;
                }
                //p(t|e)
                foreach (Labelset labelset in sije.Value[sentence].Keys.ToArray())
                {
                    if (willDenominator[Will.strong] != 0)
                    {
                        sije.Value[sentence][labelset][Will.strong] /= willDenominator[Will.strong];
                    }
                    if (willDenominator[Will.weak] != 0)
                    {
                        sije.Value[sentence][labelset][Will.weak] /= willDenominator[Will.weak];
                    }
                }
                //p(t|e)*p(x)
                if (willDenominator[Will.strong] != 0 && willDenominator[Will.weak] != 0)//有一个等于0就不用再算了
                {
                    foreach (Labelset labelset in sije.Value[sentence].Keys.ToArray())
                    {
                        sije.Value[sentence][labelset][Will.strong] *= mce.Value[sentence.Character][Will.strong];
                        sije.Value[sentence][labelset][Will.weak]   *= mce.Value[sentence.Character][Will.weak];
                    }
                }
            }
            return(sije);
        }
Пример #2
0
 static public void RunPeT(PorSForJointje PorS, Smoothing SmoothingBE, BnOrNot bnOrNot)
 {
     double[] accuracyOfPersonalityForEachGroup = new double[GroupVariable.AnnotatorGroups.Length];
     for (int groupIndex = 0; groupIndex < GroupVariable.AnnotatorGroups.Length; ++groupIndex)
     {
         IDictionary <Annotator, IDictionary <Character, IDictionary <Will, double> > > okcx = PersonalityFunction.CalculateOkcx(groupIndex);//模拟人对角色个性的标注,计算一次就不变了
         Mce mce = null;
         Sij sij = null;
         if (bnOrNot == BnOrNot.Yes)
         {
             sij = NDDSFunction.Initialize(groupIndex, Math.Pow(10, -1), IndependenceEstimation.MutualInformation);
         }
         else
         {
             sij = CoreFunction.InitializeSij(Variable.LabelArray, groupIndex);
         }
         Pje            pje    = null;//p(t|e)
         Pdata          pdata  = null;
         IList <double> Pdatas = new List <double>();
         for (int convergeTime = 1; convergeTime <= Variable.ConvergeTimeThreshold; ++convergeTime)
         {
             mce = CalculateMce(sij, groupIndex);
             PersonalityFunction.WriteMVResultFile(mce, groupIndex);
             PAkjl pakjl = CoreFunction.CalculatePAkjl(Variable.LabelArray, sij, convergeTime, groupIndex);
             BEkef bekef = PersonalityFunction.CalculateBExy(mce, okcx, SmoothingBE, convergeTime, groupIndex);
             if (PorS == PorSForJointje.P)
             {
                 pje = CalculatePje(sij, convergeTime);
             }
             if (CalculatePdataAndSij(ref sij, pakjl, bekef, pje, mce, okcx, ref pdata, Pdatas, groupIndex))//old/new
             {
                 break;
             }
         }
         DDSFunction.ObtainBinaryResult(sij, "PeT", groupIndex);
         Function.WriteBinaryResultFile("PeT", groupIndex);
         accuracyOfPersonalityForEachGroup[groupIndex] = PersonalityPaperFunction.AccuracyOfPersonalityForEachGroup(PersonalityVariable.TruePersonality, mce.EstimatedPersonality);
     }
     Function.ConsoleWriteLine("Accuracy Of PeT: " + PersonalityPaperFunction.AccuracyOfPersonality(accuracyOfPersonalityForEachGroup));
 }