예제 #1
0
        private void InitWeights(ArtificialNeuralNetworkConfig config)
        {
            switch (config.ActivationType)
            {
            case ActivationTypes.ReLU:
                InitWeightsReLU();
                break;

            default:
                InitWeightsDefault();
                break;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }