Exemple #1
0
        private static void write_about_attribute(XmlWriter writer, c_samples_set.Attribune_Info attribuneInfo)
        {
            writer.WriteStartElement("Attribute");
            writer.WriteAttributeString("Name", attribuneInfo.Name);
            if (attribuneInfo.labels_values.Count > 0)
            {
                writer.WriteAttributeString("Type", "Enum");
                writer.WriteStartElement("Enum");
                writer.WriteAttributeString("Count", XmlConvert.ToString(attribuneInfo.labels_values.Count));
                for (int i = 0; i < attribuneInfo.labels_values.Count; i++)
                {
                    writer.WriteStartElement("Enum");
                    writer.WriteAttributeString("Value", attribuneInfo.labels_values[i]);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
            else
            {
                writer.WriteAttributeString("Type", "Interval");
                writer.WriteElementString("Min", XmlConvert.ToString(attribuneInfo.Min));
                writer.WriteElementString("Max", XmlConvert.ToString(attribuneInfo.Max));
            }

            writer.WriteEndElement();
        }
Exemple #2
0
        public static c_samples_set Load_test_from_UFS(this c_samples_set table_set, string file_name)
        {       //init
            c_samples_set temp_set = null;
            List <c_samples_set.Attribune_Info> input_Attribute = new List <c_samples_set.Attribune_Info>();
            List <c_samples_set.Row_Sample>     data_Row        = new List <c_samples_set.Row_Sample>();

            c_samples_set.Attribune_Info output_Attribute = new c_samples_set.Attribune_Info();
            string opened_dataset;

            //parse_start
            XmlDocument Source = new XmlDocument();

            Source.Load(file_name);

            XmlNode table_node = Source.DocumentElement.SelectSingleNode("descendant::Table[@Type='Testing'] "); //We get learning table

            if (table_node == null)
            {
                throw new System.FormatException("В файле нет таблиц данных");
            }
            opened_dataset        = table_node.Attributes.GetNamedItem("Name").Value;
            output_Attribute.Name = table_node.Attributes.GetNamedItem("Output").Value;

            XmlNode attrib_node = table_node.SelectSingleNode("Attributes"); //We get atribute's tags

            int count_attribs = XmlConvert.ToInt32(attrib_node.Attributes.GetNamedItem("Count").Value);

            for (int k = 0; k <= count_attribs; k++)
            {
                c_samples_set.Attribune_Info temp_attib = new c_samples_set.Attribune_Info();
                temp_attib.Name = attrib_node.ChildNodes[k].Attributes.GetNamedItem("Name").Value;  // We get one attribute tag
                foreach (XmlNode Value in attrib_node.ChildNodes[k].ChildNodes)
                {
                    double temp_double = XmlConvert.ToDouble(Value.InnerXml);
                    switch (Value.Name)
                    {
                    case "Min": { temp_attib.Min = temp_double; break; }

                    case "Max": { temp_attib.Max = temp_double; break; }
                    }
                }
                if (temp_attib.Name.Equals(output_Attribute.Name, StringComparison.OrdinalIgnoreCase))
                {
                    output_Attribute = temp_attib;
                }
                else
                {
                    input_Attribute.Add(temp_attib);
                }
            }

            XmlNode rows_node = table_node.SelectSingleNode("Rows"); //We get data rows


            int count_rows = XmlConvert.ToInt32(rows_node.Attributes.GetNamedItem("Count").Value);

            for (int r = 0; r < count_rows; r++)
            {
                string   Classifier_value;
                double[] double_value = new double[count_attribs];
                string[] string_value = new string[count_attribs];
                for (int a = 0; a < count_attribs; a++)
                {
                    XmlNode value = rows_node.ChildNodes[r].SelectSingleNode(input_Attribute[a].Name);
                    try { double_value[a] = XmlConvert.ToDouble(value.InnerXml); }
                    catch
                    {
                        string_value[a] = value.InnerText;
                    }
                }

                XmlNode outvalue = rows_node.ChildNodes[r].SelectSingleNode(output_Attribute.Name);
                Classifier_value = outvalue.InnerText;


                c_samples_set.Row_Sample temp_rows = new c_samples_set.Row_Sample(double_value, string_value, Classifier_value);
                data_Row.Add(temp_rows);
            }
            temp_set = new c_samples_set(opened_dataset, data_Row, input_Attribute, output_Attribute);
            GC.Collect();
            return(temp_set);
        }