一个简单完整的神经网络的实现

# -*- 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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值