Exemplo n.º 1
0
def run_test():

    comm = MPI.COMM_WORLD
    size = comm.Get_size()
    rank = comm.Get_rank()

    if size!=3:
        if rank==0: print "###Error: the number of processors should be 3. Please use: mpiexec -n 3 python p_arpack.py"
        sys.exit(1)

    if rank == 0: a = np.array([[1,2,0]], dtype='float');
    if rank == 1: a = np.array([[2,0,3]], dtype='float');
    if rank == 2: a = np.array([[0,3,0]], dtype='float');

    slice_thread=slice(rank,rank+1)
    params= _ParallelSymmetricArpackParams(comm, a, 1)

    while not params.converged:
        params.iterate()

    vals, vecs = params.extract(return_eigenvectors=True)
    if rank == 0:
        print 'parallel arpack'
        print vecs, '\n'

    A = np.array([[1,2,0],[2,0,3],[0,3,0]], dtype='float')
    vals, vecs = eigsh(A, k=1)

    if rank==0:
        print 'serial arpack'
        print vecs
Exemplo n.º 2
0
def _layout_positions(g, g_extended=None):
    '''Return a dictionary that maps pedigree nodes to graph layout positions (x,y). Uses
    a layered spring model. Capable of handling both normal and extended pedigree graphs.'''
    g_extended = g_extended if g_extended else g
    # x-positions: spring model
    L = laplacian(g_extended, dtype=np.float)
    [_, v] = eigsh(L, 2, which='SM')
    x = v[:, 1]

    # Compute depths based on -original- graph
    y = pt.node_depth(g)
    for node in g_extended.nodes_iter():
        # Marriage node: 0.5 above child depth. Note that marriage nodes must have children
        if node < 0:
            y[node] = y[g_extended.successors_iter(node).next()] - 0.5
    
    ymax = max(d for d in y.itervalues())
    # Reverse the y-axis (generation 0 on top)
    return dict(zip(g_extended.nodes_iter(), zip(x, ((ymax - y[node]) for node in g_extended.nodes_iter()))))
Exemplo n.º 3
0
def _layout_positions(g, g_extended=None):
    '''Return a dictionary that maps pedigree nodes to graph layout positions (x,y). Uses
    a layered spring model. Capable of handling both normal and extended pedigree graphs.'''
    g_extended = g_extended if g_extended else g
    # x-positions: spring model
    L = laplacian(g_extended, dtype=np.float)
    [_, v] = eigsh(L, 2, which='SM')
    x = v[:, 1]

    # Compute depths based on -original- graph
    y = pt.node_depth(g)
    for node in g_extended.nodes_iter():
        # Marriage node: 0.5 above child depth. Note that marriage nodes must have children
        if node < 0:
            y[node] = y[g_extended.successors_iter(node).next()] - 0.5

    ymax = max(d for d in y.itervalues())
    # Reverse the y-axis (generation 0 on top)
    return dict(
        zip(g_extended.nodes_iter(),
            zip(x, ((ymax - y[node]) for node in g_extended.nodes_iter()))))
Exemplo n.º 4
0
def smallest_ev_arpack(R,U,rows,cols,tolerance=1e-4):
  X = build_sparse(R, U, rows, cols)
  (eis,_)=eigsh(X, k=1, sigma=-3, which='LM',tol=tolerance,maxiter=1000)
  ei = eis[0]
  return ei
Exemplo n.º 5
0
def is_psd_arpack(R,U,rows,cols,tolerance=1e-4):
  X = build_sparse(R, U, rows, cols)
  (eis,_)=eigsh(X, k=1, sigma=-1, which='LM')
  ei = eis[0]
  return ei>tolerance