Java Code Examples for it.unimi.dsi.fastutil.ints.Int2FloatMap#put()

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2FloatMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlimUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private void replayTrain(@Nonnull final ByteBuffer buf) {
    final int itemI = buf.getInt();
    final int knnSize = buf.getInt();

    final Int2ObjectMap<Int2FloatMap> knnItems = new Int2ObjectOpenHashMap<>(1024);
    final IntSet pairItems = new IntOpenHashSet();
    for (int i = 0; i < knnSize; i++) {
        int user = buf.getInt();
        int ruSize = buf.getInt();
        Int2FloatMap ru = new Int2FloatOpenHashMap(ruSize);
        ru.defaultReturnValue(0.f);

        for (int j = 0; j < ruSize; j++) {
            int itemK = buf.getInt();
            pairItems.add(itemK);
            float ruk = buf.getFloat();
            ru.put(itemK, ruk);
        }
        knnItems.put(user, ru);
    }

    for (int itemJ : pairItems) {
        train(itemI, knnItems, itemJ);
    }
}
 
Example 2
Source File: SlimUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Int2FloatMap int2floatMap(@Nonnull final Map<?, ?> map,
        @Nonnull final PrimitiveObjectInspector keyOI,
        @Nonnull final PrimitiveObjectInspector valueOI) {
    final Int2FloatMap result = new Int2FloatOpenHashMap(map.size());
    result.defaultReturnValue(0.f);

    for (Map.Entry<?, ?> entry : map.entrySet()) {
        float v = PrimitiveObjectInspectorUtils.getFloat(entry.getValue(), valueOI);
        if (v == 0.f) {
            continue;
        }
        int k = PrimitiveObjectInspectorUtils.getInt(entry.getKey(), keyOI);
        result.put(k, v);
    }

    return result;
}
 
Example 3
Source File: SlimUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Int2FloatMap int2floatMap(final int item, @Nonnull final Map<?, ?> map,
        @Nonnull final PrimitiveObjectInspector keyOI,
        @Nonnull final PrimitiveObjectInspector valueOI, @Nullable final FloatMatrix dataMatrix,
        @Nullable Int2FloatMap dst) {
    if (dst == null) {
        dst = new Int2FloatOpenHashMap(map.size());
        dst.defaultReturnValue(0.f);
    } else {
        dst.clear();
    }

    for (Map.Entry<?, ?> entry : map.entrySet()) {
        float rating = PrimitiveObjectInspectorUtils.getFloat(entry.getValue(), valueOI);
        if (rating == 0.f) {
            continue;
        }
        int user = PrimitiveObjectInspectorUtils.getInt(entry.getKey(), keyOI);
        dst.put(user, rating);
        if (dataMatrix != null) {
            dataMatrix.set(item, user, rating);
        }
    }

    return dst;
}
 
Example 4
Source File: UnaryInverseDocumentFrequency.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, TermFrequency... documents) {
	super(keyValues);
	for (TermFrequency document : documents) {
		IntIterator iterator = document.getKeys().iterator();
		while (iterator.hasNext()) {
			int term = iterator.nextInt();
			keyValues.put(term, 1F);
		}
	}
}
 
Example 5
Source File: UnaryInverseDocumentFrequency.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, Collection<TermFrequency> documents) {
	super(keyValues);
	for (TermFrequency document : documents) {
		IntIterator iterator = document.getKeys().iterator();
		while (iterator.hasNext()) {
			int term = iterator.nextInt();
			keyValues.put(term, 1F);
		}
	}
}
 
Example 6
Source File: UnaryInverseDocumentFrequency.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, Iterator<TermFrequency> documents) {
	super(keyValues);
	while (documents.hasNext()) {
		TermFrequency document = documents.next();
		IntIterator iterator = document.getKeys().iterator();
		while (iterator.hasNext()) {
			int term = iterator.nextInt();
			keyValues.put(term, 1F);
		}
	}
}
 
Example 7
Source File: CountTermFrequency.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
public CountTermFrequency(Int2FloatMap keyValues, int... document) {
	super(keyValues, document.length);
	for (int term : document) {
		keyValues.put(term, keyValues.getOrDefault(term, 0F) + 1F);
	}
}
 
Example 8
Source File: CountTermFrequency.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
public CountTermFrequency(Int2FloatMap keyValues, Collection<Integer> document) {
	super(keyValues, document.size());
	for (int term : document) {
		keyValues.put(term, keyValues.getOrDefault(term, 0F) + 1F);
	}
}
 
Example 9
Source File: BinaryTermFrequency.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
public BinaryTermFrequency(Int2FloatMap keyValues, int... document) {
	super(keyValues, document.length);
	for (int term : document) {
		keyValues.put(term, 1F);
	}
}
 
Example 10
Source File: BinaryTermFrequency.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
public BinaryTermFrequency(Int2FloatMap keyValues, Collection<Integer> document) {
	super(keyValues, document.size());
	for (int term : document) {
		keyValues.put(term, 1F);
	}
}