public void Initialize( ActivationFunctions hiddenLayerActFunc = ActivationFunctions.Sigmoid, ActivationFunctions outPutLayerActFunc = ActivationFunctions.Sigmoid) { //assign Layer dependencies InputLayer.ChildLayer = HiddenLayer; HiddenLayer.ParentLayer = InputLayer; HiddenLayer.ChildLayer = OutputLayer; OutputLayer.ParentLayer = HiddenLayer; //set Activation Functions HiddenLayer.ActivationFunction = hiddenLayerActFunc; OutputLayer.ActivationFunction = outPutLayerActFunc; //Assign random values to the Weights and set the bias for (int i = 0; i < NrInputNeurons; i++) { InputLayer.NeuronBiasses[i] = 1; InputLayer.BiasWeights[i] = Functions.RandomBias(); for (int j = 0; j < InputLayer.ChildLayer.NeuronValues.Length; j++) { InputLayer.SynapseWeights[i][j] = Functions.RandomBias(); } } for (int i = 0; i < NrHiddenNeurons; i++) { HiddenLayer.NeuronBiasses[i] = 1; HiddenLayer.BiasWeights[i] = Functions.RandomBias(); for (int j = 0; j < HiddenLayer.ChildLayer.NeuronValues.Length; j++) { HiddenLayer.SynapseWeights[i][j] = Functions.RandomBias(); } } }
public Matrix ApplyDerActivation(Matrix input) { if (activationFunc == ActivationType.SIGMOID) { return(ActivationFunctions.DerSigmoid(input)); } else if (activationFunc == ActivationType.TANH) { return(ActivationFunctions.DerTanh(input)); } return(null); }
// создание матриц весов и входных и выходных сигналов void Create() { if (structure.inputs < 1) { throw new Exception("Create NeuralNetwork: inputs must be greater than zero"); } if (structure.hiddens.Length == 0) { throw new Exception("Create NeuralNetwork: hiddens is null or zero"); } for (int i = 0; i < structure.hiddens.Length; i++) { if (structure.hiddens[i] < 1) { throw new Exception("Create NeuralNetwork: hiddens at " + i + " layer must be greater than zero"); } } if (structure.outputs < 1) { throw new Exception("Create NeuralNetwork: outputs must be greater than zero"); } layers = new Matrix[1 + structure.hiddens.Length]; inputs = new Vector[1 + structure.hiddens.Length]; outputs = new Vector[1 + structure.hiddens.Length]; layers[0] = new Matrix(structure.hiddens[0], structure.inputs); for (int i = 0; i < structure.hiddens.Length - 1; i++) { layers[i + 1] = new Matrix(structure.hiddens[i + 1], structure.hiddens[i]); } layers[layers.Length - 1] = new Matrix(structure.outputs, structure.hiddens[structure.hiddens.Length - 1]); hiddensActivation = ActivationFunctions.GetFunction(structure.hiddensFunction); hiddensDerivative = ActivationFunctions.GetDerivative(structure.hiddensFunction); outputActivation = ActivationFunctions.GetFunction(structure.outputFunction); outputDerivative = ActivationFunctions.GetDerivative(structure.outputFunction); }