igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Question on max id node


From: Richard Geddes
Subject: Re: [igraph] Question on max id node
Date: Mon, 10 Mar 2008 17:15:50 -0400
User-agent: Thunderbird 2.0.0.12 (X11/20080227)

G,

My cpu: AMD Athlon(tm) 64 X2 Dual Core Processor 5400+

The dataset I used:
0       1
0       2
0       10
1       2
1       10
2       3
3       4
3       5
3       6
4       7
4       8
4       9
5       6
5       7
6       7
6       8
6       9
7       8
8       9

when I use this dataset and import with the igraph edgelist function my output:

-1      -1      -0.095568       0
10      0       -0.051247       1
11      1       0.033241        2
2       12      0.105263        3
9       8       0.141274        4
4       14      0.207756        5
7       15      0.252078        6
6       16      0.306094        7
5       3       0.342105        8
18      17      0.358726        9
13      19      -0.000000       10
max node id:    -1
Node count:     11
Edge count:     19
max q:  0.358726
max q join:     9

when I use this dataset and import with the igraph ncol function my output:

-1      -1      -0.062327       0
6       5       -0.011080       1
13      17      0.037396        2
0       1       0.085873        3
8       7       0.134349        4
14      18      0.182825        5
9       22      0.229917        6
10      15      0.277008        7
4       3       0.324100        8
2       26      0.365651        9
21      27      0.437673        10
12      16      0.477839        11
20      11      0.513850        12
29      30      0.560942        13
31      23      0.594183        14
24      25      0.619114        15
33      32      0.459834        16
max node id:    -1
Node count:     19
Edge count:     19
max q:  0.619114
max q join:     15


Using your dataset and importing with the igraph edgelist function my output looks thus:

-1      -1      -0.208333       0
5       1       -0.097222       1
3       2       -0.013889       2
4       7       0.111111        3
8       6       0.000000        4
max node id:    -1
Node count:     6
Edge count:     6
max q:  0.111111
max q join:     3

Using your dataset and importing with the igraph ncol function my output looks thus:

-1      -1      -0.208333       0
4       0       -0.097222       1
2       1       -0.013889       2
3       6       0.111111        3
7       5       0.000000        4
max node id:    -1
Node count:     5
Edge count:     6
max q:  0.111111
max q join:     3


Note that the node values are slightly different and the node count reports different values.

R

Gabor Csardi wrote:
Richard, your program works fine for me. If i use it on this small 
graph:

1		2
2		3
2		4
3		4
4		5
1		5

then reading with 'ncol' results 5 vertices, which is correct ('1', '2',
'3', '4' and '5'), remember that 'ncol' means symbolic vertex names,
and reading as an edge list gives 6 vertices, which is also correct, 
vertices 0-6.

Please send me a file that breaks it. Thanks.

G.

On Mon, Mar 10, 2008 at 12:13:53PM -0400, Richard Geddes wrote:
  
G,

Here's a working fragment of my code that illustrates my results.  Note the
commented line for changing the import function.  When I swap out import
functions, my output changes.  My original intent was to be able to observe the
value (I think it may be called the 'name') with the highest node id,  setting
the attribute handler, and using the igraph_read_graph_ncol() import function
seemed to be a reasonable way to do this.   The input file format in both cases
is ascii text, one edge per line, each edge represented by 2 tab separated
integers which represent vertices.  I'm using the 0.6 version. 
-------------------------
#include <cstdio>
#include <string>
#include <iostream>
#include <igraph.h>

using namespace std;

