protected void DoWave() { TotalUpdates += 1; MSGF currentNode = StartNodes.ToList()[Rnd.Next(StartNodes.Count)]; HashSet <MSGF> uniquePathsNodes = new HashSet <MSGF>(new MsgfEqualityComparer()); double rnd = Math.Min(0.999999, Rnd.NextDouble()); uint maxSteps = (uint)Math.Floor((TargetDistance + 1) * ((Math.Log(1 - rnd)) / (Math.Log(0.05)))); maxSteps = Math.Max(0, Math.Min(2 * TargetDistance, maxSteps)); for (uint i = 0; i < maxSteps; ++i) { uniquePathsNodes.Add(currentNode); var nodesTo = MsgfGraph.GetOutgoingNodes(currentNode).FindAll(node => !uniquePathsNodes.Contains(node)); if (!nodesTo.Any()) { break; } uint outputSum = nodesTo.Select(node => MsgfGraph.GetEdgeFreq(currentNode, node)) .Aggregate((a, b) => a + b); int pathNumber = Rnd.Next((int)outputSum); foreach (var nodeTo in nodesTo) { pathNumber -= (int)MsgfGraph.GetEdgeFreq(currentNode, nodeTo); if (pathNumber <= 0) { ProbabilityGraph.AddEdge(currentNode, nodeTo); if (!StartNodes.Contains(nodeTo)) { NodesProbability[nodeTo] += 1; } currentNode = nodeTo; break; } } } }
public Dictionary <string, double> FingUsecases(uint count = 10) { Dictionary <string, double> ret = new Dictionary <string, double>(); foreach (var node in ProbabilityGraph.GetAllNodes()) { double x = (double)NodesProbability[node]; if (ret.Any()) { double min = ret.Min(pair => pair.Value); if (min < x) { if (ret.Count() >= count) { ret.Remove(ret.First(pair => Math.Abs(pair.Value - min) < 2 * Double.Epsilon).Key); } ret.Add(node.GetContent(), x); } } else { ret.Add(node.GetContent(), x); } foreach (var outgoingNode in ProbabilityGraph.GetOutgoingNodes(node)) { var tempOutgoingX = x * ProbabilityGraph.GetEdgeFreq(node, outgoingNode) * NodesProbability[outgoingNode]; double outgoingX = Math.Pow(tempOutgoingX, 1.0 / 3.0); if (ret.Any()) { double min = ret.Min(pair => pair.Value); if (min < outgoingX) { if (ret.Count() >= count) { ret.Remove(ret.First(pair => Math.Abs(pair.Value - min) < 2 * Double.Epsilon).Key); } ret.Add(node.GetContent() + "," + outgoingNode.GetContent(), outgoingX); } } else { ret.Add(node.GetContent() + "," + outgoingNode.GetContent(), outgoingX); } foreach (var outgoingNode2 in ProbabilityGraph.GetOutgoingNodes(outgoingNode)) { var tempOutgoingX2 = tempOutgoingX * ProbabilityGraph.GetEdgeFreq(outgoingNode, outgoingNode2) * NodesProbability[outgoingNode2]; double outgoingX2 = Math.Pow(tempOutgoingX2, 1.0 / 5.0); if (ret.Any()) { double min = ret.Min(pair => pair.Value); if (min < outgoingX2) { if (ret.Count() >= count) { ret.Remove(ret.First(pair => Math.Abs(pair.Value - min) < 2 * Double.Epsilon).Key); } ret.Add(node.GetContent() + "," + outgoingNode.GetContent() + "," + outgoingNode2.GetContent(), outgoingX2); } } else { ret.Add(node.GetContent() + "," + outgoingNode.GetContent() + "," + outgoingNode2.GetContent(), outgoingX2); } } } } return(ret); }