Last active
August 29, 2015 14:16
-
-
Save maekawatoshiki/05cca068e5a75d2dc5db to your computer and use it in GitHub Desktop.
Neural Networks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <cmath> | |
#define ARR_SZ 36//6x6ドットの文字 | |
#define STD_SZ 9//学習回数 | |
using namespace std; | |
struct nn | |
{ | |
int bcd[ARR_SZ];// 入力データ(パーセプトロンの入力) | |
int a;//教師信号 1 = true / 0 = false | |
}; | |
nn n[STD_SZ] = //学習データ STD_SZ個 | |
{ | |
{ | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 1 | |
}, | |
{ | |
0, 0, 1, 1, 0, 0, | |
0, 1, 0, 0, 1, 0, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 0, 0, 1, 1, | |
1, 1, 0, 0, 1, 1, 1 | |
}, | |
{ | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 1 | |
}, | |
{ | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 0, 0, 0, 1, | |
1, 1, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 1 | |
}, | |
{ | |
0, 0, 1, 1, 0, 0, | |
0, 1, 0, 0, 1, 0, | |
0, 1, 1, 1, 1, 0, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 1 | |
}, | |
{ | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, 0, 0 | |
}, | |
{ | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, 0 | |
}, | |
{ | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 0 | |
}, | |
{ | |
1, 0, 1, 1, 0, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, 1, | |
1, 0, 0, 0, 0, 1, 0 | |
} | |
}; | |
/* | |
TODO: | |
*/ | |
int main() | |
{ | |
int bcd[ARR_SZ] = { 0 }; | |
int i, j, k,m, w; | |
int al = 0, X = 2; | |
bool edit = false; | |
while(1) | |
{ | |
edit = false; | |
for( i = 0; i < STD_SZ; i++ ) | |
{ | |
al = 0; | |
for(j = 0; j<ARR_SZ; j++) | |
{ | |
al += n[i].bcd[j] * bcd[j]; | |
} | |
if(al < X)// OK | |
{ | |
if( !n[i].a )//OKなのにNGだったら | |
{ | |
X--; | |
for(j = 0; j<ARR_SZ; j++) | |
{ | |
if( n[i].bcd[j] ) | |
bcd[j]++; | |
} | |
edit = true; | |
} | |
} | |
else if(al >= X)// NG | |
{ | |
if( n[i].a )// NGなのにOKだったら | |
{ | |
X++; | |
for(j = 0; j<ARR_SZ; j++) | |
if( n[i].bcd[j] ) | |
bcd[j]--; | |
edit = true; | |
} | |
} | |
} | |
if(edit == false) break;// 変更がなかったらブレーク | |
} | |
for(i=0; i<ARR_SZ; i+=6) | |
{ | |
for(j=0; j<6; j++) | |
cout << bcd[i+j] << " "; | |
cout << endl; | |
} | |
while(1) | |
{ | |
al = 0; | |
for( i = 0; i < ARR_SZ; i += 6 ) | |
cin >> n[0].bcd[i] >> n[0].bcd[i+1] >> n[0].bcd[i+2] >> n[0].bcd[i+3] >> n[0].bcd[i+4] >> n[0].bcd[i+5]; | |
for(j = 0; j<ARR_SZ; j++) | |
if( n[0].bcd[j] == 1 ) | |
al += bcd[j]; | |
cout << ">>>>> "<< ( (X - al > 0) ? "TRUE" : "NG") << endl; | |
} | |
} | |
/* | |
Sample output: | |
input:( A ) | |
0 0 1 1 0 0 | |
0 1 0 0 1 1 | |
1 1 1 1 1 1 | |
1 1 0 0 1 1 | |
1 0 0 0 1 1 | |
1 0 0 0 0 1 | |
output: | |
>>>>>TRUE | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment