/// <summary>For internal testing purposes only.</summary> public static void Main(string[] args) { ICounter <string> c2 = new ClassicCounter <string>(); c2.IncrementCount("p", 13); c2.SetCount("q", 12); c2.SetCount("w", 5); c2.IncrementCount("x", 7.5); // System.out.println(getDistribution(c2).getCount("w") + " should be 0.13333"); ClassicCounter <string> c = new ClassicCounter <string>(); double p = 1000; string Unk = "!*UNKNOWN*!"; ICollection <string> s = Generics.NewHashSet(); s.Add(Unk); // fill counter with roughly Zipfian distribution // "1" : 1000 // "2" : 500 // "3" : 333 // ... // "UNK" : 45 // ... // "666" : 2 // "667" : 1 // ... // "1000" : 1 for (int rank = 1; rank < 2000; rank++) { string i = rank.ToString(); c.SetCount(i, Math.Round(p / rank)); s.Add(i); } for (int rank_1 = 2000; rank_1 <= 4000; rank_1++) { string i = rank_1.ToString(); s.Add(i); } Distribution <string> n = GetDistribution(c); Distribution <string> prior = GetUniformDistribution(s); Distribution <string> dir1 = DistributionWithDirichletPrior(c, prior, 4000); Distribution <string> dir2 = DynamicCounterWithDirichletPrior(c, prior, 4000); Distribution <string> add1; Distribution <string> gt; if (true) { add1 = LaplaceSmoothedDistribution(c, 4000); gt = GoodTuringSmoothedCounter(c, 4000); } else { c.SetCount(Unk, 45); add1 = LaplaceWithExplicitUnknown(c, 0.5, Unk); gt = GoodTuringWithExplicitUnknown(c, Unk); } Distribution <string> sgt = SimpleGoodTuring(c, 4000); System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "Freq", "Norm", "Add1", "Dir1", "Dir2", "GT", "SGT"); System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "----------", "----------", "----------", "----------", "----------", "----------", "----------"); for (int i_1 = 1; i_1 < 5; i_1++) { System.Console.Out.Printf("%10d ", Math.Round(p / i_1)); string @in = i_1.ToString(); System.Console.Out.Printf("%10.8f ", n.ProbabilityOf(@in.ToString())); System.Console.Out.Printf("%10.8f ", add1.ProbabilityOf(@in)); System.Console.Out.Printf("%10.8f ", dir1.ProbabilityOf(@in)); System.Console.Out.Printf("%10.8f ", dir2.ProbabilityOf(@in)); System.Console.Out.Printf("%10.8f ", gt.ProbabilityOf(@in)); System.Console.Out.Printf("%10.8f ", sgt.ProbabilityOf(@in)); System.Console.Out.WriteLine(); } System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "----------", "----------", "----------", "----------", "----------", "----------", "----------"); System.Console.Out.Printf("%10d ", 1); string last = 1500.ToString(); System.Console.Out.Printf("%10.8f ", n.ProbabilityOf(last)); System.Console.Out.Printf("%10.8f ", add1.ProbabilityOf(last)); System.Console.Out.Printf("%10.8f ", dir1.ProbabilityOf(last)); System.Console.Out.Printf("%10.8f ", dir2.ProbabilityOf(last)); System.Console.Out.Printf("%10.8f ", gt.ProbabilityOf(last)); System.Console.Out.Printf("%10.8f ", sgt.ProbabilityOf(last)); System.Console.Out.WriteLine(); System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "----------", "----------", "----------", "----------", "----------", "----------", "----------"); System.Console.Out.Printf("%10s ", "UNK"); System.Console.Out.Printf("%10.8f ", n.ProbabilityOf(Unk)); System.Console.Out.Printf("%10.8f ", add1.ProbabilityOf(Unk)); System.Console.Out.Printf("%10.8f ", dir1.ProbabilityOf(Unk)); System.Console.Out.Printf("%10.8f ", dir2.ProbabilityOf(Unk)); System.Console.Out.Printf("%10.8f ", gt.ProbabilityOf(Unk)); System.Console.Out.Printf("%10.8f ", sgt.ProbabilityOf(Unk)); System.Console.Out.WriteLine(); System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "----------", "----------", "----------", "----------", "----------", "----------", "----------"); System.Console.Out.Printf("%10s ", "RESERVE"); System.Console.Out.Printf("%10.8f ", n.GetReservedMass()); System.Console.Out.Printf("%10.8f ", add1.GetReservedMass()); System.Console.Out.Printf("%10.8f ", dir1.GetReservedMass()); System.Console.Out.Printf("%10.8f ", dir2.GetReservedMass()); System.Console.Out.Printf("%10.8f ", gt.GetReservedMass()); System.Console.Out.Printf("%10.8f ", sgt.GetReservedMass()); System.Console.Out.WriteLine(); System.Console.Out.Printf("%10s %10s %10s %10s %10s %10s %10s%n", "----------", "----------", "----------", "----------", "----------", "----------", "----------"); System.Console.Out.Printf("%10s ", "Total"); System.Console.Out.Printf("%10.8f ", n.TotalCount()); System.Console.Out.Printf("%10.8f ", add1.TotalCount()); System.Console.Out.Printf("%10.8f ", dir1.TotalCount()); System.Console.Out.Printf("%10.8f ", dir2.TotalCount()); System.Console.Out.Printf("%10.8f ", gt.TotalCount()); System.Console.Out.Printf("%10.8f ", sgt.TotalCount()); System.Console.Out.WriteLine(); }
public DynamicDistribution(Distribution <E> prior, double priorMultiplier) : base() { this.prior = prior; this.priorMultiplier = priorMultiplier; }