コード例 #1
0
ファイル: MICalculator.cs プロジェクト: skn123/iFourmi
        public void CalculateHieristicValue(ACO.DecisionComponent <Edge> Element)
        {
            iFourmi.DataMining.Data.Attribute xAttribute = this._dataset.Metadata.Attributes[Element.Element.ParentIndex];
            iFourmi.DataMining.Data.Attribute yAttribute = this._dataset.Metadata.Attributes[Element.Element.ChildIndex];
            //iFourmi.DataMining.Data.Attribute zAttribute = this._dataset.Metadata.Target;



            double MI = 0;

            double size = this._dataset.Size;

            double xy = 0;
            double x  = 0;
            double y  = 0;



            List <int> attributeIndexes2 = new List <int>();

            attributeIndexes2.Add(xAttribute.Index);
            attributeIndexes2.Add(yAttribute.Index);

            List <int> valueIndexes2 = new List <int>();

            valueIndexes2.Add(0);
            valueIndexes2.Add(0);



            for (int xi = 0; xi < xAttribute.Values.Length; xi++)
            {
                x = xAttribute.ValueCounts[xi];
                x = x / size;

                for (int yi = 0; yi < yAttribute.Values.Length; yi++)
                {
                    y = yAttribute.ValueCounts[yi];
                    y = y / size;

                    valueIndexes2[0] = xi;
                    valueIndexes2[1] = yi;


                    xy = this._dataset.Filter(attributeIndexes2, valueIndexes2).Count;
                    xy = xy / size;

                    double value = xy * Math.Log(xy / (x * y));

                    if (!double.IsNaN(value) && !double.IsInfinity(value))
                    {
                        MI += value;
                    }
                }
            }



            if (MI <= 0)
            {
                MI = 0;
            }

            Element.Heuristic = MI;
        }
コード例 #2
0
ファイル: CMICalculator.cs プロジェクト: skn123/iFourmi
        public void CalculateHieristicValue(ACO.DecisionComponent <Edge> Element)
        {
            iFourmi.DataMining.Data.Attribute xAttribute = this._dataset.Metadata.Attributes[Element.Element.ParentIndex];
            iFourmi.DataMining.Data.Attribute yAttribute = this._dataset.Metadata.Attributes[Element.Element.ChildIndex];
            iFourmi.DataMining.Data.Attribute zAttribute = this._dataset.Metadata.Target;

            double CMI = 0;

            double size = this._dataset.Size;

            double xy_z = 0;
            double x_z  = 0;
            double y_z  = 0;

            double xyz = 0;
            double xz  = 0;
            double yz  = 0;
            double z   = 0;


            List <int> attributeIndexes3 = new List <int>();

            attributeIndexes3.Add(xAttribute.Index);
            attributeIndexes3.Add(yAttribute.Index);
            attributeIndexes3.Add(zAttribute.Index);

            List <int> valueIndexes3 = new List <int>();

            valueIndexes3.Add(0);
            valueIndexes3.Add(0);
            valueIndexes3.Add(0);



            List <int> attributeIndexes2 = new List <int>();

            attributeIndexes2.Add(xAttribute.Index);
            attributeIndexes2.Add(zAttribute.Index);

            List <int> valueIndexes2 = new List <int>();

            valueIndexes2.Add(0);
            valueIndexes2.Add(0);


            for (int zi = 0; zi < zAttribute.Values.Length; zi++)
            {
                double _cmi = 0;

                for (int xi = 0; xi < xAttribute.Values.Length; xi++)
                {
                    for (int yi = 0; yi < yAttribute.Values.Length; yi++)
                    {
                        z = zAttribute.ValueCounts[zi];

                        attributeIndexes2[0] = xAttribute.Index;
                        attributeIndexes2[1] = zAttribute.Index;

                        valueIndexes2[0] = xi;
                        valueIndexes2[1] = zi;

                        xz  = this._dataset.Filter(attributeIndexes2, valueIndexes2).Count;
                        x_z = xz / z;



                        attributeIndexes2[0] = yAttribute.Index;
                        attributeIndexes2[1] = zAttribute.Index;

                        valueIndexes2[0] = yi;
                        valueIndexes2[1] = zi;

                        yz  = this._dataset.Filter(attributeIndexes2, valueIndexes2).Count;
                        y_z = yz / z;


                        valueIndexes3[0] = xi;
                        valueIndexes3[1] = yi;
                        valueIndexes3[2] = zi;

                        xyz  = this._dataset.Filter(attributeIndexes3, valueIndexes3).Count;
                        xy_z = xyz / z;

                        double value = xy_z * Math.Log(xy_z / (x_z * y_z));

                        if (!double.IsNaN(value) && !double.IsInfinity(value))
                        {
                            _cmi += value;
                        }
                    }
                }

                CMI += _cmi * (z / size);
            }


            Element.Heuristic = CMI;
        }
