Utilities
Index
Mill.code2lensMill.data_lensMill.find_lensMill.findnonempty_lensMill.lens2codeMill.list_lensMill.model_lensMill.pred_lensMill.replacein
API
Mill.list_lens — Functionlist_lens(n)Return a Vector of Accessors.jl lenses for accessing all nodes/fields in n.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ∅
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs
julia> list_lens(n)
9-element Vector{Any}:
identity (generic function with 1 method)
(@o _.data[1])
(@o _.data[1].data)
(@o _.data[1].bags)
(@o _.data[1].metadata)
(@o _.data[2])
(@o _.data[2].data)
(@o _.data[2].metadata)
(@o _.metadata)See also: pred_lens, find_lens, findnonempty_lens.
Mill.find_lens — Functionfind_lens(n, x)Return a Vector of Accessors.jl lenses for accessing all nodes/fields in n that return true when compared to x using Base.===.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ∅
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs
julia> find_lens(n, n.data[1])
1-element Vector{Any}:
(@o _.data[1])See also: pred_lens, list_lens, findnonempty_lens.
Mill.findnonempty_lens — Functionfindnonempty_lens(n)Return a Vector of Accessors.jl lenses for accessing all nodes/fields in n that contain at least one observation.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ∅
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs
julia> findnonempty_lens(n)
3-element Vector{Any}:
identity (generic function with 1 method)
(@o _.data[1])
(@o _.data[2])Mill.pred_lens — Functionpred_lens(p, n)Return a Vector of Accessors.jl lenses for accessing all nodes/fields in n conforming to predicate p.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ∅
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs
julia> pred_lens(x -> x isa ArrayNode, n)
1-element Vector{Any}:
(@o _.data[2])See also: list_lens, find_lens, findnonempty_lens.
Mill.code2lens — Functioncode2lens(n, c)Convert code c from HierarchicalUtils.jl traversal to a Vector of Accessors.jl lenses such that they access each node in tree n egal to node under code c in the tree.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])));
julia> printtree(n; trav=true)
ProductNode [""] 2 obs
├── BagNode ["E"] 2 obs
│ ╰── ∅ ["M"]
╰── ArrayNode(2×2 Array with Int64 elements) ["U"] 2 obs
julia> code2lens(n, "U")
1-element Vector{Any}:
(@o _.data[2])See also: lens2code.
Mill.lens2code — Functionlens2code(n, l)Convert Accessors.jl lens l to a Vector of codes from HierarchicalUtils.jl traversal such that they access each node in tree n egal to node accessible by lens l.
Examples
julia> n = ProductNode((BagNode(missing, bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])));
julia> printtree(n; trav=true)
ProductNode [""] 2 obs
├── BagNode ["E"] 2 obs
│ ╰── ∅ ["M"]
╰── ArrayNode(2×2 Array with Int64 elements) ["U"] 2 obs
julia> lens2code(n, (@optic _.data[2]))
1-element Vector{String}:
"U"
julia> lens2code(n, (@optic _.data[∗]))
2-element Vector{String}:
"E"
"U"
See also: code2lens.
Mill.model_lens — Functionmodel_lens(m, l)Convert Accessors.jl lens l for a data node to a new lens for accessing the same location in model m.
Examples
julia> n = ProductNode((BagNode(randn(Float32, 2, 2), bags([0:-1, 0:-1])),
ArrayNode(Float32[1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ArrayNode(2×2 Array with Float32 elements) 2 obs
╰── ArrayNode(2×2 Array with Float32 elements) 2 obs
julia> m = reflectinmodel(n)
ProductModel ↦ Dense(20 => 10) 2 arrays, 210 params, 928 bytes
├── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) 4 arrays, 240 params, 1.102 KiB
│ ╰── ArrayModel(Dense(2 => 10)) 2 arrays, 30 params, 208 bytes
╰── ArrayModel(Dense(2 => 10)) 2 arrays, 30 params, 208 bytes
julia> model_lens(m, (@optic _.data[2]))
(@o _.ms[2])See also: data_lens.
Mill.data_lens — Functiondata_lens(n, l)Convert Accessors.jl lens l for a model node to a new lens for accessing the same location in data node n.
Examples
julia> n = ProductNode((BagNode(randn(Float32, 2, 2), bags([0:-1, 0:-1])), ArrayNode(Float32[1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ArrayNode(2×2 Array with Float32 elements) 2 obs
╰── ArrayNode(2×2 Array with Float32 elements) 2 obs
julia> m = reflectinmodel(n)
ProductModel ↦ Dense(20 => 10) 2 arrays, 210 params, 928 bytes
├── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) 4 arrays, 240 params, 1.102 KiB
│ ╰── ArrayModel(Dense(2 => 10)) 2 arrays, 30 params, 208 bytes
╰── ArrayModel(Dense(2 => 10)) 2 arrays, 30 params, 208 bytes
julia> data_lens(n, (@optic _.ms[2]))
(@o _.data[2])See also: data_lens.
Mill.replacein — Functionreplacein(n, old, new)Replace in data node or model n each occurence of old by new.
Short description
Examples
julia> n = ProductNode((BagNode(randn(2, 2), bags([0:-1, 0:-1])), ArrayNode([1 2; 3 4])))
ProductNode 2 obs
├── BagNode 2 obs
│ ╰── ArrayNode(2×2 Array with Float64 elements) 2 obs
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs
julia> replacein(n, n.data[1], ArrayNode(maybehotbatch([1, 2], 1:2)))
ProductNode 2 obs
├── ArrayNode(2×2 MaybeHotMatrix with Bool elements) 2 obs
╰── ArrayNode(2×2 Array with Int64 elements) 2 obs