/// <summary> /// Стандартный конструктор класса K_Means /// CountOfClusters = 2 /// CoefficientTaboo = 0 /// Euclidian Distance /// </summary> public K_Means() { //Количество кластеров по умолчанию CountOfClusters = 2; CoefficientTaboo = 0; _metricDistance = new EuclidianDistance(); }
/// <summary> /// Converts metric to metric /// </summary> /// <param name="source">Source dimension</param> /// <param name="target">Target dimension</param> /// <param name="power"></param> /// <returns>A functor that converts metric to metric</returns> protected Func <double, double> ConvertMetricDistance(IMetricDistance source, IMetricDistance target, int power) { var from = ((AbstractDistance)source).ConvertToBase; var to = ((AbstractDistance)target).ConvertFromBase; return(x => Powerade(from, x, power, to)); }
/// <summary> /// Converts metric to metric /// </summary> /// <param name="source">Source dimension</param> /// <param name="target">Target dimension</param> /// <param name="power"></param> /// <returns>A functor that converts metric to metric</returns> protected Func<double, double> ConvertMetricDistance(IMetricDistance source, IMetricDistance target, int power) { var from = ((AbstractDistance)source).ConvertToBase; var to = ((AbstractDistance)target).ConvertFromBase; return x => Powerade(from, x, power, to); }
/// <summary> /// Converts the metric distance to an imperial distance /// </summary> /// <param name="quantity">Quantity to convert</param> /// <param name="source">Source dimension</param> /// <param name="target">Target dimension</param> /// <returns>A new unit of measure with the quantity expressed in the target distance</returns> public IUnit <IDistance> VisitMetricDistance(double quantity, IMetricDistance source, IImperialDistance target) { var meters = source.ToMeters(quantity); var feet = meters * 3.2808398950131235; return(new DistanceUnit(target.FromFeet(feet), target)); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="power"></param> /// <returns></returns> protected Func<double, double> ConvertImperialDistance(IImperialDistance source, IMetricDistance target, int power) { var from = ((AbstractDistance)source).ConvertToBase; var to = ((AbstractDistance)target).ConvertFromBase; Func<double, double> from2 = x => from(x) * 0.3048; return x => Powerade(from2, x, power, to); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="power"></param> /// <returns></returns> protected Func <double, double> ConvertMetricDistance(IMetricDistance source, IImperialDistance target, int power) { var from = ((AbstractDistance)source).ConvertToBase; var to = ((AbstractDistance)target).ConvertFromBase; Func <double, double> from2 = x => from(x) * 3.2808398950131235; return(x => Powerade(from2, x, power, to)); }
/// <summary> /// Redefining the cluster centroid according to the center of gravity /// </summary> /// <param name="metricDistance">Method of calculating distance</param> public void SetCentroidLikeGravityCenter(IMetricDistance metricDistance) { if (Data.Count != 0) { if (metricDistance.GetValueOfDistance(GetGravityCenter(), ClustersCendroid) > 0.01) { ClustersCendroid = new Centroid(GetGravityCenter().X, GetGravityCenter().Y); ChangeCentroid?.Invoke(this, null); } } else { ClustersCendroid = ClustersCendroid; } }
/// <summary> /// The calculation of the intracluster distances /// </summary> /// <param name="metricDistance">Method of calculating intracluster distance</param> /// <returns>Value of intracluster distance </returns> public double IntraClusterDistance(IMetricDistance metricDistance) { double intraClusterDistance = 0.0; //Avoiding division by zero if (Data.Count == 0) { intraClusterDistance = 0; } else { intraClusterDistance = Data.Average(a => metricDistance.GetValueOfDistance(ClustersCendroid, a)); } return(Math.Round(intraClusterDistance, 3)); }
/// <summary> /// Расширенный конструктор класса K_Means /// </summary> /// <param name="countOfClusters">Количество кластеров</param> /// <param name="coefficientTaboo"></param> /// <param name="metricDistance"></param> public K_Means(int countOfClusters, double coefficientTaboo, IMetricDistance metricDistance) { CountOfClusters = countOfClusters; CoefficientTaboo = coefficientTaboo; _metricDistance = metricDistance; }
/// <summary> /// Converts an imperial distance to a metric distance /// </summary> /// <param name="quantity"> Quantity to convert </param> /// <param name="source"> Source distance </param> /// <param name="target"> Target distance </param> /// <returns> A new unit of measure with the quantity converted to the target distance </returns> public IUnit <IDistance> VisitImperialDistance(double quantity, IImperialDistance source, IMetricDistance target) { var feet = source.ToFeet(quantity); var meters = feet * 0.3048; return(new DistanceUnit(target.FromMeters(meters), target)); }
/// <summary> /// Converts to the metric distance given a metric distance /// </summary> /// <param name="quantity"> /// Quantity to convert /// </param> /// <param name="source"> /// Source distance /// </param> /// <param name="dimension"> /// Target distance /// </param> /// <returns> /// A new unit of measure with the quantity converted to the target distance /// </returns> public IUnit <IDistance> VisitMetricDistance(double quantity, IMetricDistance source, IMetricDistance dimension) { var meters = source.ToMeters(quantity); return(new DistanceUnit(dimension.FromMeters(meters), dimension)); }