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
def affine_forward(x, w, b): | |
""" | |
Inputs: | |
- x: A numpy array containing input data, of shape (N, d_1, ..., d_k) 样本 | |
- w: A numpy array of weights, of shape (D, M) 权重 | |
- b: A numpy array of biases, of shape (M,) 偏置 | |
Returns a tuple of: | |
- out: output, of shape (N, M) | |
- cache: (x, w, b) | |
""" |
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_ |
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
def density(self,density_list=[]): | |
""" | |
compute the density of one or two cluster(depend on density_list) | |
变量 density_list 将作为此函数的内部列表,其取值范围是0,1,2,... ,元素个数是聚类类别数目 | |
""" | |
density = 0 | |
if len(density_list) == 2: # 当考虑两个聚类类别时候,给出中心点位置 | |
center_v = (self.cluster_centroids_[density_list[0]] +self.cluster_centroids_[density_list[1]])/2 | |
else: # 当只考虑某一个聚类类别的时候,给出中心点位置 | |
center_v = self.cluster_centroids_[density_list[0]] |
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
def Dens_bw(self): | |
density_list = [] | |
result = 0 | |
# 下面的变量 density_list 列表将会算出每个对应单类的密度值。 | |
for i in range(self.k): | |
density_list.append(self.density(density_list=[i])) # i 是循环类别标签 | |
# 开始循环排列 | |
for i in range(self.k): | |
for j in range(self.k): | |
if i==j: |
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
def Scat(self): | |
# 分母部分: | |
sigma_s = np.std(self.data,axis=0) | |
sigma_s_2norm = np.sqrt(np.dot(sigma_s.T,sigma_s)) | |
# 分子部分: | |
sum_sigma_2norm = 0 | |
for i in range(self.k): | |
matrix_data_i = self.data[self.data_cluster == i] | |
sigma_i = np.std(matrix_data_i,axis=0) |
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
def S_Dbw_result(self): | |
""" | |
compute the final result | |
""" | |
return self.Dens_bw()+self.Scat() |
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
import numpy as np | |
import S_Dbw as sdbw | |
from sklearn.cluster import KMeans | |
from sklearn.datasets.samples_generator import make_blobs | |
from sklearn.metrics.pairwise import pairwise_distances_argmin | |
np.random.seed(0) | |
S_Dbw_result = [] | |
batch_size = 45 |
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
""" | |
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
BSD License | |
""" | |
import numpy as np | |
# data I/O 输入训练数据 | |
data = open('input.txt', 'r').read() # should be simple plain text file | |
chars = list(set(data)) | |
data_size, vocab_size = len(data), len(chars) # 字符数目和单词数目 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
#! usr/bin/python | |
#coding=utf-8 | |
# http://gree2.github.io/python/2016/05/14/python-with-docker-redis | |
from __future__ import print_function | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import sys, os, time |
OlderNewer