Esempio n. 1
0
		public void UpdateClusterMeans()
		{
			ClusterObject newCentroid = new ClusterObject();
			double[] newCoordinates = new double[m_nDimensionCount];
			
			foreach (KeyValuePair<int, ClusterObject> kvp in m_dictObjects)
			{
				for (int i = 0; i < m_nDimensionCount; i++)
				{
					newCoordinates[i] += kvp.Value.Coordinates[i];
				}
			}

			for (int i = 0; i < m_nDimensionCount; i++)
			{
				newCoordinates[i] /= m_dictObjects.Count;
			}

			newCentroid.Coordinates = new List<double>(newCoordinates);
			
			if (m_OldClusterCentroid == null)
			{
				m_OldClusterCentroid = newCentroid;
			}
			else
			{
				m_OldClusterCentroid = m_ClusterCentroid;
			}
			
			m_ClusterCentroid = newCentroid;
			
			EuclidianDistanceStrategy e = new EuclidianDistanceStrategy();
			double dDistance = e.CalculateDistance(m_OldClusterCentroid, m_ClusterCentroid);
			if (dDistance > 0) //TODO: Set an acceptable margin to determine if the 
							   // center moved or not. To aviod osciallation, small changes 
							   // may be neglected.
			{
				CenterMoved = true;
			}
			else
			{
				CenterMoved = false;
			}
		}
		public static double CalculateDistance(ClusterObject object1, ClusterObject object2)
		{
			EuclidianDistanceStrategy distance = new EuclidianDistanceStrategy();
			return distance.CalculateDistance(object1, object2);
		}