コード例 #1
0
		public void MU2c5pTest()
		{
			double[,] matrExpected = new double[5, 2];
			matrExpected[0,0] = 0.99362303;
			matrExpected[0,1] = 0.00637697;
			matrExpected[1,0] = 0.00113771;
			matrExpected[1,1] = 0.99886229;
			matrExpected[2,0] = 0.00093486;
			matrExpected[2,1] = 0.99906514;
			matrExpected[3,0] = 0.99770535;
			matrExpected[3,1] = 0.00229465;
			matrExpected[4,0] = 0.98516935;
			matrExpected[4,1] = 0.01483065;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[5];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #2
0
		public void MU2c6pTest()
		{
			double[,] matrExpected = new double[6, 2];
			matrExpected[0,0] = 0.00833090;
			matrExpected[0,1] = 0.99166910;
			matrExpected[1,0] = 0.98813468;
			matrExpected[1,1] = 0.01186532;
			matrExpected[2,0] = 0.99991329;
			matrExpected[2,1] = 0.00008671;
			matrExpected[3,0] = 0.00256154;
			matrExpected[3,1] = 0.99743846;
			matrExpected[4,0] = 0.01959954;
			matrExpected[4,1] = 0.98040046;
			matrExpected[5,0] = 0.98262987;
			matrExpected[5,1] = 0.01737013;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[6];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #3
0
        public PointRGB[] generateRandomPoints(int count)
        {
            PointRGB[] points = new PointRGB[count];

            for (int i = 0; i < count; i++)
            {
                PointRGB p = new PointRGB(rand.Next(20, 235), rand.Next(20, 235), rand.Next(20, 235));
                points[i] = p;
            }

            return points;
        }
コード例 #4
0
        public double[,] distributeOverMatrixU(PointRGB[] arr, PointRGB[] centers, double m)
        {

            MatrixU = fillUMatrix(arr.Length, centers.Length);
     
            double previousDecisionValue = 0;
            double currentDecisionValue = 1;
            double sum;

            int pointsCount = arr.Length;
            int clustersCount = centers.Length;

            for (int a = 0; a < max_cycles_count && (Math.Abs(previousDecisionValue - currentDecisionValue) > e); a++)
            {
                previousDecisionValue = currentDecisionValue;
                centers = calculateCenters(MatrixU, m, arr);

                for (int i = 0; i < pointsCount; i++)
                {
                    for (int j = 0; j < clustersCount; j++)
                    {
                        double distance = evklidDistance3D(arr[i], centers[j]);
                        MatrixU[i, j] = Math.Pow(1 / distance, 2 / (m - 1));

                    }

                    sum = 0;

                    for (int j = 0; j < clustersCount; j++)
                    {
                        sum += MatrixU[i, j];
                    }

                    for (int j = 0; j < clustersCount; j++)
                    {
                        MatrixU[i, j] = MatrixU[i, j] / sum;
                    }

                }

                currentDecisionValue = calculateDecisionFunction(arr, centers, MatrixU);               
            }
            newCenters = centers;
            return MatrixU;
        }
コード例 #5
0
		public void MU3c10pTest()
		{
			double[,] matrExpected = new double[10, 3];
			matrExpected[0,0] = 0.00207611;
			matrExpected[0,1] = 0.00211681;
			matrExpected[0,2] = 0.99580708;
			matrExpected[1,0] = 0.04862492;
			matrExpected[1,1] = 0.86031170;
			matrExpected[1,2] = 0.09106338;
			matrExpected[2,0] = 0.00279667;
			matrExpected[2,1] = 0.99480518;
			matrExpected[2,2] = 0.00239814;
			matrExpected[3,0] = 0.00302810;
			matrExpected[3,1] = 0.00455935;
			matrExpected[3,2] = 0.99241255;
			matrExpected[4,0] = 0.01634000;
			matrExpected[4,1] = 0.02473899;
			matrExpected[4,2] = 0.95892102;
			matrExpected[5,0] = 0.10414700;
			matrExpected[5,1] = 0.87619866;
			matrExpected[5,2] = 0.01965435;
			matrExpected[6,0] = 0.00237029;
			matrExpected[6,1] = 0.99606029;
			matrExpected[6,2] = 0.00156942;
			matrExpected[7,0] = 0.15594909;
			matrExpected[7,1] = 0.80011012;
			matrExpected[7,2] = 0.04394078;
			matrExpected[8,0] = 0.02205131;
			matrExpected[8,1] = 0.01168445;
			matrExpected[8,2] = 0.96626424;
			matrExpected[9,0] = 0.99983770;
			matrExpected[9,1] = 0.00010124;
			matrExpected[9,2] = 0.00006106;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[10];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			p[9] = new PointRGB(160, 45, 120);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #6
0
		public void MU3c9pTest()
		{
			double[,] matrExpected = new double[9, 3];
			matrExpected[0,0] = 0.00392690;
			matrExpected[0,1] = 0.00067333;
			matrExpected[0,2] = 0.99539977;
			matrExpected[1,0] = 0.97633035;
			matrExpected[1,1] = 0.01134808;
			matrExpected[1,2] = 0.01232157;
			matrExpected[2,0] = 0.99971304;
			matrExpected[2,1] = 0.00022717;
			matrExpected[2,2] = 0.00005979;
			matrExpected[3,0] = 0.00669097;
			matrExpected[3,1] = 0.00152497;
			matrExpected[3,2] = 0.99178406;
			matrExpected[4,0] = 0.02290245;
			matrExpected[4,1] = 0.01418927;
			matrExpected[4,2] = 0.96290828;
			matrExpected[5,0] = 0.90399009;
			matrExpected[5,1] = 0.07025695;
			matrExpected[5,2] = 0.02575295;
			matrExpected[6,0] = 0.18064114;
			matrExpected[6,1] = 0.81296270;
			matrExpected[6,2] = 0.00639616;
			matrExpected[7,0] = 0.00367131;
			matrExpected[7,1] = 0.99562017;
			matrExpected[7,2] = 0.00070852;
			matrExpected[8,0] = 0.01868184;
			matrExpected[8,1] = 0.00418239;
			matrExpected[8,2] = 0.97713577;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[9];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #7
0
 public double evklidDistance3D(PointRGB pointA, PointRGB pointB)
 {
     double distance1 = Math.Pow((pointA.R - pointB.R),2);
     double distance2 = Math.Pow((pointA.G - pointB.G),2);
     double distance3 = Math.Pow((pointA.B - pointB.B),2);
     double distance = distance1 + distance2 + distance3;
     return Math.Sqrt(distance);
 }
コード例 #8
0
		public void MU4c10pTest()
		{
			double[,] matrExpected = new double[10, 4];
			matrExpected[0,0] = 0.00387958;
			matrExpected[0,1] = 0.00215156;
			matrExpected[0,2] = 0.00067191;
			matrExpected[0,3] = 0.99329695;
			matrExpected[1,0] = 0.97685574;
			matrExpected[1,1] = 0.00464232;
			matrExpected[1,2] = 0.00887049;
			matrExpected[1,3] = 0.00963144;
			matrExpected[2,0] = 0.99961964;
			matrExpected[2,1] = 0.00006380;
			matrExpected[2,2] = 0.00025060;
			matrExpected[2,3] = 0.00006596;
			matrExpected[3,0] = 0.00672350;
			matrExpected[3,1] = 0.00272701;
			matrExpected[3,2] = 0.00152073;
			matrExpected[3,3] = 0.98902876;
			matrExpected[4,0] = 0.02216181;
			matrExpected[4,1] = 0.01461795;
			matrExpected[4,2] = 0.01398775;
			matrExpected[4,3] = 0.94923249;
			matrExpected[5,0] = 0.78676442;
			matrExpected[5,1] = 0.10765810;
			matrExpected[5,2] = 0.07725820;
			matrExpected[5,3] = 0.02831929;
			matrExpected[6,0] = 0.16933353;
			matrExpected[6,1] = 0.00768052;
			matrExpected[6,2] = 0.81656147;
			matrExpected[6,3] = 0.00642447;
			matrExpected[7,0] = 0.00347393;
			matrExpected[7,1] = 0.00199645;
			matrExpected[7,2] = 0.99382238;
			matrExpected[7,3] = 0.00070724;
			matrExpected[8,0] = 0.01741314;
			matrExpected[8,1] = 0.02373964;
			matrExpected[8,2] = 0.00408662;
			matrExpected[8,3] = 0.95476060;
			matrExpected[9,0] = 0.00000049;
			matrExpected[9,1] = 0.99999885;
			matrExpected[9,2] = 0.00000032;
			matrExpected[9,3] = 0.00000033;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[10];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			p[9] = new PointRGB(160, 45, 120);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #9
0
		public void MU4c9pTest()
		{
			double[,] matrExpected = new double[9, 4];
			matrExpected[0,0] = 0.99379413;
			matrExpected[0,1] = 0.00312986;
			matrExpected[0,2] = 0.00268497;
			matrExpected[0,3] = 0.00039104;
			matrExpected[1,0] = 0.00076141;
			matrExpected[1,1] = 0.99446683;
			matrExpected[1,2] = 0.00445659;
			matrExpected[1,3] = 0.00031518;
			matrExpected[2,0] = 0.00149362;
			matrExpected[2,1] = 0.82210063;
			matrExpected[2,2] = 0.17460307;
			matrExpected[2,3] = 0.00180267;
			matrExpected[3,0] = 0.98836640;
			matrExpected[3,1] = 0.00610111;
			matrExpected[3,2] = 0.00462978;
			matrExpected[3,3] = 0.00090270;
			matrExpected[4,0] = 0.94361224;
			matrExpected[4,1] = 0.01690011;
			matrExpected[4,2] = 0.03066885;
			matrExpected[4,3] = 0.00881880;
			matrExpected[5,0] = 0.00524505;
			matrExpected[5,1] = 0.03630806;
			matrExpected[5,2] = 0.95317084;
			matrExpected[5,3] = 0.00527605;
			matrExpected[6,0] = 0.00286831;
			matrExpected[6,1] = 0.03732810;
			matrExpected[6,2] = 0.92023653;
			matrExpected[6,3] = 0.03956705;
			matrExpected[7,0] = 0.00000000;
			matrExpected[7,1] = 0.00000000;
			matrExpected[7,2] = 0.00000000;
			matrExpected[7,3] = NaN;
			matrExpected[8,0] = 0.96625578;
			matrExpected[8,1] = 0.01144212;
			matrExpected[8,2] = 0.01987430;
			matrExpected[8,3] = 0.00242780;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[9];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #10
0
		public void MU4c7pTest()
		{
			double[,] matrExpected = new double[7, 4];
			matrExpected[0,0] = 0.00052071;
			matrExpected[0,1] = 0.00239649;
			matrExpected[0,2] = 0.00047349;
			matrExpected[0,3] = 0.99660931;
			matrExpected[1,0] = 0.99999726;
			matrExpected[1,1] = 0.00000011;
			matrExpected[1,2] = 0.00000237;
			matrExpected[1,3] = 0.00000026;
			matrExpected[2,0] = 0.11996475;
			matrExpected[2,1] = 0.00113877;
			matrExpected[2,2] = 0.87730344;
			matrExpected[2,3] = 0.00159304;
			matrExpected[3,0] = 0.00043015;
			matrExpected[3,1] = 0.00405054;
			matrExpected[3,2] = 0.00032687;
			matrExpected[3,3] = 0.99519244;
			matrExpected[4,0] = 0.00000000;
			matrExpected[4,1] = 0.99999991;
			matrExpected[4,2] = 0.00000001;
			matrExpected[4,3] = 0.00000007;
			matrExpected[5,0] = 0.02377465;
			matrExpected[5,1] = 0.00445635;
			matrExpected[5,2] = 0.96650308;
			matrExpected[5,3] = 0.00526593;
			matrExpected[6,0] = 0.01743612;
			matrExpected[6,1] = 0.00326714;
			matrExpected[6,2] = 0.97720220;
			matrExpected[6,3] = 0.00209454;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[7];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #11
0
		public void MU2c10pTest()
		{
			double[,] matrExpected = new double[10, 2];
			matrExpected[0,0] = 0.99778699;
			matrExpected[0,1] = 0.00221301;
			matrExpected[1,0] = 0.15251194;
			matrExpected[1,1] = 0.84748806;
			matrExpected[2,0] = 0.00825304;
			matrExpected[2,1] = 0.99174696;
			matrExpected[3,0] = 0.99309844;
			matrExpected[3,1] = 0.00690156;
			matrExpected[4,0] = 0.96967201;
			matrExpected[4,1] = 0.03032799;
			matrExpected[5,0] = 0.00649101;
			matrExpected[5,1] = 0.99350899;
			matrExpected[6,0] = 0.00444359;
			matrExpected[6,1] = 0.99555641;
			matrExpected[7,0] = 0.04919440;
			matrExpected[7,1] = 0.95080560;
			matrExpected[8,0] = 0.99102517;
			matrExpected[8,1] = 0.00897483;
			matrExpected[9,0] = 0.29283491;
			matrExpected[9,1] = 0.70716509;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[10];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			p[9] = new PointRGB(160, 45, 120);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #12
0
		public void MU2c9pTest()
		{
			double[,] matrExpected = new double[9, 2];
			matrExpected[0,0] = 0.00205013;
			matrExpected[0,1] = 0.99794987;
			matrExpected[1,0] = 0.89007612;
			matrExpected[1,1] = 0.10992388;
			matrExpected[2,0] = 0.99641480;
			matrExpected[2,1] = 0.00358520;
			matrExpected[3,0] = 0.00442415;
			matrExpected[3,1] = 0.99557585;
			matrExpected[4,0] = 0.02523080;
			matrExpected[4,1] = 0.97476920;
			matrExpected[5,0] = 0.97843406;
			matrExpected[5,1] = 0.02156594;
			matrExpected[6,0] = 0.99877772;
			matrExpected[6,1] = 0.00122228;
			matrExpected[7,0] = 0.95357115;
			matrExpected[7,1] = 0.04642885;
			matrExpected[8,0] = 0.01179832;
			matrExpected[8,1] = 0.98820168;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[9];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			p[8] = new PointRGB(193, 144, 149);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #13
0
		public void MU2c8pTest()
		{
			double[,] matrExpected = new double[8, 2];
			matrExpected[0,0] = 0.00432479;
			matrExpected[0,1] = 0.99567521;
			matrExpected[1,0] = 0.90018885;
			matrExpected[1,1] = 0.09981115;
			matrExpected[2,0] = 0.99705224;
			matrExpected[2,1] = 0.00294776;
			matrExpected[3,0] = 0.00159266;
			matrExpected[3,1] = 0.99840734;
			matrExpected[4,0] = 0.01994903;
			matrExpected[4,1] = 0.98005097;
			matrExpected[5,0] = 0.98469110;
			matrExpected[5,1] = 0.01530890;
			matrExpected[6,0] = 0.99895262;
			matrExpected[6,1] = 0.00104738;
			matrExpected[7,0] = 0.95934073;
			matrExpected[7,1] = 0.04065927;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[8];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #14
0
        private PointRGB[] calculateCenters(double[,] MatrixU, double m, PointRGB[] points)
        {
            PointRGB[] MatrixCentroids = new PointRGB[MatrixU.GetLength(0)];
            int pointsCount = MatrixU.GetLength(0);
            int clustersCount = MatrixU.GetLength(1);

            for (int clusterIndex = 0; clusterIndex < clustersCount; clusterIndex++)
            {
                double tempAr = 0;
                double tempBr = 0;
                double tempAg = 0;
                double tempBg = 0;
                double tempAb = 0;
                double tempBb = 0;

                for (int j = 0; j < pointsCount; j++)
                {
                    tempAr += Math.Pow(MatrixU[j, clusterIndex], m);
                    tempBr += Math.Pow(MatrixU[j, clusterIndex], m) * points[j].R;

                    tempAg += Math.Pow(MatrixU[j, clusterIndex], m);
                    tempBg += Math.Pow(MatrixU[j, clusterIndex], m) * points[j].G;

                    tempAb += Math.Pow(MatrixU[j, clusterIndex], m);
                    tempBb += Math.Pow(MatrixU[j, clusterIndex], m) * points[j].B;
                }

                MatrixCentroids[clusterIndex] = new PointRGB((int)(tempBr / tempAr), (int)(tempBg / tempAg), (int)(tempBb / tempAb));
            }

            return MatrixCentroids;
        }
コード例 #15
0
		public void MU4c5pTest()
		{
			double[,] matrExpected = new double[5, 4];
			matrExpected[0,0] = 0.00000001;
			matrExpected[0,1] = 0.00000006;
			matrExpected[0,2] = 0.99999845;
			matrExpected[0,3] = 0.00000148;
			matrExpected[1,0] = 0.99668012;
			matrExpected[1,1] = 0.00056964;
			matrExpected[1,2] = 0.00165252;
			matrExpected[1,3] = 0.00109771;
			matrExpected[2,0] = 0.99750703;
			matrExpected[2,1] = 0.00064009;
			matrExpected[2,2] = 0.00118449;
			matrExpected[2,3] = 0.00066839;
			matrExpected[3,0] = 0.00000001;
			matrExpected[3,1] = 0.00000008;
			matrExpected[3,2] = 0.00000119;
			matrExpected[3,3] = 0.99999873;
			matrExpected[4,0] = 0.00000001;
			matrExpected[4,1] = 0.99999986;
			matrExpected[4,2] = 0.00000006;
			matrExpected[4,3] = 0.00000008;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[5];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #16
0
		public void MU4c6pTest()
		{
			double[,] matrExpected = new double[6, 4];
			matrExpected[0,0] = 0.00054555;
			matrExpected[0,1] = 0.00077408;
			matrExpected[0,2] = 0.00239571;
			matrExpected[0,3] = 0.99628466;
			matrExpected[1,0] = 0.99394929;
			matrExpected[1,1] = 0.00468394;
			matrExpected[1,2] = 0.00040216;
			matrExpected[1,3] = 0.00096462;
			matrExpected[2,0] = 0.92651765;
			matrExpected[2,1] = 0.07146868;
			matrExpected[2,2] = 0.00083941;
			matrExpected[2,3] = 0.00117426;
			matrExpected[3,0] = 0.00041649;
			matrExpected[3,1] = 0.00040590;
			matrExpected[3,2] = 0.00405028;
			matrExpected[3,3] = 0.99512733;
			matrExpected[4,0] = 0.00000001;
			matrExpected[4,1] = 0.00000001;
			matrExpected[4,2] = 0.99999991;
			matrExpected[4,3] = 0.00000007;
			matrExpected[5,0] = 0.00000004;
			matrExpected[5,1] = 0.99999996;
			matrExpected[5,2] = 0.00000000;
			matrExpected[5,3] = 0.00000000;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[6];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #17
0
		public void MU3c5pTest()
		{
			double[,] matrExpected = new double[5, 3];
			matrExpected[0,0] = 0.00054491;
			matrExpected[0,1] = 0.99705121;
			matrExpected[0,2] = 0.00240388;
			matrExpected[1,0] = 0.99807063;
			matrExpected[1,1] = 0.00136826;
			matrExpected[1,2] = 0.00056111;
			matrExpected[2,0] = 0.99847600;
			matrExpected[2,1] = 0.00089631;
			matrExpected[2,2] = 0.00062769;
			matrExpected[3,0] = 0.00041257;
			matrExpected[3,1] = 0.99550742;
			matrExpected[3,2] = 0.00408001;
			matrExpected[4,0] = 0.00000000;
			matrExpected[4,1] = 0.00000002;
			matrExpected[4,2] = 0.99999998;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[5];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #18
0
		public void MU4c8pTest()
		{
			double[,] matrExpected = new double[8, 4];
			matrExpected[0,0] = 0.00589397;
			matrExpected[0,1] = 0.00073638;
			matrExpected[0,2] = 0.00497074;
			matrExpected[0,3] = 0.98839891;
			matrExpected[1,0] = 0.99444553;
			matrExpected[1,1] = 0.00031517;
			matrExpected[1,2] = 0.00454436;
			matrExpected[1,3] = 0.00069494;
			matrExpected[2,0] = 0.81493949;
			matrExpected[2,1] = 0.00178697;
			matrExpected[2,2] = 0.18203872;
			matrExpected[2,3] = 0.00123482;
			matrExpected[3,0] = 0.00207571;
			matrExpected[3,1] = 0.00030712;
			matrExpected[3,2] = 0.00156376;
			matrExpected[3,3] = 0.99605341;
			matrExpected[4,0] = 0.01484821;
			matrExpected[4,1] = 0.00774808;
			matrExpected[4,2] = 0.02677084;
			matrExpected[4,3] = 0.95063288;
			matrExpected[5,0] = 0.04218263;
			matrExpected[5,1] = 0.00612970;
			matrExpected[5,2] = 0.94728849;
			matrExpected[5,3] = 0.00439918;
			matrExpected[6,0] = 0.03266716;
			matrExpected[6,1] = 0.03462654;
			matrExpected[6,2] = 0.93055356;
			matrExpected[6,3] = 0.00215273;
			matrExpected[7,0] = 0.00000000;
			matrExpected[7,1] = NaN;
			matrExpected[7,2] = 0.00000000;
			matrExpected[7,3] = 0.00000000;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[8];
			PointRGB[] c = new PointRGB[4];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			c[3] = new PointRGB(125, 100, 30);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #19
0
		public void MU3c6pTest()
		{
			double[,] matrExpected = new double[6, 3];
			matrExpected[0,0] = 0.99691133;
			matrExpected[0,1] = 0.00239722;
			matrExpected[0,2] = 0.00069145;
			matrExpected[1,0] = 0.01389251;
			matrExpected[1,1] = 0.00579189;
			matrExpected[1,2] = 0.98031560;
			matrExpected[2,0] = 0.00006546;
			matrExpected[2,1] = 0.00004679;
			matrExpected[2,2] = 0.99988775;
			matrExpected[3,0] = 0.99549822;
			matrExpected[3,1] = 0.00405179;
			matrExpected[3,2] = 0.00044999;
			matrExpected[4,0] = 0.00000007;
			matrExpected[4,1] = 0.99999992;
			matrExpected[4,2] = 0.00000001;
			matrExpected[5,0] = 0.01568172;
			matrExpected[5,1] = 0.01327082;
			matrExpected[5,2] = 0.97104746;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[6];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #20
0
		public void MU2c7pTest()
		{
			double[,] matrExpected = new double[7, 2];
			matrExpected[0,0] = 0.00644397;
			matrExpected[0,1] = 0.99355603;
			matrExpected[1,0] = 0.97325628;
			matrExpected[1,1] = 0.02674372;
			matrExpected[2,0] = 0.99998356;
			matrExpected[2,1] = 0.00001644;
			matrExpected[3,0] = 0.00213306;
			matrExpected[3,1] = 0.99786694;
			matrExpected[4,0] = 0.02069683;
			matrExpected[4,1] = 0.97930317;
			matrExpected[5,0] = 0.98555014;
			matrExpected[5,1] = 0.01444986;
			matrExpected[6,0] = 0.99023803;
			matrExpected[6,1] = 0.00976197;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[7];
			PointRGB[] c = new PointRGB[2];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #21
0
		public void MU3c7pTest()
		{
			double[,] matrExpected = new double[7, 3];
			matrExpected[0,0] = 0.98843361;
			matrExpected[0,1] = 0.00521983;
			matrExpected[0,2] = 0.00634656;
			matrExpected[1,0] = 0.00068811;
			matrExpected[1,1] = 0.00456865;
			matrExpected[1,2] = 0.99474323;
			matrExpected[2,0] = 0.00123014;
			matrExpected[2,1] = 0.18585713;
			matrExpected[2,2] = 0.81291273;
			matrExpected[3,0] = 0.99598016;
			matrExpected[3,1] = 0.00170797;
			matrExpected[3,2] = 0.00231187;
			matrExpected[4,0] = 0.96117425;
			matrExpected[4,1] = 0.02477243;
			matrExpected[4,2] = 0.01405332;
			matrExpected[5,0] = 0.00481470;
			matrExpected[5,1] = 0.94922143;
			matrExpected[5,2] = 0.04596387;
			matrExpected[6,0] = 0.00207998;
			matrExpected[6,1] = 0.96659160;
			matrExpected[6,2] = 0.03132843;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[7];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #22
0
		public void MU3c8pTest()
		{
			double[,] matrExpected = new double[8, 3];
			matrExpected[0,0] = 0.00788824;
			matrExpected[0,1] = 0.00135257;
			matrExpected[0,2] = 0.99075919;
			matrExpected[1,0] = 0.97776544;
			matrExpected[1,1] = 0.01136476;
			matrExpected[1,2] = 0.01086980;
			matrExpected[2,0] = 0.99972441;
			matrExpected[2,1] = 0.00022717;
			matrExpected[2,2] = 0.00004841;
			matrExpected[3,0] = 0.00247573;
			matrExpected[3,1] = 0.00056425;
			matrExpected[3,2] = 0.99696002;
			matrExpected[4,0] = 0.01887481;
			matrExpected[4,1] = 0.01169394;
			matrExpected[4,2] = 0.96943125;
			matrExpected[5,0] = 0.91088105;
			matrExpected[5,1] = 0.07079251;
			matrExpected[5,2] = 0.01832645;
			matrExpected[6,0] = 0.18082271;
			matrExpected[6,1] = 0.81377982;
			matrExpected[6,2] = 0.00539746;
			matrExpected[7,0] = 0.00367166;
			matrExpected[7,1] = 0.99571614;
			matrExpected[7,2] = 0.00061219;
			FuzzyCMean fcm = new FuzzyCMean();
			PointRGB[] p = new PointRGB[8];
			PointRGB[] c = new PointRGB[3];
			c[0] = new PointRGB(245, 14, 45);
			c[1] = new PointRGB(56, 78, 134);
			c[2] = new PointRGB(20, 25, 68);
			p[0] = new PointRGB(203, 171, 184);
			p[1] = new PointRGB(72, 162, 213);
			p[2] = new PointRGB(73, 143, 165);
			p[3] = new PointRGB(210, 212, 187);
			p[4] = new PointRGB(198, 214, 103);
			p[5] = new PointRGB(107, 113, 140);
			p[6] = new PointRGB(59, 153, 112);
			p[7] = new PointRGB(38, 121, 43);
			double[,] matr = fcm.distributeOverMatrixU(p, c, 1.5);
			for (int i = 0; i < p.Length; i++)
			{
				for (int j = 0; j < c.Length; j++)
				{
					Assert.IsTrue((matr[i, j] - matrExpected[i, j] < 0.0001) || (Math.Abs(matr[i, j] + matrExpected[i, j] - 1) < 0.0001));
				}
			}
		}
コード例 #23
0
        private double calculateDecisionFunction(PointRGB[] MatrixPointX, PointRGB[] MatrixCentroids, double[,] MatrixU)
        {
            double sum = 0;
            
            for (int i = 0; i < MatrixU.GetLength(0); i++)
            {
                for (int j = 0; j < MatrixU.GetLength(1); j++)
                {
                    sum += MatrixU[i,j] * evklidDistance3D(MatrixCentroids[j], MatrixPointX[i]);
                }
            }

            return sum;
        }