You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-4Lines changed: 34 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
[Genetic Alorithms](https://en.wikipedia.org/wiki/Genetic_algorithm) are a class of machine learning approaches that use the principles of natural selection, rather than the solving of mathematical formulae to find solutions to optimisation and search type problems. They are especially effective in complex situation that aren't easily "solved" and can often be used as a more-easily understood alternative to neural networks.
4
4
5
-
This framework takes care of most of the steps (loops) needed when developing and running a genetic algorithm, leaving you needing only to define the shape of your expected solution and a function to evaluate each solution faciliating the comparison of candidate solutions and thus the march towards an optimum.
5
+
This framework takes care of most of the steps (loops) needed when developing and running a genetic algorithm, leaving you needing only to define the shape of your expected solution and a function to evaluate each candidate faciliating their comparison and thus the march towards an optimum.
6
6
7
7
## Installation
8
8
@@ -14,6 +14,8 @@ composer require petercoles/gao
14
14
15
15
## Usage
16
16
17
+
### Framing and Finding Solutions
18
+
17
19
Firstly create a class that defines a generic solution to the problem to be solved. The class must extend this package's Solution class, which will force the implemetation of two methods: genome() which defines the shape of a valid solution and evaluate(), which will calculate a numerical value that can be used to compare solutions.
18
20
19
21
```php
@@ -39,21 +41,49 @@ class MySolution extends Solution
39
41
40
42
Then instantiate and run the optimiser, creating an initial population of possible solutions to start its evaluation.
41
43
42
-
```
44
+
```php
43
45
$optimiser = new Optimiser(new Population(MySolution::class, 100));
44
46
$optimiser->run();
45
47
foreach ($optimiser->results as $solution) {
46
48
print_r($solution->summary());
47
49
}
48
50
```
49
51
50
-
### Testing
52
+
### Data Manager
53
+
54
+
Although some use cases may not require much, if any, data against which to evaluate candidate solutions, others may need astronomical amounts. This could be be the case in financial markets where a trading strategy is sought and candidates are evaluated against the evolution of prices for many different securities, or in sports trading markets where possible strategies may be evaluated against changes in odds for thousands of events.
55
+
56
+
The DataManager class offers utilities optimised to assist with htese challenges. Here's the sort of thing that it can do:
57
+
58
+
```php
59
+
$dm - new DataManager();
60
+
61
+
// loads all files (assumed to be in CSV format) from given directory into an collection
62
+
$data = $dm->loadCsvDir('path/to/directory');
63
+
64
+
// PHP is really slow importing data into arrays - so once done, save the results (as json)
65
+
$dm->save('path/to/output/file', $data);
66
+
67
+
// It can be reloaded later from a json file in a tiny fraction of the time taken by the initial import
68
+
$data = $dm->load('path/to/output/file');
69
+
70
+
// to ensure our solutions works on data not seen during training, we may set aside some data (20% below) just for testing
0 commit comments