Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit for cocktail-mash AI #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Readme
# cocktail-mash

With [cocktail-mash-neat](./neat/README.md) you can watch a AI learning how to play cocktail-mash with NEAT.]
11 changes: 11 additions & 0 deletions cocktail-mash-ai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
neat-checkpoint-*
.idea
.vscode
__pycache__
Digraph.gv*
winner.pkl
speciation.svg
avg_fitness.svg
neat-examples
history
*.ods
22 changes: 22 additions & 0 deletions cocktail-mash-ai/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2007-2011, cesar.gomes and mirrorballu2
Copyright (c) 2015-2017, CodeReclaimers, LLC

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109 changes: 109 additions & 0 deletions cocktail-mash-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
## Interactive machine learning with Cocktail-Mash

This is a machine learning implementation for Cocktail-Mash.
Cocktail-Mash is a game developed by inovex and can be controlled by
a AI trained by this NEAT implementation.

The process of training the AI can therefore be watched with this implementation.

Additionally to the model a visualized image of the Neural Network and statistic of the learning process will be saved.

The best Neural Network and statistics supporting the understanding of the learning process are visualized at
the end of the learning process.


## How to setup:

### Install all dependencies

For visualizing the neural network ```graphviz``` must be installed at your system:

```
sudo apt-get install graphviz
```

All dependencies for this project can be installed by:

```
python3 -m pip install -r requirements.txt
```

## How to run:

### Run a model already trained:

Models saved to the disk can be run directly by providing their path to the ```neat_run.py```. For exammple to run the sample models provided in the repository use:

```
python3.6 neatrun.py model_ai_finish
```

If no path is provided the newest model from the history folder will be loaded.

### Train a new model:

To train a new model just start the training process with the following command:

```
python3.6 neattrain.py
```

All progress will be saved to the ```history/[date_time] ``` folder including: config, graph, network and checkpoints

## Individualize the learning process

There are two config files in this project ``` neat_config.json ``` for general setting and ``` config``` to change
the behaviour of the machine learning process. By changing their settings you can take impact in the traing setup and process.

### neat_config.json

The ``` neat_config.json ``` specifies the learning setup of the game. The options are described in the following:

``` numberOfEvolutions ```
The numbers of evolutions the model will take by training. Default is 100 the

``` runNewBest ```
If a genome with a better fitness then all genomes of all generations before emerges run it.

``` runEachGeneration ```
Each n-th generation will be run in the browser so you can watch the training process.



``` numberOfRandomRecipes```
Denotes with which kind of recips the Model will be trained with. There are three options:

- numberOfRandomRecipes > 0: The specified number of random recipes will be used to train the model

- numberOfRandomRecipes == 0: All 18 possible recipes of the game will be used for training

- numberOfRandomRecipes < 0: All possible recipes plus abs(numberOfRandomRecipes) random recipes will be used for training


```fillSteps``` The amouth of units filled in the glass each step. Default is 10.

```viewNetwork``` True if the Network-Image should be shown after training. They will be saved in any case.

```viewSpeciesGraph``` True if the Species-Graph should be shown after training. They will be saved in any case.

```viewFitnessGraph```True if the Fitness-Graph should be shown after training. They will be saved in any case.

```logToFile``` True if all output should be writen to a logfile. This is usufull if you want to run the training on a server and inspect the output later.

### config

Only one option has an impact to our implementation all others are just for modifying the training process.

##### num_outputs
```num_outputs``` specifies how many output nodes the model will have.
If there are 3 outputs the level will be finished by the algorithem as soon as the glass filling exceed 90%.
This is staticly programmed and thus the network doesn't has any impact on this decision.
If there are 4 outputs the fourth output will be used to decide if a level is finished. Thus the network is taking this decision by it's own.

- num_outputs == 3: The Algorithem will stop the Level as soon as the Glass is filled by more than 90%.

- num_outputs == 4: The Model itself will decide if when to stop the filling process


All other options are best described in the [NEAT-documentation ](https://neat-python.readthedocs.io/en/latest/config_file.html).
Feel free to play around with them to learn about their impact to the models quiality.
81 changes: 81 additions & 0 deletions cocktail-mash-ai/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

[NEAT]
fitness_criterion = max
fitness_threshold = 10000
no_fitness_termination = True
pop_size = 200
reset_on_extinction = False

[DefaultGenome]
# node activation options
activation_default = relu
activation_mutate_rate = 0.0
activation_options = relu

# node aggregation options
aggregation_default = sum
aggregation_mutate_rate = 0.0
aggregation_options = sum

# node bias options
bias_init_mean = 0.0
bias_init_stdev = 1.0
bias_max_value = 30.0
bias_min_value = -30.0
bias_mutate_power = 0.5
bias_mutate_rate = 0.7
bias_replace_rate = 0.1

# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient = 0.5

# connection add/remove rates
conn_add_prob = 0.0
conn_delete_prob = 0.0

# connection enable options
enabled_default = True
enabled_mutate_rate = 0.01

feed_forward = True
initial_connection = full_nodirect

# node add/remove rates
node_add_prob = 0.2
node_delete_prob = 0.2

# network parameters
num_hidden = 6
num_inputs = 7
num_outputs = 4

# node response options
response_init_mean = 1.0
response_init_stdev = 0.0
response_max_value = 30.0
response_min_value = -30.0
response_mutate_power = 0.0
response_mutate_rate = 0.0
response_replace_rate = 0.0

# connection weight options
weight_init_mean = 0.0
weight_init_stdev = 1.0
weight_max_value = 30
weight_min_value = -30
weight_mutate_power = 0.5
weight_mutate_rate = 0.8
weight_replace_rate = 0.1

[DefaultSpeciesSet]
compatibility_threshold = 3.0

[DefaultStagnation]
species_fitness_func = max
max_stagnation = 20
species_elitism = 2

[DefaultReproduction]
elitism = 2
survival_threshold = 0.2
81 changes: 81 additions & 0 deletions cocktail-mash-ai/model_ai_finish/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

[NEAT]
fitness_criterion = max
fitness_threshold = 10000
no_fitness_termination = True
pop_size = 200
reset_on_extinction = False

[DefaultGenome]
# node activation options
activation_default = relu
activation_mutate_rate = 0.0
activation_options = relu

# node aggregation options
aggregation_default = sum
aggregation_mutate_rate = 0.0
aggregation_options = sum

# node bias options
bias_init_mean = 0.0
bias_init_stdev = 1.0
bias_max_value = 30.0
bias_min_value = -30.0
bias_mutate_power = 0.5
bias_mutate_rate = 0.7
bias_replace_rate = 0.1

# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient = 0.5

# connection add/remove rates
conn_add_prob = 0.0
conn_delete_prob = 0.0

# connection enable options
enabled_default = True
enabled_mutate_rate = 0.01

feed_forward = True
initial_connection = full_nodirect

# node add/remove rates
node_add_prob = 0.2
node_delete_prob = 0.2

# network parameters
num_hidden = 6
num_inputs = 7
num_outputs = 4

# node response options
response_init_mean = 1.0
response_init_stdev = 0.0
response_max_value = 30.0
response_min_value = -30.0
response_mutate_power = 0.0
response_mutate_rate = 0.0
response_replace_rate = 0.0

# connection weight options
weight_init_mean = 0.0
weight_init_stdev = 1.0
weight_max_value = 30
weight_min_value = -30
weight_mutate_power = 0.5
weight_mutate_rate = 0.8
weight_replace_rate = 0.1

[DefaultSpeciesSet]
compatibility_threshold = 3.0

[DefaultStagnation]
species_fitness_func = max
max_stagnation = 20
species_elitism = 2

[DefaultReproduction]
elitism = 2
survival_threshold = 0.2
11 changes: 11 additions & 0 deletions cocktail-mash-ai/model_ai_finish/neat_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"numberOfEvolutions":100,
"runEachGeneration": 0,
"runNewBest": true,
"numberOfRandomRecipes": 0,
"fillSteps":5,
"viewNetwork": true,
"viewSpeciesGraph": false,
"viewFitnessGraph": false,
"logToFile": false
}
Loading