platypus.distance module

class platypus.distance.DistanceMatrix(solutions, distance_fun=<function euclidean_dist>)

Maintains pairwise distances between solutions.

The distance matrix, used by SPEA2, maintains the pairwise distances between solutions. It also provides convenient routines to lookup the distance between any two solutions, find the most crowded solution, and remove a solution.

find_most_crowded()

Finds the most crowded solution.

Returns the index of the most crowded solution, which is the solution with the smallest distance to the nearest neighbor. Any ties are broken by looking at the next distant neighbor.

kth_distance(i, k)

Returns the distance to the k-th nearest neighbor.

Parameters

iint

The index of the solution.

kint

Finds the k-th nearest neightbor distance.

remove_point(index)

Removes the distance entries for the given solution.

Parameters

indexint

The index of the solution.

platypus.distance.distance_to_nearest(solution, set)

Finds the minimum distance from the solution to the set of solutions.

Note that this uses normalized_euclidean_dist(), and hence the solutions must be normalized before calling.

Parameters

xSolution

The first solution.

ySolution

The second solution.

platypus.distance.euclidean_dist(x, y)

Computes the Euclidean distance between two solutions.

Parameters

xSolution

The first solution.

ySolution

The second solution.

platypus.distance.manhattan_dist(x, y)

Computes the Manhattan distance between two solutions.

Parameters

xSolution

The first solution.

ySolution

The second solution.

platypus.distance.normalized_euclidean_dist(x, y)

Computes the normalized Euclidean distance between two points.

The solutions must first be normalized using normalize(), otherwise this method will fail.

Parameters

xSolution

The first solution.

ySolution

The second solution.