Skip to content

Instantly share code, notes, and snippets.

View iphysresearch's full-sized avatar
🏛️
researching .....

He Wang iphysresearch

🏛️
researching .....
View GitHub Profile
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)
"""
@iphysresearch
iphysresearch / S_Dbw.py
Last active April 10, 2018 13:41
S_Dbw_part1.py
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_
@iphysresearch
iphysresearch / S_Dbw.py
Created April 10, 2018 13:42
S_Dbw_part2.py
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]]
@iphysresearch
iphysresearch / S_Dbw.py
Created April 10, 2018 13:45
S_Dbw_part3.py
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:
@iphysresearch
iphysresearch / S_Dbw.py
Last active April 10, 2018 14:09
S_Dbw_part4.py
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)
@iphysresearch
iphysresearch / S_Dbw.py
Created April 10, 2018 13:46
S_Dbw_part5.py
def S_Dbw_result(self):
"""
compute the final result
"""
return self.Dens_bw()+self.Scat()
@iphysresearch
iphysresearch / Plot_s_dbw_part1.py
Last active April 10, 2018 13:50
Plot_s_dbw.py
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
@iphysresearch
iphysresearch / min-char-rnn.py
Last active May 3, 2018 03:42 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
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) # 字符数目和单词数目
@iphysresearch
iphysresearch / test.ipynb
Last active December 24, 2018 08:37
[test] des... #pynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iphysresearch
iphysresearch / redis_demo.py
Last active January 10, 2019 08:18
[Redis-py 3.0 demo] a demo for Redis-py 3.0 (http://gree2.github.io/python/2016/05/14/python-with-docker-redis) #redis #demo #python
#! 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