@@ -14,46 +14,75 @@ class Program
14
14
private static double [ ] [ ] inputData ;
15
15
private static double [ ] [ ] expectedData ;
16
16
17
- const int TOTAL_BITS = 2 ;
17
+ private static int dataSetsPerPropagation = 1000 ;
18
+ private static double [ ] [ ] currentInputData ;
19
+ private static double [ ] [ ] currentExpectedData ;
20
+
21
+ const int TOTAL_BITS = 12 ;
18
22
private static int totalNumberLength = Math . Pow ( 2 , TOTAL_BITS ) . ToString ( ) . Length ;
19
23
20
24
static void Main ( string [ ] args )
21
25
{
22
- int totalNetworks = 100 ;
26
+ int totalNetworks = 1000 ;
23
27
int inputNodes = TOTAL_BITS ;
24
28
int hiddenNodes = 10 ;
25
29
int hiddenLayers = 2 ;
26
30
int outputNodes = totalNumberLength ;
27
31
28
32
int networksToKeep = 10 ;
29
33
int totalRandomNetworks = 10 ;
30
- double mutationRate = 0.1 ;
31
- double mutationChance = 0.0011 ;
34
+ double mutationRate = 0.01 ;
35
+ double mutationChance = 0.01 ;
32
36
33
37
SetupBinaryData ( ) ;
34
38
35
39
GeneticAlgorithm algorithm = new GeneticAlgorithm ( totalNetworks , inputNodes , hiddenNodes , hiddenLayers , outputNodes )
36
40
{
37
- PoolGenerator = new IndexBasedPoolGenerator ( )
41
+ PoolGenerator = new FitnessBasedPoolGenerator ( )
38
42
} ;
39
43
40
- algorithm . SetupTest ( inputData , expectedData ) ;
41
-
42
44
algorithm . NetworksToKeep = networksToKeep ;
43
45
algorithm . MutationRate = mutationRate ;
44
46
algorithm . MutationChance = mutationChance ;
45
47
algorithm . RandomNetworkAmount = totalRandomNetworks ;
46
48
47
49
Console . WriteLine ( "Initialization complete" ) ;
48
50
51
+ int generation = 0 ;
49
52
while ( true )
50
53
{
54
+ Console . WriteLine ( $ "Generation { generation } ") ;
55
+ SetCurrentDataSets ( ) ;
56
+ algorithm . SetupTest ( currentInputData , currentExpectedData ) ;
51
57
Console . WriteLine ( "Propagating" ) ;
52
58
algorithm . PropagateAllNetworks ( ) ;
53
59
Console . WriteLine ( "Breeding" ) ;
54
60
algorithm . BreedBestNetworks ( ) ;
55
- PrintData ( algorithm ) ;
56
- Console . ReadLine ( ) ;
61
+ if ( generation % 20 == 0 )
62
+ {
63
+ PrintData ( algorithm ) ;
64
+ }
65
+ ++ generation ;
66
+ }
67
+ }
68
+
69
+ private static void SetCurrentDataSets ( )
70
+ {
71
+ int totalDataSets = inputData . Length < dataSetsPerPropagation ? inputData . Length : dataSetsPerPropagation ;
72
+ currentInputData = new double [ totalDataSets ] [ ] ;
73
+ currentExpectedData = new double [ totalDataSets ] [ ] ;
74
+
75
+ List < int > indexedDataSets = new List < int > ( ) ;
76
+ for ( int i = 0 ; i < totalDataSets ; )
77
+ {
78
+ int index = NeuralBotMasterFramework . Helper . RandomNumberGenerator . GetNextNumber ( 0 , inputData . Length - 1 ) ;
79
+ if ( ! indexedDataSets . Contains ( index ) )
80
+ {
81
+ currentInputData [ i ] = inputData [ index ] ;
82
+ currentExpectedData [ i ] = expectedData [ index ] ;
83
+ indexedDataSets . Add ( index ) ;
84
+ ++ i ;
85
+ }
57
86
}
58
87
}
59
88
0 commit comments