public void SetLayerActivationInput(ref FeedForwardNetLayer layer, ITrainingSetItemRepository trainingSetItem) { for (int fromNo = 0; fromNo < layer.GetFromUnitCount(); fromNo++) { layer.SetFromUnitActivation(fromNo, trainingSetItem.GetInputNodeValue(fromNo)); } }
public ErrorMeasure FeedForwardPassTrain(ITrainingSetItemRepository trainingSetItem) { ErrorMeasure errorMeasure; feedForwardNet.FeedForwardPass(squashFunction, trainingSetItem); errorMeasure = ForwardPassError(trainingSetItem); UpdateNetworkAfterTrainingItem(trainingSetItem); return(errorMeasure); }
public void CalculateDeltas(ref IFeedForwardNetLayerRepository currentLayer, ITrainingSetItemRepository trainingSetItem) { double outputDelta; for (int toNo = 0; toNo < currentLayer.GetToUnitCount(); toNo++) { double outputActivation = currentLayer.GetToUnitActivation(toNo); outputDelta = (trainingSetItem.GetOutputNodeValue(toNo) - outputActivation) * outputActivation * (1 - outputActivation); currentLayer.SetToUnitDelta(toNo, outputDelta); } }
public void SetLayerActivation(ref FeedForwardNetLayer layer, ITrainingSetItemRepository trainingSetItem, FeedForwardNetLayer previousLayer, int currentLayerNo) { if (IsFirstLayer(currentLayerNo)) { SetLayerActivationInput(ref layer, trainingSetItem); } else { SetLayerActivationHidden(ref layer, previousLayer); } }
public void UpdateWeights(ITrainingSetItemRepository trainingSetItem) { IFeedForwardNetLayerRepository previousLayer = null; for (int layerNo = feedForwardNet.LayerCount() - 1; layerNo >= 0; layerNo--) { IFeedForwardNetLayerRepository currentLayer = feedForwardNet.GetLayer(layerNo); if (feedForwardNet.IsLastLayer(layerNo)) { outputUnitWeightStrategy.UpdateWeights(ref currentLayer); } else { hiddenUnitWeightStrategy.UpdateWeights(ref currentLayer); } previousLayer = currentLayer; } }
ErrorMeasure ForwardPassError(ITrainingSetItemRepository trainingSetItem) { ErrorMeasure errorMeasure; double sumError = 0.0; double localError; Boolean hasLearned = true; FeedForwardNetLayer outputLayer = feedForwardNet.GetOutputLayer(); for (int outputNo = 0; outputNo < outputLayer.GetToUnitCount(); outputNo++) { localError = Math.Abs(trainingSetItem.GetOutputNodeValue(outputNo) - outputLayer.GetToUnitActivation(outputNo)); if (localError > backPropagationConstants.OutputTolerance) { hasLearned = false; } sumError += localError; } errorMeasure = new ErrorMeasure(hasLearned, sumError); return(errorMeasure); }
public void FeedForwardPass(ISquashFunction squashFunction, ITrainingSetItemRepository trainingSetItem) { FeedForwardNetLayer currentLayer; FeedForwardNetLayer previousLayer; for (int currentLayerNo = 0; currentLayerNo < LayerCount(); currentLayerNo++) { currentLayer = GetLayer(currentLayerNo); if (currentLayerNo > 0) { previousLayer = GetLayer(currentLayerNo - 1); } else { previousLayer = null; } SetLayerActivation(ref currentLayer, trainingSetItem, previousLayer, currentLayerNo); CalculateNewLayerActivation(ref currentLayer, squashFunction); } //return ForwardPassError(trainingSetItem, currentLayerNo); }
public void AddTrainingSetItem(ITrainingSetItemRepository trainingSetItem) { trainingSet.Add((TrainingSetItem)trainingSetItem); }
public void UpdateNetworkAfterTrainingItem(ITrainingSetItemRepository trainingSetItem) { UpdateDeltas(trainingSetItem); UpdateWeights(trainingSetItem); }
// IBackPropagationConstants backPropagationConstants; public void UpdateWeightsDeltas(ref IFeedForwardNetLayerRepository currentLayer, ITrainingSetItemRepository trainingSetItem) { CalculateDeltas(ref currentLayer, trainingSetItem); UpdateWeights(ref currentLayer); }