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: [email protected]
> To: [email protected]
> 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
> > [email protected]
> > https://lists.nongnu.org/mailman/listinfo/igraph-help
> 
> 
> -- 
> T.
> 
> _______________________________________________
> igraph-help mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/igraph-help
                                          
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to