public double EstimateDc(double neighborRateLow = NeighborRateLow, double neighborRateHigh = NeighborRateHigh)
{
double tmpLow = Double.MaxValue;
double tmpHigh = Double.MinValue;
foreach (double? element in this.Distance)
{
if (element.HasValue && element < tmpLow && element > 0)
tmpLow = (double) element;
else if (element.HasValue && element > tmpHigh)
tmpHigh = (double) element;
}
double neighborRate = 0;
int segmentsLength = GetSegmentsForClustering(this.Segments);
double distanceThreshold = 0;
while (true)
{
double neighborRateTmp = 0;
distanceThreshold = (tmpLow + tmpHigh) / 2;
foreach (double? element in this.Distance)
if (element.HasValue && element < distanceThreshold)
neighborRateTmp++;
if (distanceThreshold > 0)
neighborRateTmp = neighborRateTmp + segmentsLength;
neighborRate = (neighborRateTmp * 2 / segmentsLength - 1) / segmentsLength;
if (neighborRate >= neighborRateLow && neighborRate <= neighborRateHigh)
break;
if (neighborRate < neighborRateLow)
{
tmpLow = distanceThreshold;
}
else
{
tmpHigh = distanceThreshold;
}
neighborRateTmp = 0;
}
return distanceThreshold;
}