public ConSelfARTMAP(int inputComponentCount, double initialRho, double rhoInc, double alpha, double beta, bool complementCoding, bool delayUpdate) { ARTModule = new ConSelFAM.NET.ConSelfART(inputComponentCount, -1, initialRho, alpha, beta, complementCoding); ARTModule.delayWeightUpdates(delayUpdate); mapField = new MAPField(); if (complementCoding) { ARTModule.F1 = new LayerF1(2 * inputComponentCount); } else { ARTModule.F1 = new LayerF1(inputComponentCount); } rho = initialRho; rhoIncrement = rhoInc; this.complementCoding = complementCoding; this.alpha = alpha; this.beta = beta; }
public ConSelfARTMAP(string path) { string data = ""; if (netConfigFound(path)) { try { System.IO.StreamReader reader = new System.IO.StreamReader(path); data = reader.ReadToEnd(); reader.Close(); } catch (Exception ioerror) { Console.Out.WriteLine(ioerror.ToString()); return; } // cath ends } //if (data.Contains("Rho")) POCKET PC .NET DO NOT SUPPORT String.Contains() Method { float rho = float.Parse(data.Substring(4, data.IndexOf("\r") - (4))); this.rho = rho; data = data.Substring(data.IndexOf("\r") + 2); } { float rhoIncrement = float.Parse(data.Substring(7, data.IndexOf("\r") - 7)); this.rhoIncrement = rhoIncrement; data = data.Substring(data.IndexOf("\r") + 2); } //if (data.Contains("Alpha")) { float alpha = float.Parse(data.Substring(5, data.IndexOf("\r") - 5)); this.alpha = alpha; data = data.Substring(data.IndexOf("\r") + 2); } //if (data.Contains("Beta")) { float beta = float.Parse(data.Substring(4, data.IndexOf("\r") - 4)); this.beta = beta; data = data.Substring(data.IndexOf("\r") + 2); } //if (data.Contains("CC")) bool CC = bool.Parse(data.Substring(2, data.IndexOf("\r") - 2)); this.complementCoding = CC; data = data.Substring(data.IndexOf("\r") + 2); //if (data.Contains("F1")) { int F1Count = int.Parse(data.Substring(2, data.IndexOf("\r") - 2)); if (CC) { this.ARTModule = new ConSelFAM.NET.ConSelfART(F1Count / 2, -1, this.rho, this.alpha, this.beta, this.complementCoding); } else { this.ARTModule = new ConSelFAM.NET.ConSelfART(F1Count, -1, this.rho, this.alpha, this.beta, this.complementCoding); } data = data.Substring(data.IndexOf("\r") + 2); } { int MFCategoryCount = Int32.Parse(data.Substring(16, data.IndexOf("\r") - 16)); //16 characters in 'MFCategoryCount ' data = data.Substring(data.IndexOf("\r") + 2); this.mapField = new MAPField(); for (int i = 0; i < MFCategoryCount; i++) { int catCode = Int32.Parse(data.Substring(0, data.IndexOf("\r"))); data = data.Substring(data.IndexOf("\r") + 2); string catName = data.Substring(0, data.IndexOf("\r")); data = data.Substring(data.IndexOf("\r") + 2); this.mapField.addNewCategory(catName, catCode); } int contextCount = Int32.Parse(data.Substring(13, data.IndexOf("\r") - 13)); //13 characters in 'ContextCount ' data = data.Substring(data.IndexOf("\r") + 2); for (int contextIndex = 0; contextIndex < contextCount; contextIndex++) { int contextCode = Int32.Parse(data.Substring(8 /*7 characters in 'Context '*/, data.IndexOf("\r") - 8)); LayerF2 F2Layer = new LayerF2(); this.ARTModule.contextField.Add(contextCode, F2Layer); data = data.Substring(data.IndexOf("\r") + 2); int F2Count = 0; //if (data.Contains("F2")) F2Count = int.Parse(data.Substring(8 /*8 characters in 'F2Count '*/, data.IndexOf("\r") - 8)); data = data.Substring(data.IndexOf("\r") + 2); for (int i = 0; i < F2Count; i++) { // Parse and set F2 Neuron Prototype double[] prototype = new double[this.ARTModule.F1.Count]; data = data.Substring(data.IndexOf("\r") + 2); string pt = data.Substring(0, data.IndexOf("\r")); int F1count = this.ARTModule.F1.Count; for (int j = 0; j < F1count; j++) { prototype[j] = double.Parse(pt.Substring(0, pt.IndexOf("\t")).Trim()); if (j < (this.ARTModule.F1.Count - 1)) { pt = pt.Substring(pt.IndexOf("\t") + 1); } } data = data.Substring(data.IndexOf("\r") + 2); data = data.Substring(data.IndexOf("\r") + 2);//discard tdConnWs word from data string // Parse and set tdConnection Weights double[] weights = new double[this.ARTModule.F1.Count]; string ws = data.Substring(0, data.IndexOf("\r")); for (int j = 0; j < this.ARTModule.F1.Count; j++) { weights[j] = double.Parse(ws.Substring(0, ws.IndexOf("\t")).Trim()); if (j < (this.ARTModule.F1.Count - 1)) { ws = ws.Substring(ws.IndexOf("\t") + 1); } } data = data.Substring(data.IndexOf("\r") + 2); int f2NeuronIndex = F2Layer.AddF2Neuron((LayerF1)this.ARTModule.F1, weights, prototype); // Parse and set map field connection weights data = data.Substring(data.IndexOf("\r") + 2); string catcode = data.Substring(0, data.IndexOf("\r")).Trim(); int code = int.Parse(catcode); mapField.getCategory(code).addConnection((F2Neuron)F2Layer[f2NeuronIndex]); } } } }