Example #1
0
    def test_basic(self):
        # Note: the docstrings for the argrel{min,max,extrema} functions
        # do not give a guarantee of the order of the indices, so we'll
        # sort them before testing.

        x = np.array([[1, 2, 2, 3, 2],
                      [2, 1, 2, 2, 3],
                      [3, 2, 1, 2, 2],
                      [2, 3, 2, 1, 2],
                      [1, 2, 3, 2, 1]])

        row, col = argrelmax(x, axis=0)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [4, 0, 1])

        row, col = argrelmax(x, axis=1)
        order = np.argsort(row)
        assert_equal(row[order], [0, 3, 4])
        assert_equal(col[order], [3, 1, 2])

        row, col = argrelmin(x, axis=0)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [1, 2, 3])

        row, col = argrelmin(x, axis=1)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [1, 2, 3])
Example #2
0
    def test_basic(self):
        # Note: the docstrings for the argrel{min,max,extrema} functions
        # do not give a guarantee of the order of the indices, so we'll
        # sort them before testing.

        x = np.array([[1, 2, 2, 3, 2], [2, 1, 2, 2, 3], [3, 2, 1, 2, 2],
                      [2, 3, 2, 1, 2], [1, 2, 3, 2, 1]])

        row, col = argrelmax(x, axis=0)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [4, 0, 1])

        row, col = argrelmax(x, axis=1)
        order = np.argsort(row)
        assert_equal(row[order], [0, 3, 4])
        assert_equal(col[order], [3, 1, 2])

        row, col = argrelmin(x, axis=0)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [1, 2, 3])

        row, col = argrelmin(x, axis=1)
        order = np.argsort(row)
        assert_equal(row[order], [1, 2, 3])
        assert_equal(col[order], [1, 2, 3])
 def reset(self):
     """
     Deletes stored computations.
     """
     self.minima = keydefaultdict(lambda (key, axis): argrelmin(self.data[key][:, axis], order=self.w_ext)[0])
     self.maxima = keydefaultdict(lambda (key, axis): argrelmax(self.data[key][:, axis], order=self.w_ext)[0])
     self.derivative_minima = keydefaultdict(
         lambda (key, axis): argrelmin(np.diff(self.data[key][:, axis]), order=self.w_ext)[0])
     self.derivative_maxima = keydefaultdict(
         lambda (key, axis): argrelmax(np.diff(self.data[key][:, axis]), order=self.w_ext)[0])
 def predict_all(self, t):
     """
     Detects and returns the time of all events occurrences in t.
     :param t: multidimensional time series
     :type t: np.array, shape = (len(t), len(dim(t)))
     :return: list of indices in the middle of the shapelet matches
     :rtype: np.array
     """
     ds = dist_shapelet_ts(self.shapelet, t, self.dim_s)
     ds[ds >= self.delta] = self.delta
     mins = argrelmin(ds, order=self.shapelet.shape[0] // 2)[0]
     return np.asarray(mins)
Example #5
0
    def test_empty(self):
        # Regression test for gh-2832.
        # When there are no relative extrema, make sure that
        # the number of empty arrays returned matches the
        # dimension of the input.

        empty_array = np.array([], dtype=int)

        z1 = np.zeros(5)

        i = argrelmin(z1)
        assert_equal(len(i), 1)
        assert_array_equal(i[0], empty_array)

        z2 = np.zeros((3, 5))

        row, col = argrelmin(z2, axis=0)
        assert_array_equal(row, empty_array)
        assert_array_equal(col, empty_array)

        row, col = argrelmin(z2, axis=1)
        assert_array_equal(row, empty_array)
        assert_array_equal(col, empty_array)
Example #6
0
    def test_empty(self):
        # Regression test for gh-2832.
        # When there are no relative extrema, make sure that
        # the number of empty arrays returned matches the
        # dimension of the input.

        empty_array = np.array([], dtype=int)

        z1 = np.zeros(5)

        i = argrelmin(z1)
        assert_equal(len(i), 1)
        assert_array_equal(i[0], empty_array)

        z2 = np.zeros((3,5))

        row, col = argrelmin(z2, axis=0)
        assert_array_equal(row, empty_array)
        assert_array_equal(col, empty_array)

        row, col = argrelmin(z2, axis=1)
        assert_array_equal(row, empty_array)
        assert_array_equal(col, empty_array)
Example #7
0
lt = []
for i in dataset1['msg_stamp'].map(str):
   lt.append('.' + i.zfill(3))
dataset1['ros_time'] = pandas.Series(lt)
dataset1['time_stamp'] = dataset1['eventtime'].map(str) + dataset1['ros_time']
del dataset1['eventtime']
del dataset1['msg_stamp']
del dataset1['ros_time']
del dataset1['symbols']
dataset1['time_stamp'] = pandas.to_datetime(dataset1['time_stamp'], errors = 'coerce')
dataset1_ = dataset1.set_index('time_stamp')
eigen = dataset1_.eigen_force.resample('1L')
eigen.fillna(method = 'ffill', inplace = True)
#print dataset1_
y = np.array(eigen)
p = argrelmin(y)
q = argrelmax(y)
p = list(p)
q = list(q)
for i in p:
   c = i.flatten()
for i in q:
   d = i.flatten()
c = list(c)
d = list(d)
fig, ax = plt.subplots()
#ax2.plot(range(len(skill)), skill, 'g', lw = 2)
#ax.set_xlim([0, len(eigen)])
#ax.plot(range(len(eigen)), eigen, 'b', lw = 2)
ax.set_xlim([0, len(eigen)])
ax.plot(range(len(eigen)), eigen, 'r', lw = 2)