change rate parameter in Poisson to Float32 - #147
Conversation
The VType of the rate parameter in Poisson is the same as the Type of the samples returned. For Poisson, that is Integer. But the rate should be a Float parameter. This commit decouples the two,
| stndExp / rate | ||
|
|
||
| class Poisson[T <: Tuple: Labels, V: IsInteger](val rate: Tensor[T, V]) extends IndependentDistribution[T, V]: | ||
| class Poisson[T <: Tuple: Labels, V: IsInteger](val rate: Tensor[T, Float32]) extends IndependentDistribution[T, V]: |
There was a problem hiding this comment.
Maybe we should add a vtype: VType[V] argument here? Currently, the V must be provided by the user in type parameters.
We could also hard-code this to Int32.
There was a problem hiding this comment.
I suggest adding vtype here and keeping default constructor in object Poisson that defaults to Int32
There was a problem hiding this comment.
There are two thins to distinguish:
- The rate, which is a floating point value (that was the bug
- The sampled Value, which is an integer.
One solution would be to have 2 type parameters V : IsFloat and R: IsInteger.
Having both adapted to precision makes the class a bit harder to use. I don´t have much experience with precision types and when they are strictly needed, but my guess would be that the rate (V) is maybe less critical then the number of occurences (R) . What do you think? If you had to choose to hard-code one, which would it be? Or do you think we should have both user defined?
There was a problem hiding this comment.
The rate (V) is easier for the user to define, as it is set by the rate parameter.
The occurrences (R) are the problem, as the type parameter must be provided by the user, which would require a vtype by our design.
I would suggest:
class Poisson[T <: Tuple: Labels, VRate: IsInteger, V](val vtype: VType[V], val rate: Tensor[T, VRate]) extends IndependentDistribution[T, V]:
object Possion:
def apply(...) = Poissoin(VType[Int32], ...)Note that the implementation should use the vtype that the precision actually matches the underlying tensor data type, something like:
override def sample(k: Random.Key): Tensor[T, V] =
liftPyTensor(
Jax.jrandom.poisson(k.jaxKey, lam = rate.jaxValue, shape = rate.shape.dimensions.toPythonProxy), dtype=vtype.dtype
)
There was a problem hiding this comment.
Good point. The last commit should address this.
The
VTypeof the rate parameter in Poisson is the same as the Type of the samples returned. For Poisson, that is Integer. But the rate should be a Float parameter. This commit decouples the two,A convenience constructor is added that fixes the type to
Int32. A second constructor makes it possible to specify theVType. The rate is always aFloat32`.