class GCN:
def __init__(self,alpha,adj,feature,hiddenlayer_neurons,output_layer_neurons):
self.alpha=alpha
self.adj=adj
self.feature=feature
self.hiddenlayer_neurons=hiddenlayer_neurons
self.output_layer_neurons=output_layer_neurons
def weightlayers(self):
self.weights1= np.random.normal(loc=0,scale=0.5,size=(features.shape[1],self.hiddenlayer_neurons))
print(features.shape)
print(adj.shape)
self.weights2= np.random.normal(loc=0,scale=0.5,size=(self.hiddenlayer_neurons,self.output_layer_neurons))
self.bias1= np.random.normal(loc=0, scale=0.05, size=self.hiddenlayer_neurons)
self.bias2=np.random.normal(loc=0, scale=0.05, size= self.output_layer_neurons)
return self.weights1,self.weights2,self.bias1,self.bias2
def sigmoid(self,x):
sigma=1/(1+np.exp(-x))
return sigma
def softmax(self,inputs):
inputs=inputs.astype(np.float)
inputs=np.vectorize(inputs)
f=np.exp(inputs) / float(sum(np.exp(inputs)))
#f2 = np.vectorize(f)
return f
def forwardpropagation(self):
self.weights1,self.weights2,self.bias1,self.bias2=self.weightlayers()
self.bias1=(np.reshape(self.bias1,(-1,1))).T
self.bias2=(np.reshape(self.bias2,(-1,1))).T
print(self.bias1.ndim)
#self.sigmoid=self.sigmoid()
self.adj=self.adj.T
self.input= self.adj.dot(self.feature).dot(self.weights1) + (self.bias1)
print(self.input.shape)
self.sigmaactivation= self.sigmoid(self.input)
self.hiddeninput=(self.sigmaactivation @ self.weights2 ) + (self.bias2)
self.output=self.softmax(self.hiddeninput)
return self.output
For the softmax function it is throwing the above mentioned error. Following previous answers for somewhat similar question I tried to vectorize and convert it to float.But that does't seen to work.
When I vectorize it, I get this error :
TypeError: loop of ufunc does not support argument 0 of type vectorize which has no callable exp method.
float(). Why's it there? Why thenp.vectorize? You didn't read that function''s docs.vectorizetakes afunctionthat only works with a scalar, and returns one that works with an array. You aren't doing that!. You haven't shown whatinputsis, but theastypemethod implies that it's an array.np.vectorizedoesn't make sense that way. Stop trying to usenp.vectorize; it's not helping you.