Beispiel #1
0
        /// <summary>
        /// returns a
        /// <c>double[]</c>
        /// array of length
        /// <c>depth+1</c>
        /// , containing the conditional counts on a
        /// <c>depth</c>
        /// -length list given each level of conditional
        /// distribution from 0 to
        /// <c>depth</c>
        /// .
        /// </summary>
        public virtual double[] GetCounts(IList <K> l)
        {
            if (l.Count != depth)
            {
                WrongDepth();
            }
            //throws exception
            double[] counts             = new double[depth + 1];
            GeneralizedCounter <K> next = this;

            counts[0] = next.TotalCount();
            IEnumerator <K> i = l.GetEnumerator();
            int             j = 1;
            K o = i.Current;

            while (i.MoveNext())
            {
                next      = next.ConditionalizeHelper(o);
                counts[j] = next.TotalCount();
                o         = i.Current;
                j++;
            }
            counts[depth] = next.GetCount(o);
            return(counts);
        }
Beispiel #2
0
        /// <summary>for testing purposes only</summary>
        public static void Main(string[] args)
        {
            object[] a1 = new object[] { "a", "b" };
            object[] a2 = new object[] { "a", "b" };
            System.Console.Out.WriteLine(Arrays.Equals(a1, a2));
            GeneralizedCounter <string> gc = new GeneralizedCounter <string>(3);

            gc.IncrementCount(Arrays.AsList(new string[] { "a", "j", "x" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "a", "l", "x" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "b", "k", "y" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "b", "k", "z" }), 3.0);
            System.Console.Out.WriteLine("incremented counts.");
            System.Console.Out.WriteLine(gc.DumpKeys());
            System.Console.Out.WriteLine("string representation of generalized counter:");
            System.Console.Out.WriteLine(gc.ToString());
            gc.PrintKeySet();
            System.Console.Out.WriteLine("entry set:\n" + gc.EntrySet());
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "a", "j", "x" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "a", "j", "z" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "b", "k", "w" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "b", "k", "z" })));
            GeneralizedCounter <string> gc1 = gc.Conditionalize(Arrays.AsList(new string[] { "a" }));

            gc1.IncrementCount(Arrays.AsList(new string[] { "j", "x" }));
            gc1.IncrementCount2D("j", "z");
            GeneralizedCounter <string> gc2 = gc1.Conditionalize(Arrays.AsList(new string[] { "j" }));

            gc2.IncrementCount1D("x");
            System.Console.Out.WriteLine("Pretty-printing gc after incrementing gc1:");
            gc.PrettyPrint();
            System.Console.Out.WriteLine("Total: " + gc.TotalCount());
            gc1.PrintKeySet();
            System.Console.Out.WriteLine("another entry set:\n" + gc1.EntrySet());
            ClassicCounter <IList <string> > c = gc.CounterView();

            System.Console.Out.WriteLine("string representation of counter view:");
            System.Console.Out.WriteLine(c.ToString());
            double d1 = c.GetCount(Arrays.AsList(new string[] { "a", "j", "x" }));
            double d2 = c.GetCount(Arrays.AsList(new string[] { "a", "j", "w" }));

            System.Console.Out.WriteLine(d1 + " " + d2);
            ClassicCounter <IList <string> > c1 = gc1.CounterView();

            System.Console.Out.WriteLine("Count of {j,x} -- should be 3.0\t" + c1.GetCount(Arrays.AsList(new string[] { "j", "x" })));
            System.Console.Out.WriteLine(c.KeySet() + " size " + c.KeySet().Count);
            System.Console.Out.WriteLine(c1.KeySet() + " size " + c1.KeySet().Count);
            System.Console.Out.WriteLine(c1.Equals(c));
            System.Console.Out.WriteLine(c.Equals(c1));
            System.Console.Out.WriteLine(c.Equals(c));
            System.Console.Out.WriteLine("### testing equality of regular Counter...");
            ClassicCounter <string> z1 = new ClassicCounter <string>();
            ClassicCounter <string> z2 = new ClassicCounter <string>();

            z1.IncrementCount("a1");
            z1.IncrementCount("a2");
            z2.IncrementCount("b");
            System.Console.Out.WriteLine(z1.Equals(z2));
            System.Console.Out.WriteLine(z1.ToString());
            System.Console.Out.WriteLine(z1.KeySet().ToString());
        }
Beispiel #3
0
 private void PrettyPrint(PrintWriter pw, string buffer, string bufferIncrement)
 {
     if (depth == 1)
     {
         foreach (KeyValuePair <object, double> e in EntrySet())
         {
             object key   = e.Key;
             double count = e.Value;
             pw.Println(buffer + key + "\t" + count);
         }
     }
     else
     {
         foreach (K key in TopLevelKeySet())
         {
             GeneralizedCounter <K> gc1 = Conditionalize(Arrays.AsList(ErasureUtils.UncheckedCast <K[]>(new object[] { key })));
             pw.Println(buffer + key + "\t" + gc1.TotalCount());
             gc1.PrettyPrint(pw, buffer + bufferIncrement, bufferIncrement);
         }
     }
 }