GEXF and node size

Once it's running
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Crispy
Posts:4
Joined:12 Mar 2018 15:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
GEXF and node size

Post by Crispy » 12 Mar 2018 15:41

I have a simple GEXF file with two nodes, size 20.0 and size 21.0:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<gexf xmlns="http://www.gexf.net/1.2draft" xmlns:viz="http://www.gexf.net/1.2draft/viz" version="1.2">
 <meta lastmodifieddate="2018-03-12">
  <creator>Tester</creator>
  <description>Node size test</description>
 </meta>
 <graph defaultedgetype="undirected" idtype="string" mode="static">
  <nodes count="2">
   <node id="3" label="NodeSize:21.0">
    <viz:color r="255" g="0" b="0"/>
    <viz:size value="21.0"/>
   </node>
   <node id="4" label="NodeSize:20.0">
    <viz:color r="204" g="204" b="255"/>
    <viz:size value="20.0"/>
   </node>
  </nodes>
  <edges count="0">
  </edges>
 </graph>
</gexf>
They generate vastly different size nodes as shown below. The smaller node (20.0) is just visible on the top left of the 'z'. The larger (red) node is significantly larger. What is the size ratio algorithm? I see someone asked a similar question nearly two years ago but without reply.
GEXFNodeSizes.png

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: GEXF and node size

Post by eduramiba » 12 Mar 2018 17:31

Hi,

This is the scaler https://github.com/gephi/gephi/blob/mas ... caler.java But I think you can disable it during import report.

Crispy
Posts:4
Joined:12 Mar 2018 15:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: GEXF and node size

Post by Crispy » 12 Mar 2018 23:48

Thanks. I looked at the code, hacked out the irrelevant stuff and produced this:

Code: Select all

package nodesizegephi;

import java.util.ArrayList;
import java.util.List;

public class NodeSizeGephi
{
    private static float sizeMinimum, sizeMaximum;

    private static void setDefaults() {
        sizeMaximum = 100f;
        sizeMinimum = 4f;
    }
    
    public static void main(String[] args)
    {
        setDefaults();
        
        //... Inject my two nodes
        List<Node> nodes = new ArrayList<>();
        nodes.add(new Node(20.0f));
        nodes.add(new Node(21.0f));

        float sizeMin = Float.POSITIVE_INFINITY;
        float sizeMax = Float.NEGATIVE_INFINITY;
        float sizeRatio = 0f;

        //Measure
        for( Node node : nodes )
        {
            sizeMin = Math.min(node.getSize(), sizeMin);
            sizeMax = Math.max(node.getSize(), sizeMax);
        }

        if (sizeMin != 0 && sizeMax != 0)
        {
            if (sizeMin == sizeMax) {
                sizeRatio = sizeMinimum / sizeMin;
            } else {
                sizeRatio = (sizeMaximum - sizeMinimum) / (sizeMax - sizeMin);
            }

            //Scale node size
            for( Node node : nodes )
            {
                float size = (node.getSize() - sizeMin) * sizeRatio + sizeMinimum;
                node.setSize(size);
            }
        }
        
        nodes.forEach((node)->System.out.println("Node size: " +node.getSize()));
    }
}

class Node
{
    private float size;

    public Node(float size)
    {
        this.size = size;
    }

    public float getSize() {
        return size;
    }

    public void setSize(float size) {
        this.size = size;
    }
}
Running this I get returned:
Node size: 4.0
Node size: 100.0

Which are the max and min sizes. The centroid stuff in the original code will not change things I believe as nodeSize will only be 1 (with two nodes). So my node sizes, originally marginally different become wildly altered.

Seeing this, I tried with a GEXF with just one node (size 21.0) to see what would happen (nodeSize would be zero).
:
<node id="3" label="NodeSize:21.0">
<viz:color r="255" g="0" b="0"/>
<viz:size value="21.0"/>
</node>
:

It produced this (without me having adjusted anything):

Image
Attachments
GephiOneNode.png

Crispy
Posts:4
Joined:12 Mar 2018 15:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: GEXF and node size

Post by Crispy » 12 Mar 2018 23:57

Please note, I also subsequently switched off auto-scale on loading the GEXF as you suggested. This made no difference to either the one node or two node size GEXF tests.

Crispy
Posts:4
Joined:12 Mar 2018 15:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: GEXF and node size

Post by Crispy » 13 Mar 2018 00:25

One last test. I generated a GEXF with 9 nodes: 6 x size 20.0, 1 x size 24.0, 2 x size 25.0. The resulting output shows as below. This is not usefully viewable. Could I suggest you revisit your scaling code?
Image
Attachments
Gephi9Nodes.png

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable