Problem 44353. Group-wise Euclidean distance
Input:
- x —— An array of size n-by-d, where each row vector denotes a point in a d-dimensional space;
- g —— A grouping (index) vector g of size n-by-1, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.
Output:
- y —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an m-by-m matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.
Example:
Example 1: n = 6, d = 1
g = [2 1 3 2 1].'; x = [3 10 15 8 5].'; y = [0 2 5 % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2 2 0 7 % y(1,3) = y(3,1) = min(15-10,15-5) = 5 5 7 0]; % y(2,3) = y(3,2) = min(15-3,15-8) = 7
Example 2: n = 3, d = 2
g = [1 2 2].'; x = [0 0 5 12 3 4]; y = [0 5; 5 0]; % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5
Testing:
The test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the Cody5:Hard category).
Scoring:
We have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player LY Cao), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).
Please be advised that an amazingly fast solution would earn a score < 5, meaning that it completes execution of all test cases within a second!
Update (11/21/2017): Additional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from Marco Tullio).
Solution Stats
Problem Comments
-
4 Comments
It's too bad that one stray wrong answer with an inordinately high score size ruins the scale of the solution graph. Is there any way to fix that?
Thanks for your feedback. That stray answer tried to hack the scoring in the test suite, and is now removed. Unfortunately, the current scale of the score map is still not good (hard to distinguish good solutions with score < 50). A possible workaround (from a user side) is to modify the scoring in the test suite to truncate the high scores (>=100) to 100, and the resulting y-axis scale would be [0,100] (which makes all solutions distinguishable). But this also results in a re-scoring of all solutions, which might change the current ranking of those similarly fast solutions (e.g., the current best two solutions have an equal score of 2)... I would appreciate any further suggestions (or comments from the Cody admin side) on this.
All problems should be scored by its speed rather than size imo.
leading solution is cheater solution: https://www.mathworks.com/matlabcentral/cody/problems/44353-group-wise-euclidean-distance/solutions/1391283
Solution Comments
Show commentsProblem Recent Solvers72
Suggested Problems
-
1346 Solvers
-
Project Euler: Problem 10, Sum of Primes
1717 Solvers
-
334 Solvers
-
188 Solvers
-
352 Solvers
More from this Author29
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!