/** * Like {@link ClassicCounter}, this currently returns true if the count is * explicitly 0.0 for something */ public boolean containsKey(List<K> key) { // if(! (key instanceof Object[])) // return false; // Object[] o = (Object[]) key; GeneralizedCounter<K> next = this; for (int i=0; i<key.size()-1; i++) { next = next.conditionalizeHelper(key.get(i)); if (next==null) return false; } return next.map.containsKey(key.get(key.size()-1)); }
/** * Returns a GeneralizedCounter conditioned on the given top level object. * This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>. */ public GeneralizedCounter<K> conditionalizeOnce(K o) { if (depth() < 1) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth()); } else { return conditionalizeHelper(o); } }
conditionalizeHelper(o).keySet(s, newKey, true);
/** * returns a GeneralizedCounter conditioned on the objects in the * {@link List} argument. The length of the argument {@link List} * must be less than the depth of the GeneralizedCounter. */ public GeneralizedCounter<K> conditionalize(List<K> l) { int n = l.size(); if (n >= depth()) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth() + " on a vector of length " + n); } else { GeneralizedCounter<K> next = this; for (K o: l) { next = next.conditionalizeHelper(o); } return next; } }
/** * Adds to count for the {@link #depth()}-dimensional key {@code l}. */ public void incrementCount(List<K> l, double count) { if (l.size() != depth) { wrongDepth(); //throws exception } GeneralizedCounter<K> next = this; Iterator<K> i = l.iterator(); K o = i.next(); while (i.hasNext()) { next.addToTotal(count); next = next.conditionalizeHelper(o); o = i.next(); } next.incrementCount1D(o, count); }
ClassicCounter<K> c = conditionalizeHelper(finalKey).oneDimensionalCounterView(); if (useLists) { s.add(new Entry<>(Arrays.asList(newKey), c)); conditionalizeHelper(o).lowestLevelCounterEntrySet(s, newKey, true);
/** * Equivalent to incrementCount( new Object[] { first, second }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount2D(K first, K second, double count) { if (depth != 2) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount1D(second, count); }
/** * returns a {@code double[]} array of length * {@code depth+1}, containing the conditional counts on a * {@code depth}-length list given each level of conditional * distribution from 0 to {@code depth}. */ public double[] getCounts(List<K> l) { if (l.size() != depth) { wrongDepth(); //throws exception } double[] counts = new double[depth + 1]; GeneralizedCounter<K> next = this; counts[0] = next.totalCount(); Iterator<K> i = l.iterator(); int j = 1; K o = i.next(); while (i.hasNext()) { next = next.conditionalizeHelper(o); counts[j] = next.totalCount(); o = i.next(); j++; } counts[depth] = next.getCount(o); return counts; }
conditionalizeHelper(o).entrySet(s, newKey, true);
/** * Equivalent to incrementCount( new Object[] { first, second, third }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount3D(K first, K second, K third, double count) { if (depth != 3) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount2D(second, third, count); }
/** * same as incrementCount(List, double) but as if Object o were at the end of the list */ public void incrementCount(List<K> l, K o, double count) { if (l.size() != depth - 1) { wrongDepth(); } GeneralizedCounter<K> next = this; for (K o2: l) { next.addToTotal(count); next = next.conditionalizeHelper(o2); } next.addToTotal(count); next.incrementCount1D(o, count); }
/** * Returns a GeneralizedCounter conditioned on the given top level object. * This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>. */ public GeneralizedCounter<K> conditionalizeOnce(K o) { if (depth() < 1) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth()); } else { return conditionalizeHelper(o); } }
/** * Returns a GeneralizedCounter conditioned on the given top level object. * This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>. */ public GeneralizedCounter<K> conditionalizeOnce(K o) { if (depth() < 1) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth()); } else { return conditionalizeHelper(o); } }
/** * Returns a GeneralizedCounter conditioned on the given top level object. * This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>. */ public GeneralizedCounter<K> conditionalizeOnce(K o) { if (depth() < 1) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth()); } else { return conditionalizeHelper(o); } }
/** * Returns a GeneralizedCounter conditioned on the given top level object. * This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>. */ public GeneralizedCounter<K> conditionalizeOnce(K o) { if (depth() < 1) { throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth()); } else { return conditionalizeHelper(o); } }
/** * Equivalent to incrementCount( new Object[] { first, second }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount2D(K first, K second, double count) { if (depth != 2) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount1D(second, count); }
/** * Equivalent to incrementCount( new Object[] { first, second, third }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount3D(K first, K second, K third, double count) { if (depth != 3) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount2D(second, third, count); }
/** * Equivalent to incrementCount( new Object[] { first, second, third }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount3D(K first, K second, K third, double count) { if (depth != 3) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount2D(second, third, count); }
/** * Equivalent to incrementCount( new Object[] { first, second, third }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount3D(K first, K second, K third, double count) { if (depth != 3) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount2D(second, third, count); }
/** * Equivalent to incrementCount( new Object[] { first, second, third }, count ). * Makes the special case easier, and also more efficient. */ public void incrementCount3D(K first, K second, K third, double count) { if (depth != 3) { wrongDepth(); //throws exception } this.addToTotal(count); GeneralizedCounter<K> next = this.conditionalizeHelper(first); next.incrementCount2D(second, third, count); }