コード例 #1
0
 def test_crosscorrelation(self):
     data = numpy.random.random((10, 10))
     ts = time_series.TimeSeries(data=data)
     dt = temporal_correlations.CrossCorrelation(source=ts)
     summary_info = dt.summary_info
     self.assertEqual(summary_info['Dimensions'], ['Offsets', 'Node', 'Node', 'State Variable', 'Mode'])
     self.assertEqual(summary_info['Source'], '')
     self.assertEqual(summary_info['Temporal correlation type'], 'CrossCorrelation')
     self.assertEqual(dt.labels_ordering, ['Offsets', 'Node', 'Node', 'State Variable', 'Mode'])
     self.assertTrue(dt.source is not None)
     self.assertEqual(dt.time.shape, (0,))
コード例 #2
0
 def test_crosscorrelation(self):
     data = numpy.random.random((10, 10))
     ts = time_series.TimeSeries(data=data)
     dt = temporal_correlations.CrossCorrelation(source=ts)
     summary_info = dt.summary_info
     assert summary_info['Dimensions'] == ['Offsets', 'Node', 'Node', 'State Variable', 'Mode']
     assert summary_info['Source'] == ''
     assert summary_info['Temporal correlation type'] == 'CrossCorrelation'
     assert dt.labels_ordering == ['Offsets', 'Node', 'Node', 'State Variable', 'Mode']
     assert dt.source is not None
     assert dt.time.shape == (0,)
コード例 #3
0
 def test_crosscorrelation(self):
     data = numpy.random.random((10, 10))
     ts = time_series.TimeSeries(data=data, title='meh')
     dt = temporal_correlations.CrossCorrelation(source=ts, array_data=numpy.array([0]))
     summary_info = dt.summary_info()
     assert summary_info['Dimensions'] == ('Offsets', 'Node', 'Node', 'State Variable', 'Mode')
     assert summary_info['Source'] == 'meh'
     assert summary_info['Temporal correlation type'] == 'CrossCorrelation'
     assert dt.labels_ordering == ('Offsets', 'Node', 'Node', 'State Variable', 'Mode')
     assert dt.source is not None
     assert dt.time is None
コード例 #4
0
ファイル: conftest.py プロジェクト: bvalean/tvb-root
    def build():
        time_series_index = time_series_index_factory()
        time_series = h5.load_from_index(time_series_index)
        data = numpy.random.random((10, 10, 10, 10, 10))
        cross_correlation = temporal_correlations.CrossCorrelation(source=time_series, array_data=data)

        op = operation_factory()

        cross_correlation_index = CrossCorrelationIndex()
        cross_correlation_index.fk_from_operation = op.id
        cross_correlation_index.fill_from_has_traits(cross_correlation)

        cross_correlation_h5_path = h5.path_for_stored_index(cross_correlation_index)
        with CrossCorrelationH5(cross_correlation_h5_path) as f:
            f.store(cross_correlation)

        cross_correlation_index = dao.store_entity(cross_correlation_index)
        return cross_correlation_index
コード例 #5
0
    def evaluate(self):
        """
        Cross-correlate two one-dimensional arrays.
        """
        cls_attr_name = self.__class__.__name__ + ".time_series"
        self.time_series.trait["data"].log_debug(owner=cls_attr_name)

        #(tpts, nodes, nodes, state-variables, modes)
        result_shape = self.result_shape(self.time_series.data.shape)
        LOG.info("result shape will be: %s" % str(result_shape))

        result = numpy.zeros(result_shape)

        #TODO: For region level, 4s, 2000Hz, this takes ~3hours...(which makes node_coherence seem positively speedy...)
        # Probably best to add a keyword for offsets, so we just compute +- some "small" range...
        # One inter-node correlation, across offsets, for each state-var & mode.
        for mode in range(result_shape[4]):
            for var in range(result_shape[3]):
                data = self.time_series.data[:, var, :, mode]
                data = data - data.mean(axis=0)[numpy.newaxis, :]
                #TODO: Work out a way around the 4 level loop:
                for n1 in range(result_shape[1]):
                    for n2 in range(result_shape[2]):
                        result[:, n1, n2, var, mode] = correlate(data[:, n1],
                                                                 data[:, n2],
                                                                 mode="same")

        util.log_debug_array(LOG, result, "result")

        offset = (self.time_series.sample_period *
                  numpy.arange(-numpy.floor(result_shape[0] / 2.0),
                               numpy.ceil(result_shape[0] / 2.0)))

        cross_corr = temporal_correlations.CrossCorrelation(
            source=self.time_series,
            array_data=result,
            time=offset,
            use_storage=False)

        return cross_corr