0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % A test script for ao/metropolis
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Nofrarias 17-03-09
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: test_ao_metropolis.m,v 1.1 2009/03/18 14:00:13 miquel Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %% Make gaussian distribution
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 gauss = ao(plist('xyfcn','1/(sqrt(2*pi)*2)*exp(-(x-5).^2./(2*2^2))','x',(-10:.01:20)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 gauss.setName('gaussian pdf')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 %% Sample the distribution
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 pl = plist('N',500,'J',2,'sigma',2,'range',[0 1]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 b = metropolis(gauss,pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % compute histogram
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 c = hist(b,plist('N',15));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 prob = c./len(b(1))./(c(1).x(2)-c(1).x(1))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 prob.setName('histogram')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %% Plot
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 iplot(gauss,prob,plist('LineStyles',{'-','--','--'},'Function','stairs'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|