[R] Please help me in Converting this from C# to R

rajivv rajiv_das at rediffmail.com
Sun Sep 14 07:28:24 CEST 2008


Random r = new Random();
                DirectedGraph<SimpleNode> graph = GetGraph();
                decimal B = 0.1m;
                decimal D = 0.05m;
                int nodes = graph.NodesCount;
                decimal[] E = new decimal[nodes];
                decimal[] P = new decimal[nodes];

                for (int i = 7; i <= 10; ++i)
                    P[i] = (decimal)r.NextDouble();

                
                for (int t = 0; t < 100; ++t)
                {
                  //  Writed(E, "E");
                    Writed(P, "P");

                    foreach (SimpleNode n in graph.Nodes)
                    {
                        int id = graph.index[n];

                        decimal product = 1;
                        foreach (var item in graph.GetAdjacentNodes(n))
                        {
                            int j = graph.index[item];
                            product *= (1 - B * P[j]);
                        }

                        E[id] = product;
                    }

                    foreach (SimpleNode n in graph.Nodes)
                    {
                        int i = graph.index[n];

                        P[i] = 1 - ((1 - P[i]) * E[i] + D * (1 - P[i]) *
E[i] + 0.5m * D * P[i] * (1 - E[i]));
                        
                        if (P[i] < 0)
                            P[i] = 0;
                    }
                }

            }
-- 
View this message in context: http://www.nabble.com/Please-help-me-in-Converting-this-from-C--to-R-tp19477464p19477464.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list