private void NormalizeEdgeBinary() { // nodes foreach (PDGNode node in _pdg.Nodes) { double binaryWeight = node.OutgoingEdges.Count(); if (!binaryWeight.Equals(0.0)) { binaryWeight = 1.0 / binaryWeight; } foreach (PDGEdge edge in _pdg.GetNode(node.MethodName).OutgoingEdges) { edge.Weight = binaryWeight; } } }
private string GenerateAdjacencyMatrix() { int n = _pdg.Nodes.Count(); double defaultValue = 1.0 / n; double[] rowValues = new double[n]; FileStream matrixFS = RUtil.CreateCacheFile("HITS." + _traceID + ".TPM.matrix"); TextWriter matrixWriter = new StreamWriter(matrixFS); //FileStream edgeFS = RUtil.CreateCacheFile("HITS." + _traceID + ".TPM.edges"); //TextWriter edgeWriter = new StreamWriter(edgeFS); FileStream mapFS = RUtil.CreateCacheFile("HITS." + _traceID + ".TPM.map"); _mappingFile = mapFS.Name; TextWriter mapWriter = new StreamWriter(mapFS); for (int nodeIndex = 0; nodeIndex < _pdg.Nodes.Count(); nodeIndex++) { PDGNode pdgNode = _pdg.GetNode(nodeIndex); for (int i = 0; i < n; i++) { rowValues[i] = 0; } //edgeWriter.WriteLine(pdgNode.OutgoingEdges.Count()); // write number of outgoing edges for Topical HITS algorithm for (int indexOutgoingEdge = 0; indexOutgoingEdge < pdgNode.OutgoingEdges.Count(); indexOutgoingEdge++) { PDGEdge pdgOutgoingEdge = pdgNode.OutgoingEdges.ElementAt(indexOutgoingEdge); int columnFrequencies = _pdg.IndexOf(pdgOutgoingEdge.OutgoingNodeID); // for positive values only if ((columnFrequencies < 0)) { throw new RDataException(); // continue; } if (_config.Weight == WebMiningWeightEnum.Binary) { rowValues[columnFrequencies] = 1; } else if (_config.Weight == WebMiningWeightEnum.Frequency) { rowValues[columnFrequencies] = pdgOutgoingEdge.Weight; } else { throw new RDataException("Unknown weighting scheme: " + _config.Weight); } } //for (int i=1;i<=n;i++) //{ // matrixWriter.Write(rowValuesFrequencies[i]+" "); // binaryWriter.Write(rowValuesBinary[i]+" "); //} matrixWriter.WriteLine(String.Join(" ", rowValues)); mapWriter.WriteLine(pdgNode.MethodName); } matrixWriter.Flush(); matrixWriter.Close(); //edgeWriter.Flush(); //edgeWriter.Close(); mapWriter.Flush(); mapWriter.Close(); return(matrixFS.Name); }