public Node(string title, VirtualTable vt) : this(title) { Attribute att=new Attribute(); VT = vt; //Fills the cases, maybe is not suitable for C&RT for(int x=0; x < Tree.VariableL.Count; ++x) { att = new Attribute(x); AttributeL.Add(att); for(int y=0; y < VT.RowCount; ++y) { att.AddCase(VT[x, y]); } } }
public Cluster_(VirtualTable data, Node nodeParent) { //this.DS=data; NodeParent=nodeParent; //The root parameters and cases will be set during the Fill DataSet if(Tree.Root==null) //It is OK! (workaround) return; //Set the Attributes //outdated!!! blocks changing the type of the variable // DataRow row = FrmMain.SFrmMain.DS.Tables[0].Rows[0]; // double val; // foreach(DataColumn dc in FrmMain.SFrmMain.DS.Tables[0].Columns) // { // try // { // val=Double.Parse(row[dc, DataRowVersion.Original].ToString()); // att = new Attribute(dc.ColumnName.ToString(), Attribute.TypeEnum.Numerical); // AttributeL.Add(att); // } // catch // { // att = new Attribute(dc.ColumnName.ToString(), Attribute.TypeEnum.Categorical); // AttributeL.Add(att); // } // } // // // //Set the Cases // for(int x=0; x < AttributeQty; ++x) // { // att = (Attribute) AttributeL[x]; // for(int y=0; y < RowQty; ++y) // { // att.AddCase(DS[x,y]); // } // } }
public static void QuickSortDouble(VirtualTable a, int lo0, int hi0, int col) { int lo = lo0; int hi = hi0; double mid; if ( hi0 > lo0) { /* Arbitrarily establishing partition element as the midpoint of * the array. */ mid = a.GetNumber(col, (int) ( lo0 + hi0 ) / 2); // loop through the array until indices cross while( lo <= hi ) { /* find the first element that is greater than or equal to * the partition element starting from the left Index. */ while( ( lo < hi0 ) && ( a.GetNumber(col, lo) < mid ) ) ++lo; /* find an element that is smaller than or equal to * the partition element starting from the right Index. */ while( ( hi > lo0 ) && ( a.GetNumber(col, hi) > mid ) ) --hi; // if the indexes have not crossed, swap if( lo <= hi ) { swap(a, lo, hi); ++lo; --hi; } } /* If the right index has not reached the left side of array * must now sort the left partition. */ if( lo0 < hi ) QuickSortDouble( a, lo0, hi, col ); /* If the left index has not reached the right side of array * must now sort the right partition. */ if( lo < hi0 ) QuickSortDouble( a, lo, hi0, col ); } }
public VirtualTable SubSetUpTo(int col, double threshold) { DynArrInt rowsSelected = new DynArrInt(); for(int y=0; y < RowCount; ++y) { if(GetNumber(col, y) <= threshold) try { rowsSelected.Add(row[y]); } catch(Exception e) { MessageBox.Show(e.Message); } } VirtualTable subVT = new VirtualTable(rowsSelected); return subVT; }
public VirtualTable SubSet(int col, string val) { DynArrInt rowsSelected = new DynArrInt(); for(int y=0; y < RowCount; ++y) { if(this[col, y].ToString().CompareTo(val) == 0) rowsSelected.Add(row[y]); } VirtualTable subVT = new VirtualTable(rowsSelected); return subVT; }
public static void swap(VirtualTable a, int i, int j) { int T; if(i==-1) MessageBox.Show("Index = -1", "VirtualTable.cs"); T = a[i]; a[i] = a[j]; a[j] = T; }
// QuickSort implementation for VirtualTable //QuickSort (szContents, 0, RowCount - 1); public static void sort(VirtualTable a, int col) { QuickSortDouble(a, 0, a.RowCount - 1, col); }
private void FillPhysicalTable(OdbcDataReader reader, int colCount, int rowCount) { //Resets the objects foreach(Node nd in Tree.NodeL) { nd.AttributeL.Clear(); nd.Dispose(); nd.LabelTop.Dispose(); nd.LabelBotton.Dispose(); } Tree.NodeL.Clear(); Tree.VariableL.Clear(); Tree.LevelBrotherL.Clear(); Tree.LevelLast=0; Tree.Width = 0; Tree.Height = 0; Node.CntId=-1; //End resets //Code of the static tree constructor that must be called ArrayList bL = new ArrayList(); Tree.LevelBrotherL.Add(bL); //end Code of the static tree constructor that must be called GC.Collect(); GC.WaitForPendingFinalizers(); FrmMain.SFrmMain.PT = new PhysicalTable(colCount , rowCount); int x, y; bool firstTime = true; Variable var; string colName=""; grid.Rows.Count = rowCount+1; grid.Cols.Count = colCount+1; y=0; while(reader.Read()) { grid[y+1, 0]=y; for(x=0; x < reader.FieldCount; ++x) { if(firstTime) { colName = reader.GetName(x).ToLower(); grid[y, x+1] = colName; if(reader[x] is double || reader[x] is int) { FrmMain.SFrmMain.PT.AddCol(x, colName, rowCount, PhysicalColumn.DataTypeEnum.Number); var = new Variable(colName, Variable.TypeEnum.Continuous, PhysicalColumn.DataTypeEnum.Number); } else { FrmMain.SFrmMain.PT.AddCol(x, colName, rowCount, PhysicalColumn.DataTypeEnum.Text); var = new Variable(colName, Variable.TypeEnum.Categorical, PhysicalColumn.DataTypeEnum.Text); } } FrmMain.SFrmMain.PT[x, y]=reader[x]; grid[y+1, x+1] = reader[x]; } firstTime=false; ++y; } grid.Visible=true; // grid.Cols //Set a code to autofit the columns width VirtualTable virtualTable = new VirtualTable(FrmMain.SFrmMain.PT); Node root = new Node("All data", virtualTable); Tree.Root = root; }