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

1 visualización (últimos 30 días)
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?

Respuestas (1)

Anjaneyulu Bairi
Anjaneyulu Bairi el 9 de Nov. de 2023
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.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by