public void addNewCategory(F2Neuron f2Neuron, string categoryName, int code) { MapFieldCategory categoryNode = new MapFieldCategory(categoryName, code); categoryNode.addConnection(f2Neuron); categories.Add(categoryNode); }
public void saveNetworkOnFile(string path) { // Delete the file if it exists. if (File.Exists(path)) { File.Delete(path); } FileStream fs = File.Create(path); string netConfig = ""; netConfig += "Rho " + this.rho + "\r\n"; netConfig += "RhoInc " + this.rhoIncrement + "\r\n"; netConfig += "Alpha " + this.alpha + "\r\n"; netConfig += "Beta " + this.beta + "\r\n"; netConfig += "CC " + this.complementCoding + "\r\n"; netConfig += "F1 " + this.ARTModule.F1.Count + "\r\n"; netConfig += "MFCategoryCount " + this.mapField.getCategoryCount() + "\r\n"; for (int catIndex = 0; catIndex < this.mapField.getCategoryCount(); catIndex++) { MapFieldCategory cat = (MapFieldCategory)this.mapField.categories[catIndex]; netConfig += cat.getCode() + "\r\n"; netConfig += cat.getName() + "\r\n"; } netConfig += "ContextCount " + this.ARTModule.contextField.Count + "\r\n"; ICollection contextKeys = this.ARTModule.contextField.Keys; IEnumerator contextKeysEnum = contextKeys.GetEnumerator(); while (contextKeysEnum.MoveNext()) { int contextKey = Int32.Parse(contextKeysEnum.Current.ToString()); netConfig += "Context " + contextKey + "\r\n"; LayerF2 F2 = ((LayerF2)this.ARTModule.contextField[contextKey]); netConfig += "F2Count " + F2.Count + "\r\n"; for (int f2Index = 0; f2Index < F2.Count; f2Index++) { netConfig += "Prototype\r\n"; double [] prototype = ((F2Neuron)F2[f2Index]).getProtoTypeCluster(); for (int i = 0; i < prototype.Length; i++) { netConfig += prototype[i] + "\t"; } netConfig += "\r\n"; netConfig += "tdConnWs\r\n"; SynapticConnection[] conns = ((F2Neuron)F2[f2Index]).getConnections(); for (int connIndex = 0; connIndex < conns.Length; connIndex++) { netConfig += ((SynapticConnection)conns[connIndex]).getWeight() + "\t"; } netConfig += "\r\n"; netConfig += "CatCode\r\n"; //for (int f2Index = 0; f2Index < F2.Count; f2Index++) { MapFieldConnection mapFieldConn = ((F2Neuron)F2[f2Index]).getMapFieldConnection(); netConfig += mapFieldConn.getCategory().getCode() + "\r\n"; } } } AddText(fs, netConfig); fs.Close(); }
public MapFieldConnection(MapFieldCategory category, ConSelFAM.NET.F2Neuron f2Neuron, int weight) { this.category = category; this.f2Neuron = f2Neuron; // this.f2Neuron.addMapFieldConnection(this); this.f2Neuron.setMapFieldConnection(this); this.weight = weight; }
// public MapFieldCategory getCategory(int index) { // return (MapFieldCategory)categories[index]; // } public MapFieldCategory getCategory(int catCode) { MapFieldCategory cate = null; foreach (MapFieldCategory cat in categories) { if (catCode == cat.getCode()) { cate = cat; } } return(cate); }
//public int recall(int contextCode, double[] Pattern) // THIS METHOD ASSUMES THAT EACH F2 NODE HAS CONNECTIONS WITH ALL MAPFIELD NODES //{ // ARTModule.reSetRho(rho); // int code = -1; // Don't Know // LayerF2 contextNeurons = (LayerF2)ARTModule.contextField[contextCode]; // object [,]artCluster = ARTModule.getCluster(contextCode, Pattern); // if ((int)artCluster[0, 1] == -1) // code = -1; // else // { // F2Neuron f2Neuron = (F2Neuron)contextNeurons[(int)artCluster[0, 1]]; // f2Neuron.getMapFieldConnections(); // ArrayList mapFieldConnections = f2Neuron.getMapFieldConnections(); // IEnumerator mapFieldConnEnum = mapFieldConnections.GetEnumerator(); // while (mapFieldConnEnum.MoveNext()) // { // MapFieldConnection mapFieldConn = (MapFieldConnection)mapFieldConnEnum.Current; // if (mapFieldConn.getWeight() == 1) // { // MapFieldCategory category = mapFieldConn.getCategory(); // code = category.getCode(); // //break; // } // } // } // // code = mapField.getAssociatedCategory(contextNeurons, (int)artCluster[0, 1]); // return code; //} public int recall(int contextCode, double[] Pattern) //THIS METHOD ASSUMES THAT EACH F2 NODE IS CONNECTED WITH ONLY ONE MAPFIELD NODE { ARTModule.reSetRho(rho); int code = -1; // Don't Know LayerF2 contextNeurons = (LayerF2)ARTModule.contextField[contextCode]; object[,] artCluster = ARTModule.getCluster(contextCode, Pattern); if ((int)artCluster[0, 1] == -1) { code = -1; } else { F2Neuron f2Neuron = (F2Neuron)contextNeurons[(int)artCluster[0, 1]]; MapFieldConnection mfConn = f2Neuron.getMapFieldConnection(); MapFieldCategory category = mfConn.getCategory(); code = category.getCode(); } // code = mapField.getAssociatedCategory(contextNeurons, (int)artCluster[0, 1]); return(code); }
public int learn(int contextCode, double[] Pattern, int categoryCode, string categoryName) { if (!mapField.categoryExists(categoryCode)) { mapField.addNewCategory(categoryName, categoryCode); } // Initialize Rho with System Rho ARTModule.reSetRho(rho); double rhoInc = 0.0; Repeater: rhoInc += rhoIncrement; int f2NeuronCountBefore = 0; ConSelFAM.NET.LayerF2 f2Neurons = (ConSelFAM.NET.LayerF2)ARTModule.contextField[contextCode]; // just to initialize //load context if (ARTModule.contextField.ContainsKey(contextCode)) { f2Neurons = (ConSelFAM.NET.LayerF2)ARTModule.contextField[contextCode]; f2NeuronCountBefore = f2Neurons.Count; } object [,] artCluster = ARTModule.feedInput(contextCode, Pattern, categoryCode); int J = (int)artCluster[0, 1]; double[] ZJ = (double[])artCluster[0, 0]; f2Neurons = (ConSelFAM.NET.LayerF2)ARTModule.contextField[contextCode]; int f2NeuronCountAfter = f2Neurons.Count; if (f2NeuronCountBefore != f2NeuronCountAfter) { // THIS MEANS THAT NEW F2 NEURON IS ADDED TO THIS CONTEXT MapFieldCategory cat = mapField.getCategory(categoryCode); cat.addConnection(((F2Neuron)f2Neurons[J])); } return(mapField.getAssociatedCategory((F2Neuron)f2Neurons[J])); }
public void addNewCategory(string categoryName, int code) /*This method is to be called by FuzzyArtMap(string path) method*/ { MapFieldCategory categoryNode = new MapFieldCategory(categoryName, code); categories.Add(categoryNode); }