@@ -12,13 +12,16 @@ class Program
12
12
private static double [ ] [ ] inputData ;
13
13
private static double [ ] [ ] expectedData ;
14
14
15
+ const int TOTAL_BITS = 3 ;
16
+ private static int totalNumberLength = Math . Pow ( 2 , TOTAL_BITS ) . ToString ( ) . Length ;
17
+
15
18
static void Main ( string [ ] args )
16
19
{
17
- int totalNetworks = 100 ;
18
- int inputNodes = 8 ;
20
+ int totalNetworks = 1000 ;
21
+ int inputNodes = TOTAL_BITS ;
19
22
int hiddenNodes = 10 ;
20
- int hiddenLayers = 4 ;
21
- int outputNodes = 3 ;
23
+ int hiddenLayers = 3 ;
24
+ int outputNodes = totalNumberLength ;
22
25
23
26
int networksToKeep = 10 ;
24
27
double mutationRate = 0.2 ;
@@ -34,26 +37,43 @@ static void Main(string[] args)
34
37
algorithm . MutationRate = mutationRate ;
35
38
algorithm . MutationChance = mutationChance ;
36
39
40
+ Console . WriteLine ( "Initialization complete" ) ;
41
+
37
42
while ( true )
38
43
{
44
+ Console . WriteLine ( "Propagating" ) ;
39
45
algorithm . PropagateAllNetworks ( ) ;
46
+ Console . WriteLine ( "Breeding" ) ;
40
47
algorithm . BreedBestNetworks ( ) ;
48
+ PrintData ( algorithm ) ;
49
+ Console . ReadLine ( ) ;
50
+ }
51
+ }
52
+
53
+ private static void PrintData ( GeneticAlgorithm algorithm )
54
+ {
55
+ for ( int i = 0 ; i < 10 ; ++ i )
56
+ {
57
+ Console . WriteLine ( $ "Fitness { algorithm . NetworksAndFitness . Values . ElementAt ( i ) } ") ;
41
58
}
59
+ Console . WriteLine ( ) ;
42
60
}
43
61
44
62
private static void SetupBinaryData ( )
45
63
{
46
- inputData = new double [ 256 ] [ ] ;
47
- expectedData = new double [ 256 ] [ ] ;
48
- for ( int i = 0 ; i <= 255 ; ++ i )
64
+ int TotalBinaryNumbers = ( int ) Math . Pow ( 2 , TOTAL_BITS ) ;
65
+
66
+ inputData = new double [ TotalBinaryNumbers ] [ ] ;
67
+ expectedData = new double [ TotalBinaryNumbers ] [ ] ;
68
+ for ( int i = 0 ; i < TotalBinaryNumbers ; ++ i )
49
69
{
50
- string binaryString = Convert . ToString ( i , 2 ) . PadLeft ( 8 , '0' ) ;
70
+ string binaryString = Convert . ToString ( i , 2 ) . PadLeft ( TOTAL_BITS , '0' ) ;
51
71
inputData [ i ] = new double [ binaryString . Length ] ;
52
72
for ( int j = 0 ; j < binaryString . Length ; ++ j )
53
73
{
54
74
inputData [ i ] [ j ] = binaryString [ j ] == '1' ? 1 : 0 ;
55
75
}
56
- string numberAsString = Convert . ToString ( i ) . PadLeft ( 3 , '0' ) ;
76
+ string numberAsString = Convert . ToString ( i ) . PadLeft ( totalNumberLength , '0' ) ;
57
77
expectedData [ i ] = new double [ numberAsString . Length ] ;
58
78
for ( int j = 0 ; j < numberAsString . Length ; ++ j )
59
79
{
0 commit comments