Esempio n. 1
0
        public AgentNetwork(FileInfo fileInfo)
        {
            fileInfo.Refresh();

            if (fileInfo.Exists == false)
            {
                throw new ArgumentException();
            }

            using (FileStream stream = fileInfo.OpenRead())
            {
                var layers     = NetworkSerializer.LoadLayers(new BinaryReader(stream));
                var viewRadius = AgentNetworkInputCoder.EncodedSizeToViewRadius(layers.First().Neurons.First().Weights.Length - 1);
                InputCoder = new AgentNetworkInputCoder(viewRadius);

                if (layers.Last().Neurons.Length != 1)
                {
                    throw new ArgumentException("Invalid neural network shape.");
                }

                if (layers.First().Neurons.First().Weights.Length - 1 != InputCoder.EncodedSize)
                {
                    throw new ArgumentException("Invalid neural network shape.");
                }

                Network = new Network(layers);
            }
        }
Esempio n. 2
0
        public AgentNetwork(AgentNetworkDefinition definition, ILayerInitializer initializer)
        {
            InputCoder = new AgentNetworkInputCoder(definition.ViewRadius);
            var lastLayer         = new NetworkLayerDefinition(definition.LastLayerActivationFunction, 1);
            var networkDefinition = new NetworkDefinition(InputCoder.EncodedSize, definition.Layers.Concat(new[] { lastLayer }));

            Network = NetworkBuilder.Build(networkDefinition, initializer);
        }
Esempio n. 3
0
        public string ToToolTipString()
        {
            var inputCoder = new AgentNetworkInputCoder(ViewRadius);

            string[] lines =
            {
                $"Activation Function: {Layers.First().ActivationFunction}",
                $"View Radius: {ViewRadius}",
                $"Layers: {inputCoder.EncodedSize},{string.Join(",", Layers.Select(l => l.Size))},1",
            };
            return(string.Join("\r\n", lines));
        }
Esempio n. 4
0
        public override string ToString()
        {
            var inputCoder = new AgentNetworkInputCoder(ViewRadius);

            return($"{Layers.First().ActivationFunction}, {ViewRadius}, [{inputCoder.EncodedSize},{string.Join(",", Layers.Select(l => l.Size))},1]");
        }
Esempio n. 5
0
 public AgentNetwork(AgentNetworkInputCoder inputCoder, IEnumerable <AI.NeuralNetworks.Layer> layers)
 {
     InputCoder = inputCoder;
     Network    = new Network(layers);
 }