Save network cog c #

I have a problem with how to save a neural network in the cogog cog library. I want to serialize the scales of a hidden layer and data from input and output layers. It is also necessary to save the network structure somewhere if I want to deserialize it successfully. Below the part of the code where I create the network and serialize the BasicNetwork object, this is of course not true. I found a lot of information on how to do this using the java version, but noting about C #.

                BasicNetwork network = CreateNet(nettype,res11[i],1,2);
                INeuralDataSet trainingSet = new BasicNeuralDataSet(masStudyInput, masStudyOutput);
                INeuralDataSet TestingSet = new BasicNeuralDataSet(masTestInput, mastestOutput);
                ITrain train = new ResilientPropagation(network, trainingSet);

                int epoch = 1;
                //network.Structure.Layers.
                MessageBox.Show("Start");

                do
                {

                    train.Iteration();

                    mist = GetMistake(ref network, ref TestingSet);
                    chart1.Invoke((Action)(() =>
                    {
                        chart1.Series[0].Points.AddY(train.Error);
                        chart1.Series[1].Points.AddY(mist);
                    }));
                    network.
                    if (mist < 0.8)
                   {
                    string XMLfilename = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\" + mist + ".xml";
                    System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(BasicNetwork));
                    TextWriter writerr = new StreamWriter(XMLfilename);
                    writer.Serialize(writerr, network);
                    writerr.Close();
                    }
                    epoch++;

                }
                while ((epoch < 1000));SS
+3
source share
2 answers

The network is serializable, so you can use any serializer you want. Example:

var serializer = new BinaryFormatter();
using (var ms = new MemoryStream())
{
    serializer.Serialize(ms, network);
    ms.Position = 0;
    byte[] serialized = ms.ToArray();
    return serialized;
}
+2
source

Encog also has a splash screen / bootloader:

EncogDirectoryPersistence.SaveObject(new System.IO.FileInfo(txtSaveFile.Text), _network);

_network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(new FileInfo(txtSaveFile.Text));
+8
source

All Articles