Skip to content

change rate parameter in Poisson to Float32 - #147

Merged
marcelluethi merged 2 commits into
dimwit-dev:mainfrom
marcelluethi:poisson-rate-vtype
Aug 18, 2026
Merged

change rate parameter in Poisson to Float32#147
marcelluethi merged 2 commits into
dimwit-dev:mainfrom
marcelluethi:poisson-rate-vtype

Conversation

@marcelluethi

Copy link
Copy Markdown
Contributor

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,

A convenience constructor is added that fixes the type to Int32. A second constructor makes it possible to specify the VType. The rate is always a Float32`.

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,
@marcelluethi
marcelluethi requested a review from benikm91 August 16, 2026 08:22
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]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding vtype here and keeping default constructor in object Poisson that defaults to Int32

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two thins to distinguish:

  1. The rate, which is a floating point value (that was the bug
  2. 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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
)

@marcelluethi marcelluethi Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The last commit should address this.

@marcelluethi
marcelluethi merged commit 510a7a6 into dimwit-dev:main Aug 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants