Skip to content

Commit 4553661

Browse files
authored
Merge pull request #1 from yaricom/v2
V2
2 parents 7606351 + e6cf754 commit 4553661

24 files changed

+719
-682
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# These are supported funding model platforms
22

33
patreon: io42
4+
custom: ["https://www.buymeacoffee.com/io42"]

.github/release-drafter.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name-template: 'v$RESOLVED_VERSION 🌈'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: '🚀 Features'
5+
labels:
6+
- 'feature'
7+
- 'enhancement'
8+
- title: '🐛 Bug Fixes'
9+
labels:
10+
- 'fix'
11+
- 'bugfix'
12+
- 'bug'
13+
- title: '🧰 Maintenance'
14+
label: 'chore'
15+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
16+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
17+
version-resolver:
18+
major:
19+
labels:
20+
- 'major'
21+
minor:
22+
labels:
23+
- 'minor'
24+
patch:
25+
labels:
26+
- 'patch'
27+
default: patch
28+
template: |
29+
## Changes
30+
31+
$CHANGES

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.15
20+
21+
- name: Build
22+
run: go build -v ./...
23+
env:
24+
GO111MODULE: on
25+
26+
- name: Run coverage
27+
run: go test -coverprofile=coverage.txt -covermode=atomic -timeout 40m -v ./...
28+
env:
29+
GO111MODULE: on
30+
31+
- name: Upload coverage to Codecov
32+
run: bash <(curl -s https://codecov.io/bash)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '19 8 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'go' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v2
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v1
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v1

.github/workflows/drafter.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# The release drafter
2+
# https://github.com/release-drafter/release-drafter
3+
#
4+
name: Release Drafter
5+
6+
on:
7+
push:
8+
# branches to consider in the event; optional, defaults to all
9+
branches:
10+
- master
11+
# pull_request event is required only for autolabeler
12+
pull_request:
13+
# Only following types are handled by the action, but one can default to all as well
14+
types: [opened, reopened, synchronize]
15+
16+
jobs:
17+
update_release_draft:
18+
runs-on: ubuntu-latest
19+
steps:
20+
# (Optional) GitHub Enterprise requires GHE_HOST variable set
21+
#- name: Set GHE_HOST
22+
# run: |
23+
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
24+
25+
# Drafts your next Release notes as Pull Requests are merged into "master"
26+
- uses: release-drafter/release-drafter@v5
27+
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
28+
# with:
29+
# config-name: my-config.yml
30+
# disable-autolabeler: true
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
# Lint runs golangci-lint over the entire Tendermint repository
3+
# This workflow is run on every pull request and push to master
4+
# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified.
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- master
10+
jobs:
11+
golangci:
12+
name: golangci-lint
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 8
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: technote-space/get-diff-action@v4
18+
with:
19+
PATTERNS: |
20+
**/**.go
21+
go.mod
22+
go.sum
23+
- uses: golangci/[email protected]
24+
with:
25+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
26+
version: v1.38
27+
args: --timeout 10m
28+
github-token: ${{ secrets.github_token }}
29+
if: env.GIT_DIFF

data/maze.neat

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ print_every 100
3030
babies_stolen 0
3131
num_runs 1
3232
num_generations 2000
33-
log_level 1
34-
35-
36-
linktrait_mut_sig 1.0
37-
nodetrait_mut_sig 0.5
38-
recur_prob 0.15
33+
log_level info
34+
epoch_executor sequential
35+
genome_compat_method linear

examples/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package examples package holds various examples with NEAT Novelty Search.
2+
package examples
Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// The maze solving experiments based on NEAT methodology with Novelty Search and Fitness based optimization
1+
// Package maze provides the maze solving experiments based on NEAT methodology with Novelty Search and Fitness
2+
// based optimization.
23
package maze
34

45
import (
56
"fmt"
6-
"github.com/yaricom/goNEAT/neat"
7-
"github.com/yaricom/goNEAT/neat/genetics"
8-
"github.com/yaricom/goNEAT/neat/network"
9-
"github.com/yaricom/goNEAT_NS/neatns"
7+
"github.com/yaricom/goNEAT/v2/neat"
8+
"github.com/yaricom/goNEAT/v2/neat/genetics"
9+
"github.com/yaricom/goNEAT/v2/neat/network"
10+
"github.com/yaricom/goNEAT_NS/v2/neatns"
1011
"math"
1112
)
1213

@@ -42,18 +43,29 @@ func histDiff(left, right []float64) float64 {
4243
func mazeSimulationEvaluate(env *Environment, org *genetics.Organism, record *AgentRecord, pathPoints []Point) (*neatns.NoveltyItem, bool, error) {
4344
nItem := neatns.NewNoveltyItem()
4445

46+
// get Organism phenotype's network depth
47+
netDepth, err := org.Phenotype.MaxActivationDepthFast(1) // The max depth of the network to be activated
48+
if err != nil {
49+
neat.WarnLog(fmt.Sprintf(
50+
"Failed to estimate maximal depth of the network:\n%s\nUsing default depth: %d",
51+
org.Genotype, netDepth))
52+
}
53+
neat.DebugLog(fmt.Sprintf("Network depth: %d for organism: %d\n", netDepth, org.Genotype.Id))
54+
if netDepth == 0 {
55+
neat.DebugLog(fmt.Sprintf("ALERT: Network depth is ZERO for Genome: %s", org.Genotype))
56+
}
57+
4558
// initialize maze simulation's environment specific to the provided organism - this will be a copy
4659
// of primordial environment provided
47-
orgEnv, err := mazeSimulationInit(*env, org)
60+
orgEnv, err := mazeSimulationInit(*env, org, netDepth)
4861
if err != nil {
4962
return nil, false, err
5063
}
5164

52-
// do specified amount of time steps emulations or while exit not found
65+
// do a specified amount of time steps emulations or while exit not found
5366
steps := 0
5467
for i := 0; i < orgEnv.TimeSteps && !orgEnv.ExitFound; i++ {
55-
err := mazeSimulationStep(orgEnv, org)
56-
if err != nil {
68+
if err = mazeSimulationStep(orgEnv, org, netDepth); err != nil {
5769
return nil, false, err
5870
}
5971
// store agent path points at given sample size
@@ -100,88 +112,58 @@ func mazeSimulationEvaluate(env *Environment, org *genetics.Organism, record *Ag
100112

101113
// To initialize the maze simulation within provided environment copy and for given organism.
102114
// Returns new environment for simulation against given organism
103-
func mazeSimulationInit(env Environment, org *genetics.Organism) (*Environment, error) {
104-
105-
// get Organism phenotype's network depth
106-
netDepth, err := org.Phenotype.MaxDepth() // The max depth of the network to be activated
107-
if err != nil {
108-
if err != network.NetErrDepthCalculationFailedLoopDetected {
109-
return nil, err
110-
} else {
111-
neat.InfoLog(fmt.Sprintf("Network loop detected, using default depth: %d for organism: %d\n",
112-
netDepth, org.Genotype.Id))
113-
}
114-
}
115-
neat.DebugLog(fmt.Sprintf("Network depth: %d for organism: %d\n", netDepth, org.Genotype.Id))
116-
if netDepth == 0 {
117-
neat.DebugLog(fmt.Sprintf("ALERT: Network depth is ZERO for Genome: %s", org.Genotype))
118-
}
119-
115+
func mazeSimulationInit(env Environment, org *genetics.Organism, netDepth int) (*Environment, error) {
120116
// flush the neural net
121-
if _, err = org.Phenotype.Flush(); err != nil {
117+
if _, err := org.Phenotype.Flush(); err != nil {
122118
neat.ErrorLog("Failed to flush phenotype")
123119
return nil, err
124120
}
125121
// update the maze
126-
err = env.Update()
127-
if err != nil {
122+
if err := env.Update(); err != nil {
128123
neat.ErrorLog("Failed to update environment")
129124
return nil, err
130125
}
131126

132127
// create neural net inputs from environment
133-
inputs, err := env.GetInputs()
134-
if err != nil {
128+
if inputs, err := env.GetInputs(); err != nil {
135129
return nil, err
136-
}
137-
138-
// load into neural net
139-
if err = org.Phenotype.LoadSensors(inputs); err != nil {
130+
} else if err = org.Phenotype.LoadSensors(inputs); err != nil { // load into neural net
140131
return nil, err
141132
}
142133

143134
// propagate input through the phenotype net
144135

145-
// Relax phenotype net and get output
146-
if _, err = org.Phenotype.Activate(); err != nil && err != network.NetErrExceededMaxActivationAttempts {
147-
neat.ErrorLog("Failed to activate network init 1")
136+
// Use depth to ensure full relaxation
137+
if _, err := org.Phenotype.ForwardSteps(netDepth); err != nil && err != network.ErrNetExceededMaxActivationAttempts {
138+
neat.ErrorLog(fmt.Sprintf("Failed to activate network at simulation init: %s", err))
148139
return nil, err
149140
}
150141

151-
// use depth to ensure relaxation at each layer
152-
for relax := 0; relax <= netDepth; relax++ {
153-
if _, err = org.Phenotype.Activate(); err != nil && err != network.NetErrExceededMaxActivationAttempts {
154-
neat.ErrorLog("Failed to activate network init 2")
155-
return nil, err
156-
}
157-
}
158-
159142
return &env, nil
160143
}
161144

162145
// To execute a time step of the maze simulation evaluation within given Environment for provided Organism
163-
func mazeSimulationStep(env *Environment, org *genetics.Organism) error {
146+
func mazeSimulationStep(env *Environment, org *genetics.Organism, netDepth int) error {
164147
// get simulation parameters as inputs to organism's network
165148
if inputs, err := env.GetInputs(); err != nil {
166149
return err
167150
} else if err = org.Phenotype.LoadSensors(inputs); err != nil {
168151
neat.ErrorLog("Failed to load sensors")
169152
return err
170153
}
171-
_, err := org.Phenotype.Activate()
172-
if err != nil && err != network.NetErrExceededMaxActivationAttempts {
173-
neat.ErrorLog("Failed to activate network simulation")
154+
if _, err := org.Phenotype.ForwardSteps(netDepth); err != nil && err != network.ErrNetExceededMaxActivationAttempts {
155+
neat.ErrorLog(fmt.Sprintf("Failed to activate network at simulation init: %s", err))
174156
return err
175157
}
176158

177159
// use the net's outputs to change heading and velocity of maze agent
178-
if err = env.ApplyOutputs(org.Phenotype.Outputs[0].Activation, org.Phenotype.Outputs[1].Activation); err != nil {
160+
if err := env.ApplyOutputs(org.Phenotype.Outputs[0].Activation, org.Phenotype.Outputs[1].Activation); err != nil {
179161
neat.ErrorLog("Failed to apply outputs")
180162
return err
181163
}
182164

183165
// update the environment
184-
if err = env.Update(); err != nil {
166+
if err := env.Update(); err != nil {
185167
neat.ErrorLog("Failed to update environment")
186168
return err
187169
}

0 commit comments

Comments
 (0)