/// <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); }
/// <summary>same as incrementCount(List, double) but as if Object o were at the end of the list</summary> public virtual void IncrementCount(IList <K> l, K o, double count) { if (l.Count != depth - 1) { WrongDepth(); } GeneralizedCounter <K> next = this; foreach (K o2 in l) { next.AddToTotal(count); next = next.ConditionalizeHelper(o2); } next.AddToTotal(count); next.IncrementCount1D(o, count); }
/// <summary> /// Like /// <see cref="ClassicCounter{E}"/> /// , this currently returns true if the count is /// explicitly 0.0 for something /// </summary> public virtual bool ContainsKey(IList <K> key) { // if(! (key instanceof Object[])) // return false; // Object[] o = (Object[]) key; GeneralizedCounter <K> next = this; for (int i = 0; i < key.Count - 1; i++) { next = next.ConditionalizeHelper(key[i]); if (next == null) { return(false); } } return(next.map.Contains(key[key.Count - 1])); }
/// <summary> /// returns a GeneralizedCounter conditioned on the objects in the /// <see cref="System.Collections.IList{E}"/> /// argument. The length of the argument /// <see cref="System.Collections.IList{E}"/> /// must be less than the depth of the GeneralizedCounter. /// </summary> public virtual GeneralizedCounter <K> Conditionalize(IList <K> l) { int n = l.Count; if (n >= Depth()) { throw new Exception("Error -- attempted to conditionalize a GeneralizedCounter of depth " + Depth() + " on a vector of length " + n); } else { GeneralizedCounter <K> next = this; foreach (K o in l) { next = next.ConditionalizeHelper(o); } return(next); } }
/// <summary> /// Adds to count for the /// <see cref="GeneralizedCounter{K}.Depth()"/> /// -dimensional key /// <paramref name="l"/> /// . /// </summary> public virtual void IncrementCount(IList <K> l, double count) { if (l.Count != depth) { WrongDepth(); } //throws exception GeneralizedCounter <K> next = this; IEnumerator <K> i = l.GetEnumerator(); K o = i.Current; while (i.MoveNext()) { next.AddToTotal(count); next = next.ConditionalizeHelper(o); o = i.Current; } next.IncrementCount1D(o, count); }