public void TestEmptySource() { wordsDataSource = new SimpleWordsDataSource(); WordProbability wp = wordsDataSource.GetWordProbability("myWord"); Assert.IsNull(wp); }
public void MapToWordsTest(string sequence, int wordSize, int expectedCount) { IWordProbability wp = new WordProbability(); var map = wp.MapToWords(sequence, wordSize); Assert.AreEqual(expectedCount, map.Count()); }
public void ReduceToWordsProbabilityTest() { IWordProbability wp = new WordProbability(); var map = wp.MapToWords("0010000200222", 2); var result = wp.ReduceToWordsProbability(map); Assert.AreEqual(5, result.Count); }
public IEnumerable <string> GetSequenceAsSplitedWords(Person p, int wordLengh) { string sequence = p.GetNhanceSequenceString(); IWordProbability wp = new WordProbability(); var words = wp.MapToWords(sequence, wordLengh); string traceStr = "Person " + p.Id + " has " + words.Count() + " words"; log.Debug(traceStr); return(words); }
public void TestSetAndGet() { WordProbability wp = null; WordProbability wp2 = null; wp = new WordProbability("myWord", 10, 30); ((SimpleWordsDataSource)wordsDataSource).SetWordProbability(wp); wp2 = wordsDataSource.GetWordProbability("myWord"); Assert.IsNotNull(wp2); Assert.AreEqual(wp, wp2); }
public void TestAddMultipleNonMatches() { wordsDataSource = new SimpleWordsDataSource(); string word = "myWord"; int count = 10; for (int i = 0; i < count; i++) { wordsDataSource.AddNonMatch(word); } WordProbability wp = wordsDataSource.GetWordProbability(word); Assert.IsNotNull(wp); Assert.AreEqual(count, wp.NonMatchingCount); }
public void TestAddMatch() { wordsDataSource = new SimpleWordsDataSource(); wordsDataSource.AddMatch("myWord"); WordProbability wp = wordsDataSource.GetWordProbability("myWord"); Assert.IsNotNull(wp); Assert.AreEqual(1, wp.MatchingCount); Assert.AreEqual(0, wp.NonMatchingCount); wordsDataSource.AddMatch("myWord"); Assert.AreEqual(2, wp.MatchingCount); Assert.AreEqual(0, wp.NonMatchingCount); }
public string GetDescriptionForTopic(int topic, bool include_topic_number = true, string separator = "; ", bool stop_at_word_probability_jump = true) { StringBuilder sb = new StringBuilder(); if (include_topic_number) { sb.Append(String.Format("{0}. ", topic + 1)); } LDAAnalysis lda = LDAAnalysis; WordProbability[] lda_wordprobs = lda.DensityOfWordsInTopicsSorted[topic]; ASSERT.Test(lda_wordprobs != null); double last_term_prob = 0; for (int t = 0; t < 5 && t < lda.NUM_WORDS; ++t) { WordProbability lda_node = lda_wordprobs[t]; ASSERT.Test(lda_node != null); if (last_term_prob / lda_node.prob > 10) { if (stop_at_word_probability_jump) { break; } else { sb.Append(" // "); } } last_term_prob = lda_node.prob; sb.Append(String.Format("{0}", words[lda_node.word])); sb.Append(separator); } string description = sb.ToString(); if (description.EndsWith(separator)) { description = description.Substring(0, description.Length - separator.Length); } return(description); }
public void TestMatchingAndNonMatchingCountRollover() { var wp = new WordProbability("aWord", long.MaxValue, long.MaxValue); try { wp.RegisterMatch(); Assert.Fail("Should detect rollover."); } catch {} try { wp.RegisterNonMatch(); Assert.Fail("Should detect rollover."); } catch {} }
public void TestCalculateOverallProbability() { double prob = 0.3d; WordProbability wp1 = new WordProbability("myWord1", prob); WordProbability wp2 = new WordProbability("myWord2", prob); WordProbability wp3 = new WordProbability("myWord3", prob); WordProbability[] wps = new WordProbability[] { wp1, wp2, wp3 }; double errorMargin = 0.0001d; double xy = (prob * prob * prob); double z = (1 - prob) * (1 - prob) * (1 - prob); double result = xy / (xy + z); BayesianClassifier classifier = new BayesianClassifier(); Assert.AreEqual(result, classifier.CalculateOverallProbability(wps), errorMargin); }
public void TestCalculateOverallProbability() { var prob = 0.3d; var wp1 = new WordProbability("myWord1", prob); var wp2 = new WordProbability("myWord2", prob); var wp3 = new WordProbability("myWord3", prob); var wps = new[] { wp1, wp2, wp3 }; var errorMargin = 0.0001d; var xy = (prob * prob * prob); var z = (1 - prob) * (1 - prob) * (1 - prob); var result = xy / (xy + z); var classifier = new BayesianClassifier(); Assert.AreEqual(result, classifier.CalculateOverallProbability(wps), errorMargin); }
public void TestAccessors() { WordProbability wp = null; wp = new WordProbability(string.Empty, 0.96d); Assert.AreEqual(string.Empty, wp.Word); try { Assert.AreEqual(0, wp.MatchingCount); Assert.Fail("Shouldn't be able to obtain matching count when we haven't set them."); } catch {} try { Assert.AreEqual(0, wp.NonMatchingCount); Assert.Fail("Shouldn't be able to obtain non-matchin count when we haven't set them."); } catch {} Assert.AreEqual(0.96d, wp.Probability, 0); wp = new WordProbability("aWord", 10, 30); Assert.AreEqual("aWord", wp.Word); Assert.AreEqual(10, wp.MatchingCount); Assert.AreEqual(30, wp.NonMatchingCount); Assert.AreEqual(0.25d, wp.Probability, 0d); try { wp.MatchingCount = -10; Assert.Fail("Shouldn't be able to set negative MatchingCount."); } catch {} try { wp.NonMatchingCount = -10; Assert.Fail("Shouldn't be able to set negative NonMatchingCount."); } catch {} }
public void TestComparer() { var method = "TestComparer() "; WordProbability wp = null; WordProbability wp2 = null; wp = new WordProbability("a", 0, 0); wp2 = new WordProbability("b", 0, 0); try { wp.CompareTo(new object()); Assert.Fail("Shouldn't be able to compare to objects other than WordProbability."); } catch {} Debug.WriteLine(method + "wp.Probability " + wp.Probability); Debug.WriteLine(method + "wp2.Probability " + wp2.Probability); Assert.IsTrue(wp.CompareTo(wp2) < 0); Assert.IsTrue(wp2.CompareTo(wp) > 0); }
public void TestCalculateProbability() { WordProbability wp = null; wp = new WordProbability(string.Empty, 10, 10); Assert.AreEqual(IClassifierConstants.NEUTRAL_PROBABILITY, wp.Probability, 0); wp = new WordProbability(string.Empty, 20, 10); Assert.AreEqual(0.66, wp.Probability, 0.01); wp = new WordProbability(string.Empty, 30, 10); Assert.AreEqual(0.75, wp.Probability, 0); wp = new WordProbability(string.Empty, 10, 20); Assert.AreEqual(0.33, wp.Probability, 0.01); wp = new WordProbability(string.Empty, 10, 30); Assert.AreEqual(0.25, wp.Probability, 0); wp = new WordProbability(string.Empty, 10, 0); Assert.AreEqual(IClassifierConstants.UPPER_BOUND, wp.Probability, 0); wp = new WordProbability(string.Empty, 100, 1); Assert.AreEqual(IClassifierConstants.UPPER_BOUND, wp.Probability, 0); wp = new WordProbability(string.Empty, 1000, 1); Assert.AreEqual(IClassifierConstants.UPPER_BOUND, wp.Probability, 0); wp = new WordProbability(string.Empty, 0, 10); Assert.AreEqual(IClassifierConstants.LOWER_BOUND, wp.Probability, 0); wp = new WordProbability(string.Empty, 1, 100); Assert.AreEqual(IClassifierConstants.LOWER_BOUND, wp.Probability, 0); wp = new WordProbability(string.Empty, 1, 1000); Assert.AreEqual(IClassifierConstants.LOWER_BOUND, wp.Probability, 0); }