Reservoir sampling improvements
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 30/100
Línea de trabajo
No se nombra ningún archivo ni prueba. Primero localiza la implementación de reservoir-sampling y sus rutas de serialización y combinación, y después separa las mejoras propuestas en un cambio acotado; no se considerará terminado hasta acordar un enfoque y sus pruebas de compatibilidad y probabilidad.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
We can make a number of improvements to reservoir sampling:
- We can go from 2 random draws per accepted sample to 1 by picking a random long from 0 to n and accepting if it's less than k -- which also provides the location to use. This would get around the current max size bit limit (which is unlikely to be an issue, but still) by removing the use of a double for a value in [0, 1). But that'd also require a new serialization version since n is currently stored with fewer than 64 bits.
- After discussing with a stats person about a year ago, we believe we could even switch to a random draw from the distribution for the next item, dropping the random draws to O(accepted items) rather than O(n). As long as merges happen independent of that random draw (so no adversary able to inspect it) then we should be able to merge and re-draw for the merged sample.
- Merge can be improved to give uniform second-order probabilities. This is the exciting one for me. But there's a caveat.
Proposed merge, with python pseudocode:
# Merge two random samples. Samples are lists s1 and s2. The numbers n1 and n2
# are the sizes of the sets from which s1 and s2 were sampled. Value s is the specified
# size for the merged sample. Requires s <= len(s1) and s <= len(s2).
def merge(s1, s2, n1, n2, s):
# Find number to draw from s1. (The others will be from s2.)
t = 0 # Number of observations to draw from s1.
for i in range(s):
j = random.randint(1, n1 + n2)
if j <= n1:
t += 1
n1 -= 1
else: n2 -= 1
# Draw the samples.
a = random.sample(s1, t) # Sample without replacement.
b = random.sample(s2, s - t) # Sample without replacement.
return a + b # Make one list with the elements of a and b.
The random sample without replacement is important here, which is the source of the caveat: You can almost use the first t and s-t samples from s1 and s2, respectively, except that there's a position bias from the initial reservoir fill. For items 0 to k-1, they can only ever appear at that specific index. We don't start placing randomly until after the reservoir is filled.
The options I can think of for this:
- Randomly permute items when the reservoir fills. If it hasn't filled at merge, you're just inserting as new items of weight 1 anyway. Doesn't help with already-serialized samples.
- Randomly permute the input sample at merge (a modified Fisher-Yates shuffle since you can stop after the first t or s-t items). But this is an undesirable side-effect for merging, even if it doesn't impact the probabilities.
- Copy the array and permute that. Uses more space, and potentially a lot more for a large reservoir, but avoids side-effects. Probably permute an array of integer indices to avoid creating an array of arbitrary objects.
Maybe we can mix 1 and 3? For new samples, randomly permute upon fill and track that with a flag (which would need to be serialized going forward, of course). If a sample needs to be merged and doesn't have the flag, then copy and permute the array.
This should probably have been 3 separate issues. But wanted to document the ideas before I forget yet again.
- Lenguaje dominante
- Java
- Estrellas
- 958
- Forks
- 226
- Merge medio
- 3 d 40 min
- PR fusionados (30 d)
- 13
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/datasketches-java
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
apache/datasketches-java#731 · 16 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
apache/datasketches-java#739 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
apache/datasketches-java#720 · 3 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
apache/datasketches-java#693 · 13 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
apache/datasketches-java#569 ·
Todos los issues de apache/datasketches-java
Issues similares
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Abierto1.0.0-alpha2 Type/Improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
wso2/dpdp-accelerator#272 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
apache/rocketmq-dashboard#4860 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
infinispan/infinispan#18150 ·