Esempio n. 1
0
def make_big_system(cortical_areas=None):
    # complications:
    # - AIP connections studied by Borra but not in CoCoMac
    # - CIP should maybe be split from LIP (or related to PIP?)
    # - pulvinar connectivity
    # - how to normalize FLNe
    # V6, V6A: should really use Shipp et al. 2001 rather than CoCoMac, but map to PO for now

    system = System()
    w_rf_0 = 0.2
    system.add_input(750000, w_rf_0)

    # Estimates of LGN cell numbers (one side) from:
    # Weber, Arthur J., et al. (2000) Experimental glaucoma and cell size, density, and number in the primate lateral
    # geniculate nucleus. Investigative ophthalmology & visual science 41.6: 1370 - 1379.
    n_LGN = 1270000
    n_magno_LGN = 0.103 * n_LGN
    n_parvo_LGN = 0.897 * n_LGN

    # Weber et al. say, "For normal animals, the total number of neurons in the LGN was estimated to be
    # approximately 1.27 million, with 10.3% located in the M-layers and 89.7% in the P-layers." Koniocellular
    # neurons are between these layers, and similar in number to M cells, so we'll add another 10.3%
    n_konio_LGN = 0.103 * n_LGN

    # Guessing convergence from RGC to LGN based on comments page 54 of:
    # Lee, B.B., Virsu, V., & Creutzfeldt, O.D.(1983).Linear signal transmission from prepotentials to cells in the
    # macaqie lateral geniculate nucleus. Experimental Brain Research, 52(1), 50 - 56.
    convergence_LGN = 5

    # See also re. parallel projections from retina to LGN:
    # Leventhal, A.G., Rodieck, R.W., & Dreher, B.(1981).Retinal ganglion cell classes in the Old World
    # monkey: morphology and central projections. Science, 213(4512), 1139 - 1142.

    # Magno cells have slightly larger RFs than parvo:
    # Derrington, A.M., & Lennie, P.(1984).Spatial and temporal contrast sensitivities of neurones in lateral
    # geniculate nucleus of macaque.The Journal of Physiology, 357(1), 219 - 240.

    # Pixels correspond roughly to retinal ganglion cells
    # Setting LGN RF sizes similar to input (one-pixel kernels)
    system.add("parvo_LGN", n_parvo_LGN, 5, 1.041 * w_rf_0)
    system.add("magno_LGN", n_magno_LGN, 5, 1.155 *
               w_rf_0)  # TODO reconsider; see Livingston & Hubel (1988)
    system.add(
        "konio_LGN", n_konio_LGN, 5, 1.155 * w_rf_0
    )  # RF sizes highly scattered but comparable to Magno (Xu et al., 2004, J Physiol)
    system.connect_areas(system.input_name, "parvo_LGN", 1.0)
    system.connect_areas(system.input_name, "magno_LGN", 1.0)
    system.connect_areas(system.input_name, "konio_LGN", 1.0)

    # L4A is omitted in classical models, so we leave it out, but see (Sincich et al. 2010)
    for layer in [
            "4Calpha", "4Cbeta", "4B", "2/3blob", "2/3interblob", "5", "6"
    ]:
        if "2/3" in layer:
            n = _get_num_ff_neurons("V1", "2/3")
            if "blob" in layer:
                n = n / 3  # Sincich et al. (2010, J Neurosci)
            elif "interblob" in layer:
                n = 2 * n / 3
        else:
            n = _get_num_ff_neurons("V1", layer)

        e = data.get_extrinsic_inputs("V1",
                                      "4") if layer.startswith("4C") else None

        # Livingston & Hubel (1988) cite Livingston & Hubel (1984) re larger RF sizes in blobs
        # than interblobs, but I can't find anything about this in the 1984 paper (or elsewhere).
        if "4C" in layer:
            w = data.get_receptive_field_size("V1")
        else:
            w = None
        system.add("V1_{}".format(layer), n, e, w)

    system.connect_areas("parvo_LGN", "V1_4Cbeta", 1.0)
    system.connect_areas("magno_LGN", "V1_4Calpha", 1.0)
    system.connect_areas("konio_LGN", "V1_2/3blob", 1.0)
    system.connect_areas("konio_LGN", "V1_2/3interblob", 1.0)
    system.connect_layers("V1_4Calpha", "V1_4B",
                          data.get_inputs_per_neuron("V1", "4", "2/3"))
    system.connect_layers("V1_4Cbeta", "V1_2/3blob",
                          0.5 * data.get_inputs_per_neuron("V1", "4", "2/3"))
    system.connect_layers("V1_4Cbeta", "V1_2/3interblob",
                          data.get_inputs_per_neuron("V1", "4", "2/3"))

    # feedforward magno input to ventral areas (see Merigan & Maunsell, 1983, pg 386)
    system.connect_layers("V1_4Calpha", "V1_2/3blob",
                          0.5 * data.get_inputs_per_neuron("V1", "4", "2/3"))

    # Tootell et al. (1988) (IV)
    system.connect_layers("V1_2/3blob", "V1_5",
                          0.5 * data.get_inputs_per_neuron("V1", "2/3", "5"))
    system.connect_layers("V1_2/3interblob", "V1_5",
                          0.5 * data.get_inputs_per_neuron("V1", "2/3", "5"))
    system.connect_layers("V1_4Cbeta", "V1_5",
                          data.get_inputs_per_neuron("V1", "4", "5"))

    system.connect_layers("V1_2/3blob", "V1_6",
                          data.get_inputs_per_neuron("V1", "2/3", "6"))
    system.connect_layers("V1_4Calpha", "V1_6",
                          data.get_inputs_per_neuron("V1", "4", "6"))
    system.connect_layers("V1_5", "V1_6",
                          data.get_inputs_per_neuron("V1", "5", "6"))

    for area in ["V2thick", "V2thin", "V2pale"]:
        for layer in ["2/3", "4", "5", "6"]:
            name = _pop_name(area, layer)

            n = _get_num_ff_neurons("V2", layer)
            n = n / 5 if "thin" in area else 2 * n / 5

            e = data.get_extrinsic_inputs("V2", "4") if layer == "4" else None
            w = data.get_receptive_field_size("V2") if layer == "4" else None

            system.add(name, n, e, w)

        system.connect_layers(_pop_name(area, "4"), _pop_name(area, "2/3"),
                              data.get_inputs_per_neuron("V2", "4", "2/3"))
        system.connect_layers(_pop_name(area, "2/3"), _pop_name(area, "5"),
                              data.get_inputs_per_neuron("V2", "2/3", "5"))
        system.connect_layers(_pop_name(area, "4"), _pop_name(area, "5"),
                              data.get_inputs_per_neuron("V2", "4", "5"))
        system.connect_layers(_pop_name(area, "5"), _pop_name(area, "6"),
                              data.get_inputs_per_neuron("V2", "5", "6"))
        system.connect_layers(_pop_name(area, "2/3"), _pop_name(area, "6"),
                              data.get_inputs_per_neuron("V2", "2/3", "6"))

    # There is substantial forward projection from V1_5 to V2 and V3, also from V2_5 to V3. We assume V1_5 is
    # parvo, and V2_5 is separated into stripes. Will omit parvo, V1_5, and V2thin_5 projections to dorsal areas,
    # consistent with MT supression following magno inactivation, reported in:
    # Maunsell, J. H., Nealey, T. A., & DePriest, D. D. (1990). Magnocellular and parvocellular contributions to
    # responses in the middle temporal visual area (MT) of the macaque monkey. Journal of Neuroscience, 10(10), 3323-3334.
    FLNe = data.get_FLNe("V1", "V2")
    SLN = data.get_SLN("V1", "V2")
    system.connect_areas("V1_2/3blob", "V2thin_4", FLNe * SLN / 100)
    system.connect_areas("V1_2/3interblob", "V2pale_4", FLNe * SLN / 100)
    system.connect_areas("V1_5", "V2thin_4", FLNe * (1 - SLN / 100))
    system.connect_areas("V1_4B", "V2thick_4", FLNe * SLN / 100)

    if system.find_population_index("MT_4"):
        FLNe = data.get_FLNe("V1", "MT")
        SLN = data.get_SLN("V1", "MT")
        system.connect_areas("V1_6", "MT_4", FLNe * (1 - SLN / 100))

    # Dorsal areas get connections from V1_4B and V2thick; ventral from V1_2/3, V1_5, and V2_thin
    # References on segregation in V2:
    # Shipp, S., & Zeki, S. (1985). Segregation of pathways leading from area V2 to areas V4 and V5 of
    # macaque monkey visual cortex. Nature, 315(6017), 322.
    # DeYoe, E. A., & Van Essen, D. C. (1985). Segregation of efferent connections and receptive field
    # properties in visual area V2 of the macaque. Nature, 317(6032), 58.
    # Sincich, L. C., & Horton, J. C. (2002). Divided by cytochrome oxidase: a map of the projections
    # from V1 to V2 in macaques. Science, 295(5560), 1734-1737.
    # DeYoe, E. A., & Van Essen, D. C. (1988). Concurrent processing streams in monkey visual cortex.
    # Trends in neurosciences, 11(5), 219-226.

    if cortical_areas is None:
        cortical_areas = data.get_areas()[:]
        cortical_areas.remove("MDP")  # MDP has no inputs in CoCoMac

    add_areas(system, [a for a in cortical_areas if a not in ("V1", "V2")])
    connect_areas_in_streams(system, cortical_areas)

    # It's correct to have this after making connections, as it operates
    # on actual connections between populations rather than raw FLNe data.
    system.normalize_FLNe()

    system.check_connected()

    return system
