pescadores / pescador

Stochastic multi-stream sampling for iterative learning
https://pescador.readthedocs.io
ISC License
76 stars 12 forks source link

bug with integer-valued weights in *Mux #143

Closed lostanlen closed 5 years ago

lostanlen commented 5 years ago

A minimal (non)-working example

import numpy
import pescador

def yield_0():
    while True:
        yield 0

def yield_1():
    while True:
        yield 1

stream_0 = pescador.Streamer(yield_0)
stream_1 = pescador.Streamer(yield_1)

weights = np.array([1, 1])

# This passes
mux = pescador.ShuffledMux(
    [stream_0, stream_1], weights=weights.astype('float'))

# This fails
#mux = pescador.ShuffledMux(
#    [stream_0, stream_1], weights=weights)

Traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-22c8073f17b0> in <module>()
    189 
    190     # Multiplex streamers together.
--> 191     mux = pescador.ShuffledMux(streams, weights=stream_weights)
    192     muxes.append(mux)
    193 

~/miniconda3/envs/bvfs/lib/python3.5/site-packages/pescador/mux.py in __init__(self, streamers, weights, random_state)
    884                                 'one positive value')
    885 
--> 886         self.weights /= np.sum(self.weights)
    887 
    888     def _activate(self):

TypeError: No loop matching the specified signature and casting
was found for ufunc true_divide
bmcfee commented 5 years ago

This can be fixed with a hard dtype=np.float when initializing the weights field. But we should put in some proper tests first. Meanwhile, a workaround is just to cast your weights to foats before instantiating the mux, as demonstrated in the example above.

cjacoby commented 5 years ago

I'm happy to implement that, but probably can't happen for a few days.

On Wed, Dec 5, 2018 at 9:04 AM Brian McFee notifications@github.com wrote:

This can be fixed with a hard dtype=np.float when initializing the weights field. But we should put in some proper tests first. Meanwhile, a workaround is just to cast your weights to foats before instantiating the mux, as demonstrated in the example above.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pescadores/pescador/issues/143#issuecomment-444562945, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4t88hUVijKeKdcxV6_l1rfz5d2NJrMks5u1_y6gaJpZM4ZBshh .