コード例 #3
0
        public void CalculateHieristicValue(ACO.DecisionComponent <Edge> Element)
        {
            iFourmi.DataMining.Data.Attribute xAttribute = this._dataset.Metadata.Attributes[Element.Element.ParentIndex];
            iFourmi.DataMining.Data.Attribute yAttribute = this._dataset.Metadata.Attributes[Element.Element.ChildIndex];
            iFourmi.DataMining.Data.Attribute zAttribute = this._dataset.Metadata.Target;

            double InformationGain = 0;

            double size = this._dataset.Size;

            double xy_z = 0;
            double x_z  = 0;
            double y_z  = 0;

            double xyz = 0;
            double xz  = 0;
            double yz  = 0;
            double z   = 0;


            List <int> attributeIndexes3 = new List <int>();

            attributeIndexes3.Add(xAttribute.Index);
            attributeIndexes3.Add(yAttribute.Index);
            attributeIndexes3.Add(zAttribute.Index);

            List <int> valueIndexes3 = new List <int>();

            valueIndexes3.Add(0);
            valueIndexes3.Add(0);
            valueIndexes3.Add(0);



            List <int> attributeIndexes2 = new List <int>();

            attributeIndexes2.Add(xAttribute.Index);
            attributeIndexes2.Add(zAttribute.Index);

            List <int> valueIndexes2 = new List <int>();

            valueIndexes2.Add(0);
            valueIndexes2.Add(0);


            for (int zi = 0; zi < zAttribute.Values.Length; zi++)
            {
                double baseEntropy  = 0;
                double entropy      = 0;
                double _information = 0;
                z = zAttribute.ValueCounts[zi];


                for (int yi = 0; yi < yAttribute.Values.Length; yi++)
                {
                    attributeIndexes2[0] = yAttribute.Index;
                    attributeIndexes2[1] = zAttribute.Index;

                    valueIndexes2[0] = yi;
                    valueIndexes2[1] = zi;

                    yz  = this._dataset.Filter(attributeIndexes2, valueIndexes2).Count;
                    y_z = yz / z;


                    //baseEntropy -= (y_z) * Math.Log(y_z);

                    baseEntropy -= (yz / size) * Math.Log(yz / size);

                    if (double.IsNaN(baseEntropy) || double.IsInfinity(baseEntropy))
                    {
                        baseEntropy = 1;
                    }
                }


                for (int xi = 0; xi < xAttribute.Values.Length; xi++)
                {
                    double x = xAttribute.ValueCounts[xi];

                    for (int yi = 0; yi < yAttribute.Values.Length; yi++)
                    {
                        attributeIndexes2[0] = xAttribute.Index;
                        attributeIndexes2[1] = zAttribute.Index;

                        valueIndexes2[0] = xi;
                        valueIndexes2[1] = zi;

                        xz  = this._dataset.Filter(attributeIndexes2, valueIndexes2).Count;
                        x_z = xz / z;

                        valueIndexes3[0] = xi;
                        valueIndexes3[1] = yi;
                        valueIndexes3[2] = zi;

                        xyz  = this._dataset.Filter(attributeIndexes3, valueIndexes3).Count;
                        xy_z = xyz / z;

                        //double value = (xy_z / x_z) * Math.Log((xy_z / x_z));

                        double value = -(xyz / x) * Math.Log((xyz / x));

                        if (!double.IsNaN(value) && !double.IsInfinity(value))
                        {
                            entropy += (xyz / z) * value;
                        }
                    }
                }

                _information = baseEntropy - entropy;

                InformationGain += _information * (z / size);
            }


            Element.Heuristic = InformationGain;
        }
コード例 #4
0
ファイル: Variable.cs プロジェクト: skn123/iFourmi
 public Variable(iFourmi.DataMining.Data.Attribute attribute)
 {
     this._attribute = attribute;
 }
コード例 #5
0
 internal Attribute Clone()
 {
     Data.Attribute clone = new Attribute(this._name, this._index);
     return(clone);
 }