//Ok save net works working now.  something wrong with the call not hitting so this work around.
    public void savenetwork()
    {
        #if DebugA
        GD.Print("Made it to the C# save Network script");
        #endif
        NeuralNetworks.NetworkData MyNet = MoveShootNet.GetNetworkData();

        //NeuralNetwork.SaveNetworkToFile(MyNet,"SomeNetwork.xml");  //not compatable with Mono 5.18 is compatable with 5.4
        System.Xml.Serialization.XmlSerializer Aserialiser = new  System.Xml.Serialization.XmlSerializer(typeof(NeuralNetworks.NetworkData));
        //System.Xml.Serialization.XmlSerializer Aserialiser = new XmlSerializer(typeof(List<NeuralNetworks.LayerData>));
        //System.Xml.Serialization.XmlSerializer Bserialiser = new XmlSerializer(typeof(List<NeuralNetworks.ConnectionData>));
        try
        {
            //System.IO.TextWriter writer = new System.IO.StreamWriter("TheNeworkFileA.xml");
            System.IO.TextWriter writer = new System.IO.StreamWriter("SomeNetwork.xml");
            Aserialiser.Serialize(writer, MyNet);
            writer.Close();
        }
        catch
        {
            GD.Print("But Failed to Save DataA");//Not Normaly printed.
        }

        // try
        // {
        //     System.IO.TextWriter writer = new System.IO.StreamWriter("TheNeworkFileB.xml");
        //     Bserialiser.Serialize(writer, MyNet.Connections);
        //     writer.Close();
        // }
        // catch
        // {
        //     GD.Print("But Failed to Save DataB");
        // }
    }
Example #2
0
        public static NetworkData ReadNetworkFromFile(string filename)
        {
            NetworkData data;

            if (File.Exists(filename))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(NetworkData));
                    FileStream    stream     = new FileStream(filename, FileMode.Open);
                    data = (NetworkData)serializer.Deserialize(stream);
                    stream.Close();
                }

                catch
                {
                    MessageBox.Show("Network File Read Error: " + filename, "Error");
                    data = new NetworkData();
                }
            }

            else
            {
                MessageBox.Show("File Not Found: " + filename, "Not Found");
                data = new NetworkData();
            }

            return(data);
        }
Example #3
0
 public BackPropogationNetwork(NetworkData data)
     : base(data)
 {
     if (data != null)
         //MessageBox.Show("File Read");
         ;
     else
         MessageBox.Show("From dll: File Not Found");
 }
    //Ok Load net works working now.
    //But can not write to NumLayers because it is read only but cout rectreat Using simple constructer.
    public void loadnetwork()
    {
        int Anum;

        NeuralNetworks.NetworkData MyNet = MoveShootNet.GetNetworkData();
        //NeuralNetworks.NetworkData MyNet2 = NeuralNetwork.ReadNetworkFromFile("SomeNetwork.xml"); // Not working some this about handing over to this funciton

        // NeuralNetworks.NetworkData MyNet2 = MoveShootNet.GetNetworkData();
        // System.Collections.Generic.IEnumerable <double> SomeBiases = new double[18];


        //This works which is lucky
        if (System.IO.File.Exists("SomeNetwork.xml"))
        {
            try
            {
                System.Xml.Serialization.XmlSerializer Aserialiser = new XmlSerializer(typeof(NeuralNetworks.NetworkData));
                System.IO.FileStream Astream = new System.IO.FileStream("SomeNetwork.xml", System.IO.FileMode.Open);
                MyNet = (NeuralNetworks.NetworkData)Aserialiser.Deserialize(Astream);
                Astream.Close();
            }
            catch
            {
                GD.Print("But Failed to Load File");//Not Normaly printed.
            }
        }
        else
        {
            GD.Print("But Failed to Find File"); //Not Normaly printed.
        }
        // //MoveShootNet = new BackPropogationNetwork(MyNet2);
        //MoveShootNet.Layers[0].SetValues(MyNet.Layers[0].Bias);

        MoveShootNet.Layers = new NeuralNetworks.Layer[MyNet.Layers.Count];
        foreach (NeuralNetworks.LayerData ld in MyNet.Layers)
        {
            MoveShootNet.Layers[MyNet.Layers.IndexOf(ld)] = new NeuralNetworks.Layer(MyNet.Layers.IndexOf(ld), ld.NumNeuron, ld.ActType, ld.Bias);
        }

        foreach (ConnectionData cd in MyNet.Connections)
        {
            MoveShootNet.Layers[cd.From.Layer].Neurons[cd.From.Node].AddConnection(MoveShootNet.Layers[cd.To.Layer].Neurons[cd.To.Node], true, cd.Weight);
        }

        MoveShootNet.InputIndex  = MyNet.InputLayerId;
        MoveShootNet.OutputIndex = MyNet.OutputLayerId;

        // SomeBiases = MyNet.Layers[0].Bias;
        // Anum = MyNet.Layers[0].Bias.Count;
        // Anum = SomeBiases.Count();
        // GD.Print("Anum is ",(Anum));
        // GD.Print("Bias is ",(SomeBiases));

        //MoveShootNet = new NeuralNetworks.BackPropogationNetwork(MyNet); // Not working heap miss alinment ?
    }