int main(int argc, char* argv[]) {


        igraph_i_set_attribute_table(&igraph_cattribute_table);

        igraph_t graph;
        igraph_matrix_t merges;
        igraph_vector_t modularity;
        double maxq(-999999.0), q_i(0);
        int maxq_join(0), max_id(-1);

        igraph_vector_init(&modularity,0);
        igraph_matrix_init(&merges, 1, 2);

        FILE* input_file;
        input_file = fopen(argv[1], "r");

        //  Here's where I can change the import function
        // igraph_read_graph_ncol(&graph, input_file, NULL, true, false,
IGRAPH_UNDIRECTED);
        igraph_read_graph_edgelist(&graph, input_file, 0, false);
        fclose(input_file);

        igraph_integer_t node_count(igraph_vcount(&graph));
        igraph_integer_t edge_count(igraph_ecount(&graph));

        // ----- Community (fast greedy)
        igraph_community_fastgreedy(&graph, NULL, &merges, &modularity);

        // ----- print initial modularity
        q_i = (double)igraph_vector_e(&modularity, 0);
        printf("%i\t%i\t%f\t%i\n", -1, -1, q_i, 0);

        // ----- print modularity for subsequent joins
        for (int i = 1; i < igraph_vector_size(&modularity) ; i++) {
           q_i = (double)igraph_vector_e(&modularity, i);
           printf("%i\t%i\t%f\t%i\n", (int)igraph_matrix_e(&merges, i-1, 0),
                   (int)igraph_matrix_e(&merges, i-1, 1), q_i, i);
           if (q_i > maxq) {
              maxq = q_i;
              maxq_join = i;
           }
        }

        igraph_vector_destroy(&modularity);
        igraph_matrix_destroy(&merges);

        igraph_destroy(&graph);

        printf("max node id:\t%i\n", max_id);
        printf("Node count:\t%i\n", (int)node_count);
        printf("Edge count:\t%i\n", (int)edge_count);
        printf("max q:\t%f\n", maxq);
        printf("max q join:\t%i\n", maxq_join);

        return 0;
}





Gabor Csardi wrote:

    Richard, this is quite strange indeed. I've just tried read_graph_ncol
    with various graphs and it seems to work fine. Could you send
    me a small file that reproduces the strange results?

    Btw, is this the 0.5 version?

    Thanks,
    G.

    On Sun, Mar 09, 2008 at 06:22:42PM -0400, Richard Geddes wrote:


        Well, initially I imported an edgelist with

        igraph_read_graph_edgelist(&graph, input_file, 0, false);

        and ran

        igraph_community_fastgreedy(&graph, NULL, &merges, &modularity);

        and got normal results.

        Then, to get at the graph attributes,� I attached the C attribute handler:

        igraph_i_set_attribute_table(&igraph_cattribute_table);

        imported the edgelist with:

        igraph_read_graph_ncol(&graph, input_file, NULL true, false,
        IGRAPH_UNDIRECTED);

        and ran the community function on the graph and I get different results...

        when importing with igraph_read_graph_edgelist, 11 nodes and 19 edges are
        reported are reported.. which is correct,
        however when importing with the igraph_read_graph_ncol function, 19 nodes and
        19 edges are reported.

        Am I using igraph_read_graph_ncol correctly?

        Thanks
        Richard

        Richard Geddes wrote:

            Thanks.  Looks like what I was looking for.

            Tamas Nepusz wrote:


                Hi Richard,



                    Is there a function that provides the value of the largest node id in
                    the imported graph?



                If you are using C (I assume you do), try to attach the C attribute
                handler and then read your graph using igraph_read_graph_ncol (this is
                for the NCOL format which is practically a named edge list). This is
                able to store the vertex names used in the NCOL file as a vertex
                attribute. After that, you can scan the attribute values to find the
                largest one.

                See http://cneurocvs.rmki.kfki.hu/igraph/doc-0.5/html/ch09s02.html for
                the usage of the C attribute handler.





            _______________________________________________
            igraph-help mailing list
            address@hidden
            http://lists.nongnu.org/mailman/listinfo/igraph-help









        _______________________________________________
        igraph-help mailing list
        address@hidden
        http://lists.nongnu.org/mailman/listinfo/igraph-help







    

  
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help
    


  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]