示例#1
0
        private void SaveSnapshot(int epoch, double mse, double initialMse, double accuracy, bool isFinal = false)
        {
            var final    = isFinal ? "final_" : string.Empty;
            var fileName = $"{Path.GetDirectoryName(Parameters.Arff)}{Path.GetFileNameWithoutExtension(Parameters.Arff)}_iter_{final}{epoch}.txt";

            NeuralNetSave.Save(fileName, this, epoch, mse, initialMse, accuracy);
        }
示例#2
0
        public static void Save(string fileName, NeuralNet neuralNet, int epoch, double mse, double initialMse, double accuracy)
        {
            var nns = new NeuralNetSave()
            {
                Rate               = neuralNet.Parameters.Rate,
                Momentum           = neuralNet.Parameters.Momentum,
                Activation         = neuralNet.Parameters.Activation,
                ValidationAccuracy = accuracy,
                SnapshotInterval   = neuralNet.Parameters.SnapshotInterval,
                BatchSize          = neuralNet.Parameters.BatchSize,
                Mse        = mse,
                InitialMse = initialMse,
                Epoch      = epoch,
                Layers     = new List <Layer>()
            };

            foreach (var layer in neuralNet.Layers)
            {
                var newLayer = new Layer()
                {
                    Type  = layer.Type,
                    Nodes = new List <Node>()
                };

                foreach (var node in layer.Nodes)
                {
                    var newNode = new Node()
                    {
                        Weights = node.Weights
                    };

                    switch (layer.Type)
                    {
                    case NeuralNet.LayerType.Input:
                        newNode.Feature = ((NeuralNet.InputNode)node).Feature;
                        break;

                    case NeuralNet.LayerType.Output:
                        newNode.IsContinuous = ((NeuralNet.OutputNode)node).IsContinuous;
                        newNode.LabelCol     = ((NeuralNet.OutputNode)node).LabelCol;
                        newNode.LabelVal     = ((NeuralNet.OutputNode)node).LabelVal;
                        break;
                    }

                    newLayer.Nodes.Add(newNode);
                }

                nns.Layers.Add(newLayer);
            }

            var json = JsonConvert.SerializeObject(nns, Formatting.Indented);

            using (var w = new StreamWriter(fileName))
            {
                w.Write(json);
            }
        }
示例#3
0
        public NeuralNet(Parameters parameters)
        {
            _rand      = Rand.Get();
            Parameters = parameters;
            Layers     = new List <Layer>();

            if (!string.IsNullOrEmpty(parameters.SnapshotFileName) && File.Exists(parameters.SnapshotFileName))
            {
                NeuralNetSave.Load(parameters.SnapshotFileName, this);
            }
        }