# -*- coding: utf-8 -*-
# @FileName: 一个简单完整的神经网络的实现
# @Software: PyCharm
# @Author : li Xu
# @Time :2020//01//16
import numpy as np
def sigmoid(x):
'''
定义一个激活函数
:param x: 参数
:return: 计算后的值
'''
fun = 1 / (1 + np.exp(-x))
return fun
def derive_sigmoid(x):
'''
激活函数的导数
:param x: 参数
:return: 计算后的值
'''
fx = sigmoid(x)
derive = fx * (1 - fx)
return derive
def Loss(y_true, y_pred):
'''
损失函数
:param y_true: 真实值
:param y_pred: 预测值
:return:
'''
result = ((y_true - y_pred) ** 2).mean()
return result
class NerualNetwork:
'''
定义一个神经网络的类
A neural network with:
- 2 inputs
- a hidden layer with 2 neurons (h1, h2)
- an output layer with 1 neuron (o1)
'''
def __init__(self):
'''
初始化权重w和偏置b
'''
self.w1 = np.random.normal() # np.random.normal()生成高斯分布的概率密度随机数
self.w2 = np.random.normal()
self.w3 = np.random.normal()
self.w4 = np.r
一个简单完整的神经网络的实现
最新推荐文章于 2024-03-29 20:11:25 发布