Esempio n. 2
0
    n_frames = len(data)
    initial_frame = data[0]

    system_2 = System(name=sys_comp_name,
                      n=-1.,
                      k=-1.,
                      dt=dt,
                      n_particles=n_particle,
                      dim=dim,
                      save=True)

    for ptl_idx in range(n_particle):
        ptl1 = IdenticalParticle(m=1,
                                 x_init=np.array(initial_frame[ptl_idx][0:2],
                                                 dtype=float),
                                 v_init=np.array(initial_frame[ptl_idx][2:4],
                                                 dtype=float))
        system_2.add(ptl1)

    system_2.file_init(file_index)
    for _ in range(n_frames):
        system_2.step(file_index)

    print(file_index)
    file_index += 1

for _ in range(n_particle):
    ptl1 = IdenticalParticle(m=1,
                             x_init=np.array([0] * dim, dtype=float),
                             v_init=np.array([0] * dim, dtype=float))
    system_2.add(ptl1)
'''
anim = True
save = True
frames = 1000

if anim:
    Ns = (300, 300)
    side_length = (1 / 3.)
    square_coaxial_cable = Shape(Ns,
                                 1.5, (0.5, 0.5),
                                 3e-1,
                                 side_length,
                                 shape='square',
                                 filled=True)
    cable = System(Ns)
    cable.add(square_coaxial_cable)

    all_potentials = cable.SOR_anim(w=1.9999999999999999999999999995,
                                    tol=0,
                                    max_iter=frames)
    plt.ioff()
    fig, ax = plt.subplots(figsize=(15, 15))
    image = plt.imshow(all_potentials[0].T,
                       vmin=np.min(all_potentials),
                       vmax=np.max(all_potentials),
                       interpolation='none',
                       aspect='equal',
                       extent=None,
                       origin='lower')
    iter_text = ax.text(0.05,
                        0.95,
Esempio n. 4
0
def create_EDM_system(Ns,kx,ky=None,size=None,dust_pos=None,
                      dust_size=1e-4,small_sources=True):
    '''
    Create the shapes needed to model the EDM experiment and then add
    these shapes to a system, both with the given grid size.
    kx and ky describe the space left between the end of the experimental
    setup and the boundary, which will be held at 0V.
    This distance is described as a multiple of the length of the 
    experimental setup in that axis.
    '''
    if size == None:
        size = (1.,1.) 
    if not hasattr(size,'__iter__'):
        size = (size,size) 
        
    if ky == None:
        ky = kx
    if not hasattr(Ns,'__iter__'):
        Ns = (Ns,Ns)
        
    A = Ns[1]/float(Ns[0])
    hx = 1./(26*(2*kx+1))
    hy = A/(3*(2*ky+1))
    Sx = kx * 26*hx
    Sy = ky * 3*hy
    shapes = []
    
    print('hy',hy)
    print('hx',hx)
    print('size',size)
    print('A',A)
    shapes.append(Shape(Ns,1.,  (Sx+13.*hx,Sy+5.*hy/2.),20*hx,hy,
                        shape='rectangle', filled=True))
    
    shapes.append(Shape(Ns,-1.,  (Sx+13.*hx,Sy+hy/2.),20*hx,hy,
                        shape='rectangle', filled=True))

    if small_sources:    
        shapes.append(Shape(Ns,0.25,(Sx+hx,    Sy+5.*hy/2.),2*hx,hy,
                            shape='rectangle', filled=True))
        shapes.append(Shape(Ns,0.25,(Sx+25.*hx,Sy+5.*hy/2.),2*hx,hy,
                            shape='rectangle', filled=True))
        
        shapes.append(Shape(Ns,-0.25,(Sx+hx,    Sy+hy/2.),2*hx,hy,
                            shape='rectangle', filled=True))
        shapes.append(Shape(Ns,-0.25,(Sx+25.*hx,Sy+hy/2.),2*hx,hy,
                            shape='rectangle', filled=True))
    
    system = System(Ns,size=size)
    for shape in shapes:
        system.add(shape)
        
    if dust_pos:
        if not hasattr(dust_size,'__iter__'):
            dust_size = (dust_size,dust_size)  
        #scale dust size by x-length, since the scaled length
        #in x is always 1, not so for y
        dust_size = (dust_size[0]/size[0],dust_size[1]/size[0])
        #same as system.Nsx, inverse of number of grid points
        #along an axis
        grid_spacing = 1./Ns[0]
        #using the grid spacing, determine the number of 
        #grid points covered by the dust particle
        nr_of_points_x = int(dust_size[0]/grid_spacing)
        nr_of_points_y = int(dust_size[1]/grid_spacing)        
        
        #determine where the dust particle will sit along the 
        #x axis based on the scaled position (assumed to be along x)
        #and the size of the dust particle
        lowest_x_grid = int((dust_pos/size[0] - dust_size[0]/2.)*Ns[0])    
        highest_x_grid = lowest_x_grid+nr_of_points_x

        #lowest 'real' coordinate in scaled coordinates of the
        #top sources, which all lie along one horizontal line
        y_source = Sy+2.*hy
        #translate this to an index on the grid
        y_source_grid = int(y_source/grid_spacing)
        
        #lowest position on grid of top source should be given by
        #*y_source_grid* above. If not, then no potential will be
        #assigned there, so we should start assigning at this point
        #as opposed to the point below
        if np.any(system.sources[:,y_source_grid]):
            #source already assigned, so the empty space must
            #start at the grid point below this
            top_dust_grid = y_source_grid-1
        else:
            top_dust_grid = y_source_grid
                
        #grab source potential from above grid point, which makes
        #the method more general, if a 'small' potential were
        #to be investigated, for example. This would have a 
        #potential of +0.25, not +1.
        #We are only interested in placing the dust particle
        #on the top sources, since the setup is symmetric
        assert system.sources[lowest_x_grid,top_dust_grid+1],(
               'Dust particle should be in contact with source!')
        potential = system.source_potentials[lowest_x_grid,
                                             top_dust_grid+1]
        for x_grid in np.arange(lowest_x_grid,highest_x_grid):
            for j in range(nr_of_points_y):
                y_grid = top_dust_grid-j
                index = (x_grid,y_grid)
#                print('index:',index)
                system.source_potentials[index] = potential
                system.potentials[index] = potential
                system.sources[index] = True
        return system,(nr_of_points_x*grid_spacing*size[0],
                       nr_of_points_y*grid_spacing*size[0])
    return system,()
Esempio n. 5
0
from time import clock
from copy import deepcopy
from system import System, Shape
import matplotlib.pyplot as plt

Ns = (200, 250)
tol = 1e-5
max_iter = 50000

times = []

test = System(Ns)

#test.add(Shape(Ns,-1,(0.5,0.5)))

test.add(Shape(Ns, -1, (0.6, 1.2), 0.1, shape='square'))
test.add(Shape(Ns, -1, (0.4, 0.5), 0.18, shape='circle', filled=True))
#test.add(Shape(Ns,1.8,(0.2,0.2),0.1,shape='circle',filled=False))
#test.add(Shape(Ns,2,(0.2,0.2),0.3,shape='circle',filled=False))
#test.add(Shape(Ns,-1,(0.354,0.506),0.03,shape='circle',filled=False))
#test.add(Shape(Ns,1,(0.37,0.49),0.03,shape='circle',filled=False))

#test.show_setup(title='vanilla setup')

raw = deepcopy(test)

start = clock()

raw.SOR(tol=tol, max_iter=max_iter, verbose=False)

rawtime = clock() - start
test.rectangle(1,(0.5,0.5),0.4,0.7)
test.rectangle(1,(0.2,0.4),0.02,0.02)

#test.show(color=(0,0,0,0.1))

amr_system = AMR_system(test)
amr_system.SOR(w=w,max_iter=10000,max_time=150,tol=1e-10,verbose=False)

print('amr time:',clock()-start)
#amr_system.show()

start = clock()

system = System(Ns+1)

system.add(Shape(Ns+1,1,(0.5,0.5),0.4,0.7,shape='rectangle'))
system.add(Shape(Ns+1,1,(0.2,0.4),0.02,0.02,shape='rectangle'))

#system.show_setup()

system.SOR_single(w=w,max_iter=10000,max_time=150,tol=1e-10,verbose=False)

print('normal time:',clock()-start)
#system.show()

source_diff = system.source_potentials - amr_system.grid.source_potentials
plt.figure()
plt.title('source diffs')
plt.imshow(source_diff.T,origin='lower',interpolation='none')
plt.colorbar()
Esempio n. 7
0
File: main.py Progetto: p51lee/PAT
dt = 2**(-14)

system_2 = System(name="3ptl_2dim_long",
                  n=-1.,
                  k=-1.,
                  dt=dt,
                  n_particles=n_particle,
                  dim=dim,
                  save=True)

# 시스템에 particle class 들을 초기화시켜서 넣어준다
for _ in range(n_particle):
    ptl = IdenticalParticle(m=1,
                            x_init=np.array([0] * dim, dtype=float),
                            v_init=np.array([0] * dim, dtype=float))
    system_2.add(ptl)

# system_2.make_testcase(frame_number=2048, testcase_number=200, min_distance=0.00001)
system_2.make_testcase(frame_number=65536,
                       testcase_number=1,
                       min_distance=0.00001)

# system_2.make_testcase(200, 5, 0.01)
# n = 1000000
# for i in range(n):
#     if (100 * i) % n == 0:
#         print ((100 * i) / n, "%", end='')
#     system_2.step()

print(system_2)