Bp神经网络

本文深入探讨了反向传播(Bp)神经网络的工作原理、训练过程及其在图像识别中的应用。通过理解权值更新和误差反向传播,读者将能够掌握Bp神经网络的核心概念。
摘要由CSDN通过智能技术生成

智能系统课程设计,老师要求做一个识别手写数字的神经网络算法,数据集是Mnist-image数据集。
在网上找了好多教程,结果仍然不清楚,后来在B站找了个视频才弄懂,传上来代码,以备以后回顾。

Minss-image

// newBpLearn.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include<iostream>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include <sstream>
#include<opencv2\calib3d\calib3d.hpp>
#include <opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv; 

#define INPUT_TYPE 0
#define HIDDEN_TYPE 1
#define OUTPUT_TYPE 2

class neuron
{
private:
	int type;
	//前向传播
	float InputValueForward;
	float OutputValueForward;
	//反向传播
	float errorInputBack;
	float errorOutputBack;
	//偏差值
	float bias;

public:

	float log_sigmoid(float in)
	{
		return (1/(exp(-in)+1));
	}
	float log_sigD(float in)
	{
		return OutputValueForward*(1-OutputValueForward)*in;
	}
	float Forward(float in)
	{
		switch(type)
		{
		case INPUT_TYPE:
			return in;
		case HIDDEN_TYPE:
		case OUTPUT_TYPE:
			return log_sigmoid(in);
		}
	}
	float Backward(float in)
	{
		switch(type)
		{
		case INPUT_TYPE:
			return in;
		case HIDDEN_TYPE:
		case OUTPUT_TYPE:
			return log_sigD(in);
		}
	}
	/
	void setType(int n)
	{
		type=n;
	}
	float getForwardInputValue()
	{
		return InputValueForward;
	}
	void setForwardInputValue(float in)
	{
		InputValueForward=in;
		OutputValueForward=setForwardOutputValue(in);
	}
	float getForwardOutputValue()
	{
		return OutputValueForward;
	}
	float setForwardOutputValue(float in)
	{
		return Forward(in);
	}
	float getBackwardInputValue()
	{
		return errorInputBack;
	}
	float getBackw
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值