public void CreateCRFScore(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph, List <BasisMerkmal <ICRFNodeData, ICRFEdgeData, ICRFGraphData> > BasisMerkmale) { foreach (var node in graph.Nodes) { var scores = new double[NumberOfLabels]; node.Data.Scores = scores; for (int k = 0; k < ConformityParameter.Length; k++) { for (int label = 0; label < NumberOfLabels; label++) { scores[label] += ConformityParameter[k] * BasisMerkmale[k].Score(node, label); } } } foreach (var edge in graph.Edges) { var scores = new double[NumberOfLabels, NumberOfLabels]; edge.Data.Scores = scores; for (int k = 0; k < CorrelationParameter.Length; k++) { for (int label1 = 0; label1 < NumberOfLabels; label1++) { for (int label2 = 0; label2 < NumberOfLabels; label2++) { scores[label1, label2] += CorrelationParameter[k] * BasisMerkmale[k].Score(edge, label1, label2); } } } } }
public static void AddReference(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.ReferenceLabel = random.Next(2); } }
private double CalculateAmplifierNodes(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { var I = graph.Data.ReferenceLabeling.Sum(); var N = graph.Nodes.Count() - I; return(N / I - 1); }
public static void AddObservation(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.Observation = random.Next(2); } }
public static void AddCharacteristic(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.Characteristics = new double[] { random.NextDouble() }; } }
public static CGGraphData CGGraphDataConvert(IGWGraph <CGNodeData, CGEdgeData, CGGraphData> graph) { var newData = new CGGraphData(); newData.ErdösGraph = graph.Data.ErdösGraph; return(newData); }
protected void SetWeightsCRF(double[] weightCurrent, IGWGraph <NodeData, EdgeData, GraphData> graph) { foreach (var node in graph.Nodes) { var scores = new double[Labels]; node.Data.Scores = scores; for (int k = 0; k < weightCurrent.Length; k++) { for (int label = 0; label < Labels; label++) { scores[label] += weightCurrent[k] * BasisMerkmale[k].Score(node, label); } } } foreach (var edge in graph.Edges) { var scores = new double[Labels, Labels]; edge.Data.Scores = scores; for (int k = 0; k < weightCurrent.Length; k++) { for (int label1 = 0; label1 < Labels; label1++) { for (int label2 = 0; label2 < Labels; label2++) { scores[label1, label2] += weightCurrent[k] * BasisMerkmale[k].Score(edge, label1, label2); } } } } }
public void CreateObservationThresholding(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.Observation = node.Data.Characteristics[0] >= Threshold ? 1 : 0; } }
public static double[] AnalyseClusterCoefficient(IGWGraph graph) { var coeffcients = new double[graph.Nodes.Count()]; foreach (var node in graph.Nodes) { var coefficient = 0.0; double allCons = 0; double actualCons = 0; var nbs = node.Neighbours.ToList(); for (int i1 = 0; i1 < nbs.Count; i1++) { for (int i2 = i1 + 1; i2 < nbs.Count; i2++) { allCons++; if (nbs[i1].Neighbours.Contains(nbs[i2])) { actualCons++; } } } if (allCons > 0) { coefficient = actualCons / allCons; } else { coefficient = 0; } coeffcients[node.GraphId] = coefficient; } return(coeffcients); }
public void GetCategoryGraphInfo(IGWGraph <CGNodeData, CGEdgeData, CGGraphData> categoryGraph) { if (categoryGraph == null) { Console.WriteLine("No CategoryGraph exists"); Console.WriteLine("\n"); return; } Console.WriteLine("CategoryGraph:"); Console.WriteLine("Number of Nodes: " + categoryGraph.Nodes.Count()); foreach (var node in categoryGraph.Nodes) { Console.WriteLine("Number of Nodes in Category {0}: {1}\tEdges in Category: {2}\tProbabilty Parameter: {3}", node.Data.Category, node.Data.NumberNodes, node.Data.NumberEdges, node.Data.ObservationProbabilty); } Console.WriteLine("Number of Edges: " + categoryGraph.Edges.Count()); int i = 0; foreach (var edge in categoryGraph.Edges) { Console.WriteLine("Edge {0}: Category {1} <--> Category {2}\tWeight: {3}", i++, edge.Foot.Data.Category, edge.Head.Data.Category, edge.Data.Weight); } Console.WriteLine("\n\n"); }
public static void AddViterbi(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { graph.Data.Viterbi = new int[graph.Nodes.Count()]; foreach (var node in graph.Nodes) { graph.Data.Viterbi[node.GraphId] = random.Next(2); } }
public static SGLGraphData SGLGraphDataConvert(IGWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> graph) { var newData = new SGLGraphData(); newData.NumberCategories = graph.Data.NumberCategories; //newData.CategoryGraph = graph.Data.CategoryGraph.Clone(CGNodeDataConvert, CGEdgeDataConvert, CGGraphDataConvert); return(newData); }
public static void AddDefault(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { AddCharacteristic(graph); AddScore(graph); AddObservation(graph); AddReference(graph); AddViterbi(graph); AddSample(graph); }
public static void Do(IGWGraph <SSPND, SSPED, SSPGD> graph) { var catGraph = new CategoryGraph(); var tempdict = new Dictionary <string, CGND>(); foreach (var category in graph.Data.Categories) { var cnode = catGraph.CreateNode(); cnode.Data = new CGND(); tempdict.Add(category, cnode.Data); cnode.Data.Category = category; var goodModules = 0.0; foreach (var gnode in graph.Nodes) { if (!gnode.Data.Category.Equals(category)) { continue; } cnode.Data.Modules++; if (gnode.Data.Classifiation == 0) { goodModules++; } } cnode.Data.Quality = (goodModules / cnode.Data.Modules) * (goodModules / cnode.Data.Modules); } var nodesList = catGraph.Nodes.ToList(); for (int i = 0; i < nodesList.Count - 1; i++) { for (int k = i + 1; k < nodesList.Count; k++) { var edge = catGraph.CreateEdge(nodesList[i], nodesList[k]); edge.Data = new CGED(); foreach (var gedge in graph.Edges) { if (edge.Head.Data.Category.Equals(gedge.Head.Data.Category) && edge.Foot.Data.Category.Equals(gedge.Foot.Data.Category)) { edge.Data.Connections++; } else if (edge.Head.Data.Category.Equals(gedge.Foot.Data.Category) && edge.Foot.Data.Category.Equals(gedge.Head.Data.Category)) { edge.Data.Connections++; } } } } graph.Data.CategoryGraph = catGraph; }
protected int[] CountPred(IGWGraph <NodeData, EdgeData, GraphData> graph, int[] labeling) { var countPreds = new int[BasisMerkmale.Length]; for (int i = 0; i < BasisMerkmale.Length; i++) { countPreds[i] = BasisMerkmale[i].Count(graph, labeling); } return(countPreds); }
public void CreateObservation(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { //var observation = new int[graph.Nodes.Count()]; foreach (var node in graph.Nodes) { node.Data.Observation = CreateObservation(node.Data, graph.Data.ReferenceLabeling[node.GraphId]); } //return observation; }
public void CreatePatchAndSetAsReferenceLabel(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { var patch = CreatePatches(graph); graph.Data.ReferenceLabeling = new int[graph.Nodes.Count()]; foreach (var node in patch) { graph.Data.ReferenceLabeling[node.GraphId] = 1; node.Data.ReferenceLabel = 1; } }
public static void AddSample(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { graph.Data.Sample = new List <int[]>(); for (int i = 0; i < 100; i++) { graph.Data.Sample.Add(new int[graph.Nodes.Count()]); foreach (var node in graph.Nodes) { graph.Data.Sample[i][node.GraphId] = random.Next(2); } } }
public override int Count(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph, int[] labeling) { int counter = 0; foreach (var node in graph.Nodes) { if (labeling[node.GraphId] == Classification && node.Data.Characteristics[Characteristic] >= LowerBoundary && node.Data.Characteristics[Characteristic] <= UpperBoundary) { counter++; } } return(counter); }
public static void AddScore(IGWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.Scores = new double[] { random.NextDouble(), random.NextDouble() }; } foreach (var edge in graph.Edges) { edge.Data.Scores = new double[, ] { { random.NextDouble(), random.NextDouble() }, { random.NextDouble(), random.NextDouble() } }; } }
public static double[,] AnalyseAveragePaths(IGWGraph graph) { var nodes = graph.Nodes.ToList(); var marks = new bool[nodes.Count]; var distances = new double[nodes.Count, nodes.Count]; int runs = 100; int maxSearchLength = 1000; foreach (var node in nodes) { foreach (var otherNode in nodes) { if (node.GraphId > otherNode.GraphId) { continue; } var distancesTemp = new LinkedList <double>(); for (int run = 0; run < runs; run++) { int distance = 0; var currentNode = node; while (otherNode.GraphId != currentNode.GraphId && distance <= maxSearchLength) { distance++; var nbCount = currentNode.Neighbours.Count(); if (nbCount == 0) { distance = int.MaxValue; break; } var rdm = Random.Next(nbCount); currentNode = currentNode.Neighbours.Skip(rdm).First(); } if (distance == int.MaxValue) { distancesTemp.Add(double.PositiveInfinity); } else { distancesTemp.Add(distance); } } distances[node.GraphId, otherNode.GraphId] = distancesTemp.Average(); distances[otherNode.GraphId, node.GraphId] = distancesTemp.Average(); } } return(distances); }
public static ICRFGraphData convertGraphData(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { var newData = new CRFGraphData(); try { newData.ReferenceLabeling = graph.Data.ReferenceLabeling; } catch (NullReferenceException e) { Console.WriteLine("Exception caught: " + e.Message); } return(newData); }
public void CreateCRFScore(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { foreach (var node in graph.Nodes) { node.Data.Scores = new double[NumberObservations]; for (int observationCount = 0; observationCount < NumberObservations; observationCount++) { node.Data.Scores[observationCount] = node.Data.Observation == observationCount ? ConformityParameter : -ConformityParameter; } } foreach (var edge in graph.Edges) { edge.Data.Scores = new double[NumberObservations, NumberObservations] { { CorrelationParameter, -CorrelationParameter }, { -CorrelationParameter, CorrelationParameter } }; } }
public static double[][] ConnectionProbabilityByDistance(IGWGraph graph, double[][] shortestPaths, int Maxdistance) { var conProbs = new double[graph.Nodes.Count()][]; var nodes = graph.Nodes.OrderBy(n => n.GraphId).ToList(); for (int i1 = 0; i1 < nodes.Count; i1++) { var node = nodes[i1]; conProbs[i1] = new double[Maxdistance]; for (int i2 = 1; i2 <= Maxdistance; i2++) { var possibleCons = 0.0; var actualCons = 0.0; var nodesInDist = new LinkedList <IGWNode>(); for (int i3 = 0; i3 < nodes.Count; i3++) { if (shortestPaths[i1][i3] == i2) { nodesInDist.Add(nodes[i3]); } } if (nodesInDist.NotNullOrEmpty()) { foreach (var nd in nodesInDist) { foreach (var nd2 in nodesInDist) { if (nd.GraphId >= nd2.GraphId) { continue; } possibleCons++; if (nd.Neighbours.Contains(nd2)) { actualCons++; } } } conProbs[i1][i2 - 1] = actualCons / possibleCons; } } } return(conProbs); }
public override int Count(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph, int[] labeling) { int count = 0; foreach (var edge in graph.Edges) { var labelHead = labeling[edge.Head.GraphId]; var labelFoot = labeling[edge.Foot.GraphId]; if (labelHead == LabelHead && labelFoot == LabelFoot) { if (edge.Data.MaxZellnerScore > LowerBoundary && edge.Data.MaxZellnerScore <= UpperBoundary) { count++; } } } return(count); }
public static double[] computeKeys(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph, IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData>[] graphs, int i) { double sensitivity = 0.0, specificity = 0.0, mcc = 0.0; // für jeden graphen: true positives / false positives / true negatives / fn || 0: negative 1: positive int[] tps = computeClassification(graph, graphs[i]); int tp = tps[0], tn = tps[1], fp = tps[2], fn = tps[3]; // Sensitivität / Spezifität / MCC Matthew Correlation Coefficient sensitivity = computeTPR(tp, fn); specificity = computeSPC(tn, fp); mcc = computeMCC(tp, tn, fp, fn); double[] keys = { tp, tn, fp, fn, sensitivity, specificity, mcc }; return(keys); }
public void InitCRFScore(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph) { var random = new Random(); foreach (var node in graph.Nodes) { node.Data.Scores = new double[NumberOfLabels]; for (int labelCount = 0; labelCount < NumberOfLabels; labelCount++) { node.Data.Scores[labelCount] = node.Data.Observation == labelCount ? ConformityParameter[0] : ConformityParameter[1]; } } foreach (var edge in graph.Edges) { edge.Data.Scores = new double[, ] { { CorrelationParameter[0], -CorrelationParameter[0] }, { -CorrelationParameter[0], CorrelationParameter[0] } }; } }
public void GetErdösGraphInfo(IGWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> graph) { if (graph == null) { Console.WriteLine("No Graph exists"); Console.WriteLine("\n"); return; } Console.WriteLine("ErdösGraph:"); Console.WriteLine("Number Nodes: " + graph.Nodes.Count()); Console.WriteLine("Number Categories: " + graph.Data.NumberCategories); string[] nodes_per_category = new string[graph.Data.NumberCategories]; foreach (var node in graph.Nodes) { nodes_per_category[node.Data.Category] += node.GraphId + "-" + node.Data.Observation + " | "; } int i = 0; foreach (string s in nodes_per_category) { Console.WriteLine("Category {0} (Node-Observation): {1}", i++, s); } Console.WriteLine("Number Edges: " + graph.Edges.Count()); int intraEdges = 0; int interEdges = 0; foreach (var edge in graph.Edges) { if (edge.Data.Type.Equals(EdgeType.Intra)) { intraEdges++; } else { interEdges++; } } Console.WriteLine("Number intraEdges: " + intraEdges); Console.WriteLine("Number interEdges: " + interEdges); Console.WriteLine(); }
public override int Count(IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> graph, int[] labeling) { var amplifier = CalculateAmplifierNodes(graph); int count = 0; foreach (var node in graph.Nodes) { var label = labeling[node.GraphId]; if (label == Label) { // Characteristics[0] contains Zellner Score if (node.Data.Characteristics[0] > LowerBoundary && node.Data.Characteristics[0] <= UpperBoundary) { count += label == 0 ? 1 : (int)(1 + AmplifierControlParameter * amplifier); //count++; } } } return(count); }
public static void Store <NodeData, EdgeData, GraphData>(this IGWGraph <NodeData, EdgeData, GraphData> graph, StreamWriter writer) where NodeData : GWStoreable { writer.WriteLine("graph-start"); writer.WriteLine("nodes"); foreach (var node in graph.Nodes) { StoreX.StoreObj <IGWNode>(node, writer); node.Data.Store(writer); } writer.WriteLine("nodes-end"); writer.WriteLine("edges"); foreach (var edge in graph.Edges) { writer.WriteLine(edge.Foot.GraphId + StoreX.Delimiter + edge.Head.GraphId); } writer.WriteLine("edges-end"); writer.WriteLine("graph-end"); writer.WriteLine(""); }