def testRDivide(self): a = Array.from_list([1, 2, 3, 4], dtype.s32) b = Array.from_list([1, 2, 3, 4], dtype.s32) c = a / b expected = np.array([1., 1., 1., 1.]) for d, e in zip(expected, c.to_numpy()): self.assertAlmostEqual(d, e, delta=1e-5)
def test_linear(self): euclidean_result = linear( Array.from_list([ 0.24580423, 0.59642861, 0.35879163, 0.37891011, 0.02445137, 0.23830957, 0.38793433, 0.68054104, 0.83934083, 0.76073689 ], dtype.f32), Array.from_list([ 0.2217416, 0.06344161, 0.77944375, 0.72174137, 0.19413884, 0.51146167, 0.06880307, 0.39414268, 0.98172767, 0.30490851 ], dtype.f32)) self.assertAlmostEqual(euclidean_result[0].to_numpy(), 0.344864266, delta=self.DELTA) self.assertAlmostEqual(euclidean_result[1].to_numpy(), 0.268578232, delta=self.DELTA) self.assertAlmostEqual(euclidean_result[2].to_numpy(), 0.283552942, delta=self.DELTA) self.assertAlmostEqual(euclidean_result[3].to_numpy(), 0.427239418, delta=self.DELTA) self.assertAlmostEqual(euclidean_result[4].to_numpy(), 0.412351891, delta=self.DELTA)
def test_quantile(self): result = quantile( Array.from_list([[0, 0, 0, 0, 3, 4, 13], [0, 0, 0, 0, 3, 4, 13]], dtype.f32), Array.from_list([0.6], dtype.f32)).to_numpy() self.assertAlmostEqual(result[0], 1.79999999, delta=1e-4) self.assertAlmostEqual(result[1], 1.79999999, delta=1e-4)
def test_quantile(self): result = quantile( Array.from_list([[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]], dtype.s32), Array.from_list([0.1, 0.2], dtype.f32)).to_numpy().flatten() expected = np.array([0.5, 1.0, 6.5, 7.0]) np.testing.assert_array_almost_equal(result, expected, decimal=2)
def test_cwt_coefficients(self): cwt_coefficients_result = cwt_coefficients( Array.from_list([[0.1, 0.2, 0.3], [0.1, 0.2, 0.3]], dtype.f32), Array.from_list([1, 2, 3], dtype.s32), 2, 2).to_numpy() self.assertAlmostEqual(cwt_coefficients_result[0], 0.26517161726951599, delta=self.DELTA) self.assertAlmostEqual(cwt_coefficients_result[1], 0.26517161726951599, delta=self.DELTA)
def test_moment(self): result = moment( Array.from_list([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype.s32), 2).to_numpy().flatten() expected = np.array([9.166666666, 9.166666666]) np.testing.assert_array_almost_equal(result, expected, decimal=6) result = moment( Array.from_list([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype.s32), 4).to_numpy().flatten() expected = np.array([163.1666666666, 163.1666666666]) np.testing.assert_array_almost_equal(result, expected, decimal=2)
def test_auto_covariance(self): auto_covariance_result = auto_covariance( Array.from_list([[0, 1, 2, 3], [10, 11, 12, 13]], dtype.f32)).to_numpy() self.assertAlmostEqual(auto_covariance_result[0][0], 1.25, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[0][1], 0.3125, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[0][2], -0.375, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[0][3], -0.5625, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[1][0], 1.25, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[1][1], 0.3125, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[1][2], -0.375, delta=self.DELTA) self.assertAlmostEqual(auto_covariance_result[1][3], -0.5625, delta=self.DELTA)
def test_spkt_welch_density(self): result = spkt_welch_density( Array.from_list([[0, 1, 1, 3, 4, 5, 6, 7, 8, 9], [0, 1, 1, 3, 4, 5, 6, 7, 8, 9]], dtype.f32), 0).to_numpy() self.assertAlmostEqual(result[0], 1.6666667, delta=1e-5) self.assertAlmostEqual(result[1], 1.6666667, delta=1e-5)
def test_percentage_of_reocurring_values_to_all_values(self): result = percentage_of_reoccurring_values_to_all_values( Array.from_list( [[1, 1, 2, 3, 4, 4, 5, 6], [1, 2, 2, 3, 4, 5, 6, 7]], dtype.f32), False).to_numpy() self.assertEqual(result[0], 4.0 / 8.0) self.assertEqual(result[1], 2.0 / 8.0)
def test_abs_sum_of_changes(self): abs_sum_of_changes_result = absolute_sum_of_changes( Array.from_list([[0, 1, 2, 3], [4, 6, 8, 10], [11, 14, 17, 20]], dtype.s32)).to_numpy() self.assertEqual(abs_sum_of_changes_result[0], 3) self.assertEqual(abs_sum_of_changes_result[1], 6) self.assertEqual(abs_sum_of_changes_result[2], 9)
def test_sbd(self): sbd_result = sbd( Array.from_list( [[1, 2, 3, 4, 5], [1, 1, 0, 1, 1], [10, 12, 0, 0, 1]], dtype.f32)).to_numpy().flatten() expected = np.array([0, 0, 0, 0.505025, 0, 0, 0.458583, 0.564093, 0]) np.testing.assert_array_almost_equal(sbd_result, expected, decimal=1)
def test_int_4d(self): test_input = [[[[1, 9], [2, 10]], [[3, 11], [4, 12]]], [[[5, 13], [6, 14]], [[7, 15], [8, 16]]]] a = Array.from_list(test_input, dtype.s64) expected = np.array(test_input) np.testing.assert_array_equal(a.to_numpy(), expected) np.testing.assert_array_equal(a.dims, np.array([2, 2, 2, 2]))
def testMatmul(self): a = Array.from_list([1, 2, 3, 4], dtype.f32) b = a.transpose() c = a.matmul(b) expected = np.transpose([[1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12], [4, 8, 12, 16]]) np.testing.assert_array_equal(c.to_numpy(), expected)
def test_squared_euclidean(self): squared_euclidean_result = squared_euclidean( Array.from_list([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]], dtype.s32)).to_numpy().flatten() expected = np.array([0, 0, 0, 64, 0, 0, 256, 64, 0]) np.testing.assert_array_almost_equal(squared_euclidean_result, expected)
def test_linear_trend(self): pvalue, rvalue, intercept, slope, stderr = linear_trend( Array.from_list([[0, 4, 3, 5, 5, 1], [2, 4, 1, 2, 5, 3]], dtype.f32)) pvalue = pvalue.to_numpy() self.assertAlmostEqual(pvalue[0], 0.6260380997892747, delta=self.DELTA) self.assertAlmostEqual(pvalue[1], 0.5272201945463578, delta=self.DELTA) rvalue = rvalue.to_numpy() self.assertAlmostEqual(rvalue[0], 0.2548235957188128, delta=self.DELTA) self.assertAlmostEqual(rvalue[1], 0.3268228676411533, delta=self.DELTA) intercept = intercept.to_numpy() self.assertAlmostEqual(intercept[0], 2.2857142857142856, delta=self.DELTA) self.assertAlmostEqual(intercept[1], 2.1904761904761907, delta=self.DELTA) slope = slope.to_numpy() self.assertAlmostEqual(slope[0], 0.2857142857142857, delta=self.DELTA) self.assertAlmostEqual(slope[1], 0.2571428571428572, delta=self.DELTA) stderr = stderr.to_numpy() self.assertAlmostEqual(stderr[0], 0.5421047417431507, delta=self.DELTA) self.assertAlmostEqual(stderr[1], 0.37179469135129783, delta=self.DELTA)
def test_auto_correlation(self): auto_correlation_result = auto_correlation( Array.from_list([[0, 1, 2, 3], [10, 11, 12, 13]], dtype.f32), 4, False).to_numpy().flatten() self.assertAlmostEqual(auto_correlation_result[0], 1, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[1], 0.25, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[2], -0.3, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[3], -0.45, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[4], 1.0, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[5], 0.25, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[6], -0.3, delta=self.DELTA) self.assertAlmostEqual(auto_correlation_result[7], -0.45, delta=self.DELTA)
def test_number_cwt_peaks(self): result = number_cwt_peaks( Array.from_list([[ 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1 ], [1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1] ], dtype.f32), 2).to_numpy() self.assertEqual(result[0], 2) self.assertEqual(result[1], 2)
def test_concatenated(self): a = Array.from_list([[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11]], dtype.s32) b = absolute_sum_of_changes(a).to_arrayfire() c = af.transpose(b) d = Array.from_arrayfire(c) e = abs_energy(d).to_numpy() self.assertAlmostEqual(e, 385, delta=self.DELTA)
def test_decimal_scaling_norm_in_place(self): tss = Array.from_list([[0, 1, -2, 3], [40, 50, 60, -70]], dtype.f32) decimal_scaling_norm_in_place(tss) tss = tss.to_numpy() expected = np.array([[0.0, 0.1, -0.2, 0.3], [0.4, 0.5, 0.6, -0.7]]) np.testing.assert_array_almost_equal(tss, expected, decimal=self.DECIMAL)
def test_decimal_scaling_norm(self): decimal_scaling_norm_result = decimal_scaling_norm( Array.from_list([[0, 1, -2, 3], [40, 50, 60, -70]], dtype.s32)).to_numpy() expected = np.array([[0.0, 0.1, -0.2, 0.3], [0.4, 0.5, 0.6, -0.7]]) np.testing.assert_array_almost_equal(decimal_scaling_norm_result, expected, decimal=self.DECIMAL)
def test_mean_norm_in_place(self): a = Array.from_list([[0, 1, 2, 3], [4, 5, 6, 7]], dtype.f32) mean_norm_in_place(a) expected = np.array([[-0.5, -0.166666667, 0.166666667, 0.5], [-0.5, -0.166666667, 0.166666667, 0.5]]) np.testing.assert_array_almost_equal(a.to_numpy(), expected, decimal=self.DECIMAL)
def test_group_by_double_key_double_value_column(self): group_by_result = group_by( Array.from_list([[0, 0, 0, 2, 2], [2, 2, 2, 4, 4], [0, 1, 2, 3, 4], [1, 1, 1, 1, 1]], dtype.f32), 0, 2, 2).to_numpy() expected = [[1, 3.5], [1, 1]] np.testing.assert_array_almost_equal(group_by_result, expected, decimal=self.DECIMAL)
def test_group_by_single_column(self): group_by_result = group_by( Array.from_list([[0, 1, 1, 2, 2, 3], [0, 3, 3, 1, 1, 2]], dtype.s32), 0).to_numpy() expected = [0, 3, 1, 2] np.testing.assert_array_almost_equal(group_by_result, expected, decimal=self.DECIMAL)
def test_hamming(self): result = hamming( Array.from_list([[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]], dtype.s32)).to_numpy() expected = np.array([[0, 0, 0, 0, 0], [5, 0, 0, 0, 0], [5, 5, 0, 0, 0], [5, 5, 5, 0, 0], [5, 5, 5, 5, 0]]) np.testing.assert_array_almost_equal(result, expected)
def test_mean_norm(self): result = mean_norm( Array.from_list([[0, 1, 2, 3], [4, 5, 6, 7]], dtype.s32)).to_numpy() expected = np.array([[-0.5, -0.166666667, 0.166666667, 0.5], [-0.5, -0.166666667, 0.166666667, 0.5]]) np.testing.assert_array_almost_equal(result, expected, decimal=self.DECIMAL)
def test_dtw(self): euclidean_result = dtw( Array.from_list([[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]], dtype.s32)).to_numpy() expected = np.array([[0, 0, 0, 0, 0], [5, 0, 0, 0, 0], [10, 5, 0, 0, 0], [15, 10, 5, 0, 0], [20, 15, 10, 5, 0]]) np.testing.assert_array_almost_equal(euclidean_result, expected)
def test_max_min_norm(self): max_min_norm_result = max_min_norm( Array.from_list([[0, 1, 2, 3], [4, 5, 6, 7]], dtype.s32), 2.0, 1.0).to_numpy() expected = np.array([[1.0, 1.3333333333333, 1.66666667, 2.0], [1.0, 1.3333333333333, 1.66666667, 2.0]]) np.testing.assert_array_almost_equal(max_min_norm_result, expected, decimal=self.DECIMAL)
def test_real_3d(self): test_input = [[[1.0, 5.0, 3.0, 1.0], [2.0, 6.0, 9.0, 8.0], [3.0, 4.0, 1.0, 3.0]], [[3.0, 7.0, 4.0, 2.0], [4.0, 8.0, 1.0, 9.0], [1.0, 5.0, 9.0, 2.0]]] a = Array.from_list(test_input, dtype.f32) expected = np.array(test_input) np.testing.assert_array_equal(a.to_numpy(), expected) np.testing.assert_array_equal(a.dims, np.array([4, 3, 2, 1]))
def test_max_min_norm_in_place(self): tss = Array.from_list([[0, 1, 2, 3], [4, 5, 6, 7]], dtype.f32) max_min_norm_in_place(tss, 2.0, 1.0) tss = tss.to_numpy() expected = np.array([[1.0, 1.3333333333333, 1.66666667, 2.0], [1.0, 1.3333333333333, 1.66666667, 2.0]]) np.testing.assert_array_almost_equal(tss, expected, decimal=self.DECIMAL)
def test_pla_sliding_window(self): tss = Array.from_list( [[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], [0.0, 0.1, -0.1, 5.0, 6.0, 7.0, 8.1, 9.0, 9.0, 9.0]], dtype.f32) expected = [[0, 2, 3, 7, 8, 9], [0, -0.1, 5, 9, 9, 9]] result = pla_sliding_window(tss, 1).to_numpy() np.testing.assert_array_almost_equal(result, expected, decimal=self.DECIMAL)