diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b72604..10fc5cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +## 1.20.1.0 + +* Fix Soft2D-F1 metric +* Check for invalid rectangles in Soft2D-F1 metric + ## 1.20.0.0 * Add --list-metrics options diff --git a/geval.cabal b/geval.cabal index b46a6b8..775b386 100644 --- a/geval.cabal +++ b/geval.cabal @@ -1,5 +1,5 @@ name: geval -version: 1.20.0.0 +version: 1.20.1.0 synopsis: Machine learning evaluation tools description: Please see README.md homepage: http://github.com/name/project diff --git a/src/GEval/Clippings.hs b/src/GEval/Clippings.hs index 5b20b64..9b3b527 100644 --- a/src/GEval/Clippings.hs +++ b/src/GEval/Clippings.hs @@ -104,11 +104,13 @@ rectangleParser = do x1 <- decimal char ',' y1 <- decimal - return $ Rectangle (Point x0 y0) (Point x1 y1) + if x1 < x0 || y1 < y0 + then fail "wrong coordinates" + else return $ Rectangle (Point x0 y0) (Point x1 y1) rectangleArea :: Rectangle -> Integer rectangleArea (Rectangle (Point x0 y0) (Point x1 y1)) = - (fromIntegral $ x1 - x0) * (fromIntegral $ y1 - y0) + (fromIntegral $ x1 - x0 + 1) * (fromIntegral $ y1 - y0 + 1) clippingArea :: LabeledClipping -> Integer clippingArea (LabeledClipping _ (Clipping _ rect)) = rectangleArea rect diff --git a/src/GEval/MetricsMeta.hs b/src/GEval/MetricsMeta.hs index eb84ad9..84c0fb0 100644 --- a/src/GEval/MetricsMeta.hs +++ b/src/GEval/MetricsMeta.hs @@ -121,8 +121,8 @@ expectedScore (EvaluationScheme (SoftFMeasure beta) []) recall = 0.75 in weightedHarmonicMean beta precision recall expectedScore (EvaluationScheme (Soft2DFMeasure beta) []) - = let precision = 0.21117747440273 - recall = 0.27423822714681 + = let precision = 0.211622914314256 + recall = 0.2749908502976 in (weightedHarmonicMean beta precision recall) / 2.0 listOfAvailableEvaluationSchemes :: [EvaluationScheme] diff --git a/test/Spec.hs b/test/Spec.hs index 57222e9..047eb3d 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -276,7 +276,9 @@ main = hspec $ do runGEvalTest "probabilistic-soft-f1-calibrated" `shouldReturnAlmost` 0.88888888888 describe "Soft2D-F1" $ do it "simple test" $ do - runGEvalTest "soft2d-f1-simple" `shouldReturnAlmost` 0.218457349437945 + runGEvalTest "soft2d-f1-simple" `shouldReturnAlmost` 0.22053934201995676 + it "very narrow rectangles" $ do + runGEvalTest "soft2d-f1-one-pixel" `shouldReturnAlmost` 0.281992045358382 describe "test edit-distance library" $ do it "for handling UTF8" $ do levenshteinDistance defaultEditCosts "źdźbło" "źd好bło" `shouldBe` 1 diff --git a/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel-solution/test-A/out.tsv b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel-solution/test-A/out.tsv new file mode 100644 index 0000000..252ddf8 --- /dev/null +++ b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel-solution/test-A/out.tsv @@ -0,0 +1,6 @@ +3/100,200,100,200 +3/100,200,101,200 +3/100,200,100,200 +3/100,200,102,202 +2/1000,2000,1000,2000 1/1000,2000,1000,2000 +1/100,150,300,350 diff --git a/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/config.txt b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/config.txt new file mode 100644 index 0000000..f5443ee --- /dev/null +++ b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/config.txt @@ -0,0 +1 @@ +--metric Soft2D-F1 diff --git a/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/test-A/expected.tsv b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/test-A/expected.tsv new file mode 100644 index 0000000..681b9cb --- /dev/null +++ b/test/soft2d-f1-one-pixel/soft2d-f1-one-pixel/test-A/expected.tsv @@ -0,0 +1,6 @@ +3/100,200,100,400 +3/100,200,101,201 +3/100,200,101,201 +3/100,200,101,201 +3/1000,2000,1000,2000 4/1000,2000,1000,2000 +2/100,150,300,350