1
I’m creating a neural network, and now I’m doing the part that would create the population to be trained, but I’m not getting a randomness. I just don’t understand it and I don’t know how to get around it. (except for the possibility that a function outside the class would be passed to modify the values)
the following code exemplifies the error:
import random as rd
# Criar 10 numeros aleatorios
# 10 random normal
for i in range(10):
test = rd.randrange(-1000, 1000)
print(test)
# 10 random por class
class NeuralNetwork:
random = rd.randrange(-1000, 1000)
for n in range(10):
test = NeuralNetwork()
print(test.random)
I did it in repl.it https://repl.it/@nazesaria/Acrobaticimpurebinarysearchtree#main.py
How can I get around it otherwise?
I tried to apply it to the way I built it, but unfortunately I’m not getting it, I tried it a lot. An example closer to the q structure I’m using would be like https://repl.it/@nazesaria/Lawngreenhummingusers#main.py
– Naze
Even leaving this function to an external method I have the same problem https://repl.it/@nazesaria/Glossygigatrace#main.py
– Naze
Not so that POO works, I made some annotations in a Fork because its code does not have permission for editing https://repl.it/@Ronaldovasques/Lawngreenhummingusers#main.py . Explain in detail what you are trying to do.
– Augusto Vasques
I made the example code to reproduce the problem, what I am doing is very simple, I made a Flappy Bird (bird game that keeps jumping), and a neural net to it, until then everything Ok! Now I want to make their evolution so that it is not a "Bird" at a time, but several, so I make a loop by creating several obj of the Bird class, to play simultaneously. Problem, when create they all receive same random values. That was an example to show that all obj in layers[0]. Weights[0] receive the same weight. But I wanted each one to come different. https://github.com/Pessutto/flappybird_ia
– Naze
Got it. The problem is that you want when printing the value
print(obj.brain.layers[0].weights[0])
it prints a different value, the language does not do this. You set a value for the variableobj.brain.layers[0].weights[0]
this value only changes if you reset it. If you want each print to have a new number you have to read from a property because this one can define a function to be executed at each reading.– Augusto Vasques
I modified https://repl.it/@Ronaldovasques/Lawngreenhummingusers#main.py to see if you agree with what you want now?
– Augusto Vasques
Vlw, I managed to get around this, but I did not get the success I wanted, I thought this was the problem of appearing only a 'Bird' on the screen, but even creating several groups with different Weights still only one appears. anyway thanks.
– Naze