Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Nowa wersja
Poprzednia wersja
pl:miw:miw08_rbs_ml:class1 [2008/05/27 00:39]
miw utworzono
pl:miw:miw08_rbs_ml:class1 [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +<​code="​csharp">​
 using System; using System;
 using System.Collections.Generic;​ using System.Collections.Generic;​
 using System.Text;​ using System.Text;​
 +using System.IO;
  
 namespace Morcinek.Machine_Learning namespace Morcinek.Machine_Learning
Linia 19: Linia 21:
  int Category { get; set;} // Może tylko set zostawić?  int Category { get; set;} // Może tylko set zostawić?
  int GetCategory(object[] attributes);​  int GetCategory(object[] attributes);​
- ShowedNode ShowTree();+ ShowedNode ShowTree(out string dotName);
  IList<​int>​ P { get; set;} // zbiór indeksów z etykietowanych przykładów dla danego liścia ​  IList<​int>​ P { get; set;} // zbiór indeksów z etykietowanych przykładów dla danego liścia ​
  }  }
Linia 133: Linia 135:
  }  }
  
- public ShowedNode ShowTree()+ public ShowedNode ShowTree(out string dotName)
  {  {
 + dotName = "";​
  ShowedNode node = new ShowedNode();​  ShowedNode node = new ShowedNode();​
  node.P = m_P.ToArray();​  node.P = m_P.ToArray();​
 + node.Category = this.Category;​
  return node;  return node;
  }  }
Linia 236: Linia 240:
  }  }
  
- public ShowedNode ShowTree()+ public ShowedNode ShowTree(out string dotName)
  {  {
 + dotName = "";​
  ShowedNode node = new ShowedNode();​  ShowedNode node = new ShowedNode();​
  node.P = m_P.ToArray();​  node.P = m_P.ToArray();​
  node.TestName = m_test.AttributeName;​  node.TestName = m_test.AttributeName;​
- foreach (ILeaf item in m_listOfLeaves.Values)+ 
 + foreach (int key in m_listOfLeaves.Keys)
  {  {
- node.Nodes.Add(item.ShowTree());​+ string temp; 
 + 
 + node.Nodes.Add(key, m_listOfLeaves[key].ShowTree(out temp));
  }  }
  return node;  return node;
Linia 251: Linia 259:
  }  }
  
 + /// <​summary>​
 + /// Klasa służy do pokazania sobie jak jest drzewo zbudowane
 + /// </​summary>​
  public class ShowedNode  public class ShowedNode
  {  {
  string m_testName;  string m_testName;
  int[] m_P;  int[] m_P;
- List<​ShowedNode>​ m_nodes = new List<​ShowedNode>​();​+ Dictionary<int, ShowedNode>​ m_nodes = new Dictionary<int, ShowedNode>​()
 + private int m_category;​ 
 + private static int counter = 0; 
 + 
 + public static StreamWriter sw;
  
  public string TestName  public string TestName
Linia 281: Linia 296:
  }  }
  
- public ​List<​ShowedNode>​ Nodes+ public ​int Category 
 +
 + get 
 +
 + return m_category;​ 
 +
 + set 
 +
 + m_category = value; 
 +
 +
 + 
 + public Dictionary<int, ShowedNode>​ Nodes
  {  {
  get  get
Linia 292: Linia 319:
  }  }
  }  }
 +
 + public string GetGraphvizName(StreamWriter sw)
 + {
 + string nodeName;
 + string tempChildName;​
 +
 + if (m_nodes.Count == 0) // Tylko liść
 + {
 + nodeName = (++counter).ToString();​
 + sw.WriteLine( nodeName + " [label=\""​ + ((Thermostat)this.Category).ToString() + "​\",​ shape = record];"​);​ // A [label="​1"​ , shape = record] ​
 + }
 + else
 + {
 + nodeName = (++counter).ToString();​
 + sw.WriteLine( nodeName + " [label=\""​ + this.TestName + "​\",​ shape = ellipse];"​);​ // A [label="​1"​ , shape = record] ​
 + foreach (int key in m_nodes.Keys) //​ Dla wszystkich wyników testu
 + {
 + tempChildName = m_nodes[key].GetGraphvizName(sw);​ //​ Wywołanie dla potomnych
 + sw.WriteLine(nodeName + " -> " + tempChildName + "[ label = " + key + " ];"​);​ //​ bieżący node -> nazwa którą dostałem
 + }
 + }
 +
 + return nodeName;
 + }
 +
  }  }
  
Linia 338: Linia 390:
  }  }
  row[m_attrIndex] = m_list.Count;​  row[m_attrIndex] = m_list.Count;​
 + }
 +
 + public void WriteOldNewValues<​T>​(string AttrName, int maxValue, StreamWriter sw)
 + {
 + sw.WriteLine("​Attribute name: " + AttrName);
 + sw.WriteLine("​0"​);​
 + int currValue=0;​
 + for (int i = 0; i < maxValue; i++)
 + {
 + if (currValue < m_list.Count)
 + {
 + if (i <= m_list[currValue])
 + {
 + sw.WriteLine("​\t"​ + ((T)(object)(i)).ToString());​
 + }
 + else
 + {
 + sw.WriteLine((++currValue).ToString());​
 + sw.WriteLine("​\t"​ + ((T)(object)(i)).ToString());​
 + }
 + }
 + else
 + sw.WriteLine("​\t"​ + ((T)(object)(i)).ToString());​
 + }
 +
 + sw.WriteLine(sw.NewLine);​
  }  }
  
Linia 397: Linia 475:
  {  {
  attrChange.Change(example);​  attrChange.Change(example);​
 + }
 + }
 +
 + public void WriteAggregateValues()
 + {
 + if (m_attrChangeCollection.Count > 0)
 + {
 + StreamWriter sw = new StreamWriter("​Aggregate.txt",​ false);
 +
 + m_attrChangeCollection[0].WriteOldNewValues<​Days>​("​DaysOfWeek",​ 7, sw);
 +
 + m_attrChangeCollection[1].WriteOldNewValues<​int>​("​Hour",​ 24, sw);
 +
 + m_attrChangeCollection[2].WriteOldNewValues<​Month>​("​Month",​ 12, sw);
 +
 + sw.Flush();​
 + sw.Close();​
  }  }
  }  }
Linia 404: Linia 499:
  #endregion  #endregion
 } }
 +</​code>​
pl/miw/miw08_rbs_ml/class1.1211841556.txt.gz · ostatnio zmienione: 2019/06/27 15:59 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0