mirror of
https://github.com/This-weiyuqing/ECG_by_Diffenert_CNN_Test.git
synced 2026-10-18 03:13:39 +08:00
may be last version
By completing the thesis, we have corrected the deficiencies and fixed some bugs.
This commit is contained in:
1 parent
a13e1ace47
commit
af187d92e9
49 files changed
+129
-7
No files matched your search
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun Mar 11 20:41:57 2018
|
||||
|
||||
@author: brucelau
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
x = np.linspace(-10,10)
|
||||
y_sigmoid = 1/(1+np.exp(-x))
|
||||
y_tanh = (np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))
|
||||
|
||||
fig = plt.figure()
|
||||
# plot sigmoid
|
||||
ax = fig.add_subplot(221)
|
||||
ax.plot(x,y_sigmoid)
|
||||
ax.grid()
|
||||
ax.set_title('(a) Sigmoid')
|
||||
|
||||
# plot tanh
|
||||
ax = fig.add_subplot(222)
|
||||
ax.plot(x,y_tanh)
|
||||
ax.grid()
|
||||
ax.set_title('(b) Tanh')
|
||||
|
||||
# plot relu
|
||||
ax = fig.add_subplot(223)
|
||||
y_relu = np.array([0*item if item<0 else item for item in x ])
|
||||
ax.plot(x,y_relu)
|
||||
ax.grid()
|
||||
ax.set_title('(c) ReLu')
|
||||
|
||||
#plot leaky relu
|
||||
ax = fig.add_subplot(224)
|
||||
y_relu = np.array([0.2*item if item<0 else item for item in x ])
|
||||
ax.plot(x,y_relu)
|
||||
ax.grid()
|
||||
ax.set_title('(d) Leaky ReLu')
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import pywt
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 生成DB5小波
|
||||
wavelet = pywt.Wavelet('db5')
|
||||
|
||||
# 获取尺度函数和小波函数
|
||||
phi, psi, x = wavelet.wavefun(level=5)
|
||||
|
||||
# 绘制尺度函数和小波函数
|
||||
plt.figure()
|
||||
plt.subplot(2, 1, 1)
|
||||
plt.plot(x, phi)
|
||||
plt.title('DB5 Scaling Function (Phi)')
|
||||
plt.subplot(2, 1, 2)
|
||||
plt.plot(x, psi)
|
||||
plt.title('DB5 Wavelet Function (Psi)')
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
h0=wavelet.dec_lo
|
||||
h1=wavelet.dec_hi
|
||||
g0=wavelet.rec_lo
|
||||
g1=wavelet.rec_hi
|
||||
|
||||
print('h0:', h0)
|
||||
print('h1:', h1)
|
||||
print('g0:', g0)
|
||||
print('g1:', g1)
|
||||
@@ -0,0 +1,36 @@
|
||||
import numpy as np
|
||||
import keras
|
||||
from keras.models import Sequential
|
||||
from keras.layers import Dense, Dropout, Flatten
|
||||
from keras.layers import Conv2D, MaxPooling2D
|
||||
from keras.optimizers import SGD
|
||||
|
||||
# 生成虚拟数据
|
||||
x_train = np.random.random((100, 100, 100, 3))
|
||||
y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)
|
||||
x_test = np.random.random((20, 100, 100, 3))
|
||||
y_test = keras.utils.to_categorical(np.random.randint(10, size=(20, 1)), num_classes=10)
|
||||
|
||||
model = Sequential()
|
||||
# 输入: 3 通道 100x100 像素图像 -> (100, 100, 3) 张量。
|
||||
# 使用 32 个大小为 3x3 的卷积滤波器。
|
||||
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3)))
|
||||
model.add(Conv2D(32, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Conv2D(64, (3, 3), activation='relu'))
|
||||
model.add(Conv2D(64, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Flatten())
|
||||
model.add(Dense(256, activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Dense(10, activation='softmax'))
|
||||
|
||||
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
|
||||
model.compile(loss='categorical_crossentropy', optimizer=sgd)
|
||||
|
||||
model.fit(x_train, y_train, batch_size=32, epochs=10)
|
||||
score = model.evaluate(x_test, y_test, batch_size=32)
|
||||
@@ -0,0 +1,14 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def softmax(x):
|
||||
return np.exp(x) / np.sum(np.exp(x))
|
||||
|
||||
x = np.arange(-10, 10, 0.1)
|
||||
y = softmax(x)
|
||||
|
||||
plt.plot(x, y)
|
||||
plt.title('Softmax Function')
|
||||
plt.xlabel('Input')
|
||||
plt.ylabel('Output')
|
||||
plt.show()
|
||||
Reference in new issue
Block a user