Use python sbi package in matlab, matlab give error: Python Error: TypeError: simulator() missing 1 required positional argument: 'parameter_set'
Mostra commenti meno recenti
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?
Risposte (1)
Anjaneyulu Bairi
il 9 Nov 2023
0 voti
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
- This is the function signature : sbi.inference.base.infer(simulator, prior, method, num_simulations, num_workers=1).
- It requires an input theta ‘θ’ to run.
- Visit the below link to get more details: https://web.archive.org/web/20210621214049/https://www.mackelab.org/sbi/reference/
Hope it helps to resolve the query.
Categorie
Scopri di più su Call Python from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!