Closed Qazalbash closed 7 months ago
@Qazalbash Regarding the sub-arrays being different sizes, you mean the number of samples per event, d
, being different sizes from event to event, right? Usually, the easiest way is to upsample or downsample the event to a common size, then one should be able to vmap over it without problems.
Regarding your likelihood, a number of things:
exp_rate
and likelihood function is constructing the Wysocki2019MassModel
at every call, which I am not sure whether it is intended. Depending on how the Wysocki2019MassModel
is written, this can massively slow the computation down. Same goes for the priors. I would initialize those objects outside the likelihood and pass them in as data. f(x: array, data: dict)
, where x is a 1D array of the parameters. Meaning it should something like x = jnp.array([alpha, mmin, mmax, rate]).sample
in the mass model seems to be a stochastic process to me, which I am not sure you need it. I assume lambdas are the hyperparameters, and it is for computing the rate. In that case, x
in the likelihood is your lambda, you don't have to resample it within the likelihood.@kazewong Thank you for the points. I have a few uncertainties about certain aspects of the process, which I've outlined below. I hope this doesn't inconvenience you.
Wysocki2019MassModel
inside the log_inhomogeneous_poisson_likelihood
is according to my understanding, we are running the flowMC
to recover the parameters $\alpha$, $m\text{min}$, $m\text{max}$, $\mathcal{R}$, therefore at each iteration, these values would change as we can see that we are passing them as x
in the log_inhomogeneous_poisson_likelihood
, therefore our model should also get updated according to these parameters. This is my understanding and I highly doubt it.jnp.array
. I also can not grasp how we are passing different data to the sampler in the form of dict
.This is the Wysocki2019MassModel
.
```python
# Copyright 2023 The GWKokab Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from typing_extensions import Optional
from jax import lax, numpy as jnp
from jax.random import uniform
from jaxtyping import Array
from numpyro.distributions import constraints, Distribution
from numpyro.distributions.util import promote_shapes, validate_sample
from ..utils.misc import get_key
class Wysocki2019MassModel(Distribution):
r"""It is a double-side truncated power law distribution, as
described in equation 7 of the `paper
I have pretty much got the idea where I am wrong. Your response will make it more clear. Thanks in advance.
I think this is resolved. Closing the issue.
Description
Hi, I am trying to run
flowMC
to sample from the inhomogeneous Poisson likelihood mentioned in equation 4 of the paper. I am using the following Monte-Carlo approximation for the integral.You can notice we have a different number of samples for each iteration. JAX does not support such arrays where each sub-array has a different size. Therefore my next natural choice was to use
jax.tree_map
, but you have vectorized thelog_pdf
(which is in my case the log-likelihood) byvmap
which is not working.Is there any other way to pass those pre-computed values?
I am attaching the code down here.
Wysocki2019MassModel
is equation 7 of the same paper mentioned above. Also, I have an inner feeling that there is something wrong with the likelihood function too, but I cannot point it out.