Use python sbi package in matlab, matlab give error: Python Error: TypeError: simulator() missing 1 required positional argument: 'parameter_set'

1 次查看(过去 30 天)
Hi,
I am trying to use python package sbi https://github.com/mackelab/sbi. Here is my matlab to perfom the experiment in https://www.mackelab.org/sbi/tutorial/00_getting_started/
clc;clear;
np = py.importlib.import_module('numpy');
torch = py.importlib.import_module('torch');
sbi = py.importlib.import_module('sbi');
%%
num_dim = int64(3);
low = -2*torch.ones(num_dim);
high = 2*torch.ones(num_dim);
prior = py.sbi.utils.BoxUniform(low, high);
posterior = py.sbi.inference.base.infer(py.test.simulator, prior, method='SNPE', num_simulations=1000)
My simulator function is test.py
def simulator(parameter_set):
return 1.0 + parameter_set + torch.randn(parameter_set.shape) * 0.1
The matlab give error Python Error: TypeError: simulator() missing 1 required positional argument: 'parameter_set'.
However, in python, it requires no input, but Matlab seems need one. Can anyone help?

回答(1 个)

Anjaneyulu Bairi
Anjaneyulu Bairi 2023-11-9
I understand that you are getting an error related to python arguments which is a TypeError.
I was able to reproduce the same issue and tried to check the signature of the function and noted down some points on the simulator function
Hope it helps to resolve the query.

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by