Example #1
0
File: hw1.py Project: ivanov/PyPsy
            if np.isnan(LogLik)==False and LogLik<chimin:
                chimin = LogLik
    plt.figure(2)
    X=p1; # xxx: is this **0 supposed to be matrix exponentiation?
    Y=logp2;
    V=np.append( chimin,chimin+.125*2**np.arange(0,8.001)) # include chimin, then the others
    plt.contourf(X,Y,LL.T, V);
    #plt.contourf(X,Y,LL.T);
    plt.colorbar(format='%.4g')
    plt.xlabel('75% correct (a)')
    plt.ylabel('slope (b)')
    plt.show()


log.info ("*"*30)
log.info ("Comparing to new OO method" )

# This line is redundant with stuff above, but want to make sure dealing with known values:
LogLikf, probExpect=ProbitLogit(pfinal, StimLevels, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit,1)
LogLikX2, probExpect=ProbitLogit(pfinal, StimLevels, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit,2)

testpf =  pf.pf_stan( pf.fn_logit, [params0[0], params0[1], 0.5, 1., True] )
testdata = pf.experiment( StimLevels, Ntrials, NumPos )
gof = testpf.eval_gof( testdata )
log.info( str(gof) )
log.info( "probs same? %s" % str( np.all( gof[0]==probExpect) ) )
log.info( "LL same? %s" % str(gof[1]==LogLikf) )
log.info( "X2 same? %s" % str(gof[2]==LogLikX2) )
testpf.fitpf( params0+np.random.rand(2)/10.0, testdata )
log.info( "fitted params: %s " % str(testpf.params ) )
Example #2
0
levels_frac = np.array([.1,.3,.4,.6,.7,.9]) # Prins' s2
params2=[alpha,beta,0,0] # Wichmann/Prins use this to gen some initial values
params=[alpha,beta,0.5,lapse]

alphas = np.logspace( *np.log10( pf.fn_weibull_inv(np.array([0.01,0.99]), params2) ), num=gridGrain )
betas = np.logspace( -1.0, 2.0, gridGrain)
gamma = 0.5
lambdas = np.arange( 0, .06+np.finfo(float).eps, 0.005)

# Model:
fit1 =  pf.pf_generic( pf.fn_weibull, params, [0,1,3])

# Data:
levels = pf.fn_weibull_inv( levels_frac, params2  )
trials_arr = np.tile( trials_per, numlevels)
data=pf.experiment(levels, trials_arr, pcorr=pf.fn_weibull( levels, [alpha,beta,0.5,0]) )
data.simulate()

# Rebuild the huge grid of initial LogPs if we need to
# Takes about 16.5 secs on my Thinkpad x60
#
# Like Prins, we keep it here for efficiency, but is arguable.
try:
    if logpcorr[0,0,0,0] != 0:
            pass
except NameError:
    tic=time.time()
    log.info( 'Building huge pcorr grid for search (happens once per session).')
    param_grid = [alphas, betas, lambdas]
    param_dims = [len(p) for p in param_grid]