Java Code Examples for it.unimi.dsi.fastutil.doubles.DoubleList#add()

The following examples show how to use it.unimi.dsi.fastutil.doubles.DoubleList#add() . 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: SynchronizedVariableSpace.java    From samantha with MIT License 6 votes vote down vote up
final public void ensureScalarVar(String name, int size, double initial, boolean randomize) {
    writeLock.lock();
    try {
        int curSize = scalarVars.get(name).size();
        if (curSize < size) {
            DoubleList toAdd = new DoubleArrayList(size - curSize);
            for (int i=0; i<size - curSize; i++) {
                toAdd.add(0.0);
            }
            initializeDoubleList(toAdd, initial, randomize);
            scalarVars.get(name).addAll(toAdd);
        }
        curSize = readLocks.size();
        SpaceUtilities.fillReadWriteLocks(readLocks, writeLocks, curSize, size);
    } finally {
        writeLock.unlock();
    }
}
 
Example 2
Source File: BootstrappingPreferenceKernel.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void signalNewScore(final ILabeledPath<N, A> path, final double newScore) {

	/* add the observation to all stats on the path */
	List<N> nodes = path.getNodes();
	int l = nodes.size();
	for (int i = l - 1; i >= 0; i --) {
		N node = nodes.get(i);
		DoubleList list = this.observations.computeIfAbsent(node, n -> new DoubleArrayList());
		list.add(newScore);
		if (list.size() > this.maxNumSamplesInHistory) {
			list.removeDouble(0);
		}
	}
}
 
Example 3
Source File: PLMMAlgorithm.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static DoubleList getDefaultSkillVector(final int n) {
	DoubleList skillVector = new DoubleArrayList();
	double p = 1.0 / n;
	for (int i = 0; i < n; i++) {
		skillVector.add(p);
	}
	return skillVector;
}
 
Example 4
Source File: SynchronizedVariableSpace.java    From samantha with MIT License 5 votes vote down vote up
final public void requestScalarVar(String name, int size, double initial, boolean randomize) {
    DoubleList var = new DoubleArrayList(size);
    for (int i=0; i<size; i++) {
        var.add(0.0);
    }
    initializeDoubleList(var, initial, randomize);
    writeLock.lock();
    try {
        scalarVars.put(name, var);
    } finally {
        writeLock.unlock();
    }
}
 
Example 5
Source File: BoostingUtilities.java    From samantha with MIT License 5 votes vote down vote up
public static void setStochasticOracles(List<LearningInstance> instances, List<StochasticOracle> oracles,
                                        SVDFeature svdfeaModel, DoubleList preds) {
    for (LearningInstance ins : instances) {
        GBCentLearningInstance centIns = (GBCentLearningInstance) ins;
        SVDFeatureInstance svdfeaIns = centIns.getSvdfeaIns();
        double pred = svdfeaModel.predict(svdfeaIns)[0];
        preds.add(pred);
        StochasticOracle oracle = new StochasticOracle(pred, svdfeaIns.getLabel(),
                svdfeaIns.getWeight());
        oracles.add(oracle);
    }
}
 
Example 6
Source File: ValueInTransformFunction.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private static double[] filterDoubles(DoubleSet doubleSet, double[] source) {
  DoubleList doubleList = new DoubleArrayList();
  for (double value : source) {
    if (doubleSet.contains(value)) {
      doubleList.add(value);
    }
  }
  if (doubleList.size() == source.length) {
    return source;
  } else {
    return doubleList.toDoubleArray();
  }
}
 
Example 7
Source File: GBCentLearningMethod.java    From samantha with MIT License 4 votes vote down vote up
private void initializeValidObjs(DoubleList validObjs, int size) {
    for (int i=0; i<size; i++) {
        validObjs.add(0.0);
    }
}
 
Example 8
Source File: GBCentLearningMethod.java    From samantha with MIT License 4 votes vote down vote up
private void initializeLearnObjs(DoubleList learnObjs, int size) {
    for (int i=0; i<size; i++) {
        learnObjs.add(0.0);
    }
}
 
Example 9
Source File: TensorFlowModel.java    From samantha with MIT License 4 votes vote down vote up
public LearningInstance featurize(JsonNode entity, boolean update) {
    Map<String, List<Feature>> feaMap = FeaturizerUtilities.getFeatureMap(entity, true,
            featureExtractors, indexSpace);
    if (equalSizeChecks != null) {
        for (List<String> features : equalSizeChecks) {
            int size = -1;
            for (String fea : features) {
                if (size < 0) {
                    if (feaMap.containsKey(fea)) {
                        size = feaMap.get(fea).size();
                    } else {
                        throw new BadRequestException(
                                "Feature " + fea + " is not present in the extracted feature map with keys " +
                                        feaMap.keySet().toString());
                    }
                } else if (size != feaMap.get(fea).size()) {
                    throw new ConfigurationException(
                            "Equal size checks with " + features.toString() +
                                    " failed for " + entity.toString());
                }
            }
        }
    }
    String group = null;
    if (groupKeys != null && groupKeys.size() > 0) {
        group = FeatureExtractorUtilities.composeConcatenatedKey(entity, groupKeys);
    }
    TensorFlowInstance instance = new TensorFlowInstance(group);
    for (Map.Entry<String, List<Feature>> entry : feaMap.entrySet()) {
        DoubleList doubles = new DoubleArrayList();
        IntList ints = new IntArrayList();
        for (Feature feature : entry.getValue()) {
            doubles.add(feature.getValue());
            ints.add(feature.getIndex());
        }
        double[] darr = doubles.toDoubleArray();
        instance.putValues(entry.getKey(), darr);
        int[] iarr = ints.toIntArray();
        instance.putIndices(entry.getKey(), iarr);
    }
    return instance;
}