这个网络的内部使用的是hebb学习规则

贴上两段代码:

  

package geym.nn.hopfiled;

import java.util.Arrays;

import org.neuroph.core.data.DataSet;
import org.neuroph.core.data.DataSetRow;
import org.neuroph.nnet.Hopfield;
import org.neuroph.nnet.comp.neuron.InputOutputNeuron;
import org.neuroph.nnet.learning.HopfieldLearning;
import org.neuroph.util.NeuronProperties;
import org.neuroph.util.TransferFunctionType; /**
* 识别0 1 2 使用hopfield 全连接结构
* @author Administrator
*
*/
public class HopfieldSample2 { public static double[] format(double[] data){
for(int i=0;i<data.length;i++){
if(data[i]==0)data[i]=-1;
}
return data;
} public static void main(String args[]) {
NeuronProperties neuronProperties = new NeuronProperties();
neuronProperties.setProperty("neuronType", InputOutputNeuron.class);
neuronProperties.setProperty("bias", new Double(0.0D));
neuronProperties.setProperty("transferFunction", TransferFunctionType.STEP);
neuronProperties.setProperty("transferFunction.yHigh", new Double(1.0D));
neuronProperties.setProperty("transferFunction.yLow", new Double(-1.0D)); // create training set (H and T letter in 3x3 grid)
DataSet trainingSet = new DataSet(30);
trainingSet.addRow(new DataSetRow(format(new double[] {
0,1,1,1,1,0,
1,0,0,0,0,1,
1,0,0,0,0,1,
1,0,0,0,0,1,
0,1,1,1,1,0}))); // trainingSet.addRow(new DataSetRow(format(new double[] {
0,0,0,0,0,0,
1,0,0,0,0,0,
1,1,1,1,1,1,
0,0,0,0,0,0,
0,0,0,0,0,0}))); // trainingSet.addRow(new DataSetRow(format(new double[] {
1,0,0,0,0,0,
1,0,0,1,1,1,
1,0,0,1,0,1,
1,0,0,1,0,1,
0,1,1,0,0,1}))); //2 // create hopfield network
Hopfield myHopfield = new Hopfield(30, neuronProperties);
myHopfield.setLearningRule(new StandHopfieldLearning());
// learn the training set
myHopfield.learn(trainingSet); // test hopfield network
System.out.println("Testing network"); // add one more 'incomplete' H pattern for testing - it will be
// recognized as H
// DataSetRow h=new DataSetRow(new double[] { 1, 0, 0, 1, 0, 1, 1, 0, 1
// });
// DataSetRow h=new DataSetRow(new double[] { 1, 0, 0, 1, 0, 1, 1, 0, 1
// });
DataSetRow h = new DataSetRow(format(new double[] {
1,0,0,0,0,0,
1,0,0,1,1,1,
1,0,0,1,0,1,
1,0,0,1,0,0,
0,1,1,0,0,1})); // 2 bad
trainingSet.addRow(h); myHopfield.setInput(h.getInput()); double[] networkOutput = null;
double[] preNetworkOutput = null;
while (true) {
myHopfield.calculate();
networkOutput = myHopfield.getOutput();
if (preNetworkOutput == null) {
preNetworkOutput = networkOutput;
continue;
}
if (Arrays.equals(networkOutput, preNetworkOutput)) {
break;
}
preNetworkOutput = networkOutput;
} System.out.print("Input: " + Arrays.toString(h.getInput()));
System.out.println(" Output: " + Arrays.toString(networkOutput)); System.out.println(Arrays.equals(format(new double[] {
1,0,0,0,0,0,
1,0,0,1,1,1,
1,0,0,1,0,1,
1,0,0,1,0,1,
0,1,1,0,0,1}), networkOutput));
} }

下面就是StandHopfieldLearning类的实现,里面标红的地方就是hebb学习规则,权重为输入和输出的乘积:

  

package com.cgjr.com.hopfield;

import org.neuroph.core.Connection;
import org.neuroph.core.Layer;
import org.neuroph.core.Neuron;
import org.neuroph.core.data.DataSet;
import org.neuroph.core.data.DataSetRow;
import org.neuroph.core.learning.LearningRule; /**
* Learning algorithm for the Hopfield neural network.
*
* @author Zoran Sevarac <sevarac@gmail.com>
*/
public class StandHopfieldLearning extends LearningRule { /**
* The class fingerprint that is set to indicate serialization
* compatibility with a previous version of the class.
*/
private static final long serialVersionUID = 1L; /**
* Creates new HopfieldLearning
*/
public StandHopfieldLearning() {
super();
} /**
* Calculates weights for the hopfield net to learn the specified training
* set
*
* @param trainingSet
* training set to learn
*/
public void learn(DataSet trainingSet) {
int M = trainingSet.size();
int N = neuralNetwork.getLayerAt(0).getNeuronsCount();
Layer hopfieldLayer = neuralNetwork.getLayerAt(0); for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j == i)
continue;
Neuron ni = hopfieldLayer.getNeuronAt(i);
Neuron nj = hopfieldLayer.getNeuronAt(j);
Connection cij = nj.getConnectionFrom(ni);
Connection cji = ni.getConnectionFrom(nj); double wij=0;
for(int k = 0;k < M;k++){
DataSetRow row=trainingSet.getRowAt(k);
double[] inputs=row.getInput();
wij+=inputs[i]*inputs[j];//Hebb学习规则
}
cij.getWeight().setValue(wij);
cji.getWeight().setValue(wij);
}// j
} // i } }

