private void InitWeights(ArtificialNeuralNetworkConfig config) { switch (config.ActivationType) { case ActivationTypes.ReLU: InitWeightsReLU(); break; default: InitWeightsDefault(); break; } }
public ArtificialNeuralNetwork(ArtificialNeuralNetworkConfig config) { _config = config; LearningRate = config.LearningRate; foreach (int neuronCount in config.NeuronCounts) { var prevLayer = Layers.Count > 0 ? Layers[Layers.Count - 1] : null; Layers.Add(new Layer(neuronCount, prevLayer)); } Layers[0].CreateInputConnections(config.InputDimensions); Layers[Layers.Count - 1].CreateOutputConnections(); InitWeights(config); }
public static ArtificialNeuralNetwork Load(string fileName) { ArtificialNeuralNetwork ann = null; using (var stream = new FileStream(fileName, FileMode.Open)) { using (var reader = new BinaryReader(stream)) { ArtificialNeuralNetworkConfig config = new ArtificialNeuralNetworkConfig(); config.InputDimensions = reader.ReadInt32(); config.NeuronCounts = new int[reader.ReadInt32()]; for (var i = 0; i < config.NeuronCounts.Length; i++) { config.NeuronCounts[i] = reader.ReadInt32(); } config.LearningRate = reader.ReadDouble(); config.ActivationType = (ActivationTypes)reader.ReadInt32(); ann = new ArtificialNeuralNetwork(config); foreach (var layer in ann.Layers) { foreach (var neuron in layer.Neurons) { foreach (var incomingConnection in neuron.IncomingConnections) { incomingConnection.Weight = reader.ReadDouble(); } } } reader.Close(); } } return(ann); }