Closed yqiuu closed 2 years ago
probably could be replaced by getattr(function, '__name__')
The axis argument in your functions seems like your function is already vectorized. So perhaps you want to call ReactiveNestedSampler with vectorized=True
, in which case this problem does not occur.
Using getattr(function, '__name__')
also leads to AttributeError
. This issue is not related to vectorized=True
, since you can have a function obtained by partial
which is not vectorized. In fact, I have found that the issue can be resolved by the following way:
import ultranest
from functools import partial
def test_func(x, mu):
return -np.sum((x - mu)**2, axis=-1)
test_partial = partial(test_func, mu=0.5)
test_partial.__name__ = "XX" # XX can be anything.
sampler = ultranest.ReactiveNestedSampler(['x0', 'x1'], test_partial)
sampler.run()
This is a bit wired to me. I am just wondering why the code uses loglike.__name__
.
If your function is not vectorized, ultranest creates (with the vectorize() function in utils.py) a vectorized version. For debugging neatness, it tries to give that wrapper the same names as the original function (as opposed to "vectorized" always). For example, when you do print(sampler.loglike, sampler.transform)
.
If your function is already vectorized, and you use vectorized=True
, vectorize()
is never called.
Could you try if vectorized.__name__ = getattr(function, '__name__', vectorized.__name__)
works?
Ok, I think this is fixed in the latest commit https://app.circleci.com/pipelines/github/JohannesBuchner/UltraNest/195/workflows/c6100458-973a-4323-87c4-f7a5416890d0/jobs/192
Can you please check if it works for you?
Yes, it works now. Thanks.
Description
The sampler raises an error when I use an object created by
partial
or a class with__call__
. This is not very convenient.What I Did
For example,
yields
Similarly,
yields