Skip to content

Commit eb9a63c

Browse files
committed
Brief docs for Data Manager
1 parent ccae18c commit eb9a63c

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[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.
44

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.
66

77
## Installation
88

@@ -14,6 +14,8 @@ composer require petercoles/gao
1414

1515
## Usage
1616

17+
### Framing and Finding Solutions
18+
1719
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.
1820

1921
``` php
@@ -39,21 +41,49 @@ class MySolution extends Solution
3941

4042
Then instantiate and run the optimiser, creating an initial population of possible solutions to start its evaluation.
4143

42-
```
44+
``` php
4345
$optimiser = new Optimiser(new Population(MySolution::class, 100));
4446
$optimiser->run();
4547
foreach ($optimiser->results as $solution) {
4648
print_r($solution->summary());
4749
}
4850
```
4951

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
71+
list($trainingData, $testingData) = $dm->split($data, 0.2);
72+
```
73+
74+
PHP is also rather memory hungry when constructing arrays. If you experience out of memory errors, then the following may help:
75+
76+
``` php
77+
$dm->setMemoryLimit('1G');
78+
```
79+
80+
## Testing
5181

5282
``` bash
5383
composer test
5484
```
5585

56-
### Changelog
86+
## Changelog
5787

5888
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
5989

0 commit comments

Comments
 (0)