Beispiel #1
0
def hardSweep():
    param=pd.read_pickle('/home/arya/out/vineet/param0.1_1.pd')
    reload(Simulation)
    s=0.01
    X0=param['initHaps'].mean(0)
    param['siteUnderSelection']=param['initHaps'].mean(0).argmin()
    param['s']=s
    param['numReplicates']=3
    param['maxGeneration']=500
    param['generationStep']=100
    param['startGeneration']=0
    X = Simulation.Simulation.forwardSimulationHardSweep(param)
    def sig(x): return 1./(1+np.exp(-x))
    if not param['startGeneration']: 
        x0=X0[param['siteUnderSelection']]
    else:
        x0=X[param['startGeneration']/param['generationStep'] -1,param['siteUnderSelection'],:].mean()
    x0
    c=np.log(1-x0)-np.log(x0)
    z=sig(s*np.array(range(param['startGeneration'],param['maxGeneration']+1,param['generationStep'])[1:])/2. -c)
    pd.DataFrame(np.append(X[:,3,:],z[:,None],axis=1)).plot()
    y= np.array([[np.linalg.norm(X[t,:,r])**2 for t in range(X.shape[0])] for r in range(param['numReplicates'])]).T
    
    y0=np.linalg.norm(X0)**2
    
    
    theta=Estimate.watterson(np.tile(param['initHaps'],(10,1)));n=2000
    theta=Estimate.watterson(param['initHaps']);n=200
    a=[(y0 ,Z(X0[3], n, theta))]
    for t in range(5):
        a.append((y[t] ,Z(X[t,3,:], n, theta)))
    
    pd.DataFrame(a)
    
    times=range(param['startGeneration'],param['maxGeneration']+1,param['generationStep'])[1:]
    times
    x0_ = T.scalar("x0")
    n_ = T.scalar("n")
    theta_ = T.scalar("theta")
    times_ = T.ivector("times")
    S__=theano.shared(np.asarray(s, dtype = theano.config.floatX), 'S')
    predall_, updatesRecurrence_ = theano.scan(lambda x_prev, s: (s*x_prev*x_prev+s*x_prev +2*x_prev)/(2*s*x_prev+2), outputs_info=x0_,non_sequences=S__,n_steps=times_[-1])
    pred_=Z(predall_[times_-1],n_,theta_) #we only have target at some generations e.g. 10,20,...
    Feedforward_ = theano.function(inputs=[x0_,times_,n_,theta_], outputs=pred_, updates=updatesRecurrence_)
    Feedforward_(x0,times,n,theta)
    x0
    y
    times
    Z(X[:,3,:],n,theta)
    theta,n
    z
    Z(z,2000,17)
    pd.DataFrame(np.append(X[:,3,:],z[:,None],axis=1))
Beispiel #2
0
def HAFRNN():
    x0=0.5
    s=0.1
    times=[1,10,20,30,40,50]
    yhat=direct(x0, s, times)
    param=pd.read_pickle('/home/arya/out/vineet/param0.1_1.pd')
    X0=param['initHaps']
    X=param['data']
    idx=range(param['siteUnderSelection']-5,param['siteUnderSelection']+6)
    X=X[:,idx,:]
    X.shape
    x0=param['initHaps'][param['siteUnderSelection']].mean()
    XX0=np.tile(X0,(10,1))
    theta =Estimate.watterson(XX0)
    theta
    idx,x0 ,theta
    n=2000
     
    
    theta/2 
#     y= np.array([[np.linalg.norm(X[t,:,r])**2 for t in range(5)] for r in range(3)]).T
#     y
#     x0_ = T.scalar("x0")
#     n_ = T.scalar("n")
#     theta_ = T.scalar("theta")
#     times_ = T.ivector("times")
#     S__=theano.shared(np.asarray(s, dtype = theano.config.floatX), 'S')
#     predall_, updatesRecurrence_ = theano.scan(lambda x_prev, s: (s*x_prev*x_prev+s*x_prev +2*x_prev)/(2*s*x_prev+2), outputs_info=x0_,non_sequences=S__,n_steps=times_[-1])
#     pred_=Z(predall_[times_-1],n_,theta_) #we only have target at some generations e.g. 10,20,...
#     Feedforward_ = theano.function(inputs=[x0_,times_,n_,theta_], outputs=pred_, updates=updatesRecurrence_)
#     
#     times=param['times']
#     theta=3;    n=200
#     S__.set_value(0)
#     S__.get_value()
#     Feedforward_(x0,times,n,theta)
#     idx2=range(11)
#     len(idx2)
#     y
#     
    
    
    np.linalg.norm(X0.mean(0)[idx])**2
    np.linalg.norm(XX0[:,idx].mean(0))**2
    XX0.shape,Estimate.watterson(XX0[:,idx])
    Estimate.watterson(XX0[:,idx])
    idx=range(20,25);
    import os
    files=pd.Series(os.listdir('/home/arya/out/vineet/'))
    idx_pd =files.map(lambda x: x[-3:]=='.pd')
    idx_s= files.map(lambda x: 'param' in x)
    idx=idx_pd & idx_s
    print idx.sum()
    res=[]
    for f in files[idx]:
        X0=pd.read_pickle('/home/arya/out/vineet/'+f)['initHaps']
        XX0=np.tile(X0,(10,1)) 
        res.append( (Z(nu=0.2, n=2000, theta=Estimate.watterson(XX0)), (Estimate.watterson(XX0)*(n-1))/(2*n),np.linalg.norm(XX0.mean(0))**2, XX0.mean(0).min()))
    print
    df=pd.DataFrame(res)
    df[2].plot(kind='hist')
    df[2].mean()
    df[2].std()
    df[3].describe()
    n=2000
    theta=17
    theta=Estimate.watterson(XX0[:,idx])
    theta*x0*((x0+1)/2. -  1./((1-x0)*n+1)) +theta*(1-x0)*((n+1)/(2.*n) -  1./((1-x0)*n+1))
    n
    ((n-1)/2.)*17
    np.linalg.norm(X0.mean(0))**2
    
    print
Beispiel #3
0
 def f(x): return Estimate.getEstimate(x=x, n=n, method='tajimaD', selectionPredictor=True),Estimate.getEstimate(x=x, n=n, method='H', selectionPredictor=True),Estimate.getEstimate(x=x, n=n, method='SFSelect', selectionPredictor=True, svm_model_sfselect=svm)
 for CHROM in CHROMS: