diff --git a/distance_batsim_output.py b/distance_batsim_output.py index 8b8e0865fe26cb492f1f0121c670183112d37b17..30aaa2b764b84621ab84c5a8489e4adcbcf710a1 100755 --- a/distance_batsim_output.py +++ b/distance_batsim_output.py @@ -77,12 +77,6 @@ def lateness_distance(s1, s2): return float(np.sum([y-x for x, y in zip(s1, s2)])) -def l2_norm(s): - """Return the l2 norm of the series s""" - - return float( np.sqrt(np.sum([x * x for x in s])) ) - - def distances(file1, file2, euclidean=True, lateness=False, norm_eucl=False, field=["finish_time"]): """Computes and returns a set of distances between two batsim outputs, if diff --git a/example_distance.ipynb b/example_distance.ipynb index 6a64b40379374a0e315bcbe2b455f829e073f2fc..ed2e2f47dad8e53db95cd4c9a37a4d08a7ce16cc 100644 --- a/example_distance.ipynb +++ b/example_distance.ipynb @@ -285,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -294,22 +294,20 @@ "text": [ "/home/mael/ownCloud/workspace/batmen-tools/distance_batsim_output.py:56: UserWarning: Some jobs in test/input/3jobs.csv and test/input/3jobs_zeros.csv don't have the same runtime (+/- 1sec). It is unusual, as runtime are normally an input of the simulation.\n", " warnings.warn(f\"Some jobs in {file1} and {file2} don't have the same runtime (+/- 1sec). It is unusual, as runtime are normally an input of the simulation.\")\n", - "/home/mael/ownCloud/workspace/batmen-tools/distance_batsim_output.py:114: RuntimeWarning: divide by zero encountered in double_scalars\n", - " dist[f][\"normalized_euclidean\"] = eucl / np.sqrt(sum_runtimes1 * sum_runtimes2)\n", "{\n", " \"submission_time\": {\n", " \"euclidean\": 50.0,\n", - " \"normalized_euclidean\": Infinity,\n", + " \"normalized_euclidean\": null,\n", " \"lateness\": -70.0\n", " },\n", " \"starting_time\": {\n", " \"euclidean\": 50.0,\n", - " \"normalized_euclidean\": Infinity,\n", + " \"normalized_euclidean\": null,\n", " \"lateness\": -70.0\n", " },\n", " \"finish_time\": {\n", " \"euclidean\": 100.0,\n", - " \"normalized_euclidean\": Infinity,\n", + " \"normalized_euclidean\": null,\n", " \"lateness\": -140.0\n", " }\n", "}\n" diff --git a/test/test_distance.py b/test/test_distance.py index 536faec44abe55a0bbff11e7da32c3acd5e8856c..0be21d0cba34cedd1bbcc4c2a773813c3b32cd0d 100644 --- a/test/test_distance.py +++ b/test/test_distance.py @@ -19,17 +19,6 @@ def test_lateness_distance(): assert lateness_distance(s1, s2) == - lateness_distance(s2, s1) == 6 assert lateness_distance(empty, empty) == 0 -def test_l2_norm(): - assert l2_norm(empty) == 0 - assert l2_norm(s1) == np.sqrt(10*10 + 14*14 + 500*500) - assert l2_norm(u) == 2 - assert l2_norm(v) == 1 - -def test_normalized_euclidean_distance(): - assert normalized_euclidian_distance(u, v) == .5 - - - ####### Integration tests ####### three_jobs = "test/input/3jobs.csv" @@ -40,7 +29,8 @@ mc_10days_a60 = "test/input/mc_10days_a60_jobs.csv" def test_cleaning(): # Clean session info: - distances(three_jobs_w_session, three_jobs_zero) + with pytest.warns(UserWarning): + distances(three_jobs_w_session, three_jobs_zero) # Clean unsuccessful jobs: with pytest.warns(UserWarning): @@ -63,24 +53,26 @@ def test_some_distances(): euclidean=False, lateness=True, field=fin) == 0 # Eucl distance - assert distances(three_jobs, three_jobs_zero, field=sub) == 50 - assert distances(three_jobs_zero, three_jobs, field=start) == 50 - assert distances(three_jobs, three_jobs_zero, field=fin) == 100 + with pytest.warns(UserWarning): + assert distances(three_jobs, three_jobs_zero, field=sub) == 50 + assert distances(three_jobs_zero, three_jobs, field=start) == 50 + assert distances(three_jobs, three_jobs_zero, field=fin) == 100 - assert distances(three_jobs, three_jobs_w_session, field=sub) == 0 - assert distances(three_jobs, three_jobs_w_session, field=start) == 0 - assert distances(three_jobs, three_jobs_w_session, field=fin) == 20 * np.sqrt(2) + assert distances(three_jobs, three_jobs_w_session, field=sub) == 0 + assert distances(three_jobs, three_jobs_w_session, field=start) == 0 + assert distances(three_jobs, three_jobs_w_session, field=fin) == 20 * np.sqrt(2) # Normalized eucl distance - assert distances(three_jobs, three_jobs_zero, - euclidean=False, norm_eucl=True, field=sub) == None - assert distances(three_jobs, three_jobs_w_session, - euclidean=False, norm_eucl=True, field=sub) == 0 - - norm_dis_A_B = distances(three_jobs, three_jobs_w_session, - euclidean=False, norm_eucl=True, field=fin) - norm_dis_B_A = distances(three_jobs, three_jobs_w_session, + with pytest.warns(UserWarning): + assert distances(three_jobs, three_jobs_zero, + euclidean=False, norm_eucl=True, field=sub) == None + assert distances(three_jobs, three_jobs_w_session, + euclidean=False, norm_eucl=True, field=sub) == 0 + + norm_dis_A_B = distances(three_jobs, three_jobs_w_session, + euclidean=False, norm_eucl=True, field=fin) + norm_dis_B_A = distances(three_jobs, three_jobs_w_session, euclidean=False, norm_eucl=True, field=fin) - expected = 800 / (100*100) + expected = 20 * np.sqrt(2) / 70 # eucl / sum_runtime assert norm_dis_A_B == norm_dis_B_A assert norm_dis_B_A - expected < 1e-8