API
Auto
ChainPlots.FIXED_INPUT_DIM_LAYERS — Constant
FIXED_INPUT_DIM_LAYERSList of layers with fixed-size input data
ChainPlots.NEURON_COLORS — Constant
NEURON_COLORS::Dict{Symbol, Symbol}Specify the color for each type of layer.
ChainPlots.NODE_PROPERTIES — Constant
NODE_PROPERTIESNames of the properties stored for each neuron (node) of a ChainGraph.
:layer_number:Intwith the layer the neuron belongs to, with0for the input layer,1, …, n-1for the hidden layers andnfor the output layer of a chain withnlayers;:layer_name:Stringwith the name of the layer, e.g."Dense(2 => 5, σ)", or"input layer";:layer_type:Symbolwith the type of the layer, e.g.:Dense,:LSTM,:GRUCell,:Conv, or:input_layer;:index_in_layer:Tuplewith the position of the neuron within its layer, e.g.(i,)for the output ofDense(n => m)orRNN(n => m), or(i, j, c)for a two-dimensional convolutional layer, and so on;:layer_center:Float64with the vertical mid-point of the layer;:loc_x,:loc_y:Float64with the coordinates of the neuron in the plot;:neuron_color:Symbolwith the default color of the neuron, seeNEURON_COLORS.
ChainPlots.RECURRENT_CELLS — Constant
RECURRENT_CELLSRecurrent cells that process a single time step, returning (y, state).
Since a cell returns a tuple, a Flux.Chain cannot continue after it, so a cell is only accepted on its own or as the last layer of a chain.
ChainPlots.SEQUENCE_LAYERS — Constant
SEQUENCE_LAYERSRecurrent layers that process a whole sequence at once (Flux ≥ 0.15).
ChainPlots draws them folded, as a single time step: a vector input of length in is fed to them as a sequence of length one, and their output is taken as a vector of length out.
ChainPlots.AbstractPlotBackend — Type
AbstractPlotBackendSupertype of the plotting packages plotchain can use, PlotsBackend and MakieBackend. Each is supported by a package extension, loaded with the package.
ChainPlots.ChainGraph — Type
ChainGraph <: Graphs.AbstractGraph{Int}Graph of the neurons of a neural network, as built by chaingraph, with one vertex per neuron and one edge per connection between neurons of consecutive layers.
A ChainGraph implements the Graphs.jl interface, so functions such as nv, ne, vertices, edges and neighbors work on it, and so do packages built on that interface, such as GraphPlot.jl. It is plotted with plot(cg), once Plots.jl or Makie.jl is loaded; see plotchain for the attributes of the plot recipes.
Use nodeprop and nodeprops to read the properties of a neuron (see NODE_PROPERTIES), and layer_dimensions and layer_names for the properties of each layer.
The fields of a ChainGraph are internal: the graph backend may change in a future release without notice.
ChainPlots.MakieBackend — Type
MakieBackend()Plot with Makie.jl, loaded with one of its backends, such as using CairoMakie or using GLMakie. See plotchain.
ChainPlots.ModelLayers — Type
ModelLayersInternal description of a model as a sequence of layers, which is what chaingraph works with, so that it supports models from different packages.
For each layer, it holds a function applying the layer to an array of Float32, used to infer the dimensions of each layer, a function applying it to an array of NeuralNumbers, used to infer the connections between neurons, and its name and type, such as :Dense.
ChainPlots.PlotsBackend — Type
PlotsBackend()Plot with Plots.jl, loaded with using Plots. See plotchain.
ChainPlots.UnitVector — Type
UnitVector{T}Structure for unit vectors in a linear space
Used for generating a basis to infer the layer connection
ChainPlots.applylayer — Method
applylayer(l, x)Apply layer l to x the way ChainPlots models it.
Sequence layers given a vector are run on a sequence of length one and their output is returned as a vector, and recurrent cells return only their output y, dropping the state.
ChainPlots.chaingraph — Function
chaingraph(m::Flux.Chain) -> ChainGraphReturn a ChainGraph with the graph structure of the neural network m.
In this case, the first layer must be a layer with fixed input dimension.
See chaingraph for the properties of each node of the graph.
ChainPlots.chaingraph — Function
chaingraph(l::Union{FIXED_INPUT_DIM_LAYERS...}) -> ChainGraphReturn a ChainGraph with the graph structure of a neural network composed of the single layer l.
This covers Flux.Dense, the sequence layers Flux.RNN, Flux.LSTM, Flux.GRU and Flux.GRUv3, and their cells.
ChainPlots.chaingraph — Method
chaingraph(l, input::Union{Array,Tuple}) -> ChainGraphReturn a ChainGraph with the graph structure of a neural network composed of the single layer l, such as a Flux.Conv, applied to input, or to an input of shape input.
ChainPlots.chaingraph — Method
chaingraph(ml::ModelLayers, input_data::Array) -> ChainGraphBuild the ChainGraph of the model described by ml, when applied to input_data.
This is the method all the others end up calling, after describing their model as a ModelLayers.
ChainPlots.chaingraph — Method
chaingraph(m::Flux.Chain, input_data::Array) -> ChainGraphReturn a ChainGraph with the graph structure of the neural network m when applied to input_data.
Each vertex is a neuron of the network, and each edge connects a neuron to a neuron of the next layer that it affects. The properties of each neuron, listed in NODE_PROPERTIES, are read with nodeprop and nodeprops.
The recurrent layers RNN, LSTM, GRU and GRUv3 are drawn folded, as a single time step, when the input is a vector. If the input is a sequence of size (in, len), the graph has a neuron for each time step instead, with each time step connected to the same and the later time steps of the next layer; the plot recipe does not lay the time steps out separately, though. The recurrent cells (RNNCell, …) return a tuple (y, state), so they can only be the last layer of a chain.
The plot recipe for ChainGraph draws it, as in plot(chaingraph(m, input_data)); see also plotchain.
ChainPlots.chaingraph — Method
chaingraph(m::Flux.Chain, ldim::Tuple) -> ChainGraphReturn a ChainGraph with the graph structure of the neural network m with an input of shape ldim.
See chaingraph for the properties of each node of the graph.
ChainPlots.check_chain — Method
check_chain(m::Flux.Chain)Throw an ArgumentError if a recurrent cell appears before the last layer of m.
ChainPlots.get_dimensions — Method
get_dimensions(m, input = nothing)Return the dimensions of the input and of the output data of each layer of the model m, given as a Flux.Chain or a ModelLayers.
If input is not given, the first layer is required to be a layer with fixed input dimensions, such as Flux.Dense or Flux.RNN, otherwise the given data, or the shape given as a Tuple, is used to infer the dimensions of each layer.
ChainPlots.input_array — Method
input_array(m, input::Union{Nothing,Array,Tuple})Return an input for the model m: input itself if it is an Array, a random array of shape input if it is a Tuple, and, if it is nothing, a random input of the size expected by the first layer, when it has a fixed input size.
ChainPlots.layer_dimensions — Method
layer_dimensions(cg::ChainGraph) -> Vector{Tuple}Return the dimensions of each layer of cg, starting with the input layer.
ChainPlots.layer_names — Method
layer_names(cg::ChainGraph) -> Vector{String}Return the name of each layer of cg, starting with "input layer".
ChainPlots.layerdimensions — Method
layerdimensions(l)Retrieve the dimensions (out, in) of a given fixed-input-size layer.
ChainPlots.modellayers — Method
modellayers(m::Flux.Chain) -> ModelLayersDescribe the Flux chain m as a ModelLayers.
ChainPlots.neuron_color — Method
neuron_color(s; neuron_colors = NEURON_COLORS)Grab the color for each specific type of neuron.
The color depends on the type of layer the neuron belongs to and the colorset given neuron_colors, which defaults to NEURON_COLORS.
ChainPlots.neuron_connections — Method
neuron_connections(m, input = nothing) -> Vector{Dict{Tuple, Vector{Tuple}}}Return all the connections from every neuron in each layer to the corresponding neurons in the next layer of the model m, given as a Flux.Chain or a ModelLayers.
ChainPlots.neuron_indices — Method
neuron_indices(ldim:Tuple) -> Vector{NTuple{N, Int}} where NReturn all possible indices for a given Tuple ldim.
ChainPlots.nlayers — Method
nlayers(cg::ChainGraph)Return the number of layers of the network, not counting the input layer.
ChainPlots.nodeprop — Method
nodeprop(cg::ChainGraph, v::Integer, prop::Symbol)Return the property prop of the neuron v of cg.
See NODE_PROPERTIES for the available properties. To get one property of all the neurons, broadcast over the vertices, e.g. nodeprop.(Ref(cg), vertices(cg), :loc_x).
ChainPlots.nodeprops — Method
nodeprops(cg::ChainGraph, v::Integer) -> NamedTupleReturn all the properties of the neuron v of cg as a NamedTuple.
See NODE_PROPERTIES for the available properties.
ChainPlots.plotbackend — Method
plotbackend() -> AbstractPlotBackendReturn the backend for the plotting package that is loaded, Plots.jl or Makie.jl.
Throw an ArgumentError if neither is loaded, or if both are, in which case pass the backend to plotchain explicitly.
ChainPlots.plotchain — Function
plotchain([backend,] m, input = nothing; kwargs...)Plot the topology of the neural network m, which is plot(chaingraph(m, input); kwargs...).
It works with Plots.jl and with Makie.jl, whichever is loaded, as in using Plots or using CairoMakie. If both are loaded, choose one by passing ChainPlots.PlotsBackend() or ChainPlots.MakieBackend() as the first argument.
m can be a Flux.Chain, a Lux.Chain, or a single layer. If the first layer accepts an input with arbitrary dimensions, such as a convolutional or a functional layer, an input must be given, either as an Array or as a Tuple with the dimensions of the input.
Any other keyword argument is passed on to plot, such as title with Plots.jl, or axis = (; title = "...") with Makie.jl, as well as the attributes of the plot recipe for ChainGraph:
connection_color: color of the connections;neuron_colors = NEURON_COLORS: either aDictfrom layer types to colors, as inNEURON_COLORS, or a color for all neurons;neuron_shape = :auto::autofor a marker depending on the type of the layer, or a marker shape for all neurons.
With Plots.jl, it returns a Plots.Plot; with Makie.jl, a Makie.FigureAxisPlot.
ChainPlots.plotchain! — Function
plotchain!([backend,] [target,] m, input = nothing; kwargs...)Add the topology of the neural network m to the current plot, or to target, which is a Plots.Plot with Plots.jl, or an axis, such as a Makie.Axis, with Makie.jl.
See plotchain.
ChainPlots.projection — Method
projection(z, center, max_widths, dimensions)Transform the indexing of a neuron into its x and y coordinates for plotting.
ChainPlots.NeuralNumbers.NeuralNumber — Type
NeuralNumber <: RealNeuralNumber encodes the "state" of a neuron as an Int8.
The possible states are: * state = Int8(0) for a "cold", or "off", state, meaning it can be triggered by a signal but it has not yet been triggered. It works as a neutral element in any diadic operation. * state = Int8(1) for a "hot", or "on", state, meaning it has been triggered by a signal.
The aliases are * cold = NeuralNumber(Int8(0)) * hot = NeuralNumber(Int8(1))
ChainPlots.NeuralNumbers.fneutralize — Method
fneutralize(m)Convert the parameters of a model to NeuralNumber with value cold.