def random_simulations(no,bvals,gradients,d=0.0015,fractions=[100,0,0],snr=None):    
    sticks=random_uniform_on_sphere(n=no,coords='xyz')      
    fractions=[f/100. for f in fractions]
    f0=1-np.sum(fractions)
    S=np.zeros(len(gradients)-1)        
    for (i,g) in enumerate(gradients[1:]):
        S[i]=f0*np.exp(-bvals[i+1]*d)+ np.sum([fractions[j]*np.exp(-bvals[i+1]*d*np.dot(s,g)**2) for (j,s) in enumerate(sticks)])
    if snr!=None:
        std=S/snr
        S=S+np.random.randn(len(S))*std
    return S,sticks
Exemple #2
0
    orientations = bvecs101[1:,:]
    templates = [signal_1_stick(S0,bvals64[1:],d,orientation,gradients)
                 for i, orientation in enumerate(orientations)]
    # add isotropic component as last column
    templates += [np.ones(gradients.shape[0])]

    design = np.array(templates).T

    # Make pure fiber data to test against
    #test_direction = np.array([1,2,3])/np.sqrt(14.)

    #print np.sum(test_direction**2)
    #unit vector for test signal direction

    #test_direction = gradients[15,:]
    test_directions = sphere_tools.random_uniform_on_sphere(10**2)
    sparsity = []
    lambd = 2.**18.1
    for test_direction in test_directions:
        sparsity += [qpfit1(design, S0,bvals,d,test_direction,gradients,lambd)]

    angles =[np.abs(np.dot(s['actual'],gradients[s['top']].T)) for s in sparsity] 
    max_angles =[np.max(np.abs(np.dot(s['actual'],gradients[s['top']].T))) for s in sparsity]
    lengths = np.bincount([len(s['top']) for s in sparsity])
    
    '''
    Y = signal_1_stick(S0,bvals[1:],d,test_direction,gradients)

    # Set up model according to Jonathan's recipe
    n, m = design.shape
    '''