Fit a line to data

"Find the best fit values of the slope and intercept from the data using MultNest"

Contributors

Qucik installation

First build the MultiNest libraries provided

$ cd MultiNest_v2.18_CMake/build/
$ cmake ../
$ make

Go to the FitALine directory and build the program

$ cd ../../FitALine/build/
$ cmake ../ -DMULTINEST_ROOT_HINT=../../MultiNest_v2.18_CMake/
$ make

Creating a data for analyis

The python script create_data.py will create a data with 100 points with slome m=0.7 and intercept c=2.5.

$ cd ../
$ python create_data.py

The data is written to line_data.dat.

Fitting a line to data

Run the fitting program

$ cd build
$ ./fit_a_line.exe

You will see the folowing output

 *****************************************************
 MultiNest v2.18
 Copyright Farhan Feroz & Mike Hobson
 Release Aug 2012

 no. of live points = 1000
 dimensionality =    2
 *****************************************************
 Starting MultiNest
 generating live points
 live points generated, starting sampling
Acceptance Rate:      0.999049
Replacements:             1050
Total Samples:            1051
ln(Z):          -881697.419099
Acceptance Rate:      0.993677
Replacements:             1100
Total Samples:            1107
ln(Z):          -701436.756640
Acceptance Rate:      0.988822
Replacements:             1150
Total Samples:            1163
ln(Z):          -591172.468396
Acceptance Rate:      0.981194
Replacements:             1200
Total Samples:            1223
ln(Z):          -528077.020677
Acceptance Rate:      0.974279
Replacements:             1250
Total Samples:            1283
ln(Z):          -450880.827773
Acceptance Rate:      0.963677
Replacements:             1300
Total Samples:            1349
ln(Z):          -391711.172461
Acceptance Rate:      0.950035
Replacements:             1350
Total Samples:            1421
ln(Z):          -345986.707547
Acceptance Rate:      0.936455
Replacements:             1400
Total Samples:            1495
ln(Z):          -312810.564647

..........................................................
..........................................................
..........................................................

Acceptance Rate:      0.915384
Replacements:            14150
Total Samples:           15458
ln(Z):              -65.904609
Acceptance Rate:      0.915433
Replacements:            14159
Total Samples:           15467
ln(Z):              -65.901423
 ln(ev)=  -65.549001951267400      +/-  0.10549400415943505     
 Total Likelihood Evaluations:        15467
 Sampling finished. Exiting MultiNest

All the output files are written to chains directory.

$ cd chains
$ ls -la    
-rw-r--r-- 1 sree sree 1552762 Jan 22 12:46 fit_a_line_ev.dat
-rw-r--r-- 1 sree sree   85000 Jan 22 12:46 fit_a_line_live.points
-rw-r--r-- 1 sree sree   89000 Jan 22 12:46 fit_a_line_phys_live.points
-rw-r--r-- 1 sree sree  297075 Jan 22 12:46 fit_a_line_post_equal_weights.dat
-rw-r--r-- 1 sree sree  848519 Jan 22 12:46 fit_a_line_post_separate.dat
-rw-r--r-- 1 sree sree     219 Jan 22 12:46 fit_a_line_resume.dat
-rw-r--r-- 1 sree sree     731 Jan 22 12:46 fit_a_line_stats.dat
-rw-r--r-- 1 sree sree     281 Jan 22 12:46 fit_a_line_summary.txt
-rw-r--r-- 1 sree sree  848517 Jan 22 12:46 fit_a_line_.txt

The posterior samples can be found in fit_a_line_post_post_equal_weights.dat file. The posterior statistics are written to fit_a_line_stats.dat. See the stats using

$ cat fit_a_line_stats.dat
Global Evidence:   -0.655490019512673996E+02  +/-    0.105494004159435051E+00

Local Mode Properties
-------------------------------------------

Total Modes Found:           1


Mode   1
Strictly Local Evidence   -0.655490019512673996E+02 +/-    0.105494004159435051E+00
Local Evidence   -0.655490019512673996E+02 +/-    0.105494004159435051E+00

Dim No.       Mean        Sigma
   1    0.683419243109782415E+00    0.169441339238071767E-01
   2    0.278679217846152305E+01    0.194627320053394198E+00

Maximum Likelihood Parameters
Dim No.        Parameter
   1    0.684161697417490444E+00
   2    0.277934384560164460E+01

MAP Parameters
Dim No.        Parameter
   1    0.659525928528765348E+00
   2    0.306564406503305520E+01

Plotting the posterior distribution

Come back to root directory and use the plotting script plot_posterior.py.

$ cd ../../
$ python plot_posterior.py

The plots can be found in the directory plots and are shown below

Best fit line Posterior distribution of m Posterior distribution of c