Holds the parse results for one layer.
        /// <summary>
        /// parse a layer.
        /// </summary>
        ///
        /// <param name="line">The line to parse.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>The parsed ArchitectureLayer.</returns>
        public static ArchitectureLayer ParseLayer(String line,
            int defaultValue)
        {
            var layer = new ArchitectureLayer();

            String check = line.Trim().ToUpper();

            // first check for bias
            if (check.EndsWith(":B"))
            {
                check = check.Substring(0, (check.Length - 2) - (0));
                layer.Bias = true;
            }

            // see if simple number
            try
            {
                layer.Count = Int32.Parse(check);
                if (layer.Count < 0)
                {
                    throw new EncogError("Count cannot be less than zero.");
                }
            }
            catch (FormatException f)
            {
                EncogLogging.Log(f);
            }

            // see if it is a default
            if ("?".Equals(check))
            {
                if (defaultValue < 0)
                {
                    throw new EncogError("Default (?) in an invalid location.");
                }
                layer.Count = defaultValue;
                layer.UsedDefault = true;
                return layer;
            }

            // single item, no function
            int startIndex = check.IndexOf('(');
            int endIndex = check.LastIndexOf(')');
            if (startIndex == -1)
            {
                layer.Name = check;
                return layer;
            }

            // function
            if (endIndex == -1)
            {
                throw new EncogError("Illegal parentheses.");
            }

            layer.Name = check.Substring(0, (startIndex) - (0)).Trim();

            String paramStr = check.Substring(startIndex + 1, (endIndex) - (startIndex + 1));
            IDictionary<String, String> paras = ParseParams(paramStr);
            EngineArray.PutAll(paras, layer.Params);
            return layer;
        }
Esempio n. 2
0
 public static ArchitectureLayer ParseLayer(string line, int defaultValue)
 {
     int num;
     int num2;
     ArchitectureLayer layer = new ArchitectureLayer();
     string str = line.Trim().ToUpper();
     goto Label_0170;
     Label_0043:
     if ((((uint) defaultValue) & 0) != 0)
     {
         goto Label_00E5;
     }
     Label_005A:
     layer.Name = str.Substring(0, num).Trim();
     string str2 = str.Substring(num + 1, num2 - (num + 1));
     if ((((uint) num) | 0xff) == 0)
     {
         goto Label_00F7;
     }
     IDictionary<string, string> source = ParseParams(str2);
     EngineArray.PutAll<string, string>(source, layer.Params);
     if ((((uint) num2) & 0) != 0)
     {
         goto Label_0104;
     }
     if (((uint) defaultValue) < 0)
     {
         goto Label_005A;
     }
     return layer;
     Label_00B9:
     if (num == -1)
     {
         layer.Name = str;
         return layer;
     }
     goto Label_00E5;
     Label_00BF:
     throw new EncogError("Illegal parentheses.");
     if ((((uint) num) + ((uint) defaultValue)) >= 0)
     {
         goto Label_0043;
     }
     Label_00E5:
     if (num2 == -1)
     {
         goto Label_00BF;
     }
     if (-1 != 0)
     {
         goto Label_005A;
     }
     if (0 == 0)
     {
         if ((((uint) num) + ((uint) num2)) >= 0)
         {
             if (1 == 0)
             {
                 return layer;
             }
             goto Label_0043;
         }
         goto Label_0170;
     }
     if (0 != 0)
     {
         return layer;
     }
     goto Label_00B9;
     Label_00F7:
     if ("?".Equals(str))
     {
         if (defaultValue < 0)
         {
             throw new EncogError("Default (?) in an invalid location.");
         }
         layer.Count = defaultValue;
         if ((((uint) defaultValue) | 0x7fffffff) != 0)
         {
             layer.UsedDefault = true;
             return layer;
         }
         goto Label_00BF;
     }
     Label_0104:
     num = str.IndexOf('(');
     num2 = str.LastIndexOf(')');
     goto Label_00B9;
     Label_0170:
     if (str.EndsWith(":B"))
     {
         str = str.Substring(0, str.Length - 2);
         layer.Bias = true;
     }
     try
     {
         layer.Count = int.Parse(str);
         if (layer.Count < 0)
         {
             throw new EncogError("Count cannot be less than zero.");
         }
     }
     catch (FormatException exception)
     {
         EncogLogging.Log(exception);
     }
     goto Label_00F7;
 }
        /// <summary>
        /// parse a layer.
        /// </summary>
        ///
        /// <param name="line">The line to parse.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>The parsed ArchitectureLayer.</returns>
        public static ArchitectureLayer ParseLayer(String line,
                                                   int defaultValue)
        {
            var layer = new ArchitectureLayer();

            String check = line.Trim().ToUpper();

            // first check for bias
            if (check.EndsWith(":B"))
            {
                check      = check.Substring(0, (check.Length - 2) - (0));
                layer.Bias = true;
            }

            // see if simple number
            try
            {
                layer.Count = Int32.Parse(check);
                if (layer.Count < 0)
                {
                    throw new EncogError("Count cannot be less than zero.");
                }
            }
            catch (FormatException f)
            {
                EncogLogging.Log(f);
            }

            // see if it is a default
            if ("?".Equals(check))
            {
                if (defaultValue < 0)
                {
                    throw new EncogError("Default (?) in an invalid location.");
                }
                layer.Count       = defaultValue;
                layer.UsedDefault = true;
                return(layer);
            }

            // single item, no function
            int startIndex = check.IndexOf('(');
            int endIndex   = check.LastIndexOf(')');

            if (startIndex == -1)
            {
                layer.Name = check;
                return(layer);
            }

            // function
            if (endIndex == -1)
            {
                throw new EncogError("Illegal parentheses.");
            }

            layer.Name = check.Substring(0, (startIndex) - (0)).Trim();

            String paramStr = check.Substring(startIndex + 1, (endIndex) - (startIndex + 1));
            IDictionary <String, String> paras = ParseParams(paramStr);

            EngineArray.PutAll(paras, layer.Params);
            return(layer);
        }
        /// <summary>
        /// parse a layer.
        /// </summary>
        ///
        /// <param name="line">The line to parse.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>The parsed ArchitectureLayer.</returns>
        public static ArchitectureLayer ParseLayer(String line,
            int defaultValue)
        {
            var layer = new ArchitectureLayer();

            String check = line.Trim().ToUpper();

            // first check for bias
            if (check.EndsWith(":B"))
            {
                check = check.Substring(0, (check.Length - 2) - (0));
                layer.Bias = true;
            }

            // see if simple number
            try
            {
                //This below just removes half the exceptions (not all in case it's TAHN or similar...).
                //Lets first check if the char is a digit...
                if (!char.IsDigit(Convert.ToChar(check.Substring(0, 1))))
                {
                    //Its not a digits, its probably a ? , meaning a default value.
                    // see if it is a default
                    if ("?".Equals(check))
                    {
                        if (defaultValue < 0)
                        {
                            throw new EncogError("Default (?) in an invalid location.");
                        }
                        layer.Count = defaultValue;
                        layer.UsedDefault = true;
                        return layer;
                    }
                }
                layer.Count = Int32.Parse(check);
                if (layer.Count < 0)
                {
                    throw new EncogError("Count cannot be less than zero.");
                }
            }
            catch (FormatException f)
            {
                EncogLogging.Log(f);
            }

            // see if it is a default
            if ("?".Equals(check))
            {
                if (defaultValue < 0)
                {
                    throw new EncogError("Default (?) in an invalid location.");
                }
                layer.Count = defaultValue;
                layer.UsedDefault = true;
                return layer;
            }

            // single item, no function
            int startIndex = check.IndexOf('(');
            int endIndex = check.LastIndexOf(')');
            if (startIndex == -1)
            {
                layer.Name = check;
                return layer;
            }

            // function
            if (endIndex == -1)
            {
                throw new EncogError("Illegal parentheses.");
            }

            layer.Name = check.Substring(0, (startIndex) - (0)).Trim();

            String paramStr = check.Substring(startIndex + 1, (endIndex) - (startIndex + 1));
            IDictionary<String, String> paras = ParseParams(paramStr);
            EngineArray.PutAll(paras, layer.Params);
            return layer;
        }