it.unimi.dsi.fastutil.doubles.DoubleIterator Java Examples

The following examples show how to use it.unimi.dsi.fastutil.doubles.DoubleIterator. 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: DioriteRandomUtils.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
public static <T> T getWeightedRandomReversed(Random random, Double2ObjectMap<T> choices)
{
    double i = 0;
    DoubleSet doubles = choices.keySet();
    for (DoubleIterator iterator = doubles.iterator(); iterator.hasNext(); )
    {
        double x = iterator.nextDouble();
        i += x;
    }
    i = getRandomDouble(random, 0, i);
    for (Double2ObjectMap.Entry<T> entry : choices.double2ObjectEntrySet())
    {
        i -= entry.getDoubleKey();
        if (i < 0)
        {
            return entry.getValue();
        }
    }
    return null;
}
 
Example #2
Source File: DioriteRandomUtils.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
public static <T> T getWeightedRandom(Random random, Object2DoubleMap<T> choices)
{
    double i = 0;
    DoubleCollection doubles = choices.values();
    for (DoubleIterator iterator = doubles.iterator(); iterator.hasNext(); )
    {
        double x = iterator.nextDouble();
        i += x;
    }
    i = getRandomDouble(random, 0, i);
    for (Object2DoubleMap.Entry<T> entry : choices.object2DoubleEntrySet())
    {
        i -= entry.getDoubleValue();
        if (i < 0)
        {
            return entry.getKey();
        }
    }
    return null;
}
 
Example #3
Source File: DoubleRangeIterable.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
public DoubleIterator iterator() {

    return new DoubleIterator() {

      double next = from;
      int num = 0;

      @Override
      public boolean hasNext() {
        return (count < 0 || num < count)
            && (Double.isNaN(to)
                || Math.abs(next - from) < Math.abs(to - from)
                || (including && next == to));
      }

      @Override
      public double nextDouble() {
        final double current = next;
        next += by;
        num++;
        return current;
      }
    };
  }
 
Example #4
Source File: VectorSimilarity.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
private Int2DoubleMap getProductMap(int uidx) {
    Int2DoubleOpenHashMap productMap = new Int2DoubleOpenHashMap();
    productMap.defaultReturnValue(0.0);

    if (data.useIteratorsPreferentially()) {
        IntIterator iidxs = data.getUidxIidxs(uidx);
        DoubleIterator ivs = data.getUidxVs(uidx);
        while (iidxs.hasNext()) {
            int iidx = iidxs.nextInt();
            double iv = ivs.nextDouble();
            IntIterator vidxs = data.getIidxUidxs(iidx);
            DoubleIterator vvs = data.getIidxVs(iidx);
            while (vidxs.hasNext()) {
                productMap.addTo(vidxs.nextInt(), iv * vvs.nextDouble());
            }
        }
    } else {
        data.getUidxPreferences(uidx)
                .forEach(ip -> data.getIidxPreferences(ip.v1)
                        .forEach(up -> productMap.addTo(up.v1, ip.v2 * up.v2)));
    }

    productMap.remove(uidx);

    return productMap;
}
 
Example #5
Source File: VectorSimilarity.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
private double[] getProductArray(int uidx) {
    double[] productArray = new double[data.numUsers()];

    if (data.useIteratorsPreferentially()) {
        IntIterator iidxs = data.getUidxIidxs(uidx);
        DoubleIterator ivs = data.getUidxVs(uidx);
        while (iidxs.hasNext()) {
            int iidx = iidxs.nextInt();
            double iv = ivs.nextDouble();
            IntIterator vidxs = data.getIidxUidxs(iidx);
            DoubleIterator vvs = data.getIidxVs(iidx);
            while (vidxs.hasNext()) {
                productArray[vidxs.nextInt()] += iv * vvs.nextDouble();
            }
        }
    } else {
        data.getUidxPreferences(uidx)
                .forEach(ip -> data.getIidxPreferences(ip.v1)
                        .forEach(up -> productArray[up.v1] += ip.v2 * up.v2));
    }

    productArray[uidx] = 0.0;

    return productArray;
}
 
Example #6
Source File: VectorSimilarity.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
private double getNorm2(int uidx) {
    if (data.useIteratorsPreferentially()) {
        DoubleIterator ivs = data.getUidxVs(uidx);
        double sum = 0;
        while (ivs.hasNext()) {
            double iv = ivs.nextDouble();
            sum += iv * iv;
        }
        return sum;
    } else {
        return data.getUidxPreferences(uidx)
                .mapToDouble(IdxPref::v2)
                .map(x -> x * x)
                .sum();
    }
}
 
Example #7
Source File: DoubleRangeIterable.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
public DoubleIterator iterator() {

    return new DoubleIterator() {

      double next = from;
      int num = 0;

      @Override
      public boolean hasNext() {
        return (count < 0 || num < count)
            && (Double.isNaN(to)
                || Math.abs(next - from) < Math.abs(to - from)
                || (including && next == to));
      }

      @Override
      public double nextDouble() {
        final double current = next;
        next += by;
        num++;
        return current;
      }
    };
  }
 
Example #8
Source File: FastTreeHashVector.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isBad() {
	final DoubleIterator iterator = values.values().iterator();
	while (iterator.hasNext()) {
		final double value = iterator.nextDouble();
		if (Double.isNaN(value) || Double.isInfinite(value)) {
			return true;
		}
	}
	return false;
}
 
