//Deserialization constructor. public IConvergenceZone(SerializationInfo info, StreamingContext ctxt) { modalities = new Dictionary <string, IModality>(); modalitiesInfluence = new Dictionary <string, float>(); //Get the values from info and assign them to the appropriate properties name = (String)info.GetValue("CVZName", typeof(String)); int modalitiesCount = (int)info.GetValue("ModalitiesCount", typeof(int)); for (int i = 0; i < modalitiesCount; i++) { Type modalityType = (Type)info.GetValue("ModalityType" + i, typeof(Type)); object uncastedMod = info.GetValue("Modality" + i, modalityType); IModality mod = null; if (modalityType == typeof(FileModality)) { mod = (FileModality)uncastedMod; } if (modalityType == typeof(RandomModality)) { mod = (RandomModality)uncastedMod; } if (mod == null) { throw new Exception("Type " + modalityType.ToString() + " is not handled by IConvergenceZone unserializer"); } mod.Initialise(); AddModality(mod, 1.0f); } }
public void LinkToModality(IModality mod, int refreshPeriod = 100) { m = mod; labelName.Text = mod.name; tPeriod = refreshPeriod; tRefresh = new System.Threading.Thread(refreshValues); tRefresh.Start(); }
/// <summary> /// Add a modality to this CVZ /// </summary> /// <param name="modalityName"></param> /// <param name="size"></param> public virtual void AddModality(IModality m, float influence) { modalities.Add(m.name, m); modalitiesInfluence.Add(m.name, influence); if (errorLog != null) { stopLoggingError(); Console.WriteLine("AddModality: logging of error stopped"); } }
public void LinkToModality(IModality mod, int refreshPeriod = 100) { for (int i = 0; i < mod.Size; i++) { this.dataGridViewModalities.Rows.Add(); this.dataGridViewModalities.Rows[i].HeaderCell.Value = i.ToString(); } m = mod; labelName.Text = mod.name; tPeriod = refreshPeriod; tRefresh = new System.Threading.Thread(refreshValues); tRefresh.Start(); }
/// <summary> /// Connect a modality /// </summary> /// <param name="modalityName">Modality name</param> /// <param name="size">Modality vector size</param> /// <param name="influence">Modality influence on the map</param> public override void AddModality(IModality m, float influence) { base.AddModality(m, influence); RebuildWeightsMatrix(); }
/// <summary> /// Try to establish the yarp connections for maps running on the same computer. /// Connections are crossed /// </summary> /// <param name="target"></param> /// <returns></returns> public bool ConnectHierarchicalModality(IModality target) { throw new NotImplementedException(); }
/// <summary> /// Connect a modality /// </summary> /// <param name="modalityName">Modality name</param> /// <param name="size">Modality vector size</param> /// <param name="influence">Modality influence on the map</param> public override void AddModality(IModality m, float influence) { base.AddModality(m, influence); setInputConnectivity(); }
public static IConvergenceZone Create(ResourceFinder rf) { IConvergenceZone cvz = null; string mapType = rf.check("mapType", new Value("MMCM")).asString().c_str(); string mapName = rf.check("mapName", new Value("defaultMap")).asString().c_str(); switch (mapType) { case "MMCM": { bool hSynch = rf.check("hsync"); int w = rf.check("width", new Value(10)).asInt(); int h = rf.check("height", new Value(10)).asInt(); int l = rf.check("layers", new Value(4)).asInt(); Console.WriteLine("Map " + mapName + " (" + mapType + ")"); Console.WriteLine("Shape " + l + "x(" + w + "x" + h + ")"); Console.WriteLine("HSynch= " + hSynch); cvz = new CVZ_MMCM(mapName, h, w, l, hSynch); float learningRate = (float)rf.check("learningRate", new Value(0.07f)).asDouble(); float sigma = (float)rf.check("sigma", new Value((float)((1 / 4.0) * (w + h) / 2.0))).asDouble(); Console.WriteLine("Learning Rate: " + learningRate); Console.WriteLine("Sigma: " + sigma); (cvz as CVZ_MMCM).Sigma = sigma; (cvz as CVZ_MMCM).LearningRate = learningRate; break; } case "CTPC": { bool hSynch = rf.check("hsync"); int w = rf.check("width", new Value(10)).asInt(); int h = rf.check("height", new Value(10)).asInt(); double neighborRadius = rf.check("radius", new Value(7.0)).asDouble(); Console.WriteLine("Radius= " + neighborRadius); Console.WriteLine("Map " + mapName + " (" + mapType + ")"); Console.WriteLine("HSynch= " + hSynch); cvz = new CVZ_TPC(mapName, w, h, neighborRadius, hSynch); break; } //case "MMCM_GPU": // { // cvz = new CVZ_MMCM_GPU(mapName, h, w, l); // float learningRate = (float)rf.check("learningRate", new Value(0.07f)).asDouble(); // float sigma = (float)rf.check("sigma", new Value((float)((1 / 4.0) * (w + h) / 2.0))).asDouble(); // Console.WriteLine("Learning Rate: " + learningRate); // Console.WriteLine("Sigma: " + sigma); // break; // } } //Unknown map type if (cvz == null) { Console.WriteLine("Unknown map type: " + mapType); return(null); } else { Console.WriteLine("Map created. Adding modalities..."); } int modalityCount = rf.check("modalityCount", new Value(0)).asInt(); for (int i = 0; i < modalityCount; i++) { IModality mod = null; Bottle modalityGroup = rf.findGroup("modality_" + i); string name = modalityGroup.check("name", new Value("defaultModality" + i)).asString().c_str(); string type = modalityGroup.check("type", new Value("random")).asString().c_str(); float influence = (float)modalityGroup.check("influence", new Value(1.0)).asDouble(); Console.WriteLine("Modality: " + name + " (" + type + ")"); Console.WriteLine("Influence: " + influence); switch (type) { case "random": { int size = modalityGroup.check("size", new Value(1)).asInt(); mod = new RandomModality(mapName, name, size); break; } case "yarpVector": { int size = modalityGroup.check("size", new Value(1)).asInt(); float[] minBounds = null; float[] maxBounds = null; bool isBlocking = modalityGroup.check("isBlocking"); string autoconnect = null; if (modalityGroup.check("autoconnect")) { autoconnect = modalityGroup.find("autoconnect").asString().c_str(); } Console.WriteLine("isBlocking: " + isBlocking); if (modalityGroup.check("minBounds")) { minBounds = new float[size]; Bottle minBot = modalityGroup.find("minBounds").asList(); for (int c = 0; c < minBot.size(); c++) { minBounds[c] = (float)minBot.get(c).asDouble(); } } if (modalityGroup.check("maxBounds")) { maxBounds = new float[size]; Bottle maxBot = modalityGroup.find("maxBounds").asList(); for (int c = 0; c < maxBot.size(); c++) { maxBounds[c] = (float)maxBot.get(c).asDouble(); } } mod = new YarpModalityVector(mapName, name, size, minBounds, maxBounds, isBlocking, autoconnect); //if (modalityGroup.check("autoconnect")) //{ // string sourceConnection = modalityGroup.find("autoconnect").asString().c_str(); // while (!Network.connect(sourceConnection, YarpModalityVector.getRealPortName(mapName, name))) // { // Console.WriteLine("Waiting for..." + sourceConnection); // Time.delay(1.0); // } //} break; } case "yarpString": { bool isBlocking = modalityGroup.check("isBlocking"); string autoconnect = null; if (modalityGroup.check("autoconnect")) { autoconnect = modalityGroup.find("autoconnect").asString().c_str(); } mod = new YarpModalityString(mapName, name, isBlocking, autoconnect); Console.WriteLine("isBlocking: " + isBlocking); //if (modalityGroup.check("autoconnect")) //{ // string sourceConnection = modalityGroup.find("autoconnect").asString().c_str(); // Network.connect(sourceConnection, YarpModalityVector.getRealPortName(mapName, name)); //} break; } case "yarpImageRgb": { bool isBlocking = modalityGroup.check("isBlocking"); Console.WriteLine("isBlocking: " + isBlocking); int wImg = modalityGroup.check("width", new Value(32)).asInt(); int hImg = modalityGroup.check("height", new Value(32)).asInt(); string autoconnect = null; if (modalityGroup.check("autoconnect")) { autoconnect = modalityGroup.find("autoconnect").asString().c_str(); } mod = new YarpModalityImageRgb(mapName, name, wImg, hImg, isBlocking, autoconnect); Console.WriteLine("Resolution: " + wImg + "x" + hImg); //if (modalityGroup.check("autoconnect")) //{ // string sourceConnection = modalityGroup.find("autoconnect").asString().c_str(); // Network.connect(sourceConnection, YarpModalityVector.getRealPortName(mapName, name)); //} break; } case "yarpImageFloat": { bool isBlocking = modalityGroup.check("isBlocking"); Console.WriteLine("isBlocking: " + isBlocking); int wImg = modalityGroup.check("width", new Value(32)).asInt(); int hImg = modalityGroup.check("height", new Value(32)).asInt(); int padding = modalityGroup.check("padding", new Value(0)).asInt(); string autoconnect = null; if (modalityGroup.check("autoconnect")) { autoconnect = modalityGroup.find("autoconnect").asString().c_str(); } mod = new YarpModalityImageFloat(mapName, name, wImg, hImg, padding, isBlocking, autoconnect); Console.WriteLine("Resolution: " + wImg + "x" + hImg); //if (modalityGroup.check("autoconnect")) //{ // string sourceConnection = modalityGroup.find("autoconnect").asString().c_str(); // Network.connect(sourceConnection, YarpModalityVector.getRealPortName(mapName, name)); //} break; } case "yarpSound": { bool isBlocking = modalityGroup.check("isBlocking"); Console.WriteLine("isBlocking: " + isBlocking); int size = modalityGroup.check("size", new Value(512)).asInt(); string autoconnect = null; if (modalityGroup.check("autoconnect")) { autoconnect = modalityGroup.find("autoconnect").asString().c_str(); } mod = new YarpModalitySound(mapName, name, size, isBlocking, autoconnect); Console.WriteLine("Buffer: " + size); //if (modalityGroup.check("autoconnect")) //{ // string sourceConnection = modalityGroup.find("autoconnect").asString().c_str(); // Network.connect(sourceConnection, YarpModalityVector.getRealPortName(mapName, name)); //} break; } } Console.WriteLine(); //Unknown modality type if (mod == null) { return(null); } cvz.AddModality(mod, influence); } return(cvz); }