igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] : Simplify() use


From: Gábor Csárdi
Subject: Re: [igraph] : Simplify() use
Date: Sat, 15 Nov 2014 22:11:50 -0500

On Sat, Nov 15, 2014 at 8:39 PM, patricia <address@hidden> wrote:
> Hi,
>
> I am an undergraduate student and am doing a project on Scientific
> Initiation, but I am totally inexperienced in programming, so I would kindly
> ask for your help.

Hi,

this was not the question, but I very strongly suggest to use R or
Python instead of C, unless you really need to do this in C for some
reason.

> I want to build graph average degree ranging from 1 to 5 and know to have
> average degree it is necessary to first edges 150 connected to degree 2-300
> edges and so on.

I am not sure what this means. Can you give an example? What kind of
graphs do you need? Random graphs? Those you can just generate with a
single igraph function call.

> I tried to use the simplify () function inside the while
> loop, but got error,

What error? Why are you using it in a loop? Simplify removes all
multiple and loop edges at one go. Why do you even need simplify?

> then think to use it must first setting the weight
> values; but in doing so the graphs generated do not have the correct number
> of edges that should possess to achieve the desired degree. I'll put below,
> part of the code. Please give me a suggestion how to fix it.

I don't understand this either.

I would really like to help you, but for that you need to tell me what
you want to do, in a way that I can understand.

Gabor

> void TNetData::MatrixSimilarity(float sigma, int initial_degree, int
> final_degree)
> {
>     VectorXf v1, v2;
>     MatrixXf W(NOS,NOS);
> int i, j, g, from, to;
> float value, degree_average, similarity, accuracy;
> igraph_integer_t eid;
> igraph_vector_t  weights, degree, edges;
> char namefile[256];
>     string namefilecomplete;
>     char ext[] = "xml";
>
>     igraph_attribute_combination_t comb;
>
>     FILE *file;
> file = fopen("Graph and Information.data", "w");
>
> igraph_vector_init(&weights, 0);
> igraph_vector_init(&edges,0);
> igraph_vector_init(&degree,NOS);
> igraph_vector_null(&degree);
> W = ArrayXXf::Zero(NOS,NOS);
>
> SETGAN(&net,"weighted", 1);
>
>     igraph_attribute_combination(&comb, "weight",
> IGRAPH_ATTRIBUTE_COMBINE_FIRST, IGRAPH_NO_MORE_ATTRIBUTES);
>
> nSigma = sigma;
> sigma = sigma*sigma*2.0;
>
> for (i = 0 ; i < NOS ; i++){
> v1 = data.row(i);
> for (j = 0 ; j < NOS ; j++){
>                 if(i == j)
>                 {
>                     W(i,j) = 0.0;
>                     W(j,i) = 0.0;
>                 }
>                 else{
>                 v2 = data.row(j);
>                 value = dist.GetDistance(v1,v2);
>                 value = value / sigma;
>                 value = exp(-value);
>                 W(i,j) = value;
>                 W(j,i) = value;
> }
> }
> }
>
>    eid = 0;
>     for(g = initial_degree; g <= final_degree; g++)             g => average
> degree
>    {
>         igraph_degree(&net, &degree, igraph_vss_all(), IGRAPH_ALL,
> IGRAPH_NO_LOOPS);
>         degree_average = (igraph_vector_sum(&degree)/(float)NOS);
>
>         while(degree_average <= (float)g)
>         {
>             do
>             {
>                 from = (rand()%(NOS-1));
>                 to = (rand()%(NOS-1));
>             }while(from == to);
>
>             igraph_vector_push_back(&edges,from);
>             igraph_vector_push_back(&edges,to);
>             similarity = W(from,to) = W(to,from);
>             igraph_vector_push_back(&weights,similarity);
>             igraph_add_edges(&net,&edges,0);
>             eid++;
>             igraph_degree(&net, &degree, igraph_vss_all(), IGRAPH_ALL,
> IGRAPH_NO_LOOPS);
>             degree_average = (igraph_vector_sum(&degree)/(float)NOS);
>
>         }
>
>         for (i = 0; i < eid; i++)
>         {
>             SETEAN(&net, "weight", i, VECTOR(weights)[i]);
>         }
>
>         sprintf(namefile, "%s_network%d.%s", GAS(&net, "dataset"), g, ext);
>         namefilecomplete.assign(namefile);
>         graphs.push_back(namefilecomplete);
>         SaveNetwork(g);
>         fprintf(file,"Average Degree => %f  Edges => %d\n\n",
> degree_average, eid);
>         igraph_write_graph_edgelist(&net, file);
>    }
>     fclose(file);
> igraph_vector_destroy(&weights);
> igraph_vector_destroy(&edges);
> igraph_vector_destroy(&degree);
> igraph_attribute_combination_destroy(&comb);
> }
>
> Thank you
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>



reply via email to

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