why is my variable returning as Nonetype even though when print it just before it is all ok?

I have encountered this problem in a TICTACTOE Neural Network in python. Just a simple AI in the making
It ocurrs after I return the last value from feed forward(the output) . I am kind of a beginner btw

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> def feedForward(self, input, layer):
#last activation is returned
if layer == len(self.shape):
* print(input) #* here the last activation is actually printed and works**
* return input # *here the last Activation is returned but as Nonetype?**
#output Vektor wird initialisiert mit shape
self.output = np.zeros(self.shape[layer])
print(input)
#the Neurons are gone through
for i in range(self.shape[layer]):
self.neurons[layer][i].calculateActivations(input)
self.output[i] = self.neurons[layer][i].getVar("activation")
print("neuron fired")
self.feedForward(self.output, layer + 1)
</code>
<code> def feedForward(self, input, layer): #last activation is returned if layer == len(self.shape): * print(input) #* here the last activation is actually printed and works** * return input # *here the last Activation is returned but as Nonetype?** #output Vektor wird initialisiert mit shape self.output = np.zeros(self.shape[layer]) print(input) #the Neurons are gone through for i in range(self.shape[layer]): self.neurons[layer][i].calculateActivations(input) self.output[i] = self.neurons[layer][i].getVar("activation") print("neuron fired") self.feedForward(self.output, layer + 1) </code>
    def feedForward(self, input, layer):
        #last activation is returned
        if layer == len(self.shape):
           * print(input) #* here the last activation is actually printed and works**
           * return input # *here the last Activation is returned but as Nonetype?**
        #output Vektor wird initialisiert mit shape
        self.output = np.zeros(self.shape[layer])
        print(input)
        #the Neurons are gone through
        for i in range(self.shape[layer]):
            self.neurons[layer][i].calculateActivations(input)
            self.output[i] = self.neurons[layer][i].getVar("activation")
            print("neuron fired")
        self.feedForward(self.output, layer + 1)

in this Method I print out what comes out at last from my FeedForward but it is just Nonetype
as you will see in the Console

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> def runFF(self, inputs):
print("output --->"+"n")
*out = self.feedForward(inputs, 0)*
*print(out)*
</code>
<code> def runFF(self, inputs): print("output --->"+"n") *out = self.feedForward(inputs, 0)* *print(out)* </code>
    def runFF(self, inputs):
        print("output --->"+"n")

        *out = self.feedForward(inputs, 0)*
        *print(out)*

this is the Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[1 0 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0]
#Inputs for Fields, e.g. 001 --- Empty? -> 0, is O? -> 0, is X?-> 1 = 001
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.97608829 0.98383903 0.93957521 0.93431431 0.98965643] # these are the activations for the Layer 1
neuron fired
neuron fired
neuron fired
[0.98738308 0.96916289 0.94868291] Layer 2 and so on...
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.7176812 0.885665 0.84968832 0.88980995 0.90426031]
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.95916376 0.95721362 0.91595512 0.93022966 0.94000431 0.86405699
0.93726489 0.89166409 0.89323725] # this is the last activation from the "print(input)" in feedForward()
*None* # this is what happens when I print the returned last activation
</code>
<code>[1 0 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0] #Inputs for Fields, e.g. 001 --- Empty? -> 0, is O? -> 0, is X?-> 1 = 001 neuron fired neuron fired neuron fired neuron fired neuron fired [0.97608829 0.98383903 0.93957521 0.93431431 0.98965643] # these are the activations for the Layer 1 neuron fired neuron fired neuron fired [0.98738308 0.96916289 0.94868291] Layer 2 and so on... neuron fired neuron fired neuron fired neuron fired neuron fired [0.7176812 0.885665 0.84968832 0.88980995 0.90426031] neuron fired neuron fired neuron fired neuron fired neuron fired neuron fired neuron fired neuron fired neuron fired [0.95916376 0.95721362 0.91595512 0.93022966 0.94000431 0.86405699 0.93726489 0.89166409 0.89323725] # this is the last activation from the "print(input)" in feedForward() *None* # this is what happens when I print the returned last activation </code>
[1 0 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0]
#Inputs for Fields, e.g. 001 --- Empty? -> 0, is O? -> 0, is X?-> 1 = 001
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.97608829 0.98383903 0.93957521 0.93431431 0.98965643] # these are the activations for the Layer 1
neuron fired
neuron fired
neuron fired
[0.98738308 0.96916289 0.94868291] Layer 2 and so on...
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.7176812  0.885665   0.84968832 0.88980995 0.90426031]
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
neuron fired
[0.95916376 0.95721362 0.91595512 0.93022966 0.94000431 0.86405699   
 0.93726489 0.89166409 0.89323725]  # this is the last activation from the "print(input)" in feedForward()
*None* # this is what happens when I print the returned last activation

I have used 2 Classes for this NN, this is the Neuron class

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Neuron(object):
def __init__(self):
self.weights = []
self.bias = 0.0
self.activation = 0.0
def set_weights(self, amount):
self.weights = np.array([np.random.random_sample() for i in range( amount)])
def set_bias(self):
self.bias = np.random.random_sample()
def getVar(self, var):
if var == "weights":
return self.weights
elif var == "bias":
return self.bias
elif var == "activation":
return self.activation
elif var == "all":
a = ""
for i in range (len(self.weights)):
a = (a +" "+(str)(self.weights[i]))
return a +"/" + (str)(self.bias) + " "+ (str)(self.activation)
def sigmoid(self, z):
return 1 / (1 + np.exp(-z))
def calculateActivations(self, inputs):
z = np.dot(inputs, self.weights) + self.bias
self.activation = self.sigmoid(z)
</code>
<code>class Neuron(object): def __init__(self): self.weights = [] self.bias = 0.0 self.activation = 0.0 def set_weights(self, amount): self.weights = np.array([np.random.random_sample() for i in range( amount)]) def set_bias(self): self.bias = np.random.random_sample() def getVar(self, var): if var == "weights": return self.weights elif var == "bias": return self.bias elif var == "activation": return self.activation elif var == "all": a = "" for i in range (len(self.weights)): a = (a +" "+(str)(self.weights[i])) return a +"/" + (str)(self.bias) + " "+ (str)(self.activation) def sigmoid(self, z): return 1 / (1 + np.exp(-z)) def calculateActivations(self, inputs): z = np.dot(inputs, self.weights) + self.bias self.activation = self.sigmoid(z) </code>
class Neuron(object):

    def __init__(self):

        self.weights = []
        self.bias = 0.0
        self.activation = 0.0

    def set_weights(self, amount):
        self.weights = np.array([np.random.random_sample() for i in range( amount)])
    def set_bias(self):
        self.bias = np.random.random_sample()
    def getVar(self, var):
        if var == "weights":
            return self.weights
        elif var == "bias":
            return self.bias
        elif var == "activation":
            return self.activation
        elif var == "all":
            a = ""
            for i  in range (len(self.weights)):
                a = (a +" "+(str)(self.weights[i]))
            return   a +"/" + (str)(self.bias) + " "+ (str)(self.activation)


    def sigmoid(self, z):
        return 1 / (1 + np.exp(-z))

    def calculateActivations(self, inputs):
        z = np.dot(inputs, self.weights) + self.bias
        self.activation = self.sigmoid(z)

Here is the actual MLP (without backpropagation yet just feedForward)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class MLP(object):
def __init__(self, Board):
self.Board = Board
self.shape = [5, 3, 5, 9]
self.layout = [27, 5, 3, 5, 9]
self.neurons = []
def feedForward(self, input, layer):
#rekursionsanker
if layer == len(self.shape):
print(input)
return input
#output Vektor wird initialisiert mit shape
self.output = np.zeros(self.shape[layer])
print(input)
#Die Neuronen in der Layer werden durchgegangen und berechnet
for i in range(self.shape[layer]):
self.neurons[layer][i].calculateActivations(input)
self.output[i] = self.neurons[layer][i].getVar("activation")
print("neuron fired")
self.feedForward(self.output, layer + 1)
def createNeurons(self):
for i in range(len(self.shape)):
a = np.empty(self.shape[i], Neuron)
for j in range(self.shape[i]):
a[j] = Neuron()
self.neurons.append(a)
print(self.neurons)
def initializeNeurons(self):
for i in range(len(self.shape)):
for j in range(self.shape[i]):
self.neurons[i][j].set_weights(self.layout[i])
self.neurons[i][j].set_bias()
self.printAll(i, j)
def printAll(self, i ,j):
x = self.neurons[i][j].getVar("all")
y = x.split('/')
z = y[0].split(' ')
for l in range(self.layout[i]):
print("weight " + (str)(l + 1) + " = " + z[l+1] + "n")
print("b/a : " + y[1])
def runFF(self, inputs):
print("output --->"+"n")
out = self.feedForward(inputs, 0)
print(out)
def test(self):
input = np.array([0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1])
self.runFF(input)
</code>
<code>class MLP(object): def __init__(self, Board): self.Board = Board self.shape = [5, 3, 5, 9] self.layout = [27, 5, 3, 5, 9] self.neurons = [] def feedForward(self, input, layer): #rekursionsanker if layer == len(self.shape): print(input) return input #output Vektor wird initialisiert mit shape self.output = np.zeros(self.shape[layer]) print(input) #Die Neuronen in der Layer werden durchgegangen und berechnet for i in range(self.shape[layer]): self.neurons[layer][i].calculateActivations(input) self.output[i] = self.neurons[layer][i].getVar("activation") print("neuron fired") self.feedForward(self.output, layer + 1) def createNeurons(self): for i in range(len(self.shape)): a = np.empty(self.shape[i], Neuron) for j in range(self.shape[i]): a[j] = Neuron() self.neurons.append(a) print(self.neurons) def initializeNeurons(self): for i in range(len(self.shape)): for j in range(self.shape[i]): self.neurons[i][j].set_weights(self.layout[i]) self.neurons[i][j].set_bias() self.printAll(i, j) def printAll(self, i ,j): x = self.neurons[i][j].getVar("all") y = x.split('/') z = y[0].split(' ') for l in range(self.layout[i]): print("weight " + (str)(l + 1) + " = " + z[l+1] + "n") print("b/a : " + y[1]) def runFF(self, inputs): print("output --->"+"n") out = self.feedForward(inputs, 0) print(out) def test(self): input = np.array([0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1]) self.runFF(input) </code>
class MLP(object):
    
    def __init__(self, Board):
        self.Board = Board
        self.shape = [5, 3, 5, 9]
        self.layout = [27, 5, 3, 5, 9]
        self.neurons = []

    def feedForward(self, input, layer):
        #rekursionsanker
        if layer == len(self.shape):
            print(input)
            return input
        #output Vektor wird initialisiert mit shape
        self.output = np.zeros(self.shape[layer])
        print(input)
        #Die Neuronen in der Layer werden durchgegangen und berechnet
        for i in range(self.shape[layer]):
            self.neurons[layer][i].calculateActivations(input)
            self.output[i] = self.neurons[layer][i].getVar("activation")
            print("neuron fired")
        self.feedForward(self.output, layer + 1)


    def createNeurons(self):
        for i in range(len(self.shape)):
            a = np.empty(self.shape[i], Neuron)
            for j in range(self.shape[i]):
                a[j] = Neuron()
            self.neurons.append(a)
        print(self.neurons)


    def initializeNeurons(self):
        for i in range(len(self.shape)):
            for j in range(self.shape[i]):
                self.neurons[i][j].set_weights(self.layout[i])
                self.neurons[i][j].set_bias()
                self.printAll(i, j)


    def printAll(self, i ,j):
        x = self.neurons[i][j].getVar("all")
        y = x.split('/')
        z = y[0].split(' ')
        for l in range(self.layout[i]):
            print("weight " + (str)(l + 1) + " = " + z[l+1] + "n")
        print("b/a : " + y[1])

    def runFF(self, inputs):
        print("output --->"+"n")

        out = self.feedForward(inputs, 0)
        print(out)

        def test(self):
        input = np.array([0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1])
        self.runFF(input)

there is a test method here so you can go right ahead if you want to

I have spent too much time looking for some sort of a mistake and I am lost
I have looked at other questions similar to mine but i do not seem to be able to draw a sensible conclusion from the others

New contributor

fastSnowman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật