本文整理汇总了Java中gnu.trove.map.hash.TIntIntHashMap.adjustOrPutValue方法的典型用法代码示例。如果您正苦于以下问题:Java TIntIntHashMap.adjustOrPutValue方法的具体用法?Java TIntIntHashMap.adjustOrPutValue怎么用?Java TIntIntHashMap.adjustOrPutValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.hash.TIntIntHashMap
的用法示例。
在下文中一共展示了TIntIntHashMap.adjustOrPutValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pipe
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
public Instance pipe(Instance instance) {
TIntIntHashMap localCounter = new TIntIntHashMap();
if (instance.getData() instanceof FeatureSequence) {
FeatureSequence features = (FeatureSequence) instance.getData();
for (int position = 0; position < features.size(); position++) {
localCounter.adjustOrPutValue(features.getIndexAtPosition(position), 1, 1);
}
}
else {
throw new IllegalArgumentException("Looking for a FeatureSequence, found a " +
instance.getData().getClass());
}
for (int feature: localCounter.keys()) {
counter.increment(feature);
}
numInstances++;
return instance;
}
示例2: train
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
@Override
public void train(List<? extends Annotated<OBJECT, ANNOTATION>> data) {
final HashSet<ANNOTATION> annotationsSet = new HashSet<ANNOTATION>();
final TIntIntHashMap nAnnotationCounts = new TIntIntHashMap();
int maxVal = 0;
for (final Annotated<OBJECT, ANNOTATION> sample : data) {
final Collection<ANNOTATION> annos = sample.getAnnotations();
annotationsSet.addAll(annos);
nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1);
if (annos.size() > maxVal)
maxVal = annos.size();
}
annotations = new ArrayList<ANNOTATION>(annotationsSet);
rnd = new Uniform(0, annotations.size() - 1, new MersenneTwister());
numAnnotations.train(data);
}
示例3: train
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
@Override
public <O, A> void train(List<? extends Annotated<O, A>> data) {
TIntIntHashMap nAnnotationCounts = new TIntIntHashMap();
int maxVal = 0;
for (Annotated<O, A> sample : data) {
Collection<A> annos = sample.getAnnotations();
nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1);
if (annos.size()>maxVal) maxVal = annos.size();
}
//build distribution and rng for the number of annotations
double [] distr = new double[maxVal+1];
for (int i=0; i<=maxVal; i++)
distr[i] = nAnnotationCounts.get(i);
numAnnotations = new EmpiricalWalker(distr, Empirical.NO_INTERPOLATION, new MersenneTwister());
}
示例4: findMaxClassCount
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
/**
* @param is
* @param invCor
* @return the cluster with the maximum
*/
public static IntIntPair findMaxClassCount(int[] is, Map<Integer, Integer> invCor) {
TIntIntHashMap classCounts = new TIntIntHashMap();
int max = 0;
int c = 0;
for (int i : is) {
Integer c_i = invCor.get(i);
if(c_i == null) continue;
int count = classCounts.adjustOrPutValue(c_i, 1, 1);
if(count > max){
max = count;
c = c_i;
}
}
return IntIntPair.pair(c, max);
}
示例5: processDate
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
private void processDate(String thisId, int year) {
assert(thisId != null);
if(currentId != null && !currentId.equals(thisId)) {
flush();
dateCounts = new TIntIntHashMap();
}
currentId = thisId;
dateCounts.adjustOrPutValue(year, 1, 1);
}
示例6: train
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
@Override
public void train(List<? extends Annotated<OBJECT, ANNOTATION>> data) {
final TIntIntHashMap nAnnotationCounts = new TIntIntHashMap();
final TObjectIntHashMap<ANNOTATION> annotationCounts = new TObjectIntHashMap<ANNOTATION>();
int maxVal = 0;
for (final Annotated<OBJECT, ANNOTATION> sample : data) {
final Collection<ANNOTATION> annos = sample.getAnnotations();
for (final ANNOTATION s : annos) {
annotationCounts.adjustOrPutValue(s, 1, 1);
}
nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1);
if (annos.size() > maxVal)
maxVal = annos.size();
}
// build distribution and rng for each annotation
annotations = new ArrayList<ANNOTATION>();
final TDoubleArrayList probs = new TDoubleArrayList();
annotationCounts.forEachEntry(new TObjectIntProcedure<ANNOTATION>() {
@Override
public boolean execute(ANNOTATION a, int b) {
annotations.add(a);
probs.add(b);
return true;
}
});
annotationProbability = new EmpiricalWalker(probs.toArray(), Empirical.NO_INTERPOLATION, new MersenneTwister());
numAnnotations.train(data);
}
示例7: computePaths
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
/**
* Extract paths from a user tree and an item tree
*
* @return paths map (path index:freq)
* @throws IOException
* @throws ClassNotFoundException
* @throws NumberFormatException
*/
public TIntIntHashMap computePaths(int item_id) {
TIntIntHashMap res = new TIntIntHashMap();
String item_pair_paths;
boolean reverse;
TIntIterator it = user_items.iterator();
while (it.hasNext()) {
reverse = false;
int user_item_id = it.next();
if (items_link.get(user_item_id).contains(item_id)) {
if (user_item_id != item_id) {
String user_item_rate = StringUtils.extractRate(
trainRatings.get(user_item_id), ratesThreshold);
String key = user_item_id + "-" + item_id;
if (!pathReader.containsKey(key)) {
reverse = true;
key = item_id + "-" + user_item_id;
}
item_pair_paths = loadPathsFromMap(key);
String[] pair_vals = item_pair_paths.split(",");
if (pair_vals.length > 0) {
for (String s : pair_vals) {
String[] path_freq = s.split("=");
int key1 = 0;
if (reverse)
key1 = extractKey(user_item_rate + "-inv_"
+ path_freq[0]);
else
key1 = extractKey(user_item_rate + "-"
+ path_freq[0]);
res.adjustOrPutValue(key1,
Integer.parseInt(path_freq[1]),
Integer.parseInt(path_freq[1]));
}
}
}
}
}
return res;
}
示例8: sampleTopicsForOneTestDocAll
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
private void sampleTopicsForOneTestDocAll(FeatureSequence tokenSequence,
LabelSequence topicSequence) {
// TODO Auto-generated method stub
int[] oneDocTopics = topicSequence.getFeatures();
TIntIntHashMap currentTypeTopicCounts;
int type, oldTopic, newTopic;
double tw;
double[] topicWeights = new double[numTopics];
double topicWeightsSum;
int docLength = tokenSequence.getLength();
// populate topic counts
int[] localTopicCounts = new int[numTopics];
for (int ti = 0; ti < numTopics; ti++){
localTopicCounts[ti] = 0;
}
for (int position = 0; position < docLength; position++) {
localTopicCounts[oneDocTopics[position]] ++;
}
// Iterate over the positions (words) in the document
for (int si = 0; si < docLength; si++) {
type = tokenSequence.getIndexAtPosition(si);
oldTopic = oneDocTopics[si];
// Remove this token from all counts
localTopicCounts[oldTopic] --;
currentTypeTopicCounts = typeTopicCounts[type];
assert(currentTypeTopicCounts.get(oldTopic) >= 0);
if (currentTypeTopicCounts.get(oldTopic) == 1) {
currentTypeTopicCounts.remove(oldTopic);
}
else {
currentTypeTopicCounts.adjustValue(oldTopic, -1);
}
tokensPerTopic[oldTopic]--;
// Build a distribution over topics for this token
Arrays.fill (topicWeights, 0.0);
topicWeightsSum = 0;
for (int ti = 0; ti < numTopics; ti++) {
tw = ((currentTypeTopicCounts.get(ti) + beta) / (tokensPerTopic[ti] + betaSum))
* ((localTopicCounts[ti] + alpha[ti])); // (/docLen-1+tAlpha); is constant across all topics
topicWeightsSum += tw;
topicWeights[ti] = tw;
}
// Sample a topic assignment from this distribution
newTopic = random.nextDiscrete (topicWeights, topicWeightsSum);
// Put that new topic into the counts
oneDocTopics[si] = newTopic;
currentTypeTopicCounts.adjustOrPutValue(newTopic, 1, 1);
localTopicCounts[newTopic] ++;
tokensPerTopic[newTopic]++;
}
}
示例9: sampleTopicsForOneTestDoc
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
private void sampleTopicsForOneTestDoc(FeatureSequence tokenSequence,
LabelSequence topicSequence) {
// TODO Auto-generated method stub
int[] oneDocTopics = topicSequence.getFeatures();
TIntIntHashMap currentTypeTopicCounts;
int type, oldTopic, newTopic;
double tw;
double[] topicWeights = new double[numTopics];
double topicWeightsSum;
int docLength = tokenSequence.getLength();
// populate topic counts
int[] localTopicCounts = new int[numTopics];
for (int ti = 0; ti < numTopics; ti++){
localTopicCounts[ti] = 0;
}
for (int position = 0; position < docLength; position++) {
if(oneDocTopics[position] != -1) {
localTopicCounts[oneDocTopics[position]] ++;
}
}
// Iterate over the positions (words) in the document
for (int si = 0; si < docLength; si++) {
type = tokenSequence.getIndexAtPosition(si);
oldTopic = oneDocTopics[si];
if(oldTopic == -1) {
continue;
}
// Remove this token from all counts
localTopicCounts[oldTopic] --;
currentTypeTopicCounts = typeTopicCounts[type];
assert(currentTypeTopicCounts.get(oldTopic) >= 0);
if (currentTypeTopicCounts.get(oldTopic) == 1) {
currentTypeTopicCounts.remove(oldTopic);
}
else {
currentTypeTopicCounts.adjustValue(oldTopic, -1);
}
tokensPerTopic[oldTopic]--;
// Build a distribution over topics for this token
Arrays.fill (topicWeights, 0.0);
topicWeightsSum = 0;
for (int ti = 0; ti < numTopics; ti++) {
tw = ((currentTypeTopicCounts.get(ti) + beta) / (tokensPerTopic[ti] + betaSum))
* ((localTopicCounts[ti] + alpha[ti])); // (/docLen-1+tAlpha); is constant across all topics
topicWeightsSum += tw;
topicWeights[ti] = tw;
}
// Sample a topic assignment from this distribution
newTopic = random.nextDiscrete (topicWeights, topicWeightsSum);
// Put that new topic into the counts
oneDocTopics[si] = newTopic;
currentTypeTopicCounts.adjustOrPutValue(newTopic, 1, 1);
localTopicCounts[newTopic] ++;
tokensPerTopic[newTopic]++;
}
}
示例10: sampleTopicsForOneDocWithTheta
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
private void sampleTopicsForOneDocWithTheta(FeatureSequence tokenSequence,
LabelSequence topicSequence, double[] topicDistribution) {
// TODO Auto-generated method stub
int[] oneDocTopics = topicSequence.getFeatures();
TIntIntHashMap currentTypeTopicCounts;
int type, oldTopic, newTopic;
double tw;
double[] topicWeights = new double[numTopics];
double topicWeightsSum;
int docLength = tokenSequence.getLength();
// Iterate over the positions (words) in the document
for (int si = 0; si < docLength; si++) {
type = tokenSequence.getIndexAtPosition(si);
oldTopic = oneDocTopics[si];
if(oldTopic == -1) {
continue;
}
currentTypeTopicCounts = typeTopicCounts[type];
assert(currentTypeTopicCounts.get(oldTopic) >= 0);
if (currentTypeTopicCounts.get(oldTopic) == 1) {
currentTypeTopicCounts.remove(oldTopic);
}
else {
currentTypeTopicCounts.adjustValue(oldTopic, -1);
}
tokensPerTopic[oldTopic]--;
// Build a distribution over topics for this token
Arrays.fill (topicWeights, 0.0);
topicWeightsSum = 0;
for (int ti = 0; ti < numTopics; ti++) {
tw = ((currentTypeTopicCounts.get(ti) + beta) / (tokensPerTopic[ti] + betaSum))
* topicDistribution[ti]; // (/docLen-1+tAlpha); is constant across all topics
topicWeightsSum += tw;
topicWeights[ti] = tw;
}
// Sample a topic assignment from this distribution
newTopic = random.nextDiscrete (topicWeights, topicWeightsSum);
// Put that new topic into the counts
oneDocTopics[si] = newTopic;
currentTypeTopicCounts.adjustOrPutValue(newTopic, 1, 1);
tokensPerTopic[newTopic]++;
}
}
示例11: estimateModel
import gnu.trove.map.hash.TIntIntHashMap; //导入方法依赖的package包/类
@Override
public void estimateModel(MBFImage... images) {
for (int i=0; i<ndims; i++) {
mean[i] = 0;
TFloatArrayList values = new TFloatArrayList();
TIntIntHashMap freqs = new TIntIntHashMap();
int count = 0;
for (MBFImage im : images) {
FImage band = im.getBand(i);
for (int r=0; r<band.height; r++) {
for (int c=0; c<band.width; c++) {
float val = band.pixels[r][c];
mean[i] += val;
values.add(val);
freqs.adjustOrPutValue(Math.round(val*255F), 1, 1);
count++;
}
}
}
//mean
mean[i] /= count;
//median
values.sort();
int idx = values.size() / 2;
if (values.size() % 2 == 0) {
median[i] = (values.get(idx) + values.get(idx - 1)) / 2.0;
} else {
median[i] = values.get(idx);
}
//mode
HashMax hm = new HashMax();
freqs.forEachEntry(hm);
mode[i] = hm.idx / 255.0;
//range
range[i] = values.get(values.size() - 1) - values.get(0);
//variance
variance[i] = 0;
for (int j=0; j<values.size(); j++) {
variance[i] += (values.get(j) - mean[i]) * (values.get(j) - mean[i]);
}
variance[i] = sqrt(variance[i] / values.size());
}
}