Aug-06-2021, 09:28 PM
I am establishing a multilayer perceptron neural network. Each layer has random number of perceptron. In order to connect perceptrons from
one layer to another one, I need to pick random number of perceptrons. The code is below. But the error message I get is
>>
Here is the code
one layer to another one, I need to pick random number of perceptrons. The code is below. But the error message I get is
>>
Error:TypeError: Population must be a sequence. For dicts or sets, use sorted(d). <<Here is the code
import numpy as np
import random
class MultiLayer_test():
def __init__(self):
self.H_LayerNo = 5
self.MaxPercNo = 10 # Assume that we only generate 10 perceptron on each layer
def main_Layering(self):
PercNo = []
Layers = []
Ex_N = []
#IndexCh = []
for i in range(0, self.H_LayerNo):
# Number of perceptrons per layer
PercNo.append(random.randint(1, self.MaxPercNo))
# Create tuples representing the layers
Layers.append([np.zeros((1, PercNo[i]))]) #[np.zeros((1, PercNo[i]))] [random.random(PercNo[i])]
# Number of transmitters per layer
Ex_N.append(random.randint(1, PercNo[i])) #PercNo[i]
# Get the indices of excited neurons
Idx[i] = random.sample(np.asarray(Layers[i]),Ex_N[i])
if __name__ == '__main__':
runner = MultiLayer_test()
runner.main_Layering()
