@@ -169,8 +169,9 @@ by the following keyword arguments:
169169* `scale=1` : a function of the distance matrix (see [`distancematrix`](@ref)),
170170 or a fixed number, used to scale the value of `ε`. Typical choices are
171171 `maximum` or `mean`, such that the threshold `ε` is defined as a ratio of the
172- maximum or the mean distance between data points, respectively.
173- Use `1` to keep the distances unscaled (default).
172+ maximum or the mean distance between data points, respectively (using
173+ `mean` or `maximum` calls specialized versions that are faster than the naive
174+ approach). Use `1` to keep the distances unscaled (default).
174175* `fixedrate::Bool=false` : a flag that indicates if `ε` should be
175176 taken as a target fixed recurrence rate (see [`recurrencerate`](@ref)).
176177 If `fixedrate` is set to `true`, `ε` must be a value between 0 and 1,
231232# distance matrix; otherwise return the value of `scale` itself
232233_computescale (scale:: Function , x, y, metric) = scale (distancematrix (x, y, metric))
233234_computescale (scale:: Real , args... ) = scale
235+ # specific methods to avoid `distancematrix`
236+ function _computescale (scale:: typeof (maximum), x:: T , y:: T , metric:: Metric ) where {T}
237+ maxvalue = zero (eltype (x))
238+ @inbounds for xi in x, yj in y
239+ newvalue = evaluate (metric, xi, yj)
240+ (newvalue > maxvalue) && (maxvalue = newvalue)
241+ end
242+ return maxvalue
243+ end
244+ function _computescale (scale:: typeof (mean), x, y, metric:: Metric )
245+ meanvalue = 0.0
246+ @inbounds for xi in x, yj in y
247+ meanvalue += evaluate (metric, xi, yj)
248+ end
249+ return meanvalue/ (length (x)* length (y))
250+ end
251+
234252
235253# Internal methods to calculate the matrix:
236254# If the metric is supplied as a string, get the corresponding Metric from Distances
0 commit comments