Hopfield神经网络实现污染字体的识别的更多相关文章

  1. Hopfield神经网络和TSP问题

    一.TSP问题 旅行商问题,又叫货郎担问题.它是指如下问题:在完全图中寻找一条最短的哈密尔顿回路. 哈密尔顿回路问题:给定一个图,判断图中是否存在哈密尔顿回路. 哈密尔顿回路:寻找一条回路,经过图中所 ...

  2. tensorflow神经网络与单层手写字识别

    1.知识点 """ 1.基础知识: 1.神经网络结构:1.输入层 2.隐含层 3.全连接层(类别个数=全连接层神经元个数)+softmax函数 4.输出层 2.逻辑回归: ...

  3. 五.反馈(Hopfield)神经网络

    前馈网络一般指前馈神经网络或前馈型神经网络.它是一种最简单的神经网络,各神经元分层排列.每个神经元只与前一层的神经元相连.接收前一层的输出,并输出给下一层,数据正想流动,输出仅由当前的输入和网络权值决 ...

  4. Hopfield神经网络

    神经网络分类 多层神经网络:模式识别 相互连接型网络:通过联想记忆去除数据中的噪声 1982年提出的Hopfield神经网络是最典型的相互连结型网络. 联想记忆 当输入模式为某种状态时,输出端要给出与 ...

  5. BP神经网络的手写数字识别

    BP神经网络的手写数字识别 ANN 人工神经网络算法在实践中往往给人难以琢磨的印象,有句老话叫“出来混总是要还的”,大概是由于具有很强的非线性模拟和处理能力,因此作为代价上帝让它“黑盒”化了.作为一种 ...

  6. Hopfield 神经网络及稳态性的证明

    根据其提出者,John Joseph Hopfield 命名.Hopfield 在 1982 年提出的划时代的:Neural networks and physical systems with em ...

  7. TensorFlow卷积神经网络实现手写数字识别以及可视化

    边学习边笔记 https://www.cnblogs.com/felixwang2/p/9190602.html # https://www.cnblogs.com/felixwang2/p/9190 ...

  8. 利用c++编写bp神经网络实现手写数字识别详解

    利用c++编写bp神经网络实现手写数字识别 写在前面 从大一入学开始,本菜菜就一直想学习一下神经网络算法,但由于时间和资源所限,一直未展开比较透彻的学习.大二下人工智能课的修习,给了我一个学习的契机. ...

  9. [纯C#实现]基于BP神经网络的中文手写识别算法

    效果展示 这不是OCR,有些人可能会觉得这东西会和OCR一样,直接进行整个字的识别就行,然而并不是. OCR是2维像素矩阵的像素数据.而手写识别不一样,手写可以把用户写字的笔画时间顺序,抽象成一个维度 ...

随机推荐

  1. CSS3的新特性

    CSS3中增加的新特性: (1)选择器的种类 (2)字体 font (3)text-overflow (4)文本渲染 text-decoration (5)多列布局 column-count (6)R ...

  2. 微信小程序-开发入门

    微信小程序已经火了一段时间了,之前一直也在关注,就这半年的发展来看,相对原生APP大部分公司还是不愿意将主营业务放到微信平台上,以免受制于腾讯,不过就小程序的应用场景(用完即走和二维码分发等)还是很值 ...

  3. ad_封装_ads828

    module ad_ctrl( clk,rst_n,ad_clk, ad_data,value_x,value_y,q_sig,wren,r_addr,w_addr ); input clk; inp ...

  4. IOS开发创建开发证书及发布App应用(七)——在iTunes创建填写应用基本信息

    7.在iTunes创建填写应用基本信息 依旧打开苹果的开发者网站 https://developer.apple.com/ 点击Member,如下图 (注意,下面的图示是登录之后的) 点击iTunes ...

  5. 读书笔记 effective c++ Item 43 了解如何访问模板化基类中的名字

    1. 问题的引入——派生类不会发现模板基类中的名字 假设我们需要写一个应用,使用它可以为不同的公司发送消息.消息可以以加密或者明文(未加密)的方式被发送.如果在编译阶段我们有足够的信息来确定哪个信息会 ...

  6. Eclipse插件ObjectAid(UML画图工具)

    原链接:https://my.oschina.net/keyven/blog/856594 最近想找一个Eclipse上的插件,可以方便的把java代码转换为UML图,但是由于我用的是Eclipse ...

  7. VS窗体选择BackGroupImage属性报错:已添加具有相同键的项

    高墙我今天第一次遇见这个问题.既然说是"已添加具有相同键的项."那我自然地认为会不会是文件夹哪里命名了两个相同的文件名.然后在这个Exception上越走越远. 好了不说废话.出现 ...

  8. Selenium Grid2

    简介 使用selenium-grid可以远程执行测试的代码,核心步骤:grid --> server-->chromedriver驱动 -->chrome浏览器 利用Selenium ...

  9. angular的$http.post()提交数据到Java后台接收不到参数值问题的解决方法

    本文地址:http://www.cnblogs.com/jying/p/6733408.html   转载请注明出处: 写此文的背景:在工作学习使用angular的$http.post()提交数据时, ...

  10. Vue 事件驱动和依赖追踪

    之前关于 Vue 数据绑定原理的一点分析,最近需要回顾,就顺便发到随笔上了 在之前实现一个自己的Mvvm中,用 setter 来观测model,将界面上所有的 viewModel 绑定到 model ...