/// <summary> /// Sets the base settings values for the training algorithm /// </summary> /// <param name="settings">The network settings of the network that is /// calling the class.</param> public void SetSettings(NetworkSettings settings) { this.settings = settings; if (settings.Other.ContainsKey("startlayerindex")) { int.TryParse(settings.Other["startlayerindex"], out layerIndex); } if (settings.Other.ContainsKey("startnodeindex")) { int.TryParse(settings.Other["startnodeindex"], out nodeIndex); } if (settings.Other.ContainsKey("basestepvalue")) { float.TryParse(settings.Other["basestepvalue"], out stepValue); } if (stepValue == 0) { stepValue = 1; } if (settings.Other.ContainsKey("maxflips")) { int.TryParse(settings.Other["maxflips"], out maxFlips); } if (maxFlips == 0) { maxFlips = 20; } }
public void SetUp() { basePath = "C:\\Development Projects\\ENN\\TestSuite\\TestFiles\\"; testSetting = new NetworkSettings(); target = new NetworkSettings(); SetBaseSetting(); }
/// <summary> /// Saves a NetworkSettings object to file. The object can be saved to either a binary /// file or text file. /// </summary> /// <param name="settings">The object to save to file.</param> /// <param name="filePath">The location to save the file.</param> /// <param name="binary">If true a binary file will be created. Else a text file will /// be generated. By default this parameter is false.</param> /// <exception cref="IOException">System.IO.IOException</exception> public static void Save(NetworkSettings settings, string filePath, bool binary = false) { if (binary) SaveBinary(ref settings, filePath); else SaveText(ref settings, filePath); }
static void Main(string[] args) { //variable set up settings = new NetworkSettings(); topologies = new Dictionary<string, NetworkTopology>(); objectFactory = new Dictionary<string, IUserObjectFactory>(); objectFactory.Add("standard", new StandLibFactory()); loadTool = new LoadTool(ref settings, ref topologies, ref objectFactory); updateTool = new UpdateTool(ref settings, ref topologies); saveTool = new SaveTool(ref settings, ref topologies); //start up display information Console.WriteLine("ENN Copyright (C) 2012 Tim Eck II"); Console.WriteLine("This program comes with ABSOLUTELY NO WARRANTY."); Console.WriteLine("This is free software, and you are welcome to redistribute it"); Console.WriteLine( "under certain conditions; which can be found in the COPYING.LESSER.txt file"); Console.WriteLine("that was provided with the program.\n"); Console.WriteLine( "The ENN runtime has been succesfully started. You may now enter commands"); Console.WriteLine("If you are not sure where to start enter -h."); //command line processing loop Command command = RetrieveCommand(Console.ReadLine()); while (command.BaseType != CommandType.Exit) { ProcessCommand(command); command = RetrieveCommand(Console.ReadLine()); } }
public LoadTool(ref NetworkSettings settings, ref Dictionary<string, NetworkTopology> topologies, ref Dictionary<string, IUserObjectFactory> objectFactory) { this.settings = settings; this.topologies = topologies; this.objectFactory = objectFactory; }
/// <summary> /// Loads a NetwokTopology from either a text file or binary file. /// </summary> /// <param name="file">The path to the file the contains the /// NetworkTopology</param> /// <param name="objectFactories">The object factories that will be /// used to transform types specified in a text file into objects. /// </param> /// <param name="settings">The currently loaded NetworkSettings.</param> /// <param name="binary">If true a binary file will be loaded, else /// a text file will be loaded. By default this is false.</param> /// <returns></returns> /// <exception cref="IOException">System.IO.IOException</exception> public static NetworkTopology Load( string file, ref Dictionary<string, IUserObjectFactory> objectFactories, ref NetworkSettings settings, bool binary = false) { if (binary) return LoadBinary(file); return LoadText(file, ref objectFactories, ref settings); }
public void SaveText() { SetBaseSetting(); Settings.Save(baseSetting, basePath + "testSaveSettings.nns"); testSetting = Settings.Load(basePath + "testSaveSettings.nns"); Assert.IsTrue(baseSetting.Equals(testSetting)); File.Delete(basePath + "testSaveSettings.nns"); }
public override bool Equals(object obj) { NetworkSettings other = (NetworkSettings)obj; if (other == null) { return(true); } if (this.Mode != other.Mode || this.NetworkType != other.NetworkType) { return(true); } if (this.DefaultFactory != other.DefaultFactory || this.DefaultHiddenLayer != other.DefaultHiddenLayer || this.DefaultInputLayer != other.DefaultInputLayer || this.DefaultNode != other.DefaultNode || this.DefaultOutputLayer != other.DefaultOutputLayer) { return(false); } if (this.EnableTiming != other.EnableTiming) { return(false); } if (this.TrainingAccuracy != other.TrainingAccuracy || this.TrainingIterations != other.TrainingIterations || this.TraininPool != other.TraininPool) { return(false); } if (this.Other.Count != other.Other.Count) { return(false); } foreach (KeyValuePair <string, string> key in this.Other) { if (!other.Other.ContainsKey(key.Key)) { return(false); } if (key.Value != other.Other[key.Key]) { return(false); } } return(true); }
public HillClimbAlgo() { layerIndex = 0; nodeIndex = 0; weightIndex = 0; flips = 0; maxFlips = 20; baseStepValue = 1; stepValue = baseStepValue; priorError = float.MinValue; priorWeightValue = -2.0f; settings = null; }
/// <summary> /// Loads settings from a file. /// </summary> /// <param name="commands">Commands used to customize the behavior of the /// command</param> void SettingsHandler(List<RawCommand> commands) { Console.WriteLine("Loading settings..."); if (commands[2].CommandChar != 'f') { Console.WriteLine("Settings could not be loaded"); Console.WriteLine("No file was specified"); return; } try { bool binary = false; if (commands.Count > 3) { if (commands[3].CommandChar == 'b') { binary = true; } else { binary = commands[2].Value.EndsWith("nnsc", true, null); } } settings = Settings.Load(commands[2].Value, binary); Console.WriteLine("Loading has finished"); } catch (IOException ex) { Console.WriteLine("Settings could not be loaded"); Console.WriteLine("There was an error loading the file"); #if(DEBUG) Console.WriteLine("Message: {0}\nSource: {1}", ex.Message, ex.Source); #endif } catch (IndexOutOfRangeException ex) { Console.WriteLine("Settings could not be loaded"); Console.WriteLine("There was an error in the file file formatting."); #if(DEBUG) Console.WriteLine("Message: {0}\nSource: {1}", ex.Message, ex.Source); #endif } }
/// <summary> /// Saves the NetworkSettings object to a text file. /// </summary> /// <param name="settings">The NetworkSettings object to save to disk.</param> /// <param name="filePath">The location to save the file to.</param> /// <exception cref="IOException">System.IO.IOException</exception> private static void SaveText(ref NetworkSettings settings, string filePath) { StreamWriter writer = new StreamWriter(filePath); writer.WriteLine("version:1.0\n"); writer.WriteLine("networkmode:{0}", settings.Mode); writer.WriteLine("networktype:{0}", settings.NetworkType); writer.WriteLine("\n#User Defined Binary settings"); writer.WriteLine("\n#Default data types"); writer.WriteLine("inputlayer:{0}", settings.DefaultInputLayer); writer.WriteLine("node:{0}", settings.DefaultNode); writer.WriteLine("nodelayer:{0}", settings.DefaultHiddenLayer); writer.WriteLine("outputlayer:{0}", settings.DefaultOutputLayer); writer.WriteLine("factory:{0}", settings.DefaultFactory); writer.WriteLine("\n#Debugging"); writer.WriteLine("enabletiming:{0}", settings.EnableTiming); writer.WriteLine("\nTraining Settings"); writer.WriteLine("trainingiterations:{0}", settings.TrainingIterations); writer.WriteLine("trainingaccuracy:{0}", settings.TrainingAccuracy); writer.WriteLine("trainingpool:{0}", settings.TraininPool); writer.WriteLine("\n#User Defined Settings"); //Writes all the key-value pairs that couldn't be matched to a settings //field to disk. foreach (KeyValuePair<string, string> key in settings.Other) { writer.WriteLine("{0}:{1}", key.Key, key.Value); } writer.Close(); }
/// <summary> /// Save the NetworkSettings object to a binary file. /// </summary> /// <param name="settings">The NetworkSettings object that will be saved to /// disk in a binary file.</param> /// <param name="filePath">The location to save the file.</param> /// <exception cref="IOException">System.IO.IOException</exception> private static void SaveBinary(ref NetworkSettings settings, string filePath) { Stream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); BinaryFormatter binary = new BinaryFormatter(); binary.Serialize(fs, settings); fs.Close(); }
/// <summary> /// Loads a settings file and then populates the form fields. /// </summary> private void loadMenuItem_Click(object sender, EventArgs e) { openSettings.ShowDialog(); try { settings = Settings.Load(openSettings.FileName, openSettings.FileName.EndsWith(".nnsc", true, null)); if (settings.Mode == NetworkMode.Computational) { networkMode.SelectedIndex = 1; } else { networkMode.SelectedIndex = 0; } if (settings.NetworkType == NetworkType.Traditional) { networkType.SelectedIndex = 0; } else { networkType.SelectedIndex = 1; } defaultInput.Text = settings.DefaultInputLayer; defaultNode.Text = settings.DefaultNode; defaultHidden.Text = settings.DefaultHiddenLayer; defaultOutput.Text = settings.DefaultOutputLayer; enableTiming.Checked = settings.EnableTiming; trainingAccuracy.Text = settings.TrainingAccuracy.ToString(); trainingIterations.Text = settings.TrainingIterations.ToString(); trainingPool.Text = settings.TraininPool.ToString(); customParameters.Text = ""; int i = 0; string[] lines = new string[settings.Other.Count]; foreach (KeyValuePair<string, string> key in settings.Other) { lines[i] = key.Key + ":" + key.Value; i++; } customParameters.Lines = lines; } catch (IOException ex) { MessageBox.Show("The file could not be loaded."); } catch (IndexOutOfRangeException ex) { MessageBox.Show("The settings file was not properly formated."); } catch (Exception ex) { MessageBox.Show("There was some unknown error that occured while loading the file."); } }
private void MainForm_Load(object sender, EventArgs e) { settings = new NetworkSettings(); networkMode.SelectedIndex = 0; networkType.SelectedIndex = 0; defaultInput.SelectedIndex = 0; defaultHidden.SelectedIndex = 0; defaultOutput.SelectedIndex = 0; defaultNode.SelectedIndex = 0; defaultFactory.SelectedIndex = 0; }
public void LoadText() { SetBaseSetting(); testSetting = Settings.Load(basePath + "testSettings.nns"); Assert.IsTrue(baseSetting.Equals(testSetting)); }
public EvolvingNeuralNetwork(NetworkTopology[] topologies, NetworkSettings settings) { this.topologies = topologies; this.settings = settings; }
/// <summary> /// Loads a topology from a file into the gui. /// </summary> private void LoadTopology(object sender, EventArgs e) { openTopology.ShowDialog(); Dictionary<string, IUserObjectFactory> factories = metaData.GetFactories(); NetworkSettings settings = new NetworkSettings(); NetworkTopology topology = Topology.Load(openTopology.FileName, ref factories, ref settings, openTopology.FileName.EndsWith(".nntc", true, null)); topologyMetaData = topology.MetaData; AddPreProcessor(null, null); GetLayer(0).SetMetaData(topology.PreProcessor.MetaData); AddInputLayer(null, null); GetLayer(1).SetMetaData(topology.InputLayer.MetaData); int row = 2; for(int i = 0; i < topology.HiddenLayers.Length; i++) { AddHiddenLayer(null, null); HiddenLayerView layer = (HiddenLayerView)GetLayer(row); layer.SetMetaData(topology.HiddenLayers[i].MetaData); currentSelectedLayer = layer; row++; } AddOutputLayer(null, null); AddPostProcessor(null, null); }
public NeuralNetwork(NetworkTopology topology, NetworkSettings settings) { this.topology = topology; this.settings = settings; }
/// <summary> /// Creates a NetworkTopology from a text file. /// </summary> /// <param name="file">The location of the file to read from.</param> /// <param name="objectFactories">The object factories that will /// be used to tranform the text types into objects.</param> /// <param name="settings">The currently loaded NetworkSettings.</param> /// <returns>Returns the NetworkTopology located inside of the file. /// If the file can not be parsed null is returned.</returns> /// <exception cref="IOException">System.IO.IOException</exception> private static NetworkTopology LoadText( string file, ref Dictionary<string, IUserObjectFactory> objectFactories, ref NetworkSettings settings) { //Check to varify that the file can be loaded. if (GetVersion(file) != "1.0") return null; NetworkTopology topology = new NetworkTopology(); //Retrieves the RawTypes from the file List<RawType> rawTypes = GetRawTypes(file); Dictionary<string, IHiddenLayer> hiddenLayers = new Dictionary<string, IHiddenLayer>(); //Factory to create the object with string factoryName; //Transforms all the rawTypes into objects for (int i = 0; i < rawTypes.Count; i++) { factoryName = settings.DefaultFactory; if (rawTypes[i].Fields.ContainsKey("factory")) factoryName = rawTypes[i].Fields["factory"]; if (rawTypes[i].Type == "layer") { if (rawTypes[i].Fields["type"] == "hidden") { hiddenLayers.Add(rawTypes[i].Fields["layerName"], objectFactories[factoryName].CreateUserObject<IHiddenLayer>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields)); } else if (rawTypes[i].Fields["type"] == "output") { topology.OutputLayer = objectFactories[factoryName].CreateUserObject<IOutputLayer>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields); } else if (rawTypes[i].Fields["type"] == "input") { topology.InputLayer = objectFactories[factoryName].CreateUserObject<IInputLayer>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields); } } else if (rawTypes[i].Type == "node") { INode node = objectFactories[factoryName].CreateUserObject<INode>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields); if (hiddenLayers.ContainsKey(rawTypes[i].Fields["layer"])) { hiddenLayers[rawTypes[i].Fields["layer"]].SetNode(node, -1); } } else if (rawTypes[i].Type == "preprocessor") { topology.PreProcessor = objectFactories[factoryName].CreateUserObject<IPreProcessor>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields); if(settings.Mode == NetworkMode.Training) topology.TrainingPreProcessor = objectFactories[factoryName].CreateUserObject<ITrainingPreProcessor>( rawTypes[i].Fields["dataType"], rawTypes[i].Fields); } else if (rawTypes[i].Type == "postprocessor") { topology.PostProcessor = objectFactories[factoryName]. CreateUserObject<IPostProcessor>(rawTypes[i].Fields["dataType"], rawTypes[i].Fields); } else if (rawTypes[i].Type == "topology") { topology.MetaData = rawTypes[i].Fields; if(!rawTypes[i].Fields.ContainsKey("algorithmFactory")) { rawTypes[i].Fields.Add("algorithmFactory", factoryName); } topology.TrainingAlgorithm = objectFactories[rawTypes[i].Fields["algorithmFactory"]]. CreateUserObject<ITrainingAlgorithm>( rawTypes[i].Fields["trainingAlgorithm"], rawTypes[i].Fields); } } //This tranformation is required because nodes are linked to hidden layers //by names. The name of the layer is the key in the dictionary. IHiddenLayer[] layer = new IHiddenLayer[hiddenLayers.Count]; int j = 0; foreach (KeyValuePair<string, IHiddenLayer> temp in hiddenLayers) { layer[j] = temp.Value; j++; } topology.HiddenLayers = layer; return topology; }
public void SetUp() { basePath = "C:\\Development Projects\\ENN\\TestSuite\\TestFiles\\"; objectFactory = new Dictionary<string, IUserObjectFactory>() { {"standard", new StandLibFactory()}, {"TestBinary", new TestBinary()} }; settings = new NetworkSettings(); settings.Mode = NetworkMode.Training; baseTopology = new NetworkTopology(); }
/// <summary> /// Loads NetworkSettings from a text file. Determines the settings version to load. /// </summary> /// <param name="filePath">The file path to the settings file.</param> /// <returns>Returns the NetworkSettings that were loaded from the file. Returns null /// if the file could no be parsed.</returns> /// <exception cref="IOException">System.IO.IOException</exception> private static NetworkSettings LoadText(string filePath) { NetworkSettings settings = new NetworkSettings(); //strips the key-value pairs out of the text file Dictionary<string, string> raw = rawText(filePath); if (raw.Count == 0) return null; //if know version was specified then the latest file version is specified if (!raw.ContainsKey("version")) raw.Add("version", "1.0"); if (raw["version"] != "1.0") return null; raw.Remove("version"); //parses the key-value pairs by maping the key to the proper settings field foreach (KeyValuePair<string, string> key in raw) { switch (key.Key) { case "networkmode": if (key.Value == "training") { settings.Mode = NetworkMode.Training; } else { settings.Mode = NetworkMode.Computational; } break; case "networktype": if (key.Value == "traditional") { settings.NetworkType = NetworkType.Traditional; } else { settings.NetworkType = NetworkType.Evolving; } break; case "inputlayer": settings.DefaultInputLayer = key.Value; break; case "node": settings.DefaultNode = key.Value; break; case "nodelayer": settings.DefaultHiddenLayer = key.Value; break; case "outputlayer": settings.DefaultOutputLayer = key.Value; break; case "factory": settings.DefaultFactory = key.Value; break; case "enabletiming": settings.EnableTiming = (key.Value.ToLower() == "true"); break; case "trainingaccuracy": float trainAccuracy = 0; float.TryParse(key.Value, out trainAccuracy); settings.TrainingAccuracy = trainAccuracy; break; case "trainingiterations": int iterations = 0; int.TryParse(key.Value, out iterations); settings.TrainingIterations = iterations; break; case "trainingpool": int pool = 0; int.TryParse(key.Value, out pool); settings.TraininPool = pool; break; default: //if no field is found to place the value into then it is //added to the catch-all Other field settings.Other.Add(key.Key, key.Value); break; } } return settings; }
public UpdateTool(ref NetworkSettings settings, ref Dictionary<string, NetworkTopology> topologies) { this.settings = settings; this.topologies = topologies; }
/// <summary> /// Sets the base settings values for the training algorithm /// </summary> /// <param name="settings">The network settings of the network that is /// calling the class.</param> public void SetSettings(NetworkSettings settings) { this.settings = settings; if (settings.Other.ContainsKey("startlayerindex")) int.TryParse(settings.Other["startlayerindex"], out layerIndex); if (settings.Other.ContainsKey("startnodeindex")) int.TryParse(settings.Other["startnodeindex"], out nodeIndex); if (settings.Other.ContainsKey("basestepvalue")) float.TryParse(settings.Other["basestepvalue"], out stepValue); if (stepValue == 0) stepValue = 1; if (settings.Other.ContainsKey("maxflips")) int.TryParse(settings.Other["maxflips"], out maxFlips); if (maxFlips == 0) maxFlips = 20; }