Esempio n. 1
0
        public static DataSection[] Parse(string fileName)
        {
            List<DataSection> dataSecList = new List<DataSection>();
            using (StreamReader srIni = ZStreamReader.Open(fileName))
            {
                string line;
                DataSection dataSec = null;
                while ((line = srIni.ReadLine()) != null)
                {
                    line.Trim();

                    if (line.StartsWith("["))
                    {
                        if (dataSec != null)
                        {
                            dataSecList.Add(dataSec);
                        }

                        string name = Regex.Replace(line, @"\[(.*?)\]", "$1");
                        dataSec = new DataSection(name);
                    }
                    else
                    {
                        if (line.Length > 0 &&
                            //igore comments
                            !line.StartsWith(";") &&
                            !line.StartsWith("C:", StringComparison.CurrentCultureIgnoreCase))
                        {
                            dataSec.AddData(line);
                        }
                    }
                }

                if (dataSec != null)
                {
                    dataSecList.Add(dataSec);
                }
            }
            return dataSecList.ToArray();
        }
Esempio n. 2
0
 public InputTransform(DataSection dataSec)
 {
     string[] fields = dataSec.Name.Split(':');
     this.inputID = int.Parse(fields[1]);
     for (int i = 0; i < dataSec.Data.Length; i++)
     {
         if (dataSec.Data[i].StartsWith("Name="))
         {
             fields = dataSec.Data[i].Split('=');
             this.ftrName = fields[1];
         }
         else if (dataSec.Data[i].StartsWith("Transform="))
         {
             fields = dataSec.Data[i].Split('=');
             this.funcName = fields[1];
             this.transformFunc = TransformFunction.Create(this.funcName, dataSec.Data, i + 1);
         }
     }
 }
Esempio n. 3
0
 private static bool IsType(DataSection dataSec)
 {
     if (dataSec.Name.StartsWith("NeuralNet"))
     {
         return true;
     }
     return false;
 }
Esempio n. 4
0
 private NNModelMSN(DataSection dataSec)
 {
     string[] fields;
     for (int i = 0; i < dataSec.Data.Length; i++)
     {
         if (dataSec.Data[i].StartsWith("Layers="))
         {
             fields = dataSec.Data[i].Split('=');
             this.cNodeLayer = int.Parse(fields[1]);
         }
         else if (dataSec.Data[i].StartsWith("Inputs="))
         {
             fields = dataSec.Data[i].Split('=');
             this.cInputs = int.Parse(fields[1]);
         }
     }
 }
Esempio n. 5
0
 public static bool IsType(DataSection dataSec)
 {
     if (dataSec.Name.StartsWith("Layer:"))
     {
         return true;
     }
     return false;
 }
Esempio n. 6
0
 //construct a layer from data
 public NodeLayer(DataSection dataSec)
 {
     string[] fields = dataSec.Name.Split(':');
     this.layerID = int.Parse(fields[1]);
     for (int i = 0; i < dataSec.Data.Length; i++)
     {
         if (dataSec.Data[i].StartsWith("nodes=", StringComparison.CurrentCultureIgnoreCase))
         {
             fields = dataSec.Data[i].Split('=');
             this.cNodes = int.Parse(fields[1]);
         }
     }
     nodes = new Node[this.cNodes];
     outputs = new float[this.cNodes];
 }
Esempio n. 7
0
        private float[] Weights; //Weights[0] is the bias

        #endregion Fields

        #region Constructors

        //construct node from .ini configuration/description
        public Node(DataSection dataSec)
        {
            string[] fields = dataSec.Name.Split(':');
            this.layerID = int.Parse(fields[1]);
            this.nodeID = int.Parse(fields[2]);
            List<float> weightList = new List<float>();
            List<int> idxList = new List<int>();
            for (int i = 0; i < dataSec.Data.Length; i++)
            {
                if (dataSec.Data[i].StartsWith("Weight:"))
                {
                    fields = dataSec.Data[i].Split(':');
                    fields = fields[1].Split('=');
                    idxList.Add(int.Parse(fields[0]));
                    weightList.Add(float.Parse(fields[1]));
                }
                else if (dataSec.Data[i].StartsWith("Type="))
                {
                    fields = dataSec.Data[i].Split('=');
                    if (string.Compare(fields[1], "Tanh", StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        this.transFunc = TransferFunction.Tanh;
                    }
                    else if (string.Compare(fields[1], "Sigmoid", StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        this.transFunc = TransferFunction.Sigmoid;
                    }
                    else if (string.Compare(fields[1], "Linear", StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        this.transFunc = TransferFunction.Linear;
                    }
                    else if (string.Compare(fields[1], "Logistic", StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        this.IsLogistic = true;
                    }
                }
            }
            this.Weights = new float[weightList.Count];
            for (int i = 0; i < this.Weights.Length; i++)
            {
                this.Weights[idxList[i]] = weightList[i];
            }
        }