📄 hopefield.cpp
字号:
/*
nn-utility (Provides neural networking utilities for c++ programmers)
Copyright (C) 2003 Panayiotis Thomakos
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
//To contact the author send an email to panthomakos@users.sourceforge.net
/*Demonstrates a hopefiled network that remembers 5x5 bitmap letters A, B, C and D.*/
#include <nn-utility.h>
using namespace nn_utility;
nn_utility_functions<int> derived;
//create a bitmap and a vector to store the 4 letters letters[0...3]
BITMAP<int> *bit = new BITMAP<int>( "bit.txt" );
nn_utility_functions<int>::VECTOR letters[4];
int main(){
//create an SGN network
//SGN networks are based on HOPEFIELD, but allow autoasociative backpropagation
SGN *hopefield = new SGN( );
//define it's size
hopefield->define( 25,4 );
//read the bitmap and convert it into a hopefield bitmap
//( 0's and 1's converted to -1's and 1's )
for ( int i = 0; i < 4; i++ ){
bit->readbitmap( letters[i], i );
hopefield->Hopefield( letters[i], 25 ); }
//create autoasociative vectors "a", "b", "c", and "d" respectively
nn_utility_functions<int>::VECTOR a, b, c, d;
//load the values into them
derived.LoadVectori( a, 4, 1, -1, -1, -1 );
derived.LoadVectori( b, 4, -1, 1, -1, -1 );
derived.LoadVectori( c, 4, -1, -1, 1, -1 );
derived.LoadVectori( d, 4, -1, -1, -1, 1 );
//add onto the hopefield matrix by doing the following:
hopefield->HopefieldMultiply( letters[0], a ); //associate letters[0] with a
hopefield->HopefieldAddTo( letters[1], b ); //associate letters[1] with b
hopefield->HopefieldAddTo( letters[2], c ); //associate letters[2] with c
hopefield->HopefieldAddTo( letters[3], d ); //associate letters[3] with d
//final VECTOR
nn_utility_functions<int>::VECTOR FINAL;
//verify that the output is correct
cout << '\n';
for ( int go = 0; go < 4; go++ ){
cout << "Given noisy input pattern: >= 0 means an activation at that weight\n";
bit->noise( letters[go], 25, 2 ); //add some noise or disturbance to the bitmap
//to check if the network is still learning
hopefield->FeedForward( letters[go], FINAL ); //feed the bitmap to the network
derived.PrintVector( FINAL, 4 ); //print the result
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -