Skip to content

Commit

Permalink
Merge pull request #578 from alan-turing-institute/bug-576
Browse files Browse the repository at this point in the history
Fix transposed `y` and `yhat` in measures from LossFunctions
  • Loading branch information
ablaom authored Jun 10, 2021
2 parents 2ef3a07 + 3297993 commit ab2a1ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/measures/loss_functions_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ MMI.target_scitype(::Type{<:DistanceLoss}) = Union{Vec{Continuous},Vec{Count}}

function value(measure::DistanceLoss, yhat, X, y, ::Nothing,
::Val{false}, ::Val{true})
return LossFunctions.value(getfield(measure, :loss), yhat, y)
return LossFunctions.value(getfield(measure, :loss), y, yhat)
end

function value(measure::DistanceLoss, yhat, X, y, w,
Expand All @@ -137,7 +137,7 @@ function value(measure::MarginLoss, yhat, X, y, ::Nothing,
check_pools(yhat, y)
probs_of_observed = broadcast(pdf, yhat, y)
return (LossFunctions.value).(getfield(measure, :loss),
_scale.(probs_of_observed), 1)
1, _scale.(probs_of_observed))
end

function value(measure::MarginLoss, yhat, X, y, w,
Expand Down
8 changes: 4 additions & 4 deletions test/measures/loss_functions_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const DISTANCE_LOSSES = MLJBase.DISTANCE_LOSSES
for M_ex in MARGIN_LOSSES
m = eval(:(MLJBase.$M_ex()))
@test MLJBase.value(m, yhat, X, y, nothing)
LossFunctions.value(getfield(m, :loss), yhatm, ym)
LossFunctions.value(getfield(m, :loss), ym, yhatm)
m(yhat, y)
@test mean(MLJBase.value(m, yhat, X, y, w))
LossFunctions.value(getfield(m, :loss), yhatm, ym,
LossFunctions.value(getfield(m, :loss), ym, yhatm,
LossFunctions.AggMode.WeightedMean(w))
mean(m(yhat, y, w))
end
Expand All @@ -58,10 +58,10 @@ end
m_ex = MLJBase.snakecase(M_ex)
@test m == eval(:(MLJBase.$m_ex))
@test MLJBase.value(m, yhat, X, y, nothing)
LossFunctions.value(getfield(m, :loss), yhat, y)
LossFunctions.value(getfield(m, :loss), y, yhat)
m(yhat, y)
@test mean(MLJBase.value(m, yhat, X, y, w))
LossFunctions.value(getfield(m, :loss), yhat, y,
LossFunctions.value(getfield(m, :loss), y, yhat,
LossFunctions.AggMode.WeightedMean(w))
mean(m(yhat ,y, w))
end
Expand Down

0 comments on commit ab2a1ab

Please sign in to comment.