public static ManagedDNN DeserializeDNN(string json)
        {
            var model = JsonConvert.DeserializeObject <ManagedDNNJSON>(json);

            var network = new ManagedDNN()
            {
                Weights     = new ManagedArray[model.Weights.Count],
                X           = new ManagedArray[model.Weights.Count],
                Z           = new ManagedArray[model.Weights.Count],
                D           = new ManagedArray[model.Weights.Count],
                Deltas      = new ManagedArray[model.Weights.Count],
                Activations = new ManagedArray[model.Weights.Count - 1],
                Layers      = new List <HiddenLayer>()
            };

            for (var layer = 0; layer < model.Weights.Count; layer++)
            {
                network.Weights[layer] = Set(model.Weights[layer]);
                network.Layers.Add(new HiddenLayer(network.Weights[layer].x - 1, network.Weights[layer].y));
            }

            if (model.Normalization != null && model.Normalization.Count > 1)
            {
                network.Min = model.Normalization[0];
                network.Max = model.Normalization[1];
            }

            return(network);
        }
        public static string Serialize(ManagedDNN network)
        {
            var model = Convert(network);

            var output = JsonConvert.SerializeObject(model);

            return(output);
        }
        public static ManagedDNNJSON Convert(ManagedDNN network)
        {
            var model = new ManagedDNNJSON();

            for (var layer = 0; layer < network.Weights.GetLength(0); layer++)
            {
                model.Weights.Add(Convert2D(network.Weights[layer]));
            }

            model.Normalization.Add(network.Min);
            model.Normalization.Add(network.Max);

            return(model);
        }