Vertex Creation
NaiveNASlib.inputvertex
— Functioninputvertex(name, size)
Return an immutable input type vertex with the given name
and size
.
Typically used as "entry" point to a computation graph.
Examples
julia> using NaiveNASlib
julia> inputvertex("input", 5)
InputSizeVertex(InputVertex(input, outputs=[]), 5)
NaiveNASlib.immutablevertex
— Functionimmutablevertex(computation, inputs::AbstractVertex...; traitdecoration=identity)
immutablevertex(vname::AbstractString, computation, inputs::AbstractVertex...; traitdecoration=identity)
immutablevertex(computation, vname::AbstractString, inputs::AbstractVertex...; traitdecoration=identity)
Return an immutable computation type vertex.
Use traitdecoration
to attach other traits, such as named
, logged
or validated
.
Examples
julia> using NaiveNASlib
julia> v = immutablevertex(x -> x * [1 2 3; 4 5 6], inputvertex("input", 2));
julia> v([1 2])
1×3 Matrix{Int64}:
9 12 15
julia> v = immutablevertex("v", x -> x * [1 2 3; 4 5 6], inputvertex("input", 2));
julia> name(v)
"v"
julia> v = immutablevertex("v", inputvertex("input", 2)) do x
x * [1 2 3; 4 5 6]
end;
julia> name(v)
"v"
NaiveNASlib.absorbvertex
— Functionabsorbvertex(computation, inputs::AbstractVertex...; traitdecoration=identity)
absorbvertex(vname::AbstractString, computation, inputs::AbstractVertex...; traitdecoration=identity)
absorbvertex(computation, vname::AbstractString, inputs::AbstractVertex...; traitdecoration=identity)
Return a mutable computation type vertex which absorbs size changes. Typical example of this is a neural network layer wrapping a parameter array.
Use traitdecoration
to attach other traits, such as named
, logged
or validated
.
Examples
julia> using NaiveNASlib
julia> v = absorbvertex(x -> x * [1 2 3; 4 5 6], inputvertex("input", 2));
julia> v([1 2])
1×3 Matrix{Int64}:
9 12 15
julia> v = absorbvertex("v", x -> x * [1 2 3; 4 5 6], inputvertex("input", 2));
julia> name(v)
"v"
julia> v = absorbvertex("v", inputvertex("input", 2)) do x
x * [1 2 3; 4 5 6]
end;
julia> name(v)
"v"
NaiveNASlib.invariantvertex
— Functioninvariantvertex(computation, inputs::AbstractVertex...; traitdecoration=identity)
invariantvertex(vname::AbstractString, computation, inputs::AbstractVertex...; traitdecoration=identity)
invariantvertex(computation, vname::AbstractString, inputs::AbstractVertex...; traitdecoration=identity)
Return a mutable computation type vertex which is size invariant, i.e nin == nout
.
Use traitdecoration
to attach other traits, such as named
, logged
or validated
.
Examples
julia> using NaiveNASlib
julia> v = invariantvertex(x -> 2 .* x, inputvertex("input", 2));
julia> nin(v)
1-element Vector{Int64}:
2
julia> nout(v)
2
julia> v([1 2])
1×2 Matrix{Int64}:
2 4
julia> v = invariantvertex("v", x -> 2 .* x, inputvertex("input", 2));
julia> name(v)
"v"
julia> v = invariantvertex("v", inputvertex("input", 2)) do x
2 .* x
end;
julia> name(v)
"v"
NaiveNASlib.conc
— Functionconc(v::AbstractVertex, vs::AbstractVertex...; dims, traitdecoration=identity, outwrap=identity)
conc(vname::AbstractString, v::AbstractVertex, vs::AbstractVertex...; dims, traitdecoration=identity, outwrap=identity)
Return a mutable vertex which concatenates input along dimension dim
.
Use traitdecoration
to attach other traits, such as named
, logged
or validated
.
Use outwrap=f
to wrap the concatenation function in f
.
conc(vname::AbstractString,...;traitdecoration = f, ...)
is equivalent to conc(...;traitdecoration=named(vname) ∘ f, ...)
.
Examples
julia> using NaiveNASlib
julia> v = conc(inputvertex.(["in1", "in2", "in3"], 1:3)..., dims=1);
julia> nin(v)
3-element Vector{Int64}:
1
2
3
julia> nout(v)
6
julia> v([1], [2, 3], [4, 5, 6])
6-element Vector{Int64}:
1
2
3
4
5
6
julia> v = conc(inputvertex.(["in1", "in2", "in3"], 1:3)..., dims=1, outwrap = f -> (x...) -> 2f(x...));
julia> v([1], [2, 3], [4, 5, 6])
6-element Vector{Int64}:
2
4
6
8
10
12
Base.:+
— Function+(v::AbstractVertex, vs::AbstractVertex...)
Return a mutable vertex which performs (broadcasted) elementwise addition of its inputs.
An AbstractString
, Function
or VertexConf
can be supplied through the >>
operator. An AbstractString
will be used as the name of the vertex, a Function f
will wrap the output so that the vertex computation becomes f(+.(x...))
and VertexConf
can be used to supply both a name and a function.
Examples
julia> using NaiveNASlib
julia> v = inputvertex("in1", 2) + inputvertex("in2", 2) + inputvertex("in3" ,2);
julia> nin(v)
3-element Vector{Int64}:
2
2
2
julia> nout(v)
2
julia> v([1, 2], [3, 4], [5, 6])
2-element Vector{Int64}:
9
12
julia> v = "v" >> inputvertex("in1", 3) + inputvertex("in2", 3);
julia> name(v)
"v"
Base.:-
— Function-(v1::AbstractVertex, v2::AbstractVertex)
Return a mutable vertex which performs (broadcasted) elementwise subtraction of its inputs.
An AbstractString
, Function
or VertexConf
can be supplied through the >>
operator. An AbstractString
will be used as the name of the vertex, a Function f
will wrap the output so that the vertex computation becomes f(-.(x...))
and VertexConf
can be used to supply both a name and a function.
Examples
julia> using NaiveNASlib
julia> v = inputvertex("in1", 2) - inputvertex("in2", 2);
julia> nin(v)
2-element Vector{Int64}:
2
2
julia> nout(v)
2
julia> v([1, 2], [3, 4])
2-element Vector{Int64}:
-2
-2
julia> v = "v" >> inputvertex("in1", 3) - inputvertex("in2", 3);
julia> name(v)
"v"
-(v::AbstractVertex)
Return a mutable vertex which performs elementwise negation of its input.
An AbstractString
, Function
or VertexConf
can be supplied through the >>
operator. An AbstractString
will be used as the name of the vertex, a Function f
will wrap the output so that the vertex computation becomes f(-.(x...))
and VertexConf
can be used to supply both a name and a function. Due to operator precedence, this has to be done in the following order: -(conf >> v)
#Examples
julia> using NaiveNASlib
julia> v = -inputvertex("in", 2);
julia> v([1,2])
2-element Vector{Int64}:
-1
-2
julia> v = -("v" >> inputvertex("in", 2));
julia> name(v)
"v"
Base.:*
— Function*(v::AbstractVertex, vs::AbstractVertex...)
*(conf::VertexConf, v::AbstractVertex, vs::AbstractVertex...)
Return a mutable vertex which performs (broadcasted) elementwise multiplication of its inputs.
An AbstractString
, Function
or VertexConf
can be supplied through the >>
operator. An AbstractString
will be used as the name of the vertex, a Function f
will wrap the output so that the vertex computation becomes f(*.(x...))
and VertexConf
can be used to supply both a name and a function.
Examples
julia> using NaiveNASlib
julia> v = inputvertex("in1", 2) * inputvertex("in2", 2) * inputvertex("in3" ,2);
julia> nin(v)
3-element Vector{Int64}:
2
2
2
julia> nout(v)
2
julia> v([1, 2], [3, 4], [5, 6])
2-element Vector{Int64}:
15
48
julia> v = "v" >> inputvertex("in1", 3) * inputvertex("in2", 3);
julia> name(v)
"v"
Base.:/
— Function/(v1::AbstractVertex, v2::AbstractVertex)
/(conf::VertexConf, v1::AbstractVertex, v2::AbstractVertex)
Return a mutable vertex which performs (broadcasted) elementwise division of its inputs.
An AbstractString
, Function
or VertexConf
can be supplied through the >>
operator. An AbstractString
will be used as the name of the vertex, a Function f
will wrap the output so that the vertex computation becomes f(/.(x...))
and VertexConf
can be used to supply both a name and a function.
Examples
julia> using NaiveNASlib
julia> v = inputvertex("in1", 2) / inputvertex("in2", 2);
julia> nin(v)
2-element Vector{Int64}:
2
2
julia> nout(v)
2
julia> v([6, 8], [2, 4])
2-element Vector{Float64}:
3.0
2.0
julia> v = "v" >> inputvertex("in1", 3) / inputvertex("in2", 3);
julia> name(v)
"v"
Base.:>>
— Function>>(conf::VertexConf, v::AbstractVertex)
>>(name::AbstractString, v::AbstractVertex)
>>(outwrap::Function, v::AbstractVertex)
Return inputs as a tuple. Only used to enable the conf >> v1 op v2 ...
syntax.