Example #9
Source File: RatingCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
private static <Cv> DoubleIterator getVs(Cv cvs, int len, CODEC<Cv> r_codec) {
    if (len == 0) {
        return DoubleIterators.EMPTY_ITERATOR;
    }
    int[] vsi = new int[len];
    r_codec.dec(cvs, vsi, 0, len);
    double[] vsd = new double[len];
    for (int i = 0; i < len; i++) {
        vsd[i] = vsi[i];
    }
    return new ArrayDoubleIterator(vsd);
}
 
Example #10
Source File: SQLPreferenceData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public DoubleIterator getIidxVs(int iidx) {
    return new StreamDoubleIterator(dsl
            .select(V)
            .from(DATA)
            .where(IIDX.eq(iidx))
            .fetch().stream()
            .mapToDouble(Record1::value1));
}
 
Example #11
Source File: SQLPreferenceData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public DoubleIterator getUidxVs(int uidx) {
    return new StreamDoubleIterator(dsl
            .select(V)
            .from(DATA)
            .where(UIDX.eq(uidx))
            .fetch().stream()
            .mapToDouble(Record1::value1));
}
 
Example #12
Source File: DoubleColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleColumn fillWith(final DoubleIterator iterator) {
  for (int r = 0; r < size(); r++) {
    if (!iterator.hasNext()) {
      break;
    }
    set(r, iterator.nextDouble());
  }
  return this;
}
 
Example #13
Source File: DoubleColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleColumn fillWith(final DoubleRangeIterable iterable) {
  DoubleIterator iterator = iterable.iterator();
  for (int r = 0; r < size(); r++) {
    if (!iterator.hasNext()) {
      iterator = iterable.iterator();
      if (!iterator.hasNext()) {
        break;
      }
    }
    set(r, iterator.nextDouble());
  }
  return this;
}
 
Example #14
Source File: DictionaryValuesWriter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public DictionaryPage toDictPageAndClose() {
  if (lastUsedDictionarySize > 0) {
    // return a dictionary only if we actually used it
    PlainValuesWriter dictionaryEncoder = new PlainValuesWriter(lastUsedDictionaryByteSize, maxDictionaryByteSize, allocator);
    DoubleIterator doubleIterator = doubleDictionaryContent.keySet().iterator();
    // write only the part of the dict that we used
    for (int i = 0; i < lastUsedDictionarySize; i++) {
      dictionaryEncoder.writeDouble(doubleIterator.nextDouble());
    }
    return dictPage(dictionaryEncoder);
  }
  return null;
}
 
Example #15
Source File: DoubleColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleColumn fillWith(final DoubleRangeIterable iterable) {
  DoubleIterator iterator = iterable.iterator();
  for (int r = 0; r < size(); r++) {
    if (!iterator.hasNext()) {
      iterator = iterable.iterator();
      if (!iterator.hasNext()) {
        break;
      }
    }
    set(r, iterator.nextDouble());
  }
  return this;
}
 
Example #16
Source File: DoubleColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleColumn fillWith(final DoubleIterator iterator) {
  for (int r = 0; r < size(); r++) {
    if (!iterator.hasNext()) {
      break;
    }
    set(r, iterator.nextDouble());
  }
  return this;
}
 
Example #17
Source File: PreferenceDataWrapper.java    From rival with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(int uidx) {
    return wrapper.getUidxVs(uidx);
}
 
Example #18
Source File: SingleThresholdProvider.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
OptionalDouble getNext(double threshold) {
	DoubleIterator it = steps.iterator(threshold);
	return IteratorUtils.next(it);
}
 
Example #19
Source File: PreferenceDataWrapper.java    From rival with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(int iidx) {
    return wrapper.getIidxVs(iidx);
}
 
Example #20
Source File: RatingCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(final int iidx) {
    return getVs(i_vs[iidx], i_len[iidx], r_codec);
}
 
Example #21
Source File: RatingCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(final int uidx) {
    return getVs(u_vs[uidx], u_len[uidx], r_codec);
}
 
Example #22
Source File: BinaryCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(final int iidx) {
    double[] vs = new double[i_len[iidx]];
    Arrays.fill(vs, 1.0);
    return new ArrayDoubleIterator(vs);
}
 
Example #23
Source File: BinaryCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(final int uidx) {
    double[] vs = new double[u_len[uidx]];
    Arrays.fill(vs, 1.0);
    return new ArrayDoubleIterator(vs);
}
 
Example #24
Source File: IteratorsAbstractFastPreferenceDataTest.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(int iidx) {
    return new StreamDoubleIterator(DoubleStream.of(6.0, 5.0, 4.0, 3.0, 2.0));
}
 
Example #25
Source File: IteratorsAbstractFastPreferenceDataTest.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(int uidx) {
    return new StreamDoubleIterator(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
}
 
Example #26
Source File: TransposedPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(int iidx) {
    return d.getUidxVs(iidx);
}
 
Example #27
Source File: TransposedPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(int uidx) {
    return d.getIidxVs(uidx);
}
 
Example #28
Source File: StreamsAbstractFastPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getIidxVs(int iidx) {
    return new StreamDoubleIterator(getIidxPreferences(iidx).mapToDouble(IdxPref::v2));
}
 
Example #29
Source File: StreamsAbstractFastPreferenceData.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DoubleIterator getUidxVs(int uidx) {
    return new StreamDoubleIterator(getUidxPreferences(uidx).mapToDouble(IdxPref::v2));
}
 
Example #30
Source File: FastPreferenceData.java    From RankSys with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Returns the user values of the preferences for an item.
 *
 * @param iidx item index
 * @return iterator of the values of the users
 */
DoubleIterator getIidxVs(final int iidx);