'too many input arguments' in mhsample
Afficher commentaires plus anciens
I am having the error 'too many input arguments' during my function call which itself is called by another built-in MatLab function 'mhsample'. I have not been able to figure out any reason for this error. Following is the snippet of the code:
% specification of unnormalized posterior pdf to sample from
pdfPost=@(x)posteriorDist(x,C,artificialNetwork,xPrior);
% specification of proposal distribution
pdfProp=@(x)priorDist(x,xPrior);
% specification of random number generator from proposal distribution
generator = @(x) (xPrior(:,1)+rand(7,1).*(xPrior(:,2)-xPrior(:,1)));
% calculation of posterior of model parameters (lambda)
smpl = mhsample(x0,nsamples,'pdf',pdfPost,'proppdf',pdfProp,'proprnd',generator);
Following is the error message:
Error using mhsample (line 117)
Error occurred while trying to evaluate the user-supplied
proppdf function '@(x)priorDist(x,xPrior)'.
Error in metroPolisHastingSampling (line 33)
smpl =
mhsample(x0,nsamples,'pdf',pdfPost,'proppdf',pdfProp,'proprnd',generator);
Caused by:
Error using @(x)priorDist(x,xPrior)
Too many input arguments.
'metroPolisHastingSampling' is the name of the script I have used for implementing Metropolis-Hastings sampling method.
So, the error is in proposal distribution which only has one input argument? So, why am I getting this error? Any useful comment is appreciated?
The code for priorDist is as follows:
function [p] = priorDist(x,xprior)
p=1/prod(xPrior(:,2)-xPrior(:,1));
end
I have provided all other codes below: Here is the code for 'PosteriorDist':
function ptr = posteriorDist(x,C,artificialNetwork)
lh=likelihoodPost(artificialNetwork,x,C); % likelihood of observation given these parameters
priorParam = priorDist(x); % computation of joint prior of model parameters
ptr=lh*priorParam; % computation of unnormalized posterior
end
rest of the definitions are
x0=5*ones(7,1);
nsamples=10000;
xprior=[zeros(7,1) 15*ones(15,1)];
C=rand(7,7);
I have taken a random just for testing purposes. artificialNetwork contains information and relevant data.
4 commentaires
Image Analyst
le 2 Sep 2017
You need to give us the code for priorDist(), or at least the line that says
function output = priorDist(......
Evidently priorDist wants only one input, or none, and you're passing it two.
Abhinav
le 2 Sep 2017
Image Analyst
le 2 Sep 2017
Why are you passing x into distPrior() when you don't even use it?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Uniform Distribution (Continuous) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!