Skip to content

Commit

Permalink
Get and set a node
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Oct 10, 2019
1 parent db361f6 commit 5e4b66f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MLJ.jl
Expand Up @@ -91,7 +91,7 @@ import ScientificTypes
using DocStringExtensions: SIGNATURES, TYPEDEF

# to be extended:
import Base.==
import Base: ==, getindex, setindex!
import StatsBase.fit!

# from Standard Library:
Expand Down
4 changes: 4 additions & 0 deletions src/operations.jl
Expand Up @@ -103,3 +103,7 @@ if VERSION ≥ v"1.3.0-"
inverse_transform(node::Node{<:NodalMachine{<:Unsupervised}}) =
data->inverse_transform(node.machine, data)
end # version ≥ 1.3

# Syntactic sugar to directly access hyperparameters
getindex(n::Node{<:NodalMachine{<:Model}}, s::Symbol) = getproperty(n.machine.model, s)
setindex!(n::Node{<:NodalMachine{<:Model}}, v, s::Symbol) = setproperty!(n.machine.model, s, v)
5 changes: 5 additions & 0 deletions test/operations.jl
Expand Up @@ -33,6 +33,11 @@ if VERSION ≥ v"1.3.0-"
fit!(ŷ, rows=train)

@test isapprox(rms((rows=test), ys(rows=test)), 0.627123, rtol=1e-4)

# shortcut to get and set hyperparameters of a node
ẑ[:lambda] = 5.0
fit!(ŷ, rows=train)
@test isapprox(rms((rows=test), ys(rows=test)), 0.62699, rtol=1e-4)
end
end # version

Expand Down

0 comments on commit 5e4b66f

Please sign in to comment.