/// <summary> /// Construct a gradient worker. /// </summary> /// /// <param name="network">The network to train.</param> /// <param name="owner">The owner that is doing the training.</param> /// <param name="training">The training data.</param> /// <param name="low">The low index to use in the training data.</param> /// <param name="high">The high index to use in the training data.</param> public GradientWorkerCPU(FlatNetwork network, TrainFlatNetworkProp owner, IEngineIndexableSet training, int low, int high) { this.errorCalculation = new ErrorCalculation(); this.network = network; this.training = training; this.low = low; this.high = high; this.owner = owner; this.stopwatch = new Stopwatch(); this.layerDelta = new double[network.LayerOutput.Length]; this.gradients = new double[network.Weights.Length]; this.actual = new double[network.OutputCount]; this.weights = network.Weights; this.layerIndex = network.LayerIndex; this.layerCounts = network.LayerCounts; this.weightIndex = network.WeightIndex; this.layerOutput = network.LayerOutput; this.layerFeedCounts = network.LayerFeedCounts; this.pair = BasicEngineData.CreatePair(network.InputCount, network.OutputCount); }
/// <summary> /// Sets the data value. /// </summary> /// <param name="direction">The direction.</param> /// <param name="propertyKey">The property key.</param> /// <param name="value">The value.</param> /// <exception cref="EngineException">No input property with key {propertyKey} has been registered for this element. /// or /// No output property with key {propertyKey} has been registered for this element.</exception> public void SetDataValue(EngineDataDirection direction, string propertyKey, IEngineData value) { switch (direction) { case EngineDataDirection.Input: var ip = inputProperties.SingleOrDefault(p => p.Key == propertyKey); var ipE = moduleEntry?.InputProperties?.SingleOrDefault(p => p.Key == propertyKey); if (ip == null) { throw new EngineException(logger, $"No input property with key {propertyKey} has been registered for this module."); } ip.Value = value; if (ipE != null) { ipE.Value = ip.Value.WriteToStringValue(); } break; case EngineDataDirection.Output: var op = outputProperties.SingleOrDefault(p => p.Key == propertyKey); var opE = moduleEntry?.OutputProperties?.SingleOrDefault(p => p.Key == propertyKey); if (op == null) { throw new EngineException(logger, $"No output property with key {propertyKey} has been registered for this module."); } op.Value = value; if (opE != null) { opE.Value = op.Value.WriteToStringValue(); } break; } }
public static SearchEngine Get(IEngineData searchEngineData) { var wordSearchBox = new WordSearchBox(searchEngineData.Letters, searchEngineData.Width); var expectedWords = searchEngineData.ExpectedWords; var wordList = new WordList(); wordList.AddWordsToList(expectedWords); return new SearchEngine(wordSearchBox, wordList); }
public static SearchEngine Get(IEngineData searchEngineData) { var wordSearchBox = new WordSearchBox(searchEngineData.Letters, searchEngineData.Width); var expectedWords = searchEngineData.ExpectedWords; var wordList = new WordList(); wordList.AddWordsToList(expectedWords); return(new SearchEngine(wordSearchBox, wordList)); }
/// <summary> /// Read an individual record. /// </summary> /// <param name="index">The zero-based index. Specify 0 for the first record, 1 for /// the second, and so on.</param> /// <param name="pair">The data to read.</param> public void GetRecord(long index, IEngineData pair) { double[] inputTarget = pair.InputArray; double[] idealTarget = pair.IdealArray; this.egb.SetLocation((int)index); this.egb.Read(inputTarget); this.egb.Read(idealTarget); }
/// <summary> /// Get one record from the data set. /// </summary> /// <param name="index">The index to read.</param> /// <param name="pair">The pair to read into.</param> public void GetRecord(long index, IEngineData pair) { INeuralDataPair source = this.data[(int)index]; pair.InputArray = source.Input.Data; if (pair.IdealArray != null) { pair.IdealArray = source.Ideal.Data; } }
private void LoadNewWordSearch(string wordsearchName) { cancelToolStripMenuItem_Click(null, null); this.searchEngineData = new WordSearchResourceData(wordsearchName); this.ClearFormState(); this.wordSearchPictureBox.Invalidate(false); expectedWordsListBox.Items.Clear(); expectedWordsListBox.Items.AddRange(this.searchEngineData.ExpectedWords.ToArray()); }
/// <summary> /// Get a record by index into the specified pair. /// </summary> /// /// <param name="index">The index to read.</param> /// <param name="pair">The pair to hold the data.</param> public virtual void GetRecord(long index, IEngineData pair) { IEngineData source = this.data[(int)index]; pair.InputArray = source.InputArray; if (pair.IdealArray != null) { pair.IdealArray = source.IdealArray; } }
/// <summary> /// Calculate the error for this neural network. The error is calculated /// using root-mean-square(RMS). /// </summary> /// /// <param name="data">The training set.</param> /// <returns>The error percentage.</returns> public double CalculateError(IEngineIndexableSet data) { ErrorCalculation errorCalculation = new ErrorCalculation(); double[] actual = new double[this.outputCount]; IEngineData pair = BasicEngineData.CreatePair(data.InputSize, data.IdealSize); for (int i = 0; i < data.Count; i++) { data.GetRecord(i, pair); Compute(pair.InputArray, actual); errorCalculation.UpdateError(actual, pair.IdealArray); } return(errorCalculation.Calculate()); }
/// <summary> /// Construct a kernel to train the network. /// </summary> /// /// <param name="device">The OpenCL device to use.</param> /// <param name="flat">The network to train.</param> /// <param name="training">The training data.</param> /// <param name="tempDataSize">How much temp data.</param> public KernelNetworkTrain(EncogCLDevice device, FlatNetwork flat, IEngineIndexableSet training, int tempDataSize) : base(device, "Encog.Engine.Resources.KernelNetTrain.txt", "NetworkTrain") { this.training = training; this.trainingLength = (int)this.training.Count; this.device = device; this.flat = flat; this.weightInArray = new float[flat.Weights.Length]; this.weightOutArray = new float[flat.Weights.Length]; this.tempDataArray = new float[tempDataSize]; this.gradients = new float[flat.Weights.Length]; this.layerDeltaSize = 0; for (int i = 0; i < flat.LayerCounts.Length; i++) { this.layerDeltaSize += flat.LayerCounts[i]; } int inputSize = flat.InputCount; int idealSize = flat.OutputCount; this.inputArray = new float[inputSize * this.trainingLength]; this.idealArray = new float[idealSize * this.trainingLength]; this.paramArray = new int[10]; IEngineData pair = BasicEngineData.CreatePair( flat.InputCount, flat.OutputCount); int inputIndex = 0; int idealIndex = 0; for (int i = 0; i < this.trainingLength; i++) { training.GetRecord(i, pair); for (int col = 0; col < flat.InputCount; col++) { this.inputArray[inputIndex++] = (float)pair.InputArray[col]; } for (int col = 0; col < flat.OutputCount; col++) { this.idealArray[idealIndex++] = (float)pair.IdealArray[col]; } } }
/// <summary> /// Get a record. /// </summary> /// <param name="index">The index.</param> /// <param name="pair">The record.</param> public void GetRecord(long index, IEngineData pair) { this.underlying.GetRecord(this.CurrentFoldOffset + index, pair); }
/// <summary> /// Add a neural data pair to the list. /// </summary> /// /// <param name="inputData">A NeuralDataPair object that contains both input and idealdata.</param> public void Add(IEngineData inputData) { this.data.Add(inputData); }
/// <summary> /// Adds the value. /// </summary> /// <param name="val">The value.</param> public void AddValue(IEngineData val) { ((List <IEngineData>)value).Add(val); }
/// <summary> /// Removes the value. /// </summary> /// <param name="val">The value.</param> public void RemoveValue(IEngineData val) { ((List <IEngineData>)value).Remove(val); }
/// <summary> /// Initializes a new instance of the Engine class. /// </summary> /// <param name="engineData">The interface cref="IEngineData" needed to parametrize Engine.</param> public Engine(IEngineData engineData) { EngineData = engineData; }