Git Product home page Git Product logo

Comments (6)

shchur avatar shchur commented on May 30, 2024

You should be able to convert the adjacency matrix to scipy.sparse format using this method https://networkx.org/documentation/stable/reference/generated/networkx.convert_matrix.to_scipy_sparse_matrix.html. Then you will need to call A.tocsr() to turn into a CSR matrix.

from overlapping-community-detection.

sclipman avatar sclipman commented on May 30, 2024

Great, thanks for your help! So, the converted scipy.sparse adjacency matrix would become A in your code

loader = nocd.data.load_dataset('data/mag_cs.npz')
A, X, Z_gt = loader['A'], loader['X'], loader['Z']
N, K = Z_gt.shape

X would not apply in the absence of node attributes, but where does Z_gt come from in this case?

from overlapping-community-detection.

shchur avatar shchur commented on May 30, 2024

These are the ground truth community labels. If they are not available, you will need to specify K (the # of communities to detect) yourself.

from overlapping-community-detection.

sclipman avatar sclipman commented on May 30, 2024

Perfect, that works but then it hits a snag in the training loop. Perhaps due to the adjacency matrix being a csr_matrix?

I appreciate your help troubleshooting this! We'll be sure to cite your paper and acknowledge you. Detecting overlapping communities is something we want to add on to an upcoming paper.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-3315ab7333dc> in <module>
     11             gnn.eval()
     12             # Compute validation loss
---> 13             Z = F.relu(gnn(x_norm, adj_norm))
     14             val_loss = decoder.loss_full(Z, A)
     15             print(f'Epoch {epoch:4d}, loss.full = {val_loss:.4f}, nmi = {get_nmi():.2f}')

~/opt/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

~/github/Spatial/Spectral Clustering/overlapping-community-detection-master/nocd/nn/gcn.py in forward(self, x, adj)
     85         for idx, gcn in enumerate(self.layers):
     86             if self.dropout != 0:
---> 87                 x = sparse_or_dense_dropout(x, p=self.dropout, training=self.training)
     88             x = gcn(x, adj)
     89             if idx != len(self.layers) - 1:

~/github/Spatial/Spectral Clustering/overlapping-community-detection-master/nocd/nn/gcn.py in sparse_or_dense_dropout(x, p, training)
     18         return torch.cuda.sparse.FloatTensor(x.indices(), new_values, x.size())
     19     else:
---> 20         return F.dropout(x, p=p, training=training)
     21 
     22 

~/opt/anaconda3/lib/python3.8/site-packages/torch/nn/functional.py in dropout(input, p, training, inplace)
    981     return (_VF.dropout_(input, p, training)
    982             if inplace
--> 983             else _VF.dropout(input, p, training))
    984 
    985 

TypeError: dropout(): argument 'input' (position 1) must be Tensor, not csr_matrix

from overlapping-community-detection.

shchur avatar shchur commented on May 30, 2024

Can you try restarting the notebook and executing all the cells sequentially? The matrix should be converted into a sparse tensor in cell 5 (adj_norm = gnn.normalize_adj(A)), but it seems that this hasn't happened for some reason.

from overlapping-community-detection.

sclipman avatar sclipman commented on May 30, 2024

Thanks! That instance was fine but uncommenting x_norm = nocd.utils.to_sparse_tensor(x_norm).cuda() solved this. It progresses further into the training loop now but looks like it still wants Z_gt to compare against. I actually have the modularity cluster (previously calculated) for each node saved as a 'modularity' node attribute in the NetworkX graph object. I'm not sure how yet, but I wonder if this can be easily converted to a np.ndarray binary community affiliation matrix and used as Z_gt for the ground truth here, since our ultimate goal is to see how these communities overlap.

Edit: This indeed solved it and works great – thanks again for your help!

from overlapping-community-detection.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.