def test_Headbanging_Median_Rate(self): s_ht = sm.Headbanging_Triples(self.d, self.w, k=5) sids_hb_r = sm.Headbanging_Median_Rate(self.e, self.b, s_ht) np.testing.assert_array_almost_equal(self.sids_hb_rr5, sids_hb_r.r[:5]) sids_hb_r2 = sm.Headbanging_Median_Rate(self.e, self.b, s_ht, iteration=5) np.testing.assert_array_almost_equal(self.sids_hb_r2r5, sids_hb_r2.r[:5]) sids_hb_r3 = sm.Headbanging_Median_Rate(self.e, self.b, s_ht, aw=self.b) np.testing.assert_array_almost_equal(self.sids_hb_r3r5, sids_hb_r3.r[:5])
def test_Headbanging_Triples(self): ht = sm.Headbanging_Triples(self.d, self.w) self.assertEquals(len(ht.triples), len(self.d)) ht2 = sm.Headbanging_Triples(self.d, self.w, edgecor=True) self.assertTrue(hasattr(ht2, 'extra')) self.assertEquals(len(ht2.triples), len(self.d)) htr = sm.Headbanging_Median_Rate(self.e, self.b, ht2, iteration=5) self.assertEquals(len(htr.r), len(self.e)) for i in htr.r: self.assertTrue(i is not None)
def test_Headbanging_Median_Rate(self): sids_d = np.array([i.centroid for i in self.sids]) sids_w = pysal.knnW(sids_d, k=5) if not sids_w.id_order_set: sids_w.id_order = sids_w.id_order s_ht = sm.Headbanging_Triples(sids_d, sids_w, k=5) sids_db = pysal.open(pysal.examples.get_path('sids2.dbf'), 'r') s_e, s_b = np.array(sids_db[:, 9]), np.array(sids_db[:, 8]) sids_hb_r = sm.Headbanging_Median_Rate(s_e, s_b, s_ht) sids_hb_rr5 = np.array([0.00075586, 0., 0.0008285, 0.0018315, 0.00498891]) np.testing.assert_array_almost_equal(sids_hb_rr5, sids_hb_r.r[:5]) sids_hb_r2 = sm.Headbanging_Median_Rate(s_e, s_b, s_ht, iteration=5) sids_hb_r2r5 = np.array([0.0008285, 0.00084331, 0.00086896, 0.0018315, 0.00498891]) np.testing.assert_array_almost_equal(sids_hb_r2r5, sids_hb_r2.r[:5]) sids_hb_r3 = sm.Headbanging_Median_Rate(s_e, s_b, s_ht, aw=s_b) sids_hb_r3r5 = np.array([0.00091659, 0., 0.00156838, 0.0018315, 0.00498891]) np.testing.assert_array_almost_equal(sids_hb_r3r5, sids_hb_r3.r[:5])
def test_Headbanging_Median_Rate_tabular(self): # test that dataframe columns are treated correctly s_ht = sm.Headbanging_Triples(self.d, self.w, k=5) sids_hb_r = sm.Headbanging_Median_Rate(self.df[self.ename], self.df[self.bname], s_ht) self.assertIsInstance(sids_hb_r.r, np.ndarray) np.testing.assert_array_almost_equal(self.sids_hb_rr5, sids_hb_r.r[:5]) sids_hb_r2 = sm.Headbanging_Median_Rate(self.df[self.ename], self.df[self.bname], s_ht, iteration=5) self.assertIsInstance(sids_hb_r2.r, np.ndarray) np.testing.assert_array_almost_equal(self.sids_hb_r2r5, sids_hb_r2.r[:5]) sids_hb_r3 = sm.Headbanging_Median_Rate(self.df[self.ename], self.df[self.bname], s_ht, aw=self.df[self.bname]) self.assertIsInstance(sids_hb_r3.r, np.ndarray) np.testing.assert_array_almost_equal(self.sids_hb_r3r5, sids_hb_r3.r[:5]) #test that the by col on multiple names works correctly sids_hr_df = sm.Headbanging_Median_Rate.by_col(self.df, self.enames, self.bnames, w=self.w) outcols = [ '{}-{}_headbanging_median_rate'.format(e, b) for e, b in zip(self.enames, self.bnames) ] for col, answer in zip(outcols, [self.sids_hb_rr5, self.sids79r]): this_col = sids_hr_df[col].values self.assertIsInstance(this_col, np.ndarray) np.testing.assert_allclose(sids_hr_df[col][:5], answer, rtol=RTOL, atol=ATOL * 10)