Last active
April 10, 2018 13:41
-
-
Save iphysresearch/ce548d477ca4e756b5d1f32fa8e29b87 to your computer and use it in GitHub Desktop.
S_Dbw_part1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class S_Dbw(): | |
def __init__(self,data,data_cluster,cluster_centroids_): | |
""" | |
data --> raw data | |
data_cluster --> The category that represents each piece of data(the number of category should begin 0) | |
cluster_centroids_ --> the center_id of each cluster's center | |
""" | |
self.data = data | |
self.data_cluster = data_cluster | |
self.cluster_centroids_ = cluster_centroids_ | |
# cluster_centroids_ 是一个 array, 给出类数k | |
self.k = cluster_centroids_.shape[0] | |
self.stdev = 0 # stdev 的初始化 | |
# 对每个类别标记进行循环,如:0,1,2,... | |
# 该循环计算的是下面公式里根号里的内容: | |
for i in range(self.k): | |
# 计算某类别下所有样本各自的全部特征值的方差: | |
#(vector,shape为样本的个数,相当于下面公式里的 signma) | |
std_matrix_i = np.std(data[self.data_cluster == i],axis=0) | |
# 求和 | |
self.stdev += np.sqrt(np.dot(std_matrix_i.T,std_matrix_i)) | |
self.stdev = np.sqrt(self.stdev)/self.k # 取平均 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment