Utilities

Index

API

Mill.list_lensFunction
list_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, 16 bytes
  ├── BagNode  # 2 obs, 88 bytes
  │     ╰── ∅
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes

julia> list_lens(n)
9-element Vector{Any}:
 identity (generic function with 1 method)
 (@optic _.data[1])
 (@optic _.data[1].data)
 (@optic _.data[1].bags)
 (@optic _.data[1].metadata)
 (@optic _.data[2])
 (@optic _.data[2].data)
 (@optic _.data[2].metadata)
 (@optic _.metadata)

See also: pred_lens, find_lens, findnonempty_lens.

source
Mill.find_lensFunction
find_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, 16 bytes
  ├── BagNode  # 2 obs, 88 bytes
  │     ╰── ∅
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes

julia> find_lens(n, n.data[1])
1-element Vector{Any}:
 (@optic _.data[1])

See also: pred_lens, list_lens, findnonempty_lens.

source
Mill.findnonempty_lensFunction
findnonempty_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, 16 bytes
  ├── BagNode  # 2 obs, 88 bytes
  │     ╰── ∅
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes

julia> findnonempty_lens(n)
3-element Vector{Any}:
 identity (generic function with 1 method)
 (@optic _.data[1])
 (@optic _.data[2])

See also: pred_lens, list_lens, find_lens.

source
Mill.pred_lensFunction
pred_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, 16 bytes
  ├── BagNode  # 2 obs, 88 bytes
  │     ╰── ∅
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes

julia> pred_lens(x -> x isa ArrayNode, n)
1-element Vector{Any}:
 (@optic _.data[2])

See also: list_lens, find_lens, findnonempty_lens.

source
Mill.code2lensFunction
code2lens(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, 16 bytes
  ├── BagNode ["E"]  # 2 obs, 88 bytes
  │     ╰── ∅ ["M"]
  ╰── ArrayNode(2×2 Array with Int64 elements) ["U"]  # 2 obs, 80 bytes

julia> code2lens(n, "U")
1-element Vector{Any}:
 (@optic _.data[2])

See also: lens2code.

source
Mill.lens2codeFunction
lens2code(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, 16 bytes
  ├── BagNode ["E"]  # 2 obs, 88 bytes
  │     ╰── ∅ ["M"]
  ╰── ArrayNode(2×2 Array with Int64 elements) ["U"]  # 2 obs, 80 bytes

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.

source
Mill.model_lensFunction
model_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, 24 bytes
  ├── BagNode  # 2 obs, 96 bytes
  │     ╰── ArrayNode(2×2 Array with Float32 elements)  # 2 obs, 64 bytes
  ╰── ArrayNode(2×2 Array with Float32 elements)  # 2 obs, 64 bytes

julia> m = reflectinmodel(n)
ProductModel ↦ Dense(20 => 10)  # 2 arrays, 210 params, 920 bytes
  ├── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10)  # 4 arrays, 240 params, 1.094 KiB
  │     ╰── ArrayModel(Dense(2 => 10))  # 2 arrays, 30 params, 200 bytes
  ╰── ArrayModel(Dense(2 => 10))  # 2 arrays, 30 params, 200 bytes

julia> model_lens(m, (@optic _.data[2]))
(@optic _.ms[2])

See also: data_lens.

source
Mill.data_lensFunction
data_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, 24 bytes
  ├── BagNode  # 2 obs, 96 bytes
  │     ╰── ArrayNode(2×2 Array with Float32 elements)  # 2 obs, 64 bytes
  ╰── ArrayNode(2×2 Array with Float32 elements)  # 2 obs, 64 bytes

julia> m = reflectinmodel(n)
ProductModel ↦ Dense(20 => 10)  # 2 arrays, 210 params, 920 bytes
  ├── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10)  # 4 arrays, 240 params, 1.094 KiB
  │     ╰── ArrayModel(Dense(2 => 10))  # 2 arrays, 30 params, 200 bytes
  ╰── ArrayModel(Dense(2 => 10))  # 2 arrays, 30 params, 200 bytes

julia> data_lens(n, (@optic _.ms[2]))
(@optic _.data[2])

See also: data_lens.

source
Mill.replaceinFunction
replacein(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, 24 bytes
  ├── BagNode  # 2 obs, 96 bytes
  │     ╰── ArrayNode(2×2 Array with Float64 elements)  # 2 obs, 80 bytes
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes

julia> replacein(n, n.data[1], ArrayNode(maybehotbatch([1, 2], 1:2)))
ProductNode  # 2 obs, 24 bytes
  ├── ArrayNode(2×2 MaybeHotMatrix with Bool elements)  # 2 obs, 80 bytes
  ╰── ArrayNode(2×2 Array with Int64 elements)  # 2 obs, 80 bytes
source