Exemplo n.º 1
0
        public BPTTLayer(BPTTLayerConfig config) : base(config)
        {
            Logger.WriteLine("Initializing BPTT Layer...");
            Logger.WriteLine("Layer Size: {0}", config.LayerSize);
            bptt       = config.Bptt + 1;
            bptt_block = 10;

            Logger.WriteLine("BPTT Size: {0}", bptt);
            Logger.WriteLine("BPTT Block Size: {0}", bptt_block);
        }
Exemplo n.º 2
0
        private void SetHiddenLayers()
        {
            //Get hidden layer settings
            HiddenLayersConfig = new List <LayerConfig>();
            var hiddenLayers = config.GetValueRequired(HIDDEN_LAYER);

            foreach (var layer in hiddenLayers.Split(','))
            {
                var items      = layer.Split(':');
                var sLayerSize = items[0].Trim();
                var sLayerType = items[1].Trim();

                //Parse layer size and type
                var layerSize = int.Parse(sLayerSize);
                var layerType = LayerType.None;

                foreach (
                    var type in
                    Enum.GetValues(typeof(LayerType))
                    .Cast <LayerType>()
                    .Where(
                        type => sLayerType.Equals(type.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    )
                {
                    layerType = type;
                    break;
                }

                LayerConfig baseLayerConfig;
                switch (layerType)
                {
                case LayerType.LSTM:
                {
                    var layerConfig = new LSTMLayerConfig();
                    baseLayerConfig = layerConfig;
                    Logger.WriteLine("Initialize configuration for LSTM layer.");
                }
                break;

                case LayerType.BPTT:
                {
                    if (items.Length != 3)
                    {
                        throw new ArgumentException(
                                  $"Invalidated settings for BPTT: {layer}, it should be [size:BPTT:bptt_value], such as [200:BPTT:5] .");
                    }

                    var layerConfig = new BPTTLayerConfig {
                        Bptt = int.Parse(items[2])
                    };
                    baseLayerConfig = layerConfig;
                    Logger.WriteLine($"Initialize configuration for BPTT layer. BPTT = '{layerConfig.Bptt}'");
                }
                break;

                case LayerType.DropOut:
                {
                    var layerConfig = new DropoutLayerConfig {
                        DropoutRatio = float.Parse(items[2])
                    };
                    baseLayerConfig = layerConfig;
                    Logger.WriteLine(
                        $"Initialize configuration for Dropout layer. Dropout ratio = '{layerConfig.DropoutRatio}'");
                }
                break;

                default:
                    throw new ArgumentException($"Invalidated layer type: {sLayerType}");
                }

                baseLayerConfig.LayerType = layerType;
                baseLayerConfig.LayerSize = layerSize;

                HiddenLayersConfig.Add(baseLayerConfig);
            }
            Logger.WriteLine($"Hidden layer : {HiddenLayersConfig.Count}");
            Logger.WriteLine($"Hidden layer : {hiddenLayers}");
        }