Thursday, April 29, 2010

Define parameter grid and calculate statistics - steppar functionality in Sherpa

It is trivial to define a grid in Sherpa Python and then calculate the statistic values for set of par1, par2 parameters:

low_lim1=0.1
up_lim1=2.0
nstep1=10
low_lim2=1.5
up_lim2=3.0
nstep2=20
par1_grid=numpy.linspace(low_lim1, up_lim1, nstep1)
par2_grid=numpy.linspace(low_lim2, up_lim2, nstep2)

#Now calculate the statistics for all the parameters on the grid

stat_vals=numpy.zeros((nstep1, nstep2))

for i, parval1 in enumerate(par1_grid):
    set_par(par1, parval1)
    for j, parval2 in enumerate(par2_grid):
        set_par(par2, parval2)
        stat_vals[i,j] = calc_stat()
        print '%d %.3f %d %.3f %f' % (i, parval1, j, parval2, stat_vals[i, j])
    

No comments:

Post a Comment