本文整理汇总了Java中it.unimi.dsi.fastutil.objects.Object2IntMap类的典型用法代码示例。如果您正苦于以下问题:Java Object2IntMap类的具体用法?Java Object2IntMap怎么用?Java Object2IntMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Object2IntMap类属于it.unimi.dsi.fastutil.objects包,在下文中一共展示了Object2IntMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clone
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
/**
* Create an independent copy of this read-likelihoods collection
*/
public ReadLikelihoods<A> clone() {
final int sampleCount = samples.sampleCount();
final int alleleCount = alleles.alleleCount();
final double[][][] newLikelihoodValues = new double[sampleCount][alleleCount][];
@SuppressWarnings("unchecked")
final Object2IntMap<GATKSAMRecord>[] newReadIndexBySampleIndex = new Object2IntMap[sampleCount];
final GATKSAMRecord[][] newReadsBySampleIndex = new GATKSAMRecord[sampleCount][];
for (int s = 0; s < sampleCount; s++) {
newReadsBySampleIndex[s] = readsBySampleIndex[s].clone();
for (int a = 0; a < alleleCount; a++)
newLikelihoodValues[s][a] = valuesBySampleIndex[s][a].clone();
}
// Finally we create the new read-likelihood
return new ReadLikelihoods<>(alleles, samples,
newReadsBySampleIndex,
newReadIndexBySampleIndex, newLikelihoodValues);
}
示例2: changeReads
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
public void changeReads(final Map<GATKSAMRecord, GATKSAMRecord> readRealignments) {
final int sampleCount = samples.sampleCount();
for (int s = 0; s < sampleCount; s++) {
final GATKSAMRecord[] sampleReads = readsBySampleIndex[s];
final Object2IntMap<GATKSAMRecord> readIndex = readIndexBySampleIndex[s];
final int sampleReadCount = sampleReads.length;
for (int r = 0; r < sampleReadCount; r++) {
final GATKSAMRecord read = sampleReads[r];
final GATKSAMRecord replacement = readRealignments.get(read);
if (replacement == null)
continue;
sampleReads[r] = replacement;
if (readIndex != null) {
readIndex.remove(read);
readIndex.put(replacement, r);
}
}
}
}
示例3: calculateDocVec
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
public Object2IntMap<String> calculateDocVec(List<String> tokens) {
Object2IntMap<String> docVec = new Object2IntOpenHashMap<String>();
// add the word-based vector
if(this.createWordAtts)
docVec.putAll(affective.core.Utils.calculateTermFreq(tokens,UNIPREFIX,this.freqWeights));
if(this.createClustAtts){
// calcultates the vector of clusters
List<String> brownClust=affective.core.Utils.clustList(tokens,brownDict);
docVec.putAll(affective.core.Utils.calculateTermFreq(brownClust,CLUSTPREFIX,this.freqWeights));
}
return docVec;
}
示例4: calculateDocVec
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
public Object2IntMap<String> calculateDocVec(List<String> tokens) {
Object2IntMap<String> docVec = new Object2IntOpenHashMap<String>();
// add the word-based vector
if(this.createWordAtts)
docVec.putAll(affective.core.Utils.calculateTermFreq(tokens,UNIPREFIX,this.freqWeights));
if(this.createClustAtts){
// calcultates the vector of clusters
List<String> brownClust=affective.core.Utils.clustList(tokens,brownDict);
docVec.putAll(affective.core.Utils.calculateTermFreq(brownClust,CLUSTPREFIX,this.freqWeights));
}
return docVec;
}
示例5: calculateTermFreq
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
/**
* Calculates a vector of attributes from a list of tokens
*
* @param tokens the input tokens
* @param prefix the prefix of each vector attribute
* @return an Object2IntMap object mapping the attributes to their values
*/
public static Object2IntMap<String> calculateTermFreq(List<String> tokens, String prefix, boolean freqWeights) {
Object2IntMap<String> termFreq = new Object2IntOpenHashMap<String>();
// Traverse the strings and increments the counter when the token was
// already seen before
for (String token : tokens) {
// add frequency weights if the flat is set
if(freqWeights)
termFreq.put(prefix+token, termFreq.getInt(prefix+token) + 1);
// otherwise, just consider boolean weights
else{
if(!termFreq.containsKey(token))
termFreq.put(prefix+token, 1);
}
}
return termFreq;
}
示例6: startsWith
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
default Selection startsWith(String string) {
Selection results = new BitmapBackedSelection();
IntRBTreeSet sorted = new IntRBTreeSet();
DictionaryMap dictionaryMap = this.dictionaryMap();
for (Object2IntMap.Entry<String> entry : dictionaryMap.valueToKeyMap().object2IntEntrySet()) {
String key = entry.getKey();
if (key.startsWith(string)) {
sorted.add(entry.getIntValue());
}
}
int i = 0;
for (int next : values()) {
if (sorted.contains(next)) {
results.add(i);
}
i++;
}
return results;
}
示例7: getWeightedRandom
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
@Nullable
public static <T> T getWeightedRandom(Random random, Object2IntMap<T> choices)
{
long i = 0;
IntCollection ints = choices.values();
for (IntIterator iterator = ints.iterator(); iterator.hasNext(); )
{
int x = iterator.nextInt();
i += x;
}
i = getRandomLong(random, 0, i);
for (Object2IntMap.Entry<T> entry : choices.object2IntEntrySet())
{
i -= entry.getIntValue();
if (i < 0)
{
return entry.getKey();
}
}
return null;
}
示例8: arrangeTargets
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
/**
* Rearrange the targets so that they are in a particular order.
* @return a new collection.
* @throws IllegalArgumentException if any of the following is true:
* <ul>
* <li>{@code targetsInOrder} is {@code null},</li>
* <li>is empty,</li>
* <li>it contains {@code null},</li>
* <li>contains any target not present in this collection.</li>
* </ul>
*/
public ReadCountCollection arrangeTargets(final List<Target> targetsInOrder) {
Utils.nonNull(targetsInOrder);
Utils.nonEmpty(targetsInOrder, "the input targets list cannot be empty");
final RealMatrix counts = new Array2DRowRealMatrix(targetsInOrder.size(), columnNames.size());
final Object2IntMap<Target> targetToIndex = new Object2IntOpenHashMap<>(targets.size());
for (int i = 0; i < targets.size(); i++) {
targetToIndex.put(targets.get(i), i);
}
for (int i = 0; i < targetsInOrder.size(); i++) {
final Target target = targetsInOrder.get(i);
Utils.validateArg(targetToIndex.containsKey(target), () -> String.format("target '%s' is not present in the collection", target.getName()));
counts.setRow(i, this.counts.getRow(targetToIndex.getInt(target)));
}
return new ReadCountCollection(new ArrayList<>(targetsInOrder), columnNames, counts, false);
}
示例9: remove
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
@Override
public void remove(FHashMapObjectInt<String> v) {
for (Object2IntMap.Entry<String> entry : v.object2IntEntrySet()) {
int current = getInt(entry.getKey());
sumflog -= getPLogP(current);
if (entry.getIntValue() > current) {
log.fatal("remove cannot remove value greater than current key %s current %d remove %d", entry.getKey(), current, entry.getValue());
} else if (entry.getIntValue() == current) {
remove(entry.getKey());
} else {
put(entry.getKey(), current - entry.getIntValue());
sumflog += getPLogP(current - entry.getIntValue());
total -= entry.getIntValue();
}
}
magnitude = null;
}
示例10: ReadLikelihoods
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
/**
* Constructs a new read-likelihood collection.
*
* <p>
* The initial likelihoods for all allele-read combinations are
* 0.
* </p>
*
* @param samples all supported samples in the collection.
* @param alleles all supported alleles in the collection.
* @param reads reads stratified per sample.
*
* @throws IllegalArgumentException if any of {@code allele}, {@code samples}
* or {@code reads} is {@code null},
* or if they contain null values.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public ReadLikelihoods(final SampleList samples,
final AlleleList<A> alleles,
final Map<String, List<GATKRead>> reads) {
Utils.nonNull(alleles, "allele list cannot be null");
Utils.nonNull(samples, "sample list cannot be null");
Utils.nonNull(reads, "read map cannot be null");
this.samples = samples;
this.alleles = alleles;
final int sampleCount = samples.numberOfSamples();
final int alleleCount = alleles.numberOfAlleles();
readsBySampleIndex = new GATKRead[sampleCount][];
readListBySampleIndex = (List<GATKRead>[])new List[sampleCount];
valuesBySampleIndex = new double[sampleCount][][];
referenceAlleleIndex = findReferenceAllele(alleles);
readIndexBySampleIndex = new Object2IntMap[sampleCount];
setupIndexes(reads, sampleCount, alleleCount);
sampleMatrices = (LikelihoodMatrix<A>[]) new LikelihoodMatrix[sampleCount];
}
示例11: changeReads
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
public void changeReads(final Map<GATKRead, GATKRead> readRealignments) {
final int sampleCount = samples.numberOfSamples();
for (int s = 0; s < sampleCount; s++) {
final GATKRead[] sampleReads = readsBySampleIndex[s];
final Object2IntMap<GATKRead> readIndex = readIndexBySampleIndex[s];
final int sampleReadCount = sampleReads.length;
for (int r = 0; r < sampleReadCount; r++) {
final GATKRead read = sampleReads[r];
final GATKRead replacement = readRealignments.get(read);
if (replacement == null) {
continue;
}
sampleReads[r] = replacement;
if (readIndex != null) {
readIndex.remove(read);
readIndex.put(replacement, r);
}
}
}
}
示例12: appendReads
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
private void appendReads(final List<GATKRead> newSampleReads, final int sampleIndex,
final int sampleReadCount, final int newSampleReadCount) {
final GATKRead[] sampleReads = readsBySampleIndex[sampleIndex] =
Arrays.copyOf(readsBySampleIndex[sampleIndex], newSampleReadCount);
int nextReadIndex = sampleReadCount;
final Object2IntMap<GATKRead> sampleReadIndex = readIndexBySampleIndex[sampleIndex];
for (final GATKRead newRead : newSampleReads) {
// if (sampleReadIndex.containsKey(newRead)) // might be worth handle this without exception (ignore the read?) but in practice should never be the case.
// throw new IllegalArgumentException("you cannot add reads that are already in read-likelihood collection");
if (sampleReadIndex != null ) {
sampleReadIndex.put(newRead, nextReadIndex);
}
sampleReads[nextReadIndex++] = newRead;
}
}
示例13: add
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
private <T> boolean add(Object2IntMap<T> map, T item) {
if (!map.containsKey(item)) {
map.put(item, NOT_SET);
return true;
}
return false;
}
示例14: lookup
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
private <T> int lookup(T item, Object2IntMap<T> table) {
if (item == null) {
return Constants.NO_OFFSET;
}
int offset = table.getInt(item);
assert offset != NOT_SET && offset != NOT_KNOWN;
return offset;
}
示例15: ReadLikelihoods
import it.unimi.dsi.fastutil.objects.Object2IntMap; //导入依赖的package包/类
/**
* Constructs a new read-likelihood collection.
* <p>
* <p>
* The initial likelihoods for all allele-read combinations are
* 0.
* </p>
*
* @param samples all supported samples in the collection.
* @param alleles all supported alleles in the collection.
* @param reads reads stratified per sample.
* @throws IllegalArgumentException if any of {@code allele}, {@code samples}
* or {@code reads} is {@code null},
* or if they contain null values.
*/
@SuppressWarnings("unchecked")
public ReadLikelihoods(final SampleList samples, final AlleleList<A> alleles,
final Map<String, List<GATKSAMRecord>> reads, boolean useCache) {
if (alleles == null)
throw new IllegalArgumentException("allele list cannot be null");
if (samples == null)
throw new IllegalArgumentException("sample list cannot be null");
if (reads == null)
throw new IllegalArgumentException("read map cannot be null");
this.samples = samples;
this.alleles = alleles;
final int sampleCount = samples.sampleCount();
final int alleleCount = alleles.alleleCount();
readsBySampleIndex = new GATKSAMRecord[sampleCount][];
readListBySampleIndex = new List[sampleCount];
valuesBySampleIndex = new double[sampleCount][][];
referenceAlleleIndex = findReferenceAllele(alleles);
readIndexBySampleIndex = new Object2IntMap[sampleCount];
setupIndexes(reads, sampleCount, alleleCount, useCache);
sampleMatrices = (Matrix<A>[]) new Matrix[sampleCount];
}