@Override public Iterator<Pair<KeyArgs, Double>> iterator() { return new Iterator<Pair<KeyArgs, Double>>() { private final TObjectDoubleIterator<KeyArgs> innerIterator = values.iterator(); @Override public boolean hasNext() { return innerIterator.hasNext(); } @Override public Pair<KeyArgs, Double> next() { if (innerIterator.hasNext()) { innerIterator.advance(); return Pair.of(innerIterator.key(), innerIterator.value()); } else { return null; } } @Override public void remove() { innerIterator.remove(); } }; }
@Override public Iterator<ObjectDoubleEntry<KEY>> iterator() { return new Iterator<ObjectDoubleEntry<KEY>>() { TObjectDoubleIterator<KEY> iter = paramsMap.iterator(); ObjectDoubleEntry<KEY> entry = new ObjectDoubleEntry<KEY>(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public ObjectDoubleEntry<KEY> next() { iter.advance(); entry.key = iter.key(); entry.value = iter.value(); return entry; } @Override public void remove() { throw new UnsupportedOperationException("Not supported"); } }; }
/** * compute the inner product between this and vec. */ public double dot(StringKeyedVector vec) { if (vec instanceof LazyVector) { return vec.dot(this); } ByteArrayDoubleHashMap vec_small = this.size() > vec.size() ? vec.vector : this.vector; ByteArrayDoubleHashMap vec_big = this.size() > vec.size() ? this.vector : vec.vector; double res = 0.0; for (TObjectDoubleIterator<byte[]> it = vec_small.troveIterator(); it .hasNext();) { it.advance(); if (vec_big.containsKey(it.key())) { res += it.value() * vec_big.getPrimitive(it.key()); } } return res; }
public Iterator<Map.Entry<String, Double>> iterator() { return new Iterator<Map.Entry<String, Double>>() { private TObjectDoubleIterator<byte[]> iter = troveIterator(); public boolean hasNext() { return iter.hasNext(); } public void remove() { iter.remove(); } public Map.Entry<String, Double> next() { iter.advance(); return new AbstractMap.SimpleImmutableEntry<String, Double>( byteArrayToString(iter.key()), iter.value()); } }; }
/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals( Object other ) { if ( ! ( other instanceof TObjectDoubleMap ) ) { return false; } TObjectDoubleMap that = ( TObjectDoubleMap ) other; if ( that.size() != this.size() ) { return false; } try { TObjectDoubleIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); Object key = iter.key(); double value = iter.value(); if ( value == no_entry_value ) { if ( !( that.get( key ) == that.getNoEntryValue() && that.containsKey( key ) ) ) { return false; } } else { if ( value != that.get( key ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(final Object other ) { if ( ! ( other instanceof TObjectDoubleMap ) ) { return false; } final TObjectDoubleMap that = ( TObjectDoubleMap ) other; if ( that.size() != this.size() ) { return false; } try { final TObjectDoubleIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); final Object key = iter.key(); final double value = iter.value(); if ( value == no_entry_value ) { if ( !( that.get( key ) == that.getNoEntryValue() && that.containsKey( key ) ) ) { return false; } } else { if ( value != that.get( key ) ) { return false; } } } } catch ( final ClassCastException ex ) { // unused. } return true; }
/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ @Override @SuppressWarnings("rawtypes") public boolean equals( Object other ) { if ( ! ( other instanceof TObjectDoubleMap ) ) { return false; } TObjectDoubleMap that = ( TObjectDoubleMap ) other; if ( that.size() != this.size() ) { return false; } try { TObjectDoubleIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); Object key = iter.key(); double value = iter.value(); if ( value == no_entry_value ) { if ( !( that.get( key ) == that.getNoEntryValue() && that.containsKey( key ) ) ) { return false; } } else { if ( value != that.get( key ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals( Object other ) { if ( ! ( other instanceof TObjectDoubleMap ) ) { return false; } TObjectDoubleMap that = ( TObjectDoubleMap ) other; if ( that.size() != this.size() ) { return false; } try { TObjectDoubleIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); Object key = iter.key(); double value = iter.value(); if ( value == no_entry_value ) { if ( !( that.get( key ) == that.getNoEntryValue() && that.containsKey( key ) ) ) { return false; } } else { if ( value != that.get( key ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. logger.warn("An error occurred!", ex); } return true; }
public void delazify() { for (TObjectDoubleIterator<byte[]> it = vector.troveIterator(); it .hasNext();) { it.advance(); long startIter = (long)iterations.getPrimitive(it.key()); // defaults // to 0.0 if (startIter < iteration) { it.setValue(updater.lazyUpdate(it.key().toString(), it.value(), startIter, iteration)); iterations.putPrimitive(it.key(), (double)iteration); } } removeZeroCoordinates(); }
public void skipToIteration(long iter) { delazify(); iteration = iter; for (TObjectDoubleIterator<byte[]> it = iterations.troveIterator(); it .hasNext();) { it.advance(); it.setValue((double)iter); } }
/** * Remove zeros that may have appeared as a result of a transform */ public void removeZeroCoordinates() { for (TObjectDoubleIterator<byte[]> it = vector.troveIterator(); it .hasNext();) { it.advance(); if (Utilities.floatingPointEquals(it.value(), 0d)) { iterations.removePrimitive(it.key()); it.remove(); } } }
protected double dotWithSKV(StringKeyedVector vec) { // dont figure out which ones bigger etc, since delazifying this to get // the size is too slow. double res = 0.0; for (TObjectDoubleIterator<byte[]> it = vec.vector.troveIterator(); it .hasNext();) { it.advance(); res += it.value() * delazifyCoordinate(it.key()); } return res; }
/** * add a multiple of vec to this. */ public void addScaled(StringKeyedVector vec, double scale) { if (vec instanceof LazyVector) { ((LazyVector)vec).delazify(); } for (TObjectDoubleIterator<byte[]> it = vec.vector.troveIterator(); it .hasNext();) { it.advance(); addToCoordinateInternal(it.key(), scale * it.value()); } }
public StringKeyedVector multiplyPointwise(StringKeyedVector vec) { StringKeyedVector res = new StringKeyedVector(); if (vec instanceof LazyVector) { ((LazyVector)vec).delazify(); } for (TObjectDoubleIterator<byte[]> it = vec.vector.troveIterator(); it .hasNext();) { it.advance(); res.vector.putPrimitive(it.key(), vector.getPrimitive(it.key()) * it.value()); } return res; }
public StringKeyedVector projectOntoNonZeroCoordinates(StringKeyedVector vec) { StringKeyedVector res = new StringKeyedVector(); if (vec instanceof LazyVector) { ((LazyVector)vec).delazify(); } for (TObjectDoubleIterator<byte[]> it = vec.vector.troveIterator(); it .hasNext();) { it.advance(); res.addToCoordinateInternal(it.key(), vector.getPrimitive(it.key())); } return res; }
/** * Remove zeros that may have appeared as a result of a transform */ public void removeZeroCoordinates() { @SuppressWarnings("unused") int i = 0; for (TObjectDoubleIterator<byte[]> it = vector.troveIterator(); it .hasNext();) { it.advance(); if (Utilities.floatingPointEquals(it.value(), 0d)) { i++; it.remove(); } } }
private void writeObject(ObjectOutputStream output) throws IOException { output.writeObject(keyEncoding); output.writeFloat(loadFactor); output.writeDouble(defaultValue); output.writeInt(map.size()); for (TObjectDoubleIterator<byte[]> it = map.iterator(); it.hasNext();) { it.advance(); byte[] key = it.key(); output.writeInt(key.length); for (int i = 0; i < key.length; i++) { output.writeByte(key[i]); } output.writeDouble(it.value()); } }
public void write(Kryo kryo, Output output) { output.writeString(keyEncoding); output.writeFloat(loadFactor); output.writeDouble(defaultValue); output.writeInt(map.size()); for (TObjectDoubleIterator<byte[]> it = map.iterator(); it.hasNext();) { it.advance(); byte[] key = it.key(); output.writeInt(key.length); for (int i = 0; i < key.length; i++) { output.writeByte(key[i]); } output.writeDouble(it.value()); } }
public double calculateTotalEquilibriumSurplus() { double totalSurplus = 0; TObjectDoubleIterator<AbstractTradingAgent> i = surplusTable.iterator(); while (i.hasNext()) { i.advance(); @SuppressWarnings("unused") AbstractTradingAgent agent = i.key(); totalSurplus += i.value(); } return totalSurplus; }
/** * @return an iterator over the entries in this map */ public TObjectDoubleIterator<K> iterator() { return new TObjectDoubleHashIterator<K>( this ); }
/** * @return an iterator over the entries in this map */ public TObjectDoubleIterator<K> iterator() { return new TObjectDoubleHashIterator<>(this); }