Skip to content
This repository was archived by the owner on Dec 11, 2018. It is now read-only.
This repository was archived by the owner on Dec 11, 2018. It is now read-only.

Run data through trained network #4

@azaryc2m

Description

@azaryc2m

Hi!
First i wanted to thank you for the effort you put into this project. I'm having issues evaluating even the example you posted (XOR). So i trained the network until the avg Fitness was around 1.5 and the best Fitness = 0 (which should solve all possible xor cases). But when i create a Network using the best genome and run some data through it, it doesn't seem to work. Am i doing something wrong or is there some kind of a bug regarding retrieving the best individual? Here's the code i use for the test:

package main

import (
	neat "github.com/jinyeom/neat"
	"log"
	"math"

)

func main(){
	// First, create a new instance of Config from the JSON file created above.
	// If there's a file import error, the program will crash.
	config, err := neat.NewConfigJSON("config.json")
	if err != nil{
		log.Fatal(err)
	}
	
	neatInst := neat.New(config, neat.XORTest())
	neatInst.Run()
	log.Printf("Fitness: %f\n", neatInst.Best.Fitness)
	nn := neat.NewNeuralNetwork(neatInst.Best)
	
	inputs := make([]float64, 3)
	inputs[0] = 1.0 // bias	
	b := []bool{true,false}
	for i := 0; i < len(b); i++{
		for j := 0; j < len(b); j++{
			a := b[i]
			b := b[j]
			if a{inputs[1] = 1.0}else{inputs[1] = 0.0}
			if b{inputs[2] = 1.0}else{inputs[2] = 0.0}
			output, _ := nn.FeedForward(inputs)
			log.Printf("%t, %t = %f\n",a,b,output[0])
		}
	}
}

The output of this is in most cases:

2017/07/01 03:09:31 Fitness: 0.000000
2017/07/01 03:09:31 true, true = 0.000000
2017/07/01 03:09:31 true, false = 0.000000
2017/07/01 03:09:31 false, true = 0.000000
2017/07/01 03:09:31 false, false = 0.000000

But sometimes it also goes for all of it:
2017/07/01 03:22:18 Fitness: 0.000000
2017/07/01 03:22:18 true, true = 1.000000
2017/07/01 03:22:18 true, false = 1.000000
2017/07/01 03:22:18 false, true = 1.000000
2017/07/01 03:22:18 false, false = 1.000000

I'd appreciate your feedback on this issue. Chances are i'm simply too dumb/tired to use it :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions