EMCEE Example
Keywords: sic

Next: EMCEE /BEGIN Up: EMCEE Previous: EMCEE Credits Contents Index

###
EMCEE Example

            The following demo will fit a Gaussian. Amp must be in range [5,15],
        Pos in range [-1,1] and Width in range [0,3].
          !
          ! @ gag_demo:demo-emcee  Amp Pos Width Noise
          !
          ! An example of EMCEE usage
          ! For simplicity, let us define the GAUSSIAN function
          define function gauss(x,a,b,c) a*exp(-0.5*((x-b)/c)^2)
          !
          if .not.exist(my_data) then
            ! The Gaussian parameters, Amplitude, Position and Width
            define double amp pos width /global
            ! Now the data...
            define integer nx
            let nx 512
            define double my_xx[nx] my_data[nx] my_noise /global
            ! Define the Measurement points XX
            let my_xx[i] 10*(i-nx/2)/nx
          endif
          !
          ! Fill the data with some noisy values. In reality, this may come from
          ! an experiment or observation
          let my_noise &4
          let my_data gauss(my_xx,&1,&2,&3)
          let my_data[i] my_data+my_noise*noise(i/i)
          !
          ! Start with some random value
          let amp &1*(1+noise(my_noise))
          let width &3*(1+noise(my_noise))
          let pos &2+noise(my_noise)
          !
          begin procedure my_chi2
            define double res /like my_data
            let res my_data-gauss(my_xx,amp,pos,width)
            let res (res/my_noise)^2
            compute emcee%chi2 sum res ! The Chi^2 must be returned here
            @ emcee-timer ! Optional: report advances in the chain
          end procedure my_chi2
          !
          emcee my_data "@ my_chi2" /start 'amp' 'pos' 'width' -
                /par amp pos width /bound amp 5 15 pos -1 1 width 0 10 -
                /step 0.02 0.02 0.02 /length 100 /walk 4 /begin
          for i 1 to 4
            emcee
          next
          !