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

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2DoubleMap#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: Int2DoubleArrayRow.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public Int2DoubleMap asMap() {
	Int2DoubleMap mapRow = new Int2DoubleOpenHashMap(array.length);
	for (int i = 0; i < array.length; i++) {
		double value = array[i];
		if (isNotDefault(value)) {
			mapRow.put(i, value);
		}
	}
	return mapRow;
}
 
Example 2
Source File: Int2DoubleRowTest.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsMap() {
	Int2DoubleMap map = new Int2DoubleOpenHashMap();
	map.put(1, 0.5);
	map.put(2, 0.4);
	Int2DoubleRow row = createRow(map, 3);
	assertThat(row.asMap()).hasSize(2);
	assertThat(row.asMap()).containsEntry(1, 0.5);
	assertThat(row.asMap()).containsEntry(2, 0.4);
}
 
Example 3
Source File: Int2DoubleRowTest.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetOrDefault() {
	Int2DoubleMap map = new Int2DoubleOpenHashMap();
	map.put(1, 0.5);
	map.put(2, 0.4);
	Int2DoubleRow row = createRow(map, 3);
	assertThat(row.getOrDefault(0)).isEqualTo(0.0);
	assertThat(row.getOrDefault(1)).isEqualTo(0.5);
	assertThat(row.getOrDefault(2)).isEqualTo(0.4);
}
 
Example 4
Source File: Int2DoubleRowTest.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Test
public void testValues() {
	Int2DoubleMap map = new Int2DoubleOpenHashMap();
	map.put(1, 0.5);
	map.put(2, 0.4);
	Int2DoubleRow row = createRow(map, 3);
	assertThat(row.values()).contains(0.5, 0.4);
}
 
Example 5
Source File: StandardFeaturizer.java    From samantha with MIT License 5 votes vote down vote up
public LearningInstance featurize(JsonNode entity, boolean update) {
    Map<String, List<Feature>> feaMap = new HashMap<>();
    for (FeatureExtractor extractor : featureExtractors) {
        feaMap.putAll(extractor.extract(entity, update,
                indexSpace));
    }
    Int2DoubleMap feas = new Int2DoubleOpenHashMap();
    for (String fea : features) {
        if (feaMap.containsKey(fea)) {
            for (Feature feature : feaMap.get(fea)) {
                feas.put(feature.getIndex(), feature.getValue());
            }
        }
    }
    double label = StandardLearningInstance.defaultLabel;
    double weight = StandardLearningInstance.defaultWeight;
    if (entity.has(labelName)) {
        label = entity.get(labelName).asDouble();
    } else if (feaMap.containsKey(labelName)) {
        label = feaMap.get(labelName).get(0).getIndex();
    }
    if (entity.has(weightName)) {
        weight = entity.get(weightName).asDouble();
    } else if (feaMap.containsKey(weightName)) {
        weight = feaMap.get(weightName).get(0).getValue();
    }
    String group = null;
    if (groupKeys != null && groupKeys.size() > 0) {
        group = FeatureExtractorUtilities.composeConcatenatedKey(entity, groupKeys);
    }
    return new StandardLearningInstance(feas, label, weight, group);
}
 
Example 6
Source File: BinomialModelTest.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Tests the global probability method (BinomialModel::p).
 */
@Test
public void testGlobalModel() {
    Int2DoubleMap expectedGlobalP = new Int2DoubleOpenHashMap();
    expectedGlobalP.put(1, 0.8);
    expectedGlobalP.put(2, 0.2);
    
    BinomialModel<Integer, Integer, Integer> bm = new BinomialModel<>(false, Stream.empty(), preferences, featureData, 0.0);
    
    assertEquals(expectedGlobalP.keySet(), bm.getFeatures());
    expectedGlobalP.forEach((f, p) -> assertEquals(p, bm.p(f), 0.0001));
}
 
Example 7
Source File: BinomialModelTest.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Tests the local (user) probability method with alpha = 0.0.
 */
@Test
public void testLocalModelAlpha00() {
    Int2DoubleMap expectedLocalP = new Int2DoubleOpenHashMap();
    expectedLocalP.put(1, 0.8);
    expectedLocalP.put(2, 0.2);
    
    checkLocalModel(0.0, expectedLocalP);
}
 
Example 8
Source File: BinomialModelTest.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Tests the local (user) probability method with alpha = 0.5.
 */
@Test
public void testLocalModelAlpha05() {
    Int2DoubleMap expectedLocalP = new Int2DoubleOpenHashMap();
    expectedLocalP.put(1, 0.9);
    expectedLocalP.put(2, 0.1);
    
    checkLocalModel(0.5, expectedLocalP);
}
 
Example 9
Source File: BinomialModelTest.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Tests the local (user) probability method with alpha = 1.0.
 */
@Test
public void testLocalModelAlpha10() {
    Int2DoubleMap expectedLocalP = new Int2DoubleOpenHashMap();
    expectedLocalP.put(1, 1.0);
    
    checkLocalModel(1.0, expectedLocalP);
}