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

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개)

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.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2022년 3월 30일

답변:

2023년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by