Ive been trying to implement the NeuroEvolution of Augmenting Topologies( NEAT) algorithm for a flappy bird clone, referring a tutorial on youtube.

Following the tutorial Ive run into the following problem: When executing index.html I receive the following error.

TypeError: func is not a function matrix.js:104:27

This is confusing as matrix.js and nn.js are both library functions provided to me by the person conducting the tutorial.

Looking at the code of matrix.js I found that the line throwing the error was

this.data[i][j] = func(val,i,j);

but I could not find a function definition for the function func() anywhere in either matrix.js or nn.js .

But in the code of nn.js I found that func was being referred to as a variable and not a function.

class ActivationFunction { constructor(func, dfunc) { this.func = func; this.dfunc = dfunc; } } let sigmoid = new ActivationFunction( x => 1 / (1 + Math.exp(-x)), y => y * (1 - y) ); let tanh = new ActivationFunction( x => Math.tanh(x), y => 1 - (y * y) );

and

setActivationFunction(func = sigmoid) { this.activation_function = func; }

So I assumed that func was meant to provide the sigmoid value of val to this.data[I][j] so I wrote my own sigmoid function which fed the activation function values to this.data[I][j] . which upon execution threw the error ReferenceError: NeuralNetwork is not defined[Learn More] bird.js:25:7

Therefore I decided to abandon trying to write a function and I decided to copy the value of the sigmoid activation function directly into the variable this.data[I][j] as follows:

this.data[i][j] = 1/(1+Math.pow(Math.E, -val));

This method did not throw any errors but did present me with a new problem. Earlier each member of the population of each generation would be acting independently producing an output like this:

But now what im getting is

Its not that only one player object is being generated in the second image all 250 objects are being generated but they're all on top of one another making it seem like theres only one player object. This is due to

1/(1+Math.pow(Math.E, -val));

sending the exact same value to this.data[I][j] , I've observed that when different values are passed to this.data[I][j] each player object acts independently. Does anyone have any idea as to why func is. variable in one file and func is a function in another file?

I apologise for my lack of clarity as this is an error in the library files, I am not an expert on matrix operations and I have tried to convey the problem I'm facing to the best of my ability. No one I know so far has been facing these issues.

All the required files can be found here