I know this seems like complicating a very simple problem, but I have been instructed to do this by my supervisor who wishes to find the centroid of each molecular face of a large molecule. This problem can be reduced to finding the centroid of an n-sided polygon, where n>=3
and can vary between polygons. The input to the model is a set of vertices of the polygon, where each vertex is represented as 3D coordinates, and the output must be the 3D coordinates of the centroid.
I have tried executing a Graph Convolutional Network with the ReLU function for this approach, with input dimension as 3 (for the 3D coordinates) and output dimension as 3, thinking that I would obtain the x, y and z coordinates the 3 output dimensions. However, what I get is a prediction of the centroid based on each vertex of the polygon, and not based on the polygon itself.
To tackle this problem, I have formulated the problem of finding the centroid vector z as finding weights w1, w2, w3....wn
such that z=w1 * z1 + w2 * z2 + w3 * z3 + ... + wn * zn
, where the ideal values of w1, w2, w3,.....,wn
would be 1/n
. Using the GCN with the softmax function, even though I achieved satisfactory predictions for the weights, the results for the centroid was far from satisfactory.
Your approach of using the softmax function should work, since the sum of all weights wi
should be 1. In fact, if you train the network for a fairly small number of epochs, the values of w1
will converge to your required values.
One possible architecture which I can think of is below:
def __init__(self, input, hidden, output):
# Add code here:
# GCN architecture. You can use the GCNConv instead of CustomGraphConv
self.gcn1=CustomGraphConv(input, hidden)
self.gcn2=CustomGraphConv(hidden, hidden)
self.fc=nn.Linear(hidden, output)
self.softmax=nn.Softmax(dim=0)
def forward(self, x, edges):
x=self.gcn1(x, edges)
x=F.relu(x)
x=self.gcn2(x, edges)
x=F.relu(x)
x=self.fc(x)
x=self.softmax(x)
return x
Take care of the dimensions of the tensor before proceeding with this code, especially for the Softmax function.