/***************************** Override *********************************/ public override bool Equals(Object obj) { if (obj is EgoNetwork) { EgoNetwork otherTweet = (EgoNetwork)obj; return(this.egoID == otherTweet.egoID); } else { throw new ArgumentException("Object is not EgoNetwork"); } }
/*************************** Secondary Methods *******************************/ public void convertToTrainIntputTable(DataSet trainSet) { int egoCount = trainSet.egoNetworkList.Count; EgoNetwork[] egoList = new EgoNetwork[egoCount]; trainSet.egoNetworkList.CopyTo(egoList); this.trainInputArray = new double[egoCount][]; this.trainOutputVector = new int[egoCount]; for (int i = 0; i < this.trainInputArray.Length; i++) { this.trainInputArray[i] = egoList[i].attributes; this.trainOutputVector[i] = egoList[i].optimalLabel; } }
/*************************** Primary Methods *******************************/ public void addEgoNetwork(EgoNetwork egoNetwork) { this.egoNetworkList.Add(egoNetwork); }
/*************************** Primary Methods *******************************/ public void dataSetConfiguration(SortedList columnList, string rwrFilePath, string networkFilePath) { ArrayList egoIDList = new ArrayList(); SortedDictionary <long, int> egoOptimalLabelDictionary = new SortedDictionary <long, int>(); SortedDictionary <long, double[]> egoRwrResultsDictionary = new SortedDictionary <long, double[]>(); SortedDictionary <long, double[]> egoAttributesDictionary = new SortedDictionary <long, double[]>(); using (StreamReader rwrReader = new StreamReader(rwrFilePath)) { string line = null; while ((line = rwrReader.ReadLine()) != null) { long egoID; int egoOptimalLabel; string[] rwrResult = line.Split('\t'); double[] MAP = new double[rwrResult.Length - 2]; egoID = long.Parse(rwrResult[0]); egoOptimalLabel = int.Parse(rwrResult[1]); for (int i = 2; i < rwrResult.Length; i++) { MAP[i - 2] = double.Parse(rwrResult[i]); } egoOptimalLabelDictionary.Add(egoID, egoOptimalLabel); egoRwrResultsDictionary.Add(egoID, MAP); egoIDList.Add(egoID); } } using (StreamReader networkReader = new StreamReader(networkFilePath)) { string line = null; while ((line = networkReader.ReadLine()) != null) { long egoID; string[] networkResults = line.Split('\t'); double[] attributes = new double[columnList.Count]; egoID = long.Parse(networkResults[0]); int i = 0; for (int j = 1; j < networkResults.Length; j++) { if (columnList.ContainsKey(j - 1)) { attributes[i++] = double.Parse(networkResults[j]); } } egoAttributesDictionary.Add(egoID, attributes); } } // K-Fold Split DataSets SortedList <long, EgoNetwork> egoNetworkList = new SortedList <long, EgoNetwork>(); egoIDList.Sort(); // Ascending Order foreach (long egoID in egoIDList) { egoNetworkList.Add(egoID, new EgoNetwork(egoID, egoOptimalLabelDictionary[egoID], egoRwrResultsDictionary[egoID], egoAttributesDictionary[egoID])); } int boundary = egoNetworkList.Count / nFold; for (int i = 0; i < nFold; i++) { this.dataSets[i] = new DataSet(); if (i != (nFold - 1)) { for (int j = i * boundary; j < (i + 1) * boundary; j++) // Each sub-dataset boundary { EgoNetwork egoNetWork = egoNetworkList[(long)egoIDList[j]]; dataSets[i].addEgoNetwork(egoNetWork); } } else // Incase: Last sub-dataset { for (int j = i * boundary; j < egoNetworkList.Count; j++) { EgoNetwork egoNetWork = egoNetworkList[(long)egoIDList[j]]; dataSets[i].addEgoNetwork(egoNetWork); } } } }