예제 #1
0
 public void ComputeDistance(Author otherAuthor, out Dictionary <string, double> val, out Dictionary <string, double> stdDev, IEnumerable <string> featureNames)
 {
     val    = new Dictionary <string, double>();
     stdDev = new Dictionary <string, double>();
     foreach (string featureName in featureNames)
     {
         if (mFeatures.ContainsKey(featureName))
         {
             double avg      = GetAvg(featureName);
             double var      = Math.Pow(GetStdDev(featureName), 2);
             double otherAvg = otherAuthor.GetAvg(featureName);
             double otherVar = Math.Pow(otherAuthor.GetStdDev(featureName), 2);
             val.Add(featureName, Math.Abs(avg - otherAvg));
             stdDev.Add(featureName, Math.Sqrt(var + otherVar)); // http://stattrek.com/random-variable/combination.aspx
         }
         else
         {
             Prediction <string> p = mPredictions[featureName];
             try { val.Add(featureName, p.First(x => x.Dat == otherAuthor.mName).Key); }
             catch { val.Add(featureName, -666); }
         }
     }
 }