private double Predict(Message testMessage, MessageClass msgClass, double penalty, double windowWidth) { return(Math.Log(penalty * msgClass.Prevalence) + _headerDict.Sum(word => ParsenRosenblatt(word, testMessage.GetHeaderPrevalence(word), msgClass, windowWidth, msg => msg.GetHeaderPrevalence)) + _bodyDict.Sum(word => ParsenRosenblatt(word, testMessage.GetBodyPrevalence(word), msgClass, windowWidth, msg => msg.GetBodyPrevalence))); }
public DataSet(IList <string> headerDict, IList <string> bodyDict, MessageClass trainLegit, MessageClass trainSpam, IList <Message> testLegit, IList <Message> testSpam) { _headerDict = headerDict; _bodyDict = bodyDict; _trainLegit = trainLegit; _trainSpam = trainSpam; _testLegit = testLegit; _testSpam = testSpam; }
private static double ParsenRosenblatt(string word, double prevalence, MessageClass msgClass, double windowWidth, Func <Message, Func <string, double> > prev) { var likeliness = msgClass.Sum(msg => KernelFunc(Math.Abs(prevalence - prev(msg).Invoke(word)) / windowWidth)); return(Math.Log(likeliness / msgClass.Size)); }