private static void write_about_rows(XmlWriter writer, a_samples_set samplesSet) { writer.WriteStartElement("Rows"); writer.WriteAttributeString("Count", XmlConvert.ToString(samplesSet.Data_Rows.Count())); for (int i = 0; i < samplesSet.Data_Rows.Count; i++) { writer.WriteStartElement("Row"); for (int j = 0; j < samplesSet.Count_Vars; j++) { if (samplesSet.Input_Attributes[j].labels_values.Count() > 0) { writer.WriteElementString(samplesSet.Input_Attributes[j].Name, samplesSet.Data_Rows[i].Input_Attribute_String[j]); } else { writer.WriteElementString(samplesSet.Input_Attributes[j].Name, XmlConvert.ToString(samplesSet.Data_Rows[i].Input_Attribute_Value[j])); } } writer.WriteElementString(samplesSet.Output_Attributes.Name, XmlConvert.ToString(samplesSet.Data_Rows[i].Approx_Value)); writer.WriteEndElement(); } writer.WriteEndElement(); }
public bool Load_learn_set(string file_name) { switch (new FileInfo(file_name).Extension) { case ".dat": { Approx_learn_set = new a_samples_set(file_name); return(false); } case ".ufs": { Approx_learn_set = Approx_learn_set.Load_learn_from_UFS(file_name); try { Approx_test_set = Approx_test_set.Load_test_from_UFS(file_name); is_UFS = true; return(true); } catch { return(false); } } default: { Approx_learn_set = Approx_learn_set.Load_learn_from_UFS(file_name); try { Approx_test_set = Approx_test_set.Load_test_from_UFS(file_name); is_UFS = true; return(true); } catch { return(false); } } } }
private static void write_about_table(XmlWriter writer, a_samples_set samplesSet, a_Fuzzy_System Approximate) { writer.WriteStartElement("Table"); writer.WriteAttributeString("Name", samplesSet.File_Name); if (samplesSet == Approximate.Learn_Samples_set) { writer.WriteAttributeString("Type", "Training"); } else { writer.WriteAttributeString("Type", "Testing"); } writer.WriteAttributeString("Output", samplesSet.Output_Attributes.Name); writer.WriteStartElement("Attributes"); writer.WriteAttributeString("Count", XmlConvert.ToString(samplesSet.Count_Vars)); for (int i = 0; i < samplesSet.Count_Vars; i++) { write_about_attribute(writer, samplesSet.Input_Attributes[i]); } write_about_attribute(writer, samplesSet.Output_Attributes); writer.WriteEndElement(); write_about_rows(writer, samplesSet); writer.WriteEndElement(); }
public k_mean_base(a_samples_set Learn_table, int Max_iter, double precision_needed, int needed_count_clusters, double nebula) { learn_table = Learn_table; Max_iterate = Max_iter; Needed_precision = precision_needed; count_clusters = needed_count_clusters; nebulisation_factor = nebula; }
private double[] extract_Sample_table_Out(a_samples_set learn_Set) { double[] Result = new double[learn_Set.Count_Samples]; for (int i = 0; i < learn_Set.Count_Samples; i++) { Result[i] = learn_Set.Data_Rows[i].Approx_Value; } return(Result); }
public Individ(Individ the_individ) { hrom_vector = new Hromosom(the_individ.hrom_vector); step_rotate = new List <double>(the_individ.step_rotate); step_sko = new List <double>(the_individ.step_sko); count_step_rotate = the_individ.count_step_rotate; count_step_sko = the_individ.count_step_sko; Data = the_individ.Data; }
public Population(int count_population, int count_child, int count_v, a_samples_set data) { size_populate = count_population; size_child = count_child; the_popualate = new List <Individ>(count_population); the_parents = new List <Individ>(count_population); the_childs = new List <Individ>(count_child); count_vars = count_v; Data = data; }
public void init_constrain(Random rand, a_samples_set Data) { for (int j = 0; j < Fenotip_terms.Count; j++) { Term temp_term = Fenotip_terms[j]; for (int i = 0; i < temp_term.Parametrs.Count(); i++) { temp_term.Parametrs[i] = temp_term.Parametrs[i] + Data.Attribute_Scatter(temp_term.Number_of_Input_Var) * (rand.NextDouble() - 0.5) * 0.1; } } }
private double[,] extract_Sample_table(a_samples_set learn_Set) { double[,] Result = new double[learn_Set.Count_Samples, learn_Set.Count_Vars]; for (int i = 0; i < learn_Set.Count_Samples; i++) { for (int j = 0; j < learn_Set.Count_Vars; j++) { Result[i, j] = learn_Set.Data_Rows[i].Input_Attribute_Value[j]; } } return(Result); }
public void init_random(Random rand, a_samples_set Data) { for (int j = 0; j < Fenotip_terms.Count; j++) { Term temp_term = Fenotip_terms[j]; for (int i = 0; i < temp_term.Parametrs.Count(); i++) { temp_term.Parametrs[i] = Data.Attribute_Min(temp_term.Number_of_Input_Var) + Data.Attribute_Scatter(temp_term.Number_of_Input_Var) * rand.NextDouble(); } } for (int j = 0; j < Fenotip_kons.Count; j++) { Fenotip_kons[j] = Data.Output_Attributes.Min + Data.Output_Attributes.Scatter * rand.NextDouble(); } }
public Individ(Knowlege_base_ARules Source, a_samples_set data, int count_vars, bool the_first, Random rand, Type_init par_type_init) { hrom_vector = new Hromosom(new Knowlege_base_ARules(Source)); step_sko = new List <double>(count_vars); step_rotate = new List <double>(count_vars); count_step_sko = count_vars; count_step_rotate = count_vars; Data = data; for (int i = 0; i < count_vars; i++) { step_sko.Add(0 + rand.NextDouble() * (data.Attribute_Scatter(i) * 0.05)); step_rotate.Add(-1 * Math.PI + rand.NextDouble() * 2 * Math.PI); } if (!the_first) { switch (par_type_init) { case Type_init.Случайная: hrom_vector.init_random(rand, data); break; case Type_init.Ограниченная: hrom_vector.init_constrain(rand, data); break; } } }
public void Load_test_set(string file_name) { switch (new FileInfo(file_name).Extension) { case ".dat": { Approx_test_set = new a_samples_set(file_name); break; } case ".ufs": { Approx_test_set = Approx_test_set.Load_test_from_UFS(file_name); break; } default: { Approx_test_set = Approx_test_set.Load_test_from_UFS(file_name); break; } } }
public k_mean_Gustafson_kessel(a_samples_set Learn_table, int Max_iter, double precision_needed, int needed_count_clusters, double nebula) : base(Learn_table, Max_iter, precision_needed, needed_count_clusters, nebula) { }
public static a_samples_set Load_test_from_UFS(this a_samples_set table_set, string file_name) { //init a_samples_set temp_set = null; List <a_samples_set.Attribune_Info> input_Attribute = new List <a_samples_set.Attribune_Info>(); List <a_samples_set.Row_Sample> data_Row = new List <a_samples_set.Row_Sample>(); a_samples_set.Attribune_Info output_Attribute = new a_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++) { a_samples_set.Attribune_Info temp_attib = new a_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++) { double Approx_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); Approx_value = XmlConvert.ToDouble(outvalue.InnerXml); a_samples_set.Row_Sample temp_rows = new a_samples_set.Row_Sample(double_value, string_value, Approx_value); data_Row.Add(temp_rows); } temp_set = new a_samples_set(opened_dataset, data_Row, input_Attribute, output_Attribute); GC.Collect(); return(temp_set); }