I'm building a convolution neural network and I'm using mean squared error as a cost function. I'm changing the cost function to not have error when the network output is over one so I'm thresholding the out to one when it is bigger. using this code
def MSE2(self, y):
loc = np.where(y == 1)[0]
for i in range(len(loc)):
if self.input2[loc[i]] > 1:
self.input2[loc[i]] = 1
return T.mean((y - self.input2) ** 2)
I'd like to know if theano gradient function will take this into account when it calculate the gradient or I should change something else.
Beside this, Is there any other way I can optimize this code to run faster or maybe on the GPU.
So the best way to solve this issue as I found is this
def MSE2(self, y):
loc = T.eq(y,1).nonezeros()[0]
S = T.clip(self.input2[loc],0,1)
self.input2 = T.set_subtensor(self.input2[loc], S)
return T.mean((y - self.input2) ** 2)
I already tested the result and the gradient.