/** * Returns a list of boolean columns suitable for use as dummy variables in, for example, regression analysis, * select a column of categorical data must be encoded as a list of columns, such that each column represents * a single category and indicates whether it is present (1) or not present (0) * * @return a list of {@link BooleanColumn} */ @Override public List<BooleanColumn> getDummies() { List<BooleanColumn> results = new ArrayList<>(); // createFromCsv the necessary columns for (Short2ObjectMap.Entry<String> entry : keyToValueMap().short2ObjectEntrySet()) { BooleanColumn column = BooleanColumn.create(entry.getValue()); results.add(column); } // iterate over the values, updating the dummy variable columns as appropriate for (short next : values) { String category = getValueForKey(next); for (BooleanColumn column : results) { if (category.equals(column.name())) { //TODO(lwhite): update the correct row more efficiently, by using set rather than add & only // updating true column.append(true); } else { column.append(false); } } } return results; }
/** * Returns an iterable yielding an iterator that will be * {@linkplain FastEntrySet fast}, if possible, on the * {@linkplain Map#entrySet() entry set} of the provided {@code map}. * * @param map * a map from which we will try to extract an iterable yielding a * (fast) iterator on the entry set. * @return an iterable yielding an iterator on the entry set of the given map * that will be fast, if possible. * @since 8.0.0 */ @SuppressWarnings("unchecked") public static <V> ObjectIterable<Short2ObjectMap.Entry<V>> fastIterable(Short2ObjectMap<V> map) { final ObjectSet<Short2ObjectMap.Entry<V>> entries = map.short2ObjectEntrySet(); return entries instanceof Short2ObjectMap.FastEntrySet ? new ObjectIterable<Short2ObjectMap.Entry<V>>() { public ObjectIterator<Short2ObjectMap.Entry<V>> iterator() { return ((Short2ObjectMap.FastEntrySet<V>) entries).fastIterator(); } public void forEach(final Consumer<? super Short2ObjectMap.Entry<V>> consumer) { ((Short2ObjectMap.FastEntrySet<V>) entries).fastForEach(consumer); } } : entries; } /**
/** * Returns a set view of the mappings contained in this map. * <p> * Note that this specification strengthens the one given in * {@link Map#entrySet()}. * * @return a set view of the mappings contained in this map. * @see Map#entrySet() * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override @SuppressWarnings({"unchecked", "rawtypes"}) default ObjectSet<Map.Entry<Short, V>> entrySet() { return (ObjectSet) short2ObjectEntrySet(); } /**
@Override public ObjectSet<Short2ObjectMap.Entry<V>> short2ObjectEntrySet() { if (entries == null) entries = ObjectSets.unmodifiable(map.short2ObjectEntrySet()); return entries; } /**
@Override public ObjectSet<Short2ObjectMap.Entry<V>> short2ObjectEntrySet() { synchronized (sync) { if (entries == null) entries = ObjectSets.synchronize(map.short2ObjectEntrySet(), sync); return entries; } } /**
/** * Returns an iterator that will be {@linkplain FastEntrySet fast}, if possible, * on the {@linkplain Map#entrySet() entry set} of the provided {@code map}. * * @param map * a map from which we will try to extract a (fast) iterator on the * entry set. * @return an iterator on the entry set of the given map that will be fast, if * possible. * @since 8.0.0 */ @SuppressWarnings("unchecked") public static <V> ObjectIterator<Short2ObjectMap.Entry<V>> fastIterator(Short2ObjectMap<V> map) { final ObjectSet<Short2ObjectMap.Entry<V>> entries = map.short2ObjectEntrySet(); return entries instanceof Short2ObjectMap.FastEntrySet ? ((Short2ObjectMap.FastEntrySet<V>) entries).fastIterator() : entries.iterator(); } /**
/** * Iterates {@linkplain FastEntrySet#fastForEach(Consumer) quickly}, if * possible, on the {@linkplain Map#entrySet() entry set} of the provided * {@code map}. * * @param map * a map on which we will try to iterate * {@linkplain FastEntrySet#fastForEach(Consumer) quickly}. * @param consumer * the consumer that will be passed to * {@link FastEntrySet#fastForEach(Consumer)}, if possible, or to * {@link Iterable#forEach(Consumer)}. * @since 8.1.0 */ @SuppressWarnings("unchecked") public static <V> void fastForEach(Short2ObjectMap<V> map, final Consumer<? super Short2ObjectMap.Entry<V>> consumer) { final ObjectSet<Short2ObjectMap.Entry<V>> entries = map.short2ObjectEntrySet(); if (entries instanceof Short2ObjectMap.FastEntrySet) ((Short2ObjectMap.FastEntrySet<V>) entries).fastForEach(consumer); else entries.forEach(consumer); } /**
/** * Returns a list of boolean columns suitable for use as dummy variables in, for example, regression analysis, * select a column of categorical data must be encoded as a list of columns, such that each column represents * a single category and indicates whether it is present (1) or not present (0) * * @return a list of {@link BooleanColumn} */ @Override public List<BooleanColumn> getDummies() { List<BooleanColumn> results = new ArrayList<>(); // createFromCsv the necessary columns for (Short2ObjectMap.Entry<String> entry : keyToValueMap().short2ObjectEntrySet()) { BooleanColumn column = BooleanColumn.create(entry.getValue()); results.add(column); } // iterate over the values, updating the dummy variable columns as appropriate for (short next : values) { String category = getValueForKey(next); for (BooleanColumn column : results) { if (category.equals(column.name())) { //TODO(lwhite): update the correct row more efficiently, by using set rather than add & only // updating true column.append(true); } else { column.append(false); } } } return results; }