Skip to content

Commit

Permalink
Merge pull request #468 from alan-turing-institute/dev
Browse files Browse the repository at this point in the history
Last minute addition to 0.16.2 release
  • Loading branch information
ablaom authored Nov 30, 2020
2 parents 40f2a21 + 29c7069 commit 15a1241
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/MLJBase.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MLJBase
module MLJBase

# ===================================================================
# IMPORTS
Expand Down Expand Up @@ -134,7 +134,7 @@ export params # note this is *not* an extension of StatsBase.params
export partition, unpack, complement, restrict, corestrict

# utilities.jl:
export @set_defaults, flat_values, recursive_setproperty!,
export flat_values, recursive_setproperty!,
recursive_getproperty, pretty, unwind

# show.jl
Expand Down Expand Up @@ -162,7 +162,7 @@ export machine, Machine, fit!, report, fit_only!
export make_blobs, make_moons, make_circles, make_regression

# composition:
export machines, sources, anonymize!, @from_network, @pipeline,
export machines, sources, @from_network, @pipeline,
glb, @tuple, node, @node, sources, origins, return!,
nrows_at_source, machine,
rebind!, nodes, freeze!, thaw!, models, Node, AbstractNode,
Expand Down Expand Up @@ -284,7 +284,7 @@ export DWDMarginLoss, ExpLoss, L1HingeLoss, L2HingeLoss, L2MarginLoss,
SmoothedL1HingeLoss, ZeroOneLoss, HuberLoss, L1EpsilonInsLoss,
L2EpsilonInsLoss, LPDistLoss, LogitDistLoss, PeriodicLoss,
QuantileLoss

# -------------------------------------------------------------------
# re-export from Random, StatsBase, Statistics, Distributions,
# OrderedCollections, CategoricalArrays, InvertedIndices:
Expand Down
2 changes: 1 addition & 1 deletion src/composition/learning_networks/inspection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function machines(W::Node, model=nothing)
(machines(arg) for arg in W.args)...,
(machines(arg) for arg in W.machine.args)...) |> unique
end
model == nothing && return machs
model === nothing && return machs
return filter(machs) do mach
mach.model == model
end
Expand Down
10 changes: 5 additions & 5 deletions src/measures/finite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# -----------------------------------------------------
# LogLoss

struct LogLoss{R} <: Measure where R <: Real
struct LogLoss{R <: Real} <: Measure
tol::R
end
LogLoss(;eps=eps(), tol=eps) = LogLoss(tol)
Expand Down Expand Up @@ -107,12 +107,12 @@ function (::BrierScore)(ŷ::Vec{<:UnivariateFinite},
y::Vec,
w::Union{Nothing,Vec{<:Real}}=nothing)
check_dimensions(ŷ, y)
w == nothing || check_dimensions(w, y)
w === nothing || check_dimensions(w, y)

check_pools(ŷ, y)
unweighted = broadcast(_brier_score, ŷ, y)

if w == nothing
if w === nothing
return unweighted
end
return w.*unweighted
Expand All @@ -125,7 +125,7 @@ function (::BrierScore)(
w::Union{Nothing,Vec{<:Real}}=nothing) where {S,V,R,P<:Real}

check_dimensions(ŷ, y)
w == nothing || check_dimensions(w, y)
w === nothing || check_dimensions(w, y)

isempty(y) && return P(0)

