def main_thread(): global main_array global score_array temp_return = user_score.main_thread(file_path) temp_return = nom.min_max_normalize(temp_return) main_array[0][1] = temp_return['3544'] main_array[1][1] = temp_return['48117'] main_array[2][1] = temp_return['58744'] main_array[3][1] = temp_return['60606'] main_array[4][1] = temp_return['60619'] main_array[5][1] = temp_return['60708'] main_array[6][1] = temp_return['60728'] main_array[7][1] = temp_return['60797'] main_array[8][1] = temp_return['61143'] temp_return = frac.main_thread(file_path) temp_return = nom.min_max_normalize(temp_return) main_array[0][2] = temp_return['3544'] main_array[1][2] = temp_return['48117'] main_array[2][2] = temp_return['58744'] main_array[3][2] = temp_return['60606'] main_array[4][2] = temp_return['60619'] main_array[5][2] = temp_return['60708'] main_array[6][2] = temp_return['60728'] main_array[7][2] = temp_return['60797'] main_array[8][2] = temp_return['61143'] temp_return = time.main_thread(file_path) temp_return = nom.min_max_normalize(temp_return) main_array[0][3] = temp_return['3544'] main_array[1][3] = temp_return['48117'] main_array[2][3] = temp_return['58744'] main_array[3][3] = temp_return['60606'] main_array[4][3] = temp_return['60619'] main_array[5][3] = temp_return['60708'] main_array[6][3] = temp_return['60728'] main_array[7][3] = temp_return['60797'] main_array[8][3] = temp_return['61143'] X_matrix = np.array(main_array) Y_matrix_t = np.array(score_array) Y_matrix = Y_matrix_t.transpose() res_vector_t = np.dot( np.dot(np.linalg.inv(np.dot(X_matrix.transpose(), X_matrix)), X_matrix.transpose()), Y_matrix) res_vector = list(res_vector_t.transpose()) for i in range(len(res_vector)): res_vector[i] = float(res_vector[i]) print(res_vector) print(main_array[0][0] * res_vector[1] + main_array[0][1] * res_vector[2] + main_array[0][2] * res_vector[3] + main_array[0][3] * res_vector[4] - res_vector[0]) return res_vector
def json_read(): global main_array f = open(file_path_style, 'r', encoding='utf-8') data = json.load(f) data = nom.min_max_normalize(data) main_array[0][4] = data['3544'] main_array[1][4] = data['48117'] main_array[2][4] = data['58744'] main_array[3][4] = data['60606'] main_array[4][4] = data['60619'] main_array[5][4] = data['60708'] main_array[6][4] = data['60728'] main_array[7][4] = data['60797'] main_array[8][4] = data['61143']
def main_thread(): temp_return = userScore.main_thread(file_path) temp_return = normal.min_max_normalize(temp_return) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) temp_return = fraction.main_thread(file_path) temp_return = normal.min_max_normalize(temp_return) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) temp_return = firstUpload.main_thread(file_path) temp_return = normal.min_max_normalize(temp_return) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) temp_return = time.main_thread(file_path) temp_return = normal.min_max_normalize(temp_return) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) temp_return = compare.main_thread(file_path) temp_return = normal.min_max_normalize(temp_return) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) f = open('SampleCodingStyleOutput.json', 'r', encoding='utf-8') # codingStyle这个速度,还是直接读文件比较好 data = json.load(f) temp_return = normal.min_max_normalize(data) temp_value_list = list(temp_return.values()) diff_return.append(temp_value_list) a = np.asarray(diff_return) # print(a) # correlation_matrix = np.corrcoef(a, rowvar=True) # print(correlation_matrix.round(2)) positive_relations = [] negative_relations = [] corr_matrix_list = [] p_matrix_list = [] for i in range(len(a)): tmp_0 = [] tmp_1 = [] for j in range(len(a)): corr, p = pearsonr(a[i], a[j]) tmp_0.append(corr) tmp_1.append(p) if p < 0.01 and i != j: if corr > 0.9 and [j, i] not in positive_relations: positive_relations.append([i, j]) # list_merge(positive_relations) if corr < -0.9 and [j, i] not in negative_relations: negative_relations.append([i, j]) # list_merge(negative_relations) corr_matrix_list.append(tmp_0) p_matrix_list.append(tmp_1) corr_matrix = np.asarray(corr_matrix_list) p_matrix = np.asarray(p_matrix_list) print(corr_matrix.round(2)) print(p_matrix.round(2)) positive_negative = [positive_relations, negative_relations] print(positive_negative) return positive_negative
def main_thread(): temp_return = firstgit.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][0] = temp_return[case_id] temp_return = final.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][1] = temp_return[case_id] temp_return = avg.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][2] = temp_return[case_id] temp_return = frac.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][3] = temp_return[case_id] temp_return = slope.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][4] = temp_return[case_id] temp_return = time.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][5] = temp_return[case_id] temp_return = com.main_thread(file_path) temp_return = nomal.min_max_normalize(temp_return) temp_case_list = temp_return.keys() for case_id in temp_case_list: diff_return[int(case_id)][6] = temp_return[case_id] for i in range(3000): num = aver(diff_return[i]) for j in range(7): diff_return[i][j] -= num matrix_diff_origin = numpy.array(diff_return) # use numpy to calculate covariance(协方差) matrix of the matrix and view each row as a var cov_matrix = numpy.cov(matrix_diff_origin, rowvar=False) # calculate matrix eigenvalues of the matrix # eig_matrix_list[0]特征值,[1]特征向量 eig_matrix_list = numpy.linalg.eig(cov_matrix) eig_matrix_value = list(numpy.linalg.eigvals(cov_matrix)) main_var_index = eig_matrix_value.index(max( eig_matrix_value)) # eig_matrix_list[0].index(max(eig_matrix_value)) # have Eigenvector of the matrix eig_vector_matrix = numpy.array(list(eig_matrix_list[1][main_var_index])) # transpose the matrix trans_eig_vec_matrix = eig_vector_matrix.transpose( ) # numpy.transpose(eig_vector_matrix) # 两矩阵相乘 res_matrix = list(numpy.dot(matrix_diff_origin, trans_eig_vec_matrix)) for i in range(3000): res_matrix[i] = float(res_matrix[i]) min_val = min(res_matrix) max_val = max(res_matrix) sub_val = max_val - min_val for i in range(len(res_matrix)): res_matrix[i] = round((res_matrix[i] - min_val) / sub_val, 2) # print(res_matrix) return res_matrix