public NeuronGPUEx(NeuronDataModel neuron, int globalId) { GlobalId = globalId; Id = neuron.Id; IsBias = neuron.IsBias; IsBiasConnected = neuron.IsBiasConnected; Activation = neuron.Activation; // ActivationFunction = null;// GPU.Instance.Accelerator.CompileKernel(typeof(ActivationFunction).GetMethod("None1")); ActivationFuncParamA = 0;// neuron.ActivationFuncParamA; }
public NeuronGPU(NeuronDataModel neuron) { Id = neuron.Id; IsBias = neuron.IsBias; IsBiasConnected = neuron.IsBiasConnected; Activation = neuron.Activation; ActivationFunction = neuron.ActivationFunction; ActivationFuncParamA = neuron.ActivationFuncParamA; var weights = GPU.Instance.Accelerator.Allocate <WeightGPU>(neuron.Weights.Count); for (int i = 0; i < neuron.Weights.Count; ++i) { weights.CopyFrom(new WeightGPU(neuron.Weights[i]), i); } Weights = weights.View; }
private void DrawLayerNeurons(bool fullState, NetworkDataModel model, LayerDataModel layer) { double threshold = model.Layers[0] == layer ? model.InputThreshold : 0; var biasColor = Tools.Draw.GetPen(Colors.Orange); NeuronDataModel prevNeuron = null; foreach (var neuron in layer.Neurons) { if (fullState || neuron.IsBias || neuron.Activation > threshold || layer.Id > 0) { if (!Coordinator.ContainsKey(neuron)) { Coordinator.Add(neuron, Points.Get(LayerX(model, layer), TOP_OFFSET + VerticalShift(model, layer) + neuron.Id * VerticalDistance(layer.Height))); } // Skip intersected neurons on first layer to improove performance. if (!fullState && !neuron.IsBias && model.Layers[0] == layer && prevNeuron != null) { if (Coordinator[neuron].Y - Coordinator[prevNeuron].Y < NEURON_SIZE) { continue; } } prevNeuron = neuron; var pen = Tools.Draw.GetPen(neuron.Activation); var brush = pen.Brush; if (neuron.IsBias) { CtlPresenter.DrawEllipse(Brushes.Orange, biasColor, Coordinator[neuron], BIAS_RADIUS, BIAS_RADIUS); } CtlPresenter.DrawEllipse(brush, pen, Coordinator[neuron], NEURON_RADIUS, NEURON_RADIUS); } } }
private void DrawLayersLinks(bool fullState, NetworkDataModel model, LayerDataModel layer1, LayerDataModel layer2, bool isOnlyWeights, bool isOnlyChangedWeights, bool isHighlightChangedWeights) { double threshold = model.Layers[0] == layer1 ? model.InputThreshold : 0; NeuronDataModel prevNeuron = null; foreach (var neuron1 in layer1.Neurons) { if (!Coordinator.ContainsKey(neuron1)) { Coordinator.Add(neuron1, Points.Get(LayerX(model, layer1), TOP_OFFSET + VerticalShift(model, layer1) + neuron1.Id * VerticalDistance(layer1.Height))); } // Skip intersected neurons on first layer to improove performance. if (!fullState && !neuron1.IsBias && model.Layers[0] == layer1 && prevNeuron != null) { if (Coordinator[neuron1].Y - Coordinator[prevNeuron].Y < NEURON_SIZE) { continue; } } if (fullState || neuron1.IsBias || neuron1.Activation > threshold) { foreach (var neuron2 in layer2.Neurons) { if (!neuron2.IsBias || (neuron2.IsBiasConnected && neuron1.IsBias)) { if (fullState || ((neuron1.IsBias || neuron1.Activation > threshold) && neuron1.AxW(neuron2) != 0)) { Pen pen = null; Pen penChange = null; bool isWeightChanged = false; var weight = neuron1.WeightTo(neuron2); if (WeightsData.TryGetValue(weight, out double prevWeight)) { if (prevWeight != weight.Weight) { isWeightChanged = true; WeightsData[weight] = weight.Weight; } } else { prevWeight = 0; isWeightChanged = true; WeightsData.Add(weight, weight.Weight); } double fraction = Math.Min(1, Math.Abs((prevWeight - weight.Weight) / prevWeight)); if (fraction <= 0.001) { isWeightChanged = false; } if (isWeightChanged && isHighlightChangedWeights) { penChange = Tools.Draw.GetPen(Colors.Lime); } if (isOnlyWeights) { if ((isWeightChanged && isOnlyChangedWeights) || !isOnlyChangedWeights) { pen = Tools.Draw.GetPen(weight.Weight, 1); } } else { pen = Tools.Draw.GetPen(neuron1.AxW(neuron2), 1); } if (!isOnlyChangedWeights && isHighlightChangedWeights && isWeightChanged) { pen = penChange; penChange = null; } if (pen != null) { if (!Coordinator.ContainsKey(neuron2)) { Coordinator.Add(neuron2, Points.Get(LayerX(model, layer2), TOP_OFFSET + VerticalShift(model, layer2) + neuron2.Id * VerticalDistance(layer2.Height))); } CtlPresenter.DrawLine(pen, Coordinator[neuron1], Coordinator[neuron2]); prevNeuron = neuron1; } if (penChange != null) { CtlPresenter.DrawLine(penChange, Coordinator[neuron1], Coordinator[neuron2]); prevNeuron = neuron1; } } } } } } }
public double Derivative(NetworkDataModel model, NeuronDataModel neuron) { return(neuron.Target - neuron.Activation); }