/** Returns a duplicate copy of this object. */ public FloatDict copy() { FloatDict outgoing = new FloatDict(count); System.arraycopy(keys, 0, outgoing.keys, 0, count); System.arraycopy(values, 0, outgoing.values, 0, count); for (int i = 0; i < count; i++) { outgoing.indices.put(keys[i], i); } outgoing.count = count; return outgoing; }
/** Returns a duplicate copy of this object. */ public FloatDict copy() { FloatDict outgoing = new FloatDict(count); System.arraycopy(keys, 0, outgoing.keys, 0, count); System.arraycopy(values, 0, outgoing.values, 0, count); for (int i = 0; i < count; i++) { outgoing.indices.put(keys[i], i); } outgoing.count = count; return outgoing; }
public FloatDict getFloatDict(int keyColumn, int valueColumn) { return new FloatDict(getStringColumn(keyColumn), getFloatColumn(valueColumn)); }
public FloatDict getFloatDict(String keyColumnName, String valueColumnName) { return new FloatDict(getStringColumn(keyColumnName), getFloatColumn(valueColumnName)); }
public FloatDict getFloatDict(String keyColumnName, String valueColumnName) { return new FloatDict(getStringColumn(keyColumnName), getFloatColumn(valueColumnName)); }
public FloatDict getFloatDict(int keyColumn, int valueColumn) { return new FloatDict(getStringColumn(keyColumn), getFloatColumn(valueColumn)); }
/** * Sum all of the values in this dictionary, then return a new FloatDict of * each key, divided by the total sum. The total for all values will be ~1.0. * @return an IntDict with the original keys, mapped to their pct of the total */ public FloatDict getPercent() { double sum = sum(); // a little more accuracy FloatDict outgoing = new FloatDict(); for (int i = 0; i < size(); i++) { double percent = value(i) / sum; outgoing.set(key(i), (float) percent); } return outgoing; }
/** * Sum all of the values in this dictionary, then return a new FloatDict of * each key, divided by the total sum. The total for all values will be ~1.0. * @return a FloatDict with the original keys, mapped to their pct of the total */ public FloatDict getPercent() { double sum = sum(); FloatDict outgoing = new FloatDict(); for (int i = 0; i < size(); i++) { double percent = value(i) / sum; outgoing.set(key(i), (float) percent); } return outgoing; }
/** * Sum all of the values in this dictionary, then return a new FloatDict of * each key, divided by the total sum. The total for all values will be ~1.0. * @return a Dict with the original keys, mapped to their pct of the total */ public FloatDict getPercent() { double sum = 0; for (float value : valueArray()) { sum += value; } FloatDict outgoing = new FloatDict(); for (int i = 0; i < size(); i++) { double percent = value(i) / sum; outgoing.set(key(i), (float) percent); } return outgoing; }
/** * Sum all of the values in this dictionary, then return a new FloatDict of * each key, divided by the total sum. The total for all values will be ~1.0. * @return a Dict with the original keys, mapped to their pct of the total */ public FloatDict getPercent() { double sum = 0; for (int value : valueArray()) { sum += value; } FloatDict outgoing = new FloatDict(); for (int i = 0; i < size(); i++) { double percent = value(i) / sum; outgoing.set(key(i), (float) percent); } return outgoing; }