internal Layer(int size, ActivateFunction updFunc, bool hasBias) { Input = new float[size]; Unit = new float[size + (hasBias ? 1 : 0)]; Delta = new float[size]; Function = updFunc; _diff = ChooseDiffFunction(); HasBias = hasBias; if (HasBias) { Unit[Input.Length] = 1.0f; } DiffFunction ChooseDiffFunction() { switch (updFunc.Method.Name) { case "Identity": return(DiffIdentity); case "Tanh": return(DiffTanh); case "Sigmoid": return(DiffSigmoid); case "ReLU": return(DiffReLU); case "LeakyReLU": return(DiffLeakyReLU); default: return(null); } } }
/// <summary> /// Constructs a new menu item object. /// </summary> /// <param name="text">The text to be shown on the LCD.</param> /// <param name="selectable">Is this menu item selectable?</param> /// <param name="visibleFunction">The function used to determine /// if this menu item is visible.</param> /// <param name="activateFunction">The function used when this menu /// item is activated.</param> /// <param name="destination">The menu that is the destination after /// this menu item is activated.</param> public MenuItem(string text, bool selectable, VisibleFunction visibleFunction, ActivateFunction activateFunction, Menu destination) { _text = text; _selectable = selectable; _visibleFunction = visibleFunction; _activateFunction = activateFunction; _destination = destination; }
public Layer(int neuronsCount, double[][] weights) { ActivateFunction activateFunction = (double x) => { return(1 / (1 + Math.Exp((-1) * x))); }; ActivateFunction activateFunctionDerivative = (double x) => { return((1 / (1 + Math.Exp((-1) * x))) * (1 - (1 / (1 + Math.Exp((-1) * x))))); }; this.AcivateFunc = activateFunction; this.ActivateFunctionDerivative = activateFunctionDerivative; this.Weights = weights; this.NeuronsCount = neuronsCount; }
private Layer ApplyActivationFunction(Layer layer, ActivateFunction activateFunction) { var result = new Layer(layer.size); for (int i = 0; i < layer.size; i++) { result.Items[i] = activateFunction(layer.Items[i]); } return(result); }
public Layer(int neuronsCount, double[][] weights, ActivateFunction func, ActivateFunction funcDerivative) { if (neuronsCount != weights[0].Length) { throw new Exception("Size of weights and neurons count is not right, please make changes"); } this.AcivateFunc = func; this.ActivateFunctionDerivative = funcDerivative; this.NeuronsCount = neuronsCount; this.Weights = weights; }
public void FeedForward(float[] inputs) { ActivateFunction activateFunction = ActivateFunctions.Sigmoid; Hiddens[0] = ApplyActivationFunction(Task.Run(() => Feed(WeightsIH, Matrix.ArrayToMatrix(inputs), Bias[0, 0])).Result, activateFunction); for (int i = 0; i < Hiddens.Count() - 1; i++) { Hiddens[i + 1] = ApplyActivationFunction(Task.Run(() => Feed(WeightsH[i], Matrix.ArrayToMatrix(Hiddens[i].Items), Bias[i + 1, 0])).Result, activateFunction); } var lastBias = Bias.GetLength(0) - 1; Outputs = ApplyActivationFunction(Task.Run(() => Feed(WeightsHO, Matrix.ArrayToMatrix(Hiddens.LastOrDefault().Items), Bias[lastBias, 0])).Result, activateFunction); }
public static FlattenLayer CreateFlattenLayer() { //ActivateFunction activateFunction = (double x) => { return 1 / (1 + Math.Exp((-1) * x)); }; //ActivateFunction activateFunctionDerivative = (double x) => { return (1 / (1 + Math.Exp((-1) * x))) * (1 - (1 / (1 + Math.Exp((-1) * x)))); }; ActivateFunction activateFunction = (double x) => { return(Math.Tanh(x)); }; ActivateFunction activateFunctionDerivative = (double x) => { return(1 - Math.Pow(Math.Tanh(x), 2)); }; return(new FlattenLayer { ActivateFunction = activateFunction, ActivateFunctionDerivative = activateFunctionDerivative }); }
public Network CreateStandart(params int[] param) { /*var inputLayerNeuronsCount = 784; * var hiddenLayerNeuronsCount = 100; * var outputLayerNeuronsCount = 10;*/ var inputLayerNeuronsCount = param[0]; var hiddenLayerNeuronsCount = param[1]; var outputLayerNeuronsCount = param[2]; ActivateFunction activateFunction = (double x) => { return(1 / (1 + Math.Exp((-1) * x))); }; ActivateFunction activateFunctionDerivative = (double x) => { return((1 / (1 + Math.Exp((-1) * x))) * (1 - (1 / (1 + Math.Exp((-1) * x))))); }; //normal distribution Normal normal = new Normal(0, Math.Pow(inputLayerNeuronsCount, -0.5)); double[][] hiddenLayerWeights = new double[inputLayerNeuronsCount][]; for (int i = 0; i < inputLayerNeuronsCount; ++i) { hiddenLayerWeights[i] = new double[hiddenLayerNeuronsCount]; for (int j = 0; j < hiddenLayerNeuronsCount; ++j) { hiddenLayerWeights[i][j] = normal.Sample(); } } //normal distribution normal = new Normal(0, Math.Pow(hiddenLayerNeuronsCount, -0.5)); double[][] outputLayerWeights = new double[hiddenLayerNeuronsCount][]; for (int i = 0; i < hiddenLayerNeuronsCount; ++i) { outputLayerWeights[i] = new double[outputLayerNeuronsCount]; for (int j = 0; j < outputLayerNeuronsCount; ++j) { outputLayerWeights[i][j] = normal.Sample(); } } var layers = new List <Layer> { new Layer(hiddenLayerNeuronsCount, hiddenLayerWeights, activateFunction, activateFunctionDerivative), new Layer(outputLayerNeuronsCount, outputLayerWeights, activateFunction, activateFunctionDerivative), }; var netwrokToReturn = new MultilayerPerceptron(layers); return(netwrokToReturn); }
public NeuroNetsMainWindow() { InitializeComponent(); Type ourtype = typeof(ActivateFunction); // Базовый тип Assembly ast = Assembly.GetAssembly(ourtype); Type[] types = ast.GetTypes(); IEnumerable <Type> list = Assembly.GetAssembly(ourtype).GetTypes().Where(type => type.IsSubclassOf(ourtype)); // using System.Linq List <Type> aa = new List <Type>(list); foreach (Type itm in aa) { ActivateFunction af1 = (ActivateFunction)Activator.CreateInstance(itm); string name = af1.GetType().Name; } dbHandler = new DataBaseHandler(); neuroNetsInfo = new DataContainer <List <string[]> >(); learningInfo = new DataContainer <DataContainer <List <string> > >(); dgwNeuroNets.ColumnHeadersDefaultCellStyle.Font = new Font("Book Antiqua", 9); dgwNeuroNets.Columns.Add("Name", "Имя"); dgwNeuroNets.Columns.Add("TopologyTypeName", "Топология"); dgwNeuroNets.Columns.Add("Task", "Задача"); dgwNeuroNets.Columns.Add("NeuronCount", "Количество нейронов"); dgwNeuroNets.Columns.Add("LayerCount", "Количество слоев"); dgwNeuroNets.Columns.Add("ActivateFunction", "Активационная функция"); dgwNeuronsInLayers.Columns.Add("Layer", "Слой"); dgwNeuronsInLayers.Columns.Add("Neurons", "Число нейронов"); dgwParamsAF.Columns.Add("Parameter", "Параметр"); dgwParamsAF.Columns.Add("Value", "Значение"); dgwNets.ColumnHeadersDefaultCellStyle.Font = new Font("Book Antiqua", 9); dgwNets.Columns.Add("NeuroNet", "Нейронная сеть"); dgwNets.Columns.Add("TopologyTypeName", "Топология"); dgwNets.Columns.Add("NeuronCount", "Количество нейронов"); dgwNets.Columns.Add("LayerCount", "Количество слоев"); dgwLA.ColumnHeadersDefaultCellStyle.Font = new Font("Book Antiqua", 9); dgwLA.Columns.Add("LearningAlgorithm", "Алгоритм обучения"); dgwLA.Columns.Add("LearningStatus", "Статус обучения"); LoadInformationForUsingNeuroNets(); FillNeuroNetChangingTable(); }
private void RefreshDgwParametersAF() { dgwEditParametersAF.Rows.Clear(); int countParameters = LibraryOfActivateFunctions.GetCountParametersOfAF(cbActivateFunction.SelectedItem.ToString(), LibraryOfActivateFunctions.GetterParameter.ActivateFunctionName); ActivateFunction af = LibraryOfActivateFunctions.GetActivateFunction(cbActivateFunction.SelectedItem.ToString(), LibraryOfActivateFunctions.GetterParameter.ActivateFunctionName); for (int i = 0; i < countParameters; i++) { string[] row = new string[2]; row[0] = Convert.ToString(af.GetNameOfParameter(i)); row[1] = Convert.ToString(af.GetDefaultValueOfParameter(i)); dgwEditParametersAF.Rows.Add(row); dgwEditParametersAF.Rows[i].Cells[0].ReadOnly = true; } }
private void btnUse_Click(object sender, EventArgs e) { int countInputNeurons = dbHandler.SelectCountInputParametersInTask(lbTaskSelected.Text); int countOutputNeurons = 1; ActivateFunction af = LibraryOfActivateFunctions. GetActivateFunction(dbHandler.SelectActivateFunctionTypeByNeuroNet(lbNetSelected.Text), LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName); List <double> valuesOfParametersAF = dbHandler.SelectValuesOfParametersOfAF(lbNetSelected.Text); int k = 0; foreach (double item in valuesOfParametersAF) { af.SetValueOfParameter(k, item); k++; } int countNeurons = dbHandler.SelectCountNeuronsInNet(lbNetSelected.Text); bool[,] connections = new bool[countNeurons, countNeurons]; double[,] weights = new double[countNeurons, countNeurons]; List <Tuple <int, int, double> > ls = dbHandler.SelectLearnedTopology(lbNetSelected.Text, lbSelSelected.Text, LearningAlgorithmsLibrary.GetNameOfTypeOfAlgoritm(lbLASelected.Text)); for (int i = 0; i < countNeurons; i++) { for (int j = 0; j < countNeurons; j++) { connections[i, j] = false; weights[i, j] = 0.0; } } foreach (Tuple <int, int, double> item in ls) { connections[item.Item2, item.Item1] = true; weights[item.Item2, item.Item1] = item.Item3; } int[] neuronsInLayers = dbHandler.SelectNeuronsInLayers(lbNetSelected.Text); NeuroNet net = new NeuroNet(countInputNeurons, countOutputNeurons, neuronsInLayers, connections, weights, af); NeuroNetSolvingWindow solvingWnd = new NeuroNetSolvingWindow(net); solvingWnd.Show(); }
public Neuron(ActivateFunction af) { act_func = af; inputs = null; }
protected Neuron() { act_func = null; inputs = null; }
public PerceptronMonocouche(ActivateFunction f, WeightInitialisation weight) : base(f, weight) { }
public Functions(ActivateFunction func, OutErrorFunction outError, HiddenLayerErrorFunction hiddenError) { ActivateFunc = func; OutErrorFunc = outError; HiddenLayerErrorFunc = hiddenError; }
public static void AddLayer(int size, ActivateFunction function = null, bool bias = true) => _network._layers.Add(new Layer(size, function ?? ReLU, bias));
public InputNeuron(ActivateFunction af) { act_func = af; InputValue = 0.0; }
public InputNeuron(ActivateFunction af, double inputValue) { act_func = af; InputValue = inputValue; }
public InputNeuron(ActivateFunction af, double inputValue, NeuronInputConnection[] _inputs) { act_func = af; InputValue = inputValue; SetInputConnections(_inputs); }
public OutputNeuron(ActivateFunction af) { act_func = af; }
public Perceptron(ActivateFunction f, WeightInitialisation weight) { activateFunction = f; weightInitialisation = weight; ConnectTo(Biais.GetInstance()); }
public Neuron(ActivateFunction af, NeuronInputConnection[] _inputs) { act_func = af; SetInputConnections(_inputs); }
public Perceptron(ActivateFunction f, WeightInitialisation weight) { activateFunction = f; weightInitialisation = weight; ConnectTo(new Biais()); }
public List <string[]> SelectParametersOfAF(string NeuroNetName, int countNeurons, string NameAF) { int IDAF = LibraryOfActivateFunctions.GetCountParametersOfAF(NameAF, LibraryOfActivateFunctions.GetterParameter.ActivateFunctionName); ActivateFunction af = LibraryOfActivateFunctions.GetActivateFunction(NameAF, LibraryOfActivateFunctions.GetterParameter.ActivateFunctionName); if (IDAF != -1) { List <string[]> ls = new List <string[]>(); connector.ConnectToDB(); SQLiteCommand cmd = new SQLiteCommand(connector.connection); int[] neurons = new int[countNeurons]; double[] valuesPars = new double[IDAF]; cmd.CommandText = "SELECT AFParameters " + "FROM NeuroNet,TASK WHERE NeuroNet.TaskID = TASK.ID AND NeuroNet.Name ='" + NeuroNetName + "'"; try { string line = Convert.ToString(cmd.ExecuteScalar()); int k = 0; int j = 0; string buf = ""; string[] row; while (j < line.Length) { row = new string[2]; if (line[j] != ' ') { buf += line[j]; } else { row[0] = af.GetNameOfParameter(k); row[1] = buf; ls.Add(row); k++; buf = ""; } j++; } row = new string[2]; row[0] = af.GetNameOfParameter(k); row[1] = buf; ls.Add(row); } catch (SQLiteException ex) { MessageBox.Show(ex.Message); } connector.DisconnectFromDB(); return(ls); } else { throw new Exception("No such name of Activate Function!"); } }
public NeuroNet(int numb_input_neurons, int numb_output_neurons, int[] numbNeuronsInLayers, bool[,] _connections, double[,] _weights, ActivateFunction af) { if (_connections.GetLength(0) != _connections.GetLength(1) || _weights.GetLength(0) != _weights.GetLength(1) || _connections.GetLength(0) != _weights.GetLength(0)) { throw new Exception("Invalid dimensions of connection or weight matrices"); } int countNeurons = _connections.GetLength(0); if (numb_input_neurons <= 0 || numb_input_neurons >= countNeurons) { throw new Exception("Number of input neurons is out of range"); } if (numb_output_neurons <= 0 || numb_output_neurons >= countNeurons) { throw new Exception("Number of output neurons is out of range"); } if (af == null) { throw new Exception("Not initialized activate function"); } if (numbNeuronsInLayers.GetLength(0) < 2 || numbNeuronsInLayers.GetLength(0) > countNeurons) { throw new Exception("Invalid count of layers"); } int sum = 0; foreach (int item in numbNeuronsInLayers) { if (item <= 0) { throw new Exception("Must be at least one neuron in each layer"); } sum += item; } if (sum != countNeurons) { throw new Exception("Invalid count of neurons in layers"); } neuronsInLayers = numbNeuronsInLayers; input_neurons = new InputNeuron[numb_input_neurons]; neurons = new Neuron[countNeurons]; output_neurons = new OutputNeuron[numb_output_neurons]; topology = new bool[countNeurons, countNeurons]; weights = new double[countNeurons, countNeurons]; evaluation_machine = new Queue <Queue <Neuron> >(); for (int i = 0; i < numb_input_neurons; i++) { input_neurons[i] = new InputNeuron(af); neurons[i] = input_neurons[i]; } for (int i = numb_input_neurons; i < countNeurons - numb_output_neurons; i++) { neurons[i] = new Neuron(af); } for (int i = 0; i < numb_output_neurons; i++) { output_neurons[i] = new OutputNeuron(af); neurons[i + countNeurons - numb_output_neurons] = output_neurons[i]; } for (int i = 0; i < countNeurons; i++) { Neuron cur = neurons[i]; for (int j = 0; j < countNeurons; j++) { topology[j, i] = false; if (_connections[j, i] == true) { topology[j, i] = true; weights[j, i] = _weights[j, i]; } } } setInputConnections(); isIterationsFinished = true; isWaveCameToOutputNeuron = false; }