Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to fix StaticNetworkComposite issue #931

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/composition/learning_networks/signatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function fitted_params(signature::Signature; supplement=true)
end

"""
output_and_report(signature, operation, Xnew)
output_and_report(signature, operation, Xnew...)

**Private method.**

Expand All @@ -375,3 +375,6 @@ function output_and_report(signature, operation, Xnew)
report = MLJBase.report(signature_clone; supplement=false)
return output, report
end
# special case for static transformers with multiple inputs:
output_and_report(signature, operation, Xnew...) =
output_and_report(signature, operation, Xnew)
4 changes: 2 additions & 2 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ for operation in [:predict,
:transform,
:inverse_transform]
quote
function $operation(model::NetworkComposite, fitresult, Xnew)
function $operation(model::NetworkComposite, fitresult, Xnew...)
if $(QuoteNode(operation)) in MLJBase.operations(fitresult)
return output_and_report(fitresult, $(QuoteNode(operation)), Xnew)
return output_and_report(fitresult, $(QuoteNode(operation)), Xnew...)
end
throw(err_unsupported_operation($operation))
end
Expand Down
33 changes: 33 additions & 0 deletions test/composition/models/network_composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,39 @@ end

end

# # STATIC MODEL WITH MULTIPLE INPUTS

mutable struct Balancer <: Static end
MLJBase.transform(::Balancer, _, X, y) = (selectrows(X, 1:2), selectrows(y, 1:2))

struct ThinWrapper <: StaticNetworkComposite
balancer
end

function MLJBase.prefit(wrapper::ThinWrapper, verbosity)

data = source() # empty source because there is no training data
Xs = first(data)
ys = last(data)

mach=machine(:balancer)

output = transform(mach, Xs, ys)

(; transform = output)

end

balancer = Balancer()
wrapper = ThinWrapper(balancer)

X, y = make_blobs()
mach = machine(wrapper)
Xunder, yunder = transform(mach, X, y)
@test Xunder == selectrows(X, 1:2)
@test yunder == selectrows(y, 1:2)



# # MACHINE INTEGRATION TESTS

Expand Down