Example #1
0
        public VirtualTable(PhysicalTable _source)
        {
            int i;
            int rc = _source.RowCount;

            source = _source;
            row = new DynArrInt(rc);
            for(i=0; i < rc; ++i)
                row.Add(i);
        }
Example #2
0
 public VirtualTable(DynArrInt subRows)
 {
     row = subRows;
 }
Example #3
0
 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;
 }
Example #4
0
 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;
 }
Example #5
0
        public static double InfoContinuousAttribute(Node nd, Attribute att, ref double thresholdMinInfo, ref bool splitValid)
        {
            Case classCs;
            double infoActual, infoActualUptoT, infoActualUptoTp2, infoActualHigherT, infoActualHigherTp2;
            double infoAttributeMin;
            int attributeMatchClass=0;
            int y;
            int DependentVariableAttributeCaseLCount = nd.DependentVariableAttribute.CaseL.Count;
            bool infoAttributeIsSet = false;

            infoAttributeMin=0;

            DynArrInt threshold = new DynArrInt();
            SetThresholdIndexes(threshold, nd, att.VariableIndex);
            if(threshold.Count==0)
            {
                splitValid=false;
                return -1;
            }
            for(int ti=0; ti < threshold.Count; ++ti)
            {
                infoActual=0;
                infoActualUptoT = (double) (threshold[ti] + 1) / nd.VT.RowCount ;
                infoActualUptoTp2 = 0;
                attributeMatchClass = 0;
                infoActualHigherT = (double) (nd.VT.RowCount - (threshold[ti] + 1)) / nd.VT.RowCount ;
                infoActualHigherTp2 = 0;
                attributeMatchClass = 0;

                for (int classIndex = 0; classIndex < DependentVariableAttributeCaseLCount; ++classIndex)
                {

                    //Calculation of the info up to threshold second part
                    attributeMatchClass = 0;
                    classCs = (Case) nd.DependentVariableAttribute.CaseL[classIndex];
                    for(y = 0; y <= threshold[ti]; ++y)
                    {
                        if(classCs.Val.ToString().CompareTo(nd.VT[Variable.DependentVariableIndex, y].ToString()) == 0)
                            ++attributeMatchClass;
                    }
                    if(attributeMatchClass > 0)
                        infoActualUptoTp2 += -1 * Math.Log( (double) attributeMatchClass / (double) (threshold[ti] + 1), 2);

                    //Calculation of the info higher threshold second part
                    attributeMatchClass = 0;
                    for(y = threshold[ti] + 1; y < nd.VT.RowCount; ++y)
                    {
                            if(classCs.Val.ToString().CompareTo(nd.VT[Variable.DependentVariableIndex, y].ToString()) == 0)
                            ++attributeMatchClass;
                    }
                    if(attributeMatchClass > 0)
                        infoActualHigherTp2 += -1 * Math.Log( (double) attributeMatchClass / (double) (nd.VT.RowCount - (threshold[ti] + 1)), 2);
                }
                infoActualUptoT = infoActualUptoT * infoActualUptoTp2;
                infoActualHigherT = infoActualHigherT * infoActualHigherTp2;
                infoActual = infoActualUptoT + infoActualHigherT;

                if(infoAttributeIsSet == false)
                {
                    infoAttributeMin = infoActual;
                    infoAttributeIsSet = true;
                    //This is the real threshold as a value
                    thresholdMinInfo = nd.VT.GetNumber(att.VariableIndex, threshold[ti]);
                }
                else
                if(infoActual < infoAttributeMin)
                {
                    infoAttributeMin = infoActual;
                    //This is the real threshold as a value
                    thresholdMinInfo = nd.VT.GetNumber(att.VariableIndex, threshold[ti]);
                }
            }
            return infoAttributeMin;
        }
Example #6
0
        private static void SetThresholdIndexes(DynArrInt threshold, Node nd, int attIndex)
        {
            int uniqueLastIdx=0;
            double uniqueLast = nd.VT.GetNumber(attIndex, uniqueLastIdx);
            int uniqueIdx, thIdx, i, rc = nd.VT.RowCount;
            double unique, th, valMin;

            //Ends when there are not enough rows at the end
            for(uniqueIdx = Option.C45MinNumOfCasesPerContinuosSplit -1; uniqueIdx + Option.C45MinNumOfCasesPerContinuosSplit < rc; ++uniqueIdx)
            {
                //outdated can be optimised
                if(nd.VT.GetNumber(attIndex, uniqueIdx) != nd.VT.GetNumber(attIndex, uniqueIdx+1))
                    threshold.Add(uniqueIdx);
            }
        }