Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
danehkar authored Nov 4, 2022
1 parent d5c67ef commit b19e069
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions Notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"metadata":{"language_info":{"name":"gdl","codemirror_mode":"idl","mimetype":"text/x-idl","file_extension":".pro"},"kernelspec":{"name":"gdl","display_name":"GDL","language":"GDL"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"markdown","source":"**How to Use**\n\nFirst, you need to define your function. For example: ","metadata":{},"id":"477eeace-67f9-429a-af3b-92d02a8e9f87"},{"cell_type":"code","source":"function myfunc1, input\n result1 = total(input)\n result2 = input[1]^input[0]\n return, [result1, result2]\nend","metadata":{"trusted":true},"execution_count":1,"outputs":[{"name":"stdout","text":"","output_type":"stream"}],"id":"59cc2aaa-3d83-4590-9b52-a86d46c90479"},{"cell_type":"markdown","source":"Then, specify the upper and lower uncertainties of the prior parameters:","metadata":{},"id":"3e89d99d-da50-4399-a836-79ec4b623188"},{"cell_type":"code","source":"input=[1. , 2.]\ninput_err=[0.2, 0.5]\ninput_err_p=input_err\ninput_err_m=-input_err\noutput=myfunc1(input)\ntemp=size(output,/DIMENSIONS)\noutput_num=temp[0]","metadata":{"trusted":true},"execution_count":2,"outputs":[{"name":"stdout","text":"","output_type":"stream"}],"id":"d259476e-89f3-46dc-aeb4-c4cf140dbe6e"},{"cell_type":"markdown","source":"Choose the appropriate uncertainty distribution. For example, for a uniform distribution, use_gaussian=0, and for a Gaussian distribution, use_gaussian=1. Then, specify the number of walkers and the number of iterations, e.g. walk_num=30 and iteration_num=100. ou can then create the MCMC sample and propagate the uncertainties of the input parameters into your defined functions as follows::","metadata":{},"id":"61ada492-3acf-4b46-b219-95d95a701acb"},{"cell_type":"code","source":"use_gaussian=0 ; uniform distribution from min value to max value\nwalk_num=30 ; number of walkers\niteration_num=100 ; number of samplers\nmcmc_sim=emcee_hammer('myfunc1', input, input_err_m, input_err_p, $\n output, walk_num, iteration_num, $\n use_gaussian, print_progress=1)","metadata":{"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Progress (%): 0 10 20 30 40 50 60 70 80 90 100\n","output_type":"stream"}],"id":"d09d7d8b-1b85-484b-9684-71b172ef3008"},{"cell_type":"raw","source":"To determine the upper and lower errors of the function outputs, you need to run with the chosen appropriate confidence level. For example, a 1.645-sigma standard deviation can be specified with clevel=0.90. For a 1-sigma standard deviation, we have clevel=0.682:","metadata":{},"id":"0083c273-bc77-4101-a78a-190d44aedbb4"},{"cell_type":"code","source":"clevel=0.68268949 ; 1-sigma\noutput_error=emcee_find_errors(output, mcmc_sim, clevel)","metadata":{"trusted":true},"execution_count":4,"outputs":[{"name":"stdout","text":"","output_type":"stream"}],"id":"e5b94480-d0c7-43a5-b481-9953a28ca717"},{"cell_type":"markdown","source":"To plot the histograms, you should set do_plot=1. To print the results:","metadata":{},"id":"30365e5f-6625-476f-9420-773c6c900e9d"},{"cell_type":"code","source":"for i=0, output_num-1 do begin\n print, output[i], transpose(output_error[i,*])\nendfor","metadata":{"trusted":true},"execution_count":5,"outputs":[{"name":"stdout","text":" 3.00000 -0.29439239 0.41795791\n 2.00000 -0.32437726 0.47199511\n","output_type":"stream"}],"id":"06e49385-a910-4536-8c63-66d47fca5587"},{"cell_type":"markdown","source":"Now defined a function having two arguments:","metadata":{},"id":"986d2c3e-4e08-476f-9080-385c1c40f7fc"},{"cell_type":"code","source":"function myfunc2, input, FUNCTARGS=fcnargs\n result1 = fcnargs.scale1*total(input)\n result2 = fcnargs.scale2*(input[1]^input[0])\n return, [result1, result2]\nend\n\ninput=[1. , 2.]\ninput_err=[0.2, 0.5]\ninput_err_p=input_err\ninput_err_m=-input_err\nscale1=2.\nscale2=3.\nfcnargs = {scale1:scale1, scale2:scale2}\noutput=myfunc2(input, FUNCTARGS=fcnargs)\ntemp=size(output,/DIMENSIONS)\noutput_num=temp[0]","metadata":{"trusted":true},"execution_count":6,"outputs":[{"name":"stdout","text":"","output_type":"stream"}],"id":"aa6d93c3-63ee-42a9-baf2-3cc1101c91c3"},{"cell_type":"code","source":"use_gaussian=0 ; uniform distribution from min value to max value\nwalk_num=30 ; number of walkers\niteration_num=100 ; number of samplers\nmcmc_sim=emcee_hammer('myfunc1', input, input_err_m, input_err_p, $\n output, walk_num, iteration_num, $\n use_gaussian, print_progress=1, FUNCTARGS=fcnargs)","metadata":{"trusted":true},"execution_count":7,"outputs":[{"name":"stdout","text":"Progress (%): 0 10 20 30 40 50 60 70 80 90 100\n","output_type":"stream"}],"id":"baabcc7d-d886-42fa-a9a4-6eeda3179d3b"},{"cell_type":"code","source":"output_error=emcee_find_errors(output, mcmc_sim, clevel)","metadata":{"trusted":true},"execution_count":8,"outputs":[{"name":"stdout","text":"","output_type":"stream"}],"id":"e0fe1e2f-b4e0-4b65-9cac-7a76e9726548"},{"cell_type":"code","source":"for i=0, output_num-1 do print, output[i], transpose(output_error[i,*])","metadata":{"trusted":true},"execution_count":9,"outputs":[{"name":"stdout","text":" 6.00000 -3.3429190 -2.6642226\n 6.00000 -4.3686684 -3.7064721\n","output_type":"stream"}],"id":"b4c20309-b795-4651-9b13-40f7143563b1"},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[],"id":"c056400f-cc98-4f9a-a410-52027c7b45ff"}]}

0 comments on commit b19e069

Please sign in to comment.