自学内容网 自学内容网

python写一个可以深度学习的程序

import numpy as np
import matplotlib.pyplot as plt

class NeuralNetwork:
def init(self, layers, activation=‘sigmoid’):
self.layers = layers
self.num_layers = len(layers)
self.weights = [np.random.randn(layers[i], layers[i-1]) for i in range(1, self.num_layers)]
self.biases = [np.random.randn(layers[i], 1) for i in range(1, self.num_layers)]
self.activation = activation

def forward_propagation(self, x):
    a = np.array(x).reshape(-1, 1)
    zs = []
    activations = [a]
    for w, b in zip(self.weights, self.biases):
        z = np.dot(w, a) + b
        zs.append(z)
        a = self.activate(z)
        activations.append(a)
    return zs, activations

def backward_propagation(self, zs, activations, y):
    delta = self.cost_derivative(activations[-1], y) * self.activation_derivative(zs[-1])
    nabla_w = [np.dot(delta, activations[-2].T)]
    nabl

原文地址:https://blog.csdn.net/huanghm88/article/details/140595535

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!