📄 kohen_example_not_sofm.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 non-Self-Organizing Feature Map that learns four letters*/
#include <nn-utility.h>
using namespace nn_utility;
//create a bitmap handler
BITMAP<float> *bit = new BITMAP<float>( "bitmap.txt" );
//define the VECTOR to load the bitmap letters
nn_utility_functions<float>::VECTOR letters[4];
//define a global classify layer
KOHEN *classify;
//overload and define floating-point nn-utility-functions
class kohen_example : public nn_utility_functions<float>{
public:
typedef float VECTOR[NN_UTIL_SIZE];
void GetInput( int interation, VECTOR &send, VECTOR &target ){
CopyVector( send, letters[interation % 4], 256 );
classify->radius = interation % 4;
}
}derived; //global derived
//see kohen_example.cpp
void SetRandomWeights( KOHEN **in, int row, int col ){
for ( int i = 0; i < row; i++ ){
for ( int e = 0; e < col; e++ ){
float it = rand() % 10;
(*in)->matrix[i][e] = it/100*( (rand() % 2) == 0 ? -1 : 1 );
}
}
}
int main(){
//read the bitmap
for ( int i = 0; i < 4; i++ )
bit->readbitmap( letters[i], i );
//define KOHEN, not KOHEN_SOFM
//the rest of this file mimicks kohen_example.cpp, open
//that file to see the remaining comments.
classify = new KOHEN();
classify->define( 256,9 );
SetRandomWeights( &classify, 256,9 );
nn_utility_functions<float>::VECTOR FINAL;
layer<float> *ppClassify = classify;
derived.train( &ppClassify, 4, 1.0F, false );
cout << '\n';
for ( int go = 0; go < 4; go++ ){
classify->FeedForward( letters[go], FINAL );
cout << go << " Original Classification: ";
derived.PrintVector( FINAL, 9 );
bit->noise( letters[go], 256, 1, 5 );
classify->FeedForward( letters[go], FINAL );
cout << go << " Noisy Classification : ";
derived.PrintVector( FINAL, 9 );
}
cout << '\n';
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -