コード例 #1
0
 public void loadLVQNet(string path)
 {
     if (neuralReader.netConfigFound(path))
     {
         try
         {
             WeightsMatrix wm = neuralReader.readConfiguration(path);
             lvqNet = new LVQNet(wm);
         }
         catch (Exception e) {
             throw e;
         }
     }
 }
コード例 #2
0
        public WeightsMatrix readConfiguration(string path)
        {
            WeightsMatrix wm;
            string        data = "";

            try
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(path);
                data = reader.ReadToEnd();
                reader.Close();

                float[] weightsRow = new float[1];

                ArrayList netConfigMatrix = new ArrayList();

                string strctr = data.Substring(1, data.IndexOf("]", 0) - 1);
                data = data.Substring(strctr.Length + 2);
                ArrayList structure  = new ArrayList();
                int       spaceindex = 0;
                string    s          = "";
                while (true)
                {
                    spaceindex = strctr.IndexOf(" ", 0);
                    if (spaceindex == -1)
                    {
                        structure.Add(Convert.ToInt16(strctr));
                        break;
                    }
                    s = strctr.Substring(0, spaceindex);
                    structure.Add(Convert.ToInt16(s));
                    strctr = strctr.Substring(spaceindex, strctr.Length - spaceindex);
                    strctr = strctr.Trim();
                }
                netConfigMatrix.Add(structure);

                string iw = data.Substring(1, data.IndexOf("]", 0) - 1);
                data         = data.Substring(iw.Length + 2);
                double[,] IW = new double[Int32.Parse(structure[1].ToString()), Int32.Parse(structure[0].ToString())];
                spaceindex   = 0;
                int semicolonindex = 0;
                int rowCount       = 0;
                int columnCount    = 0;
                s = "";
                int inputNeruronCount = int.Parse(structure[structure.Count - 2].ToString());
                int inputNeruronIndex = 0;

                while (inputNeruronIndex < inputNeruronCount)
                {
                    semicolonindex = iw.IndexOf(";");
                    string w = "";
                    if (semicolonindex == -1)
                    {
                        w = iw.Substring(0).Trim();
                    }
                    else
                    {
                        w  = iw.Substring(0, semicolonindex).Trim();
                        iw = iw.Substring(semicolonindex + 1);
                    }
                    for (int colCount = 0; columnCount < IW.GetLength(1); colCount++)
                    {
                        spaceindex = w.IndexOf(" ", 0);
                        if (spaceindex == -1)
                        {
                            IW[rowCount, colCount] = double.Parse(w);
                            break;
                        }
                        s = w.Substring(0, spaceindex);
                        IW[rowCount, colCount] = double.Parse(s);
                        w = w.Substring(spaceindex, w.Length - spaceindex).Trim();
                    }
                    rowCount++;
                    inputNeruronIndex++;
                }

                string lw = data.Substring(1, data.IndexOf("]", 0) - 1);
                int[,] LW      = new int[Int32.Parse(structure[2].ToString()), Int32.Parse(structure[1].ToString())];
                spaceindex     = 0;
                semicolonindex = 0;
                rowCount       = 0;
                columnCount    = 0;
                s = "";
                int outputNeruronCount = int.Parse(structure[structure.Count - 1].ToString());
                int outputNeruronIndex = 0;
                while (outputNeruronIndex < outputNeruronCount)
                {
                    semicolonindex = lw.IndexOf(";");
                    string w = "";
                    if (semicolonindex == -1)
                    {
                        w = lw.Substring(0).Trim();
                    }
                    else
                    {
                        w  = lw.Substring(0, semicolonindex).Trim();
                        lw = lw.Substring(semicolonindex + 1);
                    }
                    for (int colCount = 0; columnCount < LW.GetLength(1); colCount++)
                    {
                        spaceindex = w.IndexOf(" ", 0);
                        if (spaceindex == -1)
                        {
                            LW[rowCount, colCount] = Int32.Parse(w);
                            break;
                        }
                        s = w.Substring(0, spaceindex);
                        LW[rowCount, colCount] = Int32.Parse(s);
                        w = w.Substring(spaceindex, w.Length - spaceindex).Trim();
                    }
                    rowCount++;
                    outputNeruronIndex++;
                }
                wm = new WeightsMatrix(IW, LW);
                return(wm);
            }
            catch (Exception ioerror)
            {
                throw ioerror;
            }
        }
コード例 #3
0
 public LVQNet(WeightsMatrix wm)
 {
     layerOne = new HiddenLayer(wm.IW);
     layerTwo = new OutputLayer(wm.LW);
 }