Dear Tutors,<br><br>My original email was this:<br><br>"Dear tutors,<br>
<br>
I'm trying to create a neural network program. Each neuron is in a<br>
dictionary and each of its connections and their strengths are in a nested<br>
dictionary. So {0:{1:4, 2:5}}, 1:{0:6}, 2:{1:2}} would mean that neuron 0<br>
is connected to neuron 1 with a strength of 4. And it also means that<br>
neuron 1 is connected to neuron 0 with a strength of 6.<br>
<br>
The problem is that I'm working on a function that is supposed to add the<br>
total strengths of each neuron. So, for example, neuron 0's connections<br>
have a total strength of 9 (4+5). The other problem is getting all of the<br>
total strengths and ordering the neurons into a list. So, from the example,<br>
the list would be from [0,1,2] because zero has the greatest total strength<br>
of 9, then 1 with a total strength of 6 and so on. I've been working on<br>
this problem for at least 2 hours now and still haven't found anything<br>
close to a solution."<br><br>And here's my source code:<br><br>class neuron(object):<br> def __init__(self):<br> self.neurons = {}<br> self.neuron_total = 0<br><br> def create_neurons(self, number):<br>
for i in range(number):<br> self.neuron_total += 1<br> self.neurons[self.neuron_total] = {}<br><br> def connect_neurons(self,connecter,connectee):<br> try:<br> self.neurons[connecter][connectee] += 1<br>
except(KeyError):<br> try:<br> self.neurons[connecter][connectee] = 1<br> except(KeyError):<br> self.neurons[connecter] = {connectee:1}<br><br> def ping(self,neuron,choice):<br>
if choice == True: #If the neuron pinged needs to choose only one neuron<br> most_connected = 0<br> for connections in self.neurons[neuron]:<br> if max(str(self.neurons[neuron][connections])) > most_connected:<br>
most_connected = connections<br> else:<br> pass<br> return most_connected <br> else:<br> for neuron in self.neurons:<br>
for connections in self.neurons[choice]:<br> return connections<br> def total(self, neuron):<br> total = 0<br> for connection in self.neurons[neuron]:<br> total = total+self.neurons[neuron][connection]<br>
<br> <br><br> def smartest(self): #Return the neurons in order from smartest to dumbest in list form.<br> for neuron in self.neurons:<br> sorted(neuron, key=self.total(neuron))<br><br>
The total function works when it returns the strength of a neuron, but I don't think the "sorted" function is the best because, with its current configuration, it returns a type error. I have been doing python for several years now. I don't know EVERYTHING there is to know, but I am able to do most tasks without error. Please help me get the neurons into an order in a list as described in my original email. Also, I do thank you for your original replies!<br>
<br>-- <br>Thank you,<br><div>Jacob</div><br>