Example #5
0
 public BackPropogationNetwork(NetworkData data)
     : base(data)
 {
     if (data != null)
     {
         //MessageBox.Show("File Read");
         ;
     }
     else
     {
         MessageBox.Show("From dll: File Not Found");
     }
 }
Example #6
0
        public static void SaveNetworkToFile(NetworkData netdata, string filename)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(NetworkData));
                TextWriter    writer     = new StreamWriter(filename);
                serializer.Serialize(writer, netdata);
                writer.Close();
            }

            catch
            {
                MessageBox.Show("File Not Saved: ", filename);
            }
        }
Example #7
0
        public NeuralNetwork(NetworkData network)
        {
            Layers = new Layer[network.Layers.Count];

            NumLayers = network.Layers.Count;
            foreach (LayerData ld in network.Layers)
            {
                Layers[network.Layers.IndexOf(ld)] = new Layer(network.Layers.IndexOf(ld), ld.NumNeuron, ld.ActType, ld.Bias);
            }

            foreach (ConnectionData cd in network.Connections)
            {
                Layers[cd.From.Layer].Neurons[cd.From.Node].AddConnection(Layers[cd.To.Layer].Neurons[cd.To.Node], true, cd.Weight);
            }

            InputIndex  = network.InputLayerId;
            OutputIndex = network.OutputLayerId;
        }
Example #8
0
        public static void SaveNetworkToFile(NetworkData netdata, string filename)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(NetworkData));
                TextWriter writer = new StreamWriter(filename);
                serializer.Serialize(writer, netdata);
                writer.Close();
            }

            catch
            {
                MessageBox.Show("File Not Saved: ", filename);
            }
        }
Example #9
0
        public static NetworkData ReadNetworkFromFile(string filename)
        {
            NetworkData data;

            if (File.Exists(filename))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(NetworkData));
                    FileStream stream = new FileStream(filename, FileMode.Open);
                    data = (NetworkData)serializer.Deserialize(stream);
                    stream.Close();
                }

                catch
                {
                    MessageBox.Show("Network File Read Error: " + filename, "Error");
                    data = new NetworkData();
                }
            }

            else
            {
                MessageBox.Show("File Not Found: " + filename, "Not Found");
                data = new NetworkData();
            }

            return data;
        }
Example #10
0
        public NeuralNetwork(NetworkData network)
        {
            Layers = new Layer[network.Layers.Count];

            NumLayers = network.Layers.Count;
            foreach (LayerData ld in network.Layers)
            {

                Layers[network.Layers.IndexOf(ld)] = new Layer(network.Layers.IndexOf(ld), ld.NumNeuron, ld.ActType, ld.Bias);
            }

            foreach (ConnectionData cd in network.Connections)
            {
                Layers[cd.From.Layer].Neurons[cd.From.Node].AddConnection(Layers[cd.To.Layer].Neurons[cd.To.Node], true, cd.Weight);
            }

            InputIndex = network.InputLayerId;
            OutputIndex = network.OutputLayerId;
        }