def test_reconstruction(): assert np.all( pypsr.reconstruct(np.arange(10), 1, 2) == np.vstack((np.arange(9), np.arange(1, 10))).transpose() ) assert np.all( pypsr.reconstruct(np.arange(10), 2, 3) == np.vstack((np.arange(6), np.arange(2, 8), np.arange(4, 10))).transpose() )
return 0 input_file = r'/home/mty/conflictNUM20181024.csv' df = pd.read_csv(input_file) origin_info = list(df.iloc[:, 1]) origin_time = list(df.iloc[:, 2]) new_info = [] new_time = [] for index, row in enumerate(origin_info): if index % 2 == 0: new_info.append(row) new_time.append(int(origin_time[index])) warnings.filterwarnings("error") reconstruct_list = pypsr.reconstruct(new_info, 12, 6) threshold = 0.92 node_couple_set = [] for index1, vector1 in enumerate(reconstruct_list): tem_list = reconstruct_list[index1:, :] if len(tem_list) > 1: for index2, vector2 in enumerate(tem_list): try: correlation_coefficient = np.corrcoef(vector1, vector2) D = heaviside(correlation_coefficient[0][1], threshold) if D == 1: node_couple_set.append((index1, index2 + index1 + 1)) except: pass node_set = [] for node_couple in node_couple_set:
import warnings def heaviside(value, threshold=0.7): if value >= threshold: return 1 else: return 0 input_file = r'/home/mty/conflictNUM.csv' df = pd.read_csv(input_file) origin_info = list(df.iloc[:, 1]) warnings.filterwarnings("error") reconstruct_list = pypsr.reconstruct(origin_info, 12, 6) average_clustering = [] for i in np.arange(0.80, 1., 0.01): threshold = round(i, 2) print(threshold) node_couple_set = [] for index1, vector1 in enumerate(reconstruct_list): tem_list = reconstruct_list[index1:, :] if len(tem_list) > 1: for index2, vector2 in enumerate(tem_list): try: correlation_coefficient = np.corrcoef(vector1, vector2) D = heaviside(correlation_coefficient[0][1], threshold) if D == 1: node_couple_set.append((index1, index2 + index1 + 1)) except:
def test_reconstruction_too_long_lag(): with pytest.raises(ValueError): pypsr.reconstruct(np.ones(10), 5, 2) with pytest.raises(ValueError): pypsr.reconstruct(np.ones(10), 2, 5)
def test_reconstruction_wrong_dimension_input(): with pytest.raises(ValueError): pypsr.reconstruct(np.ones((10, 10)), 1, 2)