Both sides previous revision
Poprzednia wersja
Nowa wersja
|
Poprzednia wersja
|
pl:miw:miw08_rbs_ml:class1 [2008/05/27 00:59] miw |
pl:miw:miw08_rbs_ml:class1 [2019/06/27 15:50] (aktualna) |
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 |
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 |
} | } |
} | } |
| |
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; |
} | } |
} | } |
| |
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; |
} | } |
| |
| /// <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 |
} | } |
| |
public List<ShowedNode> Nodes | public int Category |
| { |
| get |
| { |
| return m_category; |
| } |
| set |
| { |
| m_category = value; |
| } |
| } |
| |
| public Dictionary<int, ShowedNode> Nodes |
{ | { |
get | get |
} | } |
} | } |
| |
| 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; |
| } |
| |
} | } |
| |
} | } |
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); |
} | } |
| |
{ | { |
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(); |
} | } |
} | } |