private bool runSim6() // calculate n/N where n - the number of leading eigen vector components exceeding 10% of the average component size. { bool symRunStop = true; int runs = 0; parameters.Connectivity = ExpPars.K; parameters.K = ExpPars.K; adjMat = null; Matrix M; int maxLambdaIndex = 0; if (parameters.NetType == "BA") { adjMat = ResearchNetwork.barbasiAlbert(parameters.N, (int)parameters.K); M = new Matrix(adjMat); M.calcEigen(); } else { genAdjMat(); // gen new network (this updates only the adjMat) M = new Matrix(adjMat); // get eigen vectors. M.CalcEigenGeneral(); // find largest eigen vector. for (int i = 0; i < M.LambdaR.Length; i++) { if (M.LambdaR[i] > M.LambdaR[maxLambdaIndex]) { maxLambdaIndex = i; } } } // get the avg componet size. double norm = 0; double max = 0; List <double> v = new List <double>(parameters.N); for (int i = 0; i < parameters.N; i++) { double e; if (parameters.NetType == "BA") { e = Math.Abs(M.EigenV[i][0]); } else { e = Math.Abs(M.EigenVectors[i, maxLambdaIndex]); } norm += Math.Pow(e, 2); if (e > max) { max = e; } v.Add(e); } norm = Math.Sqrt(norm); // get the number of components exceeding the threshold. int numberAboveThreshold = 0; double threshold = ExpPars.StopCodition * max / 100; for (int i = 0; i < parameters.N; i++) { if (v[i] > threshold) { numberAboveThreshold++; } } M = null; // record result. Results.MeanActivity = numberAboveThreshold; // use this container to store the output. Results.Success = true; return(true); //throw new NotImplementedException(); }
protected void genAdjMat() // generates the network adjMatrix. { adjMat = new List <double[]>(); bool useWeightedAlgorithmForDynamics = false; if (parameters.NetType.Equals("BA")) //powerLaw - Barabási–Albert { ResearchNetwork barbasi = new ResearchNetwork(parameters.N, (int)parameters.K, parameters.nClustes); adjMat = barbasi.adjMatrix; } else if (parameters.NetType.Equals(netTypes[3])) // Chain network. { bool closeLoop = parameters.K > 1; // connect tail to head if K > 1 useWeightedAlgorithmForDynamics = ResearchNetwork.ChainNet(adjMat, parameters.N, closeLoop, parameters.DirectedNetwork, parameters.SpecialPars); } else { double L_SQUARED = Math.Pow((parameters.K * parameters.bc.x) / (2 * Math.Sqrt(parameters.N)), 2.0); double conn = parameters.Connectivity / 100d; for (int i = 0; i < sysSize; i++) { double[] dist = new double[sysSize]; adjMat.Add(new double[sysSize]); } for (int i = 0; i < sysSize; i++) { //double[] dist = new double[sysSize]; //adjMat.Add(new double[sysSize]); for (int j = i; j < sysSize; j++) { if (parameters.NetType.Equals("DF")) // Diffusive { if (i == j) { adjMat[i][j] = 0; continue; } adjMat[i][j] = Math.Pow((systemState[i][0] - systemState[j][0]), 2) + Math.Pow((systemState[i][1] - systemState[j][1]), 2); //dist[j] = PARAM_R / Math.Exp(dist[j] / L_SQUARED); adjMat[i][j] = 1 / Math.Exp(adjMat[i][j] / L_SQUARED); adjMat[j][i] = adjMat[i][j]; //symertry } else if (parameters.NetType.Equals("ER")) //uniform - Erdős–Rényi { if (i == j) { adjMat[i][j] = 0; continue; } if (rdn.NextDouble() < conn) { adjMat[i][j] = 1; } else { adjMat[i][j] = 0; } adjMat[j][i] = adjMat[i][j]; //symertry } } //adjMat[i] = dist; } } if (parameters.DirectedNetwork && !parameters.NetType.Equals(netTypes[3])) // randomize connection directions if not a circle net. { GetDirectedNetwork(); } if (parameters.Weights && !parameters.NetType.Equals(netTypes[0])) // randomize connection directions if not a circle net. { ApplyRandomWeights(); } if (!parameters.Weights && useWeightedAlgorithmForDynamics) // if special weights are used bypassing the ApplyRandomWeights() this statement makes sure the right algo is used for the dynamics { parameters.Weights = true; } if (adjMat != null) { ready = true; } }