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

Where do I find/change the potential of a neuron? (trying to seed/directly modify a population) #283

Open
The-Odor opened this issue Oct 3, 2024 · 0 comments

Comments

@The-Odor
Copy link

The-Odor commented Oct 3, 2024

I am trying to have a CTRNN emulate a sine function and want to use the CTRNN demo neurons as seed. The neurons that I try to modify, however, are completely non-deterministic; they change their behavior every time I run the code unless I put a seed before pop=neat.Population(config). The only value I have not found is the "potential" or decay of the neurons (as described by this documentation. I have looked in the github source code, the documentation, and through the object descriptions of various Python objects using the dir command.

Here is the specific code, with seed for determinism), using the config-ctrnn from the single-pole-balancing.

import neat
import numpy as np
import matplotlib.pyplot as plt
import random


simulationSteps = 100
timeConst = 1/100
goalFunc = lambda step: np.sin(step*25)

config = neat.Config(
    neat.DefaultGenome,
    neat.DefaultReproduction,
    neat.DefaultSpeciesSet,
    neat.DefaultStagnation,
    r"path_to\CTRNNconfig"
)

random.seed(5)
pop = neat.Population(config)
pop.add_reporter(neat.StdOutReporter(False))

# Seeding
for i in range(100, 200):
    gen = pop.population[i+1]
    n1, n2 = list(gen.nodes.keys())[1:]
    for node, bias in zip((n1,n2), (-2.75/5, -1.75/5)):
        # gen.nodes[node].aggregation = sum
        # gen.nodes[node].activation = sigmoid_activation
        gen.nodes[node].bias = bias
        gen.nodes[node].response = 1
    gen.add_connection(config.genome_config, n1, n1, 0.9, True)
    gen.add_connection(config.genome_config, n1, n2, 0.2, True)
    gen.add_connection(config.genome_config, n2, n1,-0.2, True)
    gen.add_connection(config.genome_config, n2, n2, 0.9, True)


# Just drawing out the last seeded genome
network = neat.ctrnn.CTRNN.create(gen, config, timeConst)
network.set_node_value(n1, 0)
network.set_node_value(n2, 0)
network.set_node_value(0, 0.5)


actions = []
correct = []
for step in range(simulationSteps):
    action = network.advance(
        [], 
        timeConst, 
        timeConst,
    )
    actions.append(action[0])
    correct.append(goalFunc(step)/3 + 0.5)


plt.plot(actions, label="Network")
plt.plot(correct, label="Goal")
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant