private void btnNetworkNew_Click(object sender, EventArgs e)
        {
            string numInputs  = this.txtNumInput.Text;
            string numHiddens = this.txtNumHidden.Text;
            string numOutputs = this.txtNumOutput.Text;

            if (numInputs == "" || numHiddens == "" || numOutputs == "")
            {
                System.Windows.Forms.MessageBox.Show("Please insert the number of Input Nodes, Hidden Nodes, Output Nodes", null, System.Windows.Forms.MessageBoxButtons.OK);
                return;
            }
            try
            {
                NeuralModel = new Neural(Int32.Parse(numInputs), Int32.Parse(numHiddens), Int32.Parse(numOutputs));
                NeuralModel.SetData(_errorSeries);
                System.Windows.Forms.MessageBox.Show("NetWork configuration successfull, You can train it");

                this.txtNumOutput.Enabled    = false;
                this.txtNumHidden.Enabled    = false;
                this.txtNumInput.Enabled     = false;
                this.btnNetworkNew.Enabled   = false;
                this.btnNetworkLoad.Enabled  = false;
                this.btnNetworkSave.Enabled  = true;
                this.btnNetworkClear.Enabled = true;

                this.btnTrainNeural.Enabled = true;
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show(exception.Message);
            }
        }
 private void InitData()
 {
     _dataSeries  = new List <double>();
     _errorSeries = new List <double>();
     ARIMAModel   = new ARIMA();
     NeuralModel  = new Neural();
 }
 private void button1_Click(object sender, EventArgs e)
 {
     _errorSeries = _dataSeries.FindAll(item => true);
     NeuralModel  = new Neural();
     NeuralModel.SetData(_errorSeries);
     btnNetworkNew.Enabled     = true;
     btnNetworkLoad.Enabled    = true;
     btnPlotNeural.Enabled     = true;
     this.txtNumOutput.Enabled = false;
     this.txtNumHidden.Enabled = true;
     this.txtNumInput.Enabled  = true;
 }
        private void btnNetworkClear_Click(object sender, EventArgs e)
        {
            NeuralModel = new Neural();
            NeuralModel.SetData(_errorSeries);

            this.txtNumInput.Text     = "";
            this.txtNumHidden.Text    = "";
            this.txtNumInput.Enabled  = true;
            this.txtNumHidden.Enabled = true;

            this.btnNetworkNew.Enabled   = true;
            this.btnNetworkLoad.Enabled  = true;
            this.btnNetworkSave.Enabled  = false;
            this.btnNetworkClear.Enabled = false;

            this.btnTrainNeural.Enabled    = false;
            this.btnTestNeural.Enabled     = false;
            this.btnForecastNeural.Enabled = false;
        }
        private void btnNetworkSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Title      = "Save Network Config File";
            saveDialog.DefaultExt = "xml";
            DialogResult result   = saveDialog.ShowDialog();
            string       dataFile = "";

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                dataFile = saveDialog.FileName;
                bool exportResult = Neural.Export(NeuralModel, dataFile);
            }
            else
            {
                return;
            }
        }
        private void btnNetworkLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Title      = "Load Network Config File";
            fileDialog.DefaultExt = "xml";
            DialogResult result   = fileDialog.ShowDialog();
            string       dataFile = "";

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                dataFile = fileDialog.FileName;
                Neural temp = Neural.Import(dataFile);
                if (temp == null)
                {
                    System.Windows.Forms.MessageBox.Show("The Input file is not correct format !!!", null, System.Windows.Forms.MessageBoxButtons.OK);
                }
                else
                {
                    NeuralModel = temp;
                    NeuralModel.SetData(_errorSeries);

                    this.txtNumInput.Text        = NeuralModel.m_iNumInputNodes.ToString();
                    this.txtNumHidden.Text       = NeuralModel.m_iNumHiddenNodes.ToString();
                    this.btnNetworkNew.Enabled   = false;
                    this.btnNetworkLoad.Enabled  = false;
                    this.btnNetworkSave.Enabled  = true;
                    this.btnNetworkClear.Enabled = true;

                    this.btnTrainNeural.Enabled    = true;
                    this.btnForecastNeural.Enabled = true;
                    this.btnTestNeural.Enabled     = true;

                    this.btnForecast.Enabled = true;
                    this.btnTest.Enabled     = true;
                }
            }
            else
            {
                return;
            }
        }
Пример #7
0
        public static bool Export(Neural network, string pathFile)
        {
            XmlDocument doc  = new XmlDocument();
            XmlElement  root = doc.CreateElement("Network");

            doc.AppendChild(root);
            //save number of Input, Hidden, Output Nodes
            XmlElement numInput = doc.CreateElement("numInputNodes");

            numInput.InnerText = Convert.ToString(network.m_iNumInputNodes);
            XmlElement numHidden = doc.CreateElement("numHiddenNodes");

            numHidden.InnerText = Convert.ToString(network.m_iNumHiddenNodes);
            XmlElement numOutput = doc.CreateElement("numOutputNodes");

            numOutput.InnerText = Convert.ToString(network.m_iNumOutputNodes);
            root.AppendChild(numInput);
            root.AppendChild(numHidden);
            root.AppendChild(numOutput);
            //save input nodes
            XmlElement InputNodes = doc.CreateElement("InputNodes");

            for (int i = 0; i <= network.m_iNumInputNodes; i++)
            {
                XmlElement aInputNode = doc.CreateElement("Input" + Convert.ToString(i + 1));
                //save activation func
                if (network.m_arInputNodes[i].m_activeFuncType == ActionvationFunction.SIGMOID_FUNCTION)
                {
                    XmlElement actFunc = doc.CreateElement("activateFunc");
                    actFunc.InnerText = "SIGMOID_FUNCTION";
                    aInputNode.AppendChild(actFunc);
                }

                //save weight for in-hid connection
                for (int j = 0; j < network.m_iNumHiddenNodes; j++)
                {
                    XmlElement aWeight = doc.CreateElement("InHid" + Convert.ToString(i + 1) + Convert.ToString(j + 1));
                    aWeight.InnerText = Convert.ToString(network.m_arInputHiddenConn[i, j]);
                    aInputNode.AppendChild(aWeight);
                }
                InputNodes.AppendChild(aInputNode);
            }
            root.AppendChild(InputNodes);

            //save hidden nodes
            XmlElement HiddenNodes = doc.CreateElement("HiddenNodes");

            for (int i = 0; i <= network.m_iNumHiddenNodes; i++)
            {
                XmlElement aHiddenNode = doc.CreateElement("Hidden" + Convert.ToString(i + 1));
                //save activation func
                if (network.m_arHiddenNodes[i].m_activeFuncType == ActionvationFunction.SIGMOID_FUNCTION)
                {
                    XmlElement actFunc = doc.CreateElement("activateFunc");
                    actFunc.InnerText = "SIGMOID_FUNCTION";
                    aHiddenNode.AppendChild(actFunc);
                }

                //save weight for hid-out connection
                for (int j = 0; j < network.m_iNumOutputNodes; j++)
                {
                    XmlElement aWeight = doc.CreateElement("HidOut" + Convert.ToString(i + 1) + Convert.ToString(j + 1));
                    aWeight.InnerText = Convert.ToString(network.m_arHiddenOutputConn[i, j]);
                    aHiddenNode.AppendChild(aWeight);
                }
                HiddenNodes.AppendChild(aHiddenNode);
            }
            root.AppendChild(HiddenNodes);

            //save output nodes
            XmlElement OutputNodes = doc.CreateElement("OutputNodes");

            for (int i = 0; i < network.m_iNumOutputNodes; i++)
            {
                XmlElement aOutputNode = doc.CreateElement("Output" + Convert.ToString(i + 1));
                //save activation func
                if (network.m_arOutputNodes[i].m_activeFuncType == ActionvationFunction.SIGMOID_FUNCTION)
                {
                    XmlElement actFunc = doc.CreateElement("activateFunc");
                    actFunc.InnerText = "SIGMOID_FUNCTION";
                    aOutputNode.AppendChild(actFunc);
                }

                OutputNodes.AppendChild(aOutputNode);
            }
            root.AppendChild(OutputNodes);
            doc.Save(pathFile);
            return(true);
        }
Пример #8
0
        public static Neural Import(string pathFile)
        {
            XmlDocument input         = new XmlDocument();
            Neural      loadedNetwork = null;

            try
            {
                input.Load(pathFile);
                XmlNode root = input.FirstChild;
                //Get number of input, hidden, output nodes
                int numInputNodes  = Int32.Parse(root.SelectSingleNode("descendant::numInputNodes").InnerText);
                int numHiddenNodes = Int32.Parse(root.SelectSingleNode("descendant::numHiddenNodes").InnerText);
                int numOutputNodes = Int32.Parse(root.SelectSingleNode("descendant::numOutputNodes").InnerText);
                //create a network
                loadedNetwork = new Neural(numInputNodes, numHiddenNodes, numOutputNodes);
                //Get Input Nodes
                for (int i = 0; i <= loadedNetwork.m_iNumInputNodes; i++)
                {
                    //get a input node
                    XmlNode tempNode = root.SelectSingleNode("descendant::Input" + Convert.ToString(i + 1));
                    //get activation function type
                    string activationFunc = tempNode.SelectSingleNode("descendant::activateFunc").InnerText;
                    if (activationFunc.Equals("SIGMOID_FUNCTION"))
                    {
                        loadedNetwork.m_arInputNodes[i].m_activeFuncType = ActionvationFunction.SIGMOID_FUNCTION;
                    }
                    //get weight
                    for (int j = 0; j < loadedNetwork.m_iNumHiddenNodes; j++)
                    {
                        loadedNetwork.m_arInputHiddenConn[i, j] = Convert.ToDouble(tempNode.SelectSingleNode("descendant::InHid" + Convert.ToString(i + 1) + Convert.ToString(j + 1)).InnerText);
                    }
                }
                //Get Hidden Nodes
                for (int i = 0; i <= loadedNetwork.m_iNumHiddenNodes; i++)
                {
                    //get a hidden node
                    XmlNode tempNode = root.SelectSingleNode("descendant::Hidden" + Convert.ToString(i + 1));
                    //get activation function type
                    string activationFunc = tempNode.SelectSingleNode("descendant::activateFunc").InnerText;
                    if (activationFunc.Equals("SIGMOID_FUNCTION"))
                    {
                        loadedNetwork.m_arHiddenNodes[i].m_activeFuncType = ActionvationFunction.SIGMOID_FUNCTION;
                    }

                    for (int j = 0; j < loadedNetwork.m_iNumOutputNodes; j++)
                    {
                        loadedNetwork.m_arHiddenOutputConn[i, j] = Convert.ToDouble(tempNode.SelectSingleNode("descendant::HidOut" + Convert.ToString(i + 1) + Convert.ToString(j + 1)).InnerText);
                    }
                }
                //Get Output Nodes
                for (int i = 0; i < loadedNetwork.m_iNumOutputNodes; i++)
                {
                    //get a output node
                    XmlNode tempNode = root.SelectSingleNode("descendant::Output" + Convert.ToString(i + 1));
                    //get activation function type
                    string activationFunc = tempNode.SelectSingleNode("descendant::activateFunc").InnerText;
                    if (activationFunc.Equals("SIGMOID_FUNCTION"))
                    {
                        loadedNetwork.m_arOutputNodes[i].m_activeFuncType = ActionvationFunction.SIGMOID_FUNCTION;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
            return(loadedNetwork);
        }
        private void btnGetData_Click(object sender, EventArgs e)
        {
            _dataSeries = new List <double>();
            System.IO.StreamReader file = null;
            string line = null;
            bool   isFormatFileRight = true;
            int    beginRow          = Convert.ToInt32(this.txtTrainDataFromRow.Text);
            int    endRow            = Convert.ToInt32(this.txtTrainDataToRow.Text);
            int    columnSelected    = Convert.ToInt32(this.txtTrainDataColumn.Text);
            int    idxRow            = 0;

            try
            {
                file = new System.IO.StreamReader(m_TrainingDataFile);
                while ((line = file.ReadLine()) != null)
                {
                    idxRow++;
                    if (idxRow < beginRow || idxRow > endRow)
                    {
                        continue;
                    }

                    char[]        delimiterChars = { ' ', ',' };
                    List <String> words          = new List <string>();
                    words.AddRange(line.Split(delimiterChars));
                    words.RemoveAll(item => "" == item);

                    if (columnSelected <= words.Count)
                    {
                        _dataSeries.Add(Double.Parse(words[columnSelected - 1]));
                    }
                    else
                    {
                        isFormatFileRight = false;
                        break;
                    }
                }
                if (!isFormatFileRight)
                {
                    MessageBox.Show("Input is wrong format", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _dataSeries = null;
                }
            }
            catch (System.OutOfMemoryException outOfMemory)
            {
                _dataSeries = null;
                MessageBox.Show("File does not found", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.IO.IOException io)
            {
                _dataSeries = null;
                MessageBox.Show("File does not found", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.Exception excp)
            {
                _dataSeries = null;
                MessageBox.Show("Input is wrong format", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }

            if (_dataSeries != null)
            {
                SettingGetData();
                ARIMAModel  = new ARIMA();
                NeuralModel = new Neural();
                ARIMAModel.SetData(_dataSeries);
            }
            else
            {
                MessageBox.Show("Load data fail", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }