Distance metric performs distance calculation between two points in line with encapsulated function, for example, euclidean distance or chebyshev distance, or even user-defined. More...
Public Member Functions | |
def | __init__ (self, metric_type, kwargs) |
Creates distance metric instance for calculation distance between two points. More... | |
def | __call__ (self, point1, point2) |
Calculates distance between two points. More... | |
def | get_type (self) |
Return type of distance metric that is used. More... | |
def | get_arguments (self) |
Return additional arguments that are used by distance metric. More... | |
def | get_function (self) |
Return user-defined function for calculation distance metric. More... | |
def | enable_numpy_usage (self) |
Start numpy for distance calculation. More... | |
def | disable_numpy_usage (self) |
Stop using numpy for distance calculation. More... | |
Distance metric performs distance calculation between two points in line with encapsulated function, for example, euclidean distance or chebyshev distance, or even user-defined.
Example of Euclidean distance metric:
Example of Chebyshev distance metric:
In following example additional argument should be specified (generally, 'degree' is a optional argument that is equal to '2' by default) that is specific for Minkowski distance:
User may define its own function for distance calculation. In this case input is two points, for example, you want to implement your own version of Manhattan distance:
def pyclustering.utils.metric.distance_metric.__init__ | ( | self, | |
metric_type, | |||
kwargs | |||
) |
Creates distance metric instance for calculation distance between two points.
[in] | metric_type | (type_metric): |
[in] | **kwargs | Arbitrary keyword arguments (available arguments: 'numpy_usage' 'func' and corresponding additional argument for for specific metric types). |
Keyword Args:
def pyclustering.utils.metric.distance_metric.__call__ | ( | self, | |
point1, | |||
point2 | |||
) |
def pyclustering.utils.metric.distance_metric.disable_numpy_usage | ( | self | ) |
Stop using numpy for distance calculation.
Useful in case of big amount of small data portion when numpy call is longer than calculation itself. No effect in case of type_metric.USER_DEFINED type.
def pyclustering.utils.metric.distance_metric.enable_numpy_usage | ( | self | ) |
Start numpy for distance calculation.
Useful in case matrices to increase performance. No effect in case of type_metric.USER_DEFINED type.
def pyclustering.utils.metric.distance_metric.get_arguments | ( | self | ) |
def pyclustering.utils.metric.distance_metric.get_function | ( | self | ) |
def pyclustering.utils.metric.distance_metric.get_type | ( | self | ) |
Return type of distance metric that is used.