Search in sources :

Example 1 with Entry

use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project gridss by PapenfussLab.

the class IntervalCoverageAccumulator method writeToBed.

public void writeToBed(File bed) throws IOException {
    try (BedWriter writer = new BedWriter(dictionary, bed)) {
        for (int i = 0; i < coverage.length; i++) {
            ObjectBidirectionalIterator<Entry> it = coverage[i].iterator();
            while (it.hasNext()) {
                Entry e = it.next();
                int start = e.getIntKey();
                int binWidth = coverage[i].getBinSize(start);
                int end = start + binWidth - 1;
                writer.write(i, start, end, coverage[i].getMeanValue(start));
            }
        }
    }
}
Also used : Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) BedWriter(au.edu.wehi.idsv.bed.BedWriter)

Example 2 with Entry

use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project angel by Tencent.

the class ByteBufSerdeUtils method serializeIntDoubleVector.

// IntDoubleVector
private static void serializeIntDoubleVector(ByteBuf out, IntDoubleVector vector) {
    IntDoubleVectorStorage storage = vector.getStorage();
    if (storage.isDense()) {
        serializeInt(out, DENSE_STORAGE_TYPE);
        serializeDoubles(out, storage.getValues());
    } else if (storage.isSparse()) {
        serializeInt(out, SPARSE_STORAGE_TYPE);
        serializeInt(out, storage.size());
        ObjectIterator<Entry> iter = storage.entryIterator();
        while (iter.hasNext()) {
            Entry e = iter.next();
            serializeInt(out, e.getIntKey());
            serializeDouble(out, e.getDoubleValue());
        }
    } else if (storage.isSorted()) {
        serializeInt(out, SORTED_STORAGE_TYPE);
        int[] indices = vector.getStorage().getIndices();
        double[] values = vector.getStorage().getValues();
        serializeInts(out, indices);
        serializeDoubles(out, values);
    } else {
        throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
    }
}
Also used : Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 3 with Entry

use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project angel by Tencent.

the class StreamSerdeUtils method serializeIntDoubleVector.

// IntDoubleVector
private static void serializeIntDoubleVector(DataOutputStream out, IntDoubleVector vector) throws IOException {
    IntDoubleVectorStorage storage = vector.getStorage();
    if (storage.isDense()) {
        serializeInt(out, DENSE_STORAGE_TYPE);
        serializeDoubles(out, storage.getValues());
    } else if (storage.isSparse()) {
        serializeInt(out, SPARSE_STORAGE_TYPE);
        serializeInt(out, storage.size());
        ObjectIterator<Entry> iter = storage.entryIterator();
        while (iter.hasNext()) {
            Entry e = iter.next();
            serializeInt(out, e.getIntKey());
            serializeDouble(out, e.getDoubleValue());
        }
    } else if (storage.isSorted()) {
        serializeInt(out, SORTED_STORAGE_TYPE);
        int[] indices = vector.getStorage().getIndices();
        double[] values = vector.getStorage().getValues();
        serializeInts(out, indices);
        serializeDoubles(out, values);
    } else {
        throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
    }
}
Also used : Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 4 with Entry

use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project gridss by PapenfussLab.

the class IntervalAccumulator method add.

/**
 * Add the given value at all positions in the given interval
 * @param start start position (inclusive)
 * @param end end position (inclusive)
 * @param value value to add
 */
public void add(int start, int end, double value) {
    if (binWidth == null) {
        throw new IllegalStateException("Must be called after finaliseBins()");
    }
    if (end < start) {
        throw new IllegalArgumentException("end cannot be before start");
    }
    // double perBaseValue = value / (end - start + 1);
    start = Math.max(start, firstBinStart);
    end = Math.min(end, lastBinEnd);
    int startBinStartKey = bins.headMap(start + 1).lastIntKey();
    int endBinStartKey = bins.headMap(end + 1).lastIntKey();
    Int2DoubleSortedMap toUpdate = bins.subMap(startBinStartKey, endBinStartKey + 1);
    ObjectBidirectionalIterator<Int2DoubleMap.Entry> it = toUpdate.int2DoubleEntrySet().iterator();
    int widthLeft = end - start + 1;
    while (widthLeft > 0) {
        assert (it.hasNext());
        Int2DoubleMap.Entry entry = it.next();
        int entryStartPosition = entry.getIntKey();
        int overlap = IntervalUtil.overlapsWidthClosed(start, end, entryStartPosition, entryStartPosition + getBinSize(entryStartPosition) - 1);
        entry.setValue(entry.getDoubleValue() + overlap * value);
        widthLeft -= overlap;
    }
}
Also used : Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) Int2DoubleSortedMap(it.unimi.dsi.fastutil.ints.Int2DoubleSortedMap) Int2DoubleMap(it.unimi.dsi.fastutil.ints.Int2DoubleMap) Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry)

Aggregations

Entry (it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry)4 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)2 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)2 BedWriter (au.edu.wehi.idsv.bed.BedWriter)1 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)1 Int2DoubleSortedMap (it.unimi.dsi.fastutil.ints.Int2DoubleSortedMap)1