igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] : multiple edges


From: patricia
Subject: Re: [igraph] : multiple edges
Date: Wed, 19 Nov 2014 00:57:08 +0300

Hello,

I sent a message and the link where is the code via dropbox; the code is on PROJECT IC folder on PROJETO.rar file. Any problem please follow the link:



Thank you.

> Date: Tue, 18 Nov 2014 20:15:25 +0100
> From: address@hidden
> To: address@hidden
> Subject: Re: [igraph] : multiple edges
>
> Hi,
>
> Your code is not self-contained so I cannot compile it. But it wouldn't compile
> anyway because you refer to a unknown variable named "initial_degree" in the
> main for loop while the incoming parameter of the function is called
> "degree_initial". Also, the issue could be anywhere, even in parts that you
> have not provided -- for instance, it could be the case that the SaveNetwork()
> method has some kind of a bug that prevents the weights from being saved
> properly. So please send us a *self-contained* example that 1) can be compiled on
> its own without any extra dependencies and 2) does not contain any extra
> unrelated code.
>
> One thing that is immediately obvious is that you never initialize your "net"
> variable anywhere. (It is not even declared, but I assume that it is an
> igraph_t somewhere in a global variable). You need to call igraph_init() on in
> in every iteration of the main for loop before resetting "eid" to zero, and
> then you need to destroy it once you are done with it after SaveNetwork().
>
> By the way, when you add the edge, why don't you simply check whether it exists
> already? This way you could avoid creating multiple edges and there would be no
> need to call igraph_simplify() at all.
>
> --
> T.
>
>
> On 11/18, patricia wrote:
> > Hello,
> >
> > I want to build non-directed and weighted graphs with average degree ranging 1-5 (variation variable g). The weights are assigned to edges are stored in W (symmetric matrix of size 300 x 300, which is not changed) matrix. The stretch of the highlighted code creates multiple edges, for this reason, I am using the igraph_simplify () function. But probably the logic of the code is incorrect, because the weight of the same edge is changing when the average degree undergoes variation. For example, if I have 20 vertex connected to vertex 40 weighing 0123 on a graph with average degree equal to 1, when the average degree is incremented the same edge appears with a distinct weight, for example, 0555. The weights should remain constant throughout the execution of the code, because the matrix W keeps unchanged. Segue abaixo, o trecho de código.:
> >
> > void TNetData::MatrixSimilarity(float sigma, int degree_initial, int degree_final)
> > {
> > VectorXf v1, v2;
> > MatrixXf W(NOS,NOS);
> > int g, i, j, from, to;
> > float value, degree_average, similarity;
> > igraph_integer_t eid;
> > igraph_vector_t weights, degree;
> >
> >
> > igraph_attribute_combination_t edge_comb;
> > igraph_attribute_combination(&edge_comb, "weight" , IGRAPH_ATTRIBUTE_COMBINE_FIRST, IGRAPH_NO_MORE_ATTRIBUTES);
> >
> > igraph_vector_init(&weights, 0);
> > igraph_vector_init(&degree,NOS);
> > igraph_vector_null(&degree);
> > W = ArrayXXf::Zero(NOS,NOS);
> >
> > SETGAN(&net,"weighted", 1);
> >
> > nSigma = sigma;
> > sigma = sigma*sigma*2.0;
> >
> > // Construction of symmetric weight matrix
> >
> > 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; // value is obtained using the Euclidean distance between vectors of examples
> > W(j,i) = value;
> > }
> > }
> > }
> >
> > for(g = initial_degree; g <= final_degree; g++) // g variation of the average degree
> > {
> >
> > igraph_degree(&net, &degree, igraph_vss_all(), IGRAPH_ALL, IGRAPH_NO_LOOPS);
> > degree_average = (igraph_vector_sum(&degree)/(float)NOS);
> > eid = 0;
> > while(degree_average <= (float)g)
> > {
> > do
> > {
> > from = (rand()%(NOS-1)); // vertices are drawn and connected // NOS - number of Samples
> > to = (rand()%(NOS-1));
> > }while(from == to);
> >
> > igraph_add_edge(&net,from,to); // edge is connected to the graph
> > similarity = W(from,to) = W(to,from); // similarity variable receives the value of the weight stored in W
> > //igraph_vector_push_back(&weights,similarity);
> > SETEAN(&net, "weight", eid, similarity); // the edge is set to the value of the weight matrix W sought in
> > eid++; // stores the number of edges connected to the graph
> > igraph_degree(&net, &degree, igraph_vss_all(), IGRAPH_ALL, IGRAPH_NO_LOOPS);
> > degree_average = (igraph_vector_sum(&degree)/(float)NOS); // average degree is calculated
> > }
> >
> > //for (i = 0; i < eid; i++)
> > //{
> > //SETEAN(&net, "weight", i, VECTOR(weights)[i]);
> > //}
> >
> > igraph_simplify(&net,1,1,&edge_comb);
> >
> > SaveNetwork(g); // method responsible for saving the graph generated for each average degree
> > }
> >
> > igraph_vector_destroy(&weights);
> > igraph_vector_destroy(&degree);
> > igraph_attribute_combination_destroy(&edge_comb);
> > }
> >
> > Thank you!
> >
> >
> >
> > > Date: Tue, 18 Nov 2014 10:44:58 +0100
> > > From: address@hidden
> > > To: address@hidden
> > > Subject: Re: [igraph] : multiple edges
> > >
> > > Hello,
> > >
> > > We cannot tell you what's wrong with your code without showing us a *small*
> > > example that demonstrates the problem.
> > >
> > > T.
> > >
> > > On 11/18, patricia wrote:
> > > > I am creating a weighted and undirected graph as follows:
> > > > - Draw two vertices randomly and make the connection between them, with a weight value that is stored in an array in assorted positions. The values that are stored in this matrix are unchanged.
> > > > For example, the sorteei positions 10 and 15 will in the weight matrix on the line 10 and column 15, the value stored in that position will be the weight of edge 10 --- 15.
> > > > But my code is generating multiple edges, so I'm using the igraph_simplify (& net, 1,1, & edge_comb) with igraph_attribute_combination attribute (& edge_comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_FIRST, IGRAPH_NO_MORE_ATTRIBUTES) function to eliminate them. But I want the value of the weights remain unchanged; but even using the above attribute (COMBINE_FIRST) weights are changing. What can I do to correct this error?
> > > >
> > > > Thank you
> > >
> > > > _______________________________________________
> > > > igraph-help mailing list
> > > > address@hidden
> > > > https://lists.nongnu.org/mailman/listinfo/igraph-help
> > >
> > >
> > > --
> > > T.
> > >
> > > _______________________________________________
> > > igraph-help mailing list
> > > address@hidden
> > > https://lists.nongnu.org/mailman/listinfo/igraph-help
> >
>
> > _______________________________________________
> > igraph-help mailing list
> > address@hidden
> > https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
> --
> T.
>
> _______________________________________________
> 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]