Expand All @@ -136,7 +136,7 @@ function (::BrierScore)(

unweighted = P(2) .* broadcast(pdf, ŷ, y) .- offset

if w == nothing
if w === nothing
return unweighted
end
return w.*unweighted
Expand Down
4 changes: 2 additions & 2 deletions src/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ function _process_accel_settings(accel::CPUThreads)
throw(ArgumentError("`n`used in `acceleration = CPUThreads(n)`must" *
"be an instance of type `T<:Signed`"))
accel.settings > 0 ||
throw(error("Can't create $(acceleration.settings) tasks)"))
throw(error("Can't create $(accel.settings) tasks)"))
_accel = accel
end
return _accel
Expand Down Expand Up @@ -790,7 +790,7 @@ function evaluate!(mach::Machine, resampling, weights,
fit!(mach; rows=train, verbosity=verbosity - 1, force=force)
Xtest = selectrows(X, test)
ytest = selectrows(y, test)
if weights == nothing
if weights === nothing
wtest = nothing
else
wtest = weights[test]
Expand Down
38 changes: 19 additions & 19 deletions src/univariate_finite/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ for func in [:pdf, :logpdf]
function Distributions.$func(
u::AbstractArray{UnivariateFinite{S,V,R,P},N},
C::AbstractVector{<:Union{V, CategoricalValue{V,R}}}) where {S,V,R,P,N}

#ret = Array{P,N+1}(undef, size(u)..., length(C))
ret = zeros(P, size(u)..., length(C))
for i in eachindex(C)
Expand All @@ -117,9 +117,9 @@ end
# v - a vector of CategoricalArrays

# dummy function
# returns `x[i]` for `Array` inputs `x`
# returns `x[i]` for `Array` inputs `x`
# For non-Array inputs returns `zero(dtype)`
#This avoids using an if statement
#This avoids using an if statement
_getindex(x::Array,i, dtype)=x[i]
_getindex(::Nothing, i, dtype) = zero(dtype)

Expand All @@ -130,15 +130,15 @@ function Base.Broadcast.broadcasted(
cv::CategoricalValue) where {S,V,R,P,N}

cv in classes(u) || _err_missing_class(cv)
f() = zeros(P, size(u)) #default caller function

f() = zeros(P, size(u)) #default caller function

return Base.Broadcast.Broadcasted(
identity,
(get(f, u.prob_given_ref, int(cv)),)
)
end

# pdf.(u, v)
function Base.Broadcast.broadcasted(
::typeof(pdf),
Expand All @@ -149,14 +149,14 @@ function Base.Broadcast.broadcasted(
"Arrays could not be broadcast to a common size; "*
"got a dimension with lengths $(length(u)) and $(length(v))"))
for cv in v
cv in classes(u) || _err_missing_class(c)
cv in classes(u) || _err_missing_class(cv)
end

# will use linear indexing:
v_flat = ((v[i], i) for i in 1:length(v))

getter((cv, i), dtype) = _getindex(get(u.prob_given_ref, int(cv), nothing), i, dtype)

ret_flat = getter.(v_flat, P)
return reshape(ret_flat, size(u))
end
Expand All @@ -173,9 +173,9 @@ end

# logpdf.(u::UniFinArr{S,V,R,P,N}, cv::CategoricalValue)
# logpdf.(u::UniFinArr{S,V,R,P,N}, v::AbstractArray{<:CategoricalValue{V,R},N})
# logpdf.(u::UniFinArr{S,V,R,P,N}, raw::AbstractArray{V,N})
# logpdf.(u::UniFinArr{S,V,R,P,N}, raw::V)
for typ in (:CategoricalValue,
# logpdf.(u::UniFinArr{S,V,R,P,N}, raw::AbstractArray{V,N})
# logpdf.(u::UniFinArr{S,V,R,P,N}, raw::V)
for typ in (:CategoricalValue,
:(AbstractArray{<:CategoricalValue{V,R},N}),
:V,
:(AbstractArray{V,N}))
Expand All @@ -188,11 +188,11 @@ for typ in (:CategoricalValue,

# Start with the pdf array
# take advantage of loop fusion
result = log.(pdf.(u, c))
result = log.(pdf.(u, c))
return result
end
end)

else
eval(quote
function Base.Broadcast.broadcasted(
Expand All @@ -201,18 +201,18 @@ for typ in (:CategoricalValue,
c::$typ) where {S,V,R,P,N}

# Start with the pdf array
result = pdf.(u, c)
result = pdf.(u, c)

# Take the log of each entry in-place
@simd for j in eachindex(result)
@inbounds result[j] = log(result[j])
end

return result
end
end)
end

end

## PERFORMANT BROADCASTING OF mode:
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function reduce_nested_field(ex)
tail = ex.args[2]
tail isa QuoteNode || throw(ArgumentError)
field = tail.value
field isa Symbol || throw(ArgmentError)
field isa Symbol || throw(ArgumentError)
subex = ex.args[1]
return (subex, field)
end
Expand Down

0 comments on commit 15a1241

Please sign in to comment.