Exemplo n.º 1
0
def analyze_complexity(full_matrix,
                       simple_sheet_name,
                       complex_sheet_name,
                       filename=None):
    """
    Compute modulation ratio for each neuron, to distinguish complex from simple cells.

    Uses full_matrix data obtained from measure_or_pref().

    If there is a sheet named as specified in simple_sheet_name,
    also plots its phase preference as a scatter plot.
    """
    import topo
    measured_sheets = [
        s for s in topo.sim.objects(CFSheet).values()
        if hasattr(s, 'measure_maps') and s.measure_maps
    ]

    for sheet in measured_sheets:
        # Divide by two to get into 0-1 scale - that means simple/complex boundry is now at 0.5
        complx = array(complexity(full_matrix[sheet])) / 2.0
        # Should this be renamed to ModulationRatio?
        sheet.sheet_views['ComplexSelectivity'] = SheetView(
            (complx, sheet.bounds), sheet.name, sheet.precedence,
            topo.sim.time(), sheet.row_precedence)
    import topo.command.pylabplot
    topo.command.pylabplot.plot_modulation_ratio(
        full_matrix,
        simple_sheet_name=simple_sheet_name,
        complex_sheet_name=complex_sheet_name,
        filename=filename)
Exemplo n.º 2
0
 def test_sheetview_release(self):
     s = Sheet()
     s.activity = array([[1, 2], [3, 4]])
     # Call s.sheet_view(..) with a parameter
     sv2 = SheetView((s.activity, s.bounds), src_name=s.name)
     self.assertEqual(len(s.sheet_views.keys()), 0)
     s.sheet_views['Activity'] = sv2
     self.assertEqual(len(s.sheet_views.keys()), 1)
     s.release_sheet_view('Activity')
     self.assertEqual(len(s.sheet_views.keys()), 0)
Exemplo n.º 3
0
    def _generate_plots(self):
        dynamic_plots = []
        for kw in [dict(sheet=sheet) for sheet in self.sheets()]:
            sheet = kw['sheet']
            new_view = SheetView((sheet.input_generator(),sheet.bounds),
                                  sheet.name,sheet.precedence,topo.sim.time())
            sheet.sheet_views['Activity']=new_view
            channels = {'Strength':'Activity','Hue':None,'Confidence':None}

            ### JCALERT! it is not good to have to pass '' here... maybe a test in plot would be better
            dynamic_plots.append(make_template_plot(channels,sheet.sheet_views,
                                                    sheet.xdensity,sheet.bounds,self.normalize,
                                                    name=''))

        return self._static_plots[:]+dynamic_plots
Exemplo n.º 4
0
def compute_ACDC_orientation_tuning_curves(full_matrix, curve_label, sheet):
    """ This function allows and alternative computation of orientation tuning curve where
    for each given orientation the response is computed as a maximum of AC or DC component 
    across the phases instead of the maximum used as a standard in Topographica"""
    # this method assumes that only single frequency has been used
    i = 0
    for f in full_matrix.features:
        if f.name == "phase":
            phase_index = i
        if f.name == "orientation":
            orientation_index = i
        if f.name == "frequency":
            frequency_index = i
        i = i + 1
    print sheet.curve_dict
    if not sheet.curve_dict.has_key("orientationACDC"):
        sheet.curve_dict["orientationACDC"] = {}
    sheet.curve_dict["orientationACDC"][curve_label] = {}

    rows, cols = full_matrix.matrix_shape
    for o in xrange(size(full_matrix.features[orientation_index].values)):
        s_w = zeros(full_matrix.matrix_shape)
        for x in range(rows):
            for y in range(cols):
                or_response = []
                for p in xrange(size(
                        full_matrix.features[phase_index].values)):
                    index = [0, 0, 0]
                    index[phase_index] = p
                    index[orientation_index] = o
                    index[frequency_index] = 0
                    or_response.append(
                        full_matrix.full_matrix[tuple(index)][x][y])

                fft = numpy.fft.fft(
                    or_response + or_response + or_response + or_response,
                    2048)
                first_har = 2048 / len(or_response)
                s_w[x][y] = numpy.maximum(2 * abs(fft[first_har]), abs(fft[0]))
        s = SheetView((s_w, sheet.bounds), sheet.name, sheet.precedence,
                      topo.sim.time(), sheet.row_precedence)
        sheet.curve_dict["orientationACDC"][curve_label].update(
            {full_matrix.features[orientation_index].values[o]: s})
Exemplo n.º 5
0
    def setUp(self):

        ### Simple case: we only pass a dictionnary to Plot()
        ### that does not belong to a Sheet:
        self.view_dict = {}

        ### SheetView1:
        ### Find a way to assign randomly the matrix.
        self.matrix1 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds1 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view1 = SheetView((self.matrix1, self.bounds1),
                                     src_name='TestInputParam')
        self.key1 = 'sv1'
        self.view_dict[self.key1] = self.sheet_view1

        ### SheetView2:
        ### Find a way to assign randomly the matrix.
        self.matrix2 = zeros((10, 10), Float) + 0.3
        self.bounds2 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view2 = SheetView((self.matrix2, self.bounds2),
                                     src_name='TestInputParam')
        self.key2 = ('sv2', 0, 10)
        self.view_dict[self.key2] = self.sheet_view2

        ### SheetView3:
        ### Find a way to assign randomly the matrix.
        self.matrix3 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds3 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view3 = SheetView((self.matrix3, self.bounds3),
                                     src_name='TestInputParam')
        self.key3 = ('sv3', 0, 'hello', (10, 0))
        self.view_dict[self.key3] = self.sheet_view3

        ### SheetView4: for testing clipping + different bounding box
        ### Find a way to assign randomly the matrix.
        self.matrix4 = zeros((10, 10), Float) + 1.6
        self.bounds4 = BoundingBox(points=((-0.7, -0.7), (0.7, 0.7)))
        self.sheet_view4 = SheetView((self.matrix4, self.bounds4),
                                     src_name='TestInputParam')
        self.key4 = 'sv4'
        self.view_dict[self.key4] = self.sheet_view4

        ### JCALERT! for the moment we can only pass a triple when creating plot
        ### adding more sheetView to test when plot will be fixed for accepting
        ### as much as you want.

        # plot0: empty plot + no sheetviewdict passed: error or empty plot?
        ### JCALERT! It has to be fixed what to do in this case in plot..
        ### disabled test for the moment.
        #self.plot0 = Plot((None,None,None),None,name='plot0')
        ### CATCH EXCEPTION

        plot_channels1 = {'Strength': None, 'Hue': None, 'Confidence': None}
        # plot1: empty plot
        self.plot1 = make_template_plot(plot_channels1,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot1')

        plot_channels2 = {
            'Strength': self.key1,
            'Hue': None,
            'Confidence': None
        }
        # plot2: sheetView 1, no normalize, no clipping
        self.plot2 = make_template_plot(plot_channels2,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot2')

        plot_channels3 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': None
        }
        # plot3: sheetView 1+2, no normalize, no clipping
        self.plot3 = make_template_plot(plot_channels3,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot3')

        plot_channels4 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot4: sheetView 1+2+3, no normalize , no clipping
        self.plot4 = make_template_plot(plot_channels4,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot4')

        plot_channels5 = {
            'Strength': self.key1,
            'Hue': None,
            'Confidence': self.key3
        }
        # plot5: sheetView 1+3, no normalize, no clipping
        self.plot5 = make_template_plot(plot_channels5,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot5')

        plot_channels6 = {
            'Strength': None,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot6: sheetView 2+3, no normalize , no clipping
        self.plot6 = make_template_plot(plot_channels6,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot6')

        plot_channels7 = {
            'Strength': self.key4,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot7: sheetView 1+2+3, no normalize , clipping
        self.plot7 = make_template_plot(plot_channels7,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot7')

        plot_channels8 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot8: sheetView 1+2+3, normalize , no clipping
        self.plot8 = make_template_plot(plot_channels8,
                                        self.view_dict,
                                        density=10.0,
                                        normalize=True,
                                        name='plot8')

        ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE.
        ### WE WILL SEE IF IT REMAINS IN PLOT FIRST.

        ### also makes a sheet to test realease_sheetviews

        self.sheet = Sheet()
        self.sheet.sheet_views[self.key1] = self.sheet_view1
        self.sheet.sheet_views[self.key2] = self.sheet_view2
        self.sheet.sheet_views[self.key3] = self.sheet_view3
        self.sheet.sheet_views[self.key4] = self.sheet_view4

        plot_channels9 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        self.plot9 = make_template_plot(plot_channels9,
                                        self.sheet.sheet_views,
                                        density=10.0,
                                        name='plot9')