Skip to content

Commit

Permalink
add default values to weight andconnection_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
harisorgn committed Jan 11, 2025
1 parent 9ac7796 commit 91218e4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions _literate/blox_connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ equations(lif)
# The first one will print only the connection equations
@named ifn = IFNeuron() ## create an Integrate-and-Fire neuron, simpler than the `LIFNeuron`

connection_equations(lif, ifn)
connection_equations(lif, ifn, weight=1, connection_rule="basic")
# While the second function prints out all fields that take part in the connection rule
connection_rule(lif, ifn)
# The output of both functions now seems very similar. However `connection_rule` will be more useful later on when we start using more complex Bloxs and connection rules.
connection_rule(lif, ifn, weight=1, connection_rule="psp")
# The `weight` and `connection_rule` are keyword arguments that can be ommitted. If we ommit them then we will get a message informing us about the default values that they take. The `connection_rule` argument applies to connections between `Neuron` types; `"basic"` is a simple weighted connection and `"psp"` applies a postsynaptic potential type of connection. The output of both `connection_equations` and `connection_rule` functions now seems very similar. However `connection_rule` will be more useful later on when we start using more complex Bloxs and connection rules that do more than just adding an equation and a symbolic weight.

# ## Simulating connected Bloxs
# We are now ready to define a couple of Bloxs, connect them and simulate the final model.
# Every Neuroblox model starts off as a graph. Every vertex of the graph is a Blox and every edge is a connection between two Bloxs.
# Let's build a simple circuit by using the two neurons we created above; `lif` connects to `ifn`.
g = MetaDiGraph()
add_edge!(g, lif => ifn)
add_edge!(g, lif => ifn, weight=1) ## add connection with specific weight value

@named sys = system_from_graph(g)
prob = ODEProblem(sys, [], (0, 200.0))
Expand Down Expand Up @@ -106,8 +106,8 @@ end
# One benefit of assigning `IzhNeuron <: Neuron` is now apparent. Without defining a new connection equation for it, `IzhNeuron` can connect to `LIFNeuron` and to any other neuron type using a generic connection equation in Neuroblox.
# We can see what this equation looks like by running

connection_equations(izh, lif) ## connection from izh to lif
connection_equations(lif, izh) ## connection from lif to izh
connection_equations(izh, lif, weight=1, connection_rule="basic") ## connection from izh to lif
connection_equations(lif, izh, weight=1, connection_rule="basic") ## connection from lif to izh

# We even get a warning saying that the connection rule is not specified so Neuroblox defaults to this basic weighted connection.

Expand All @@ -127,7 +127,7 @@ end
# Internally Neuroblox will call the function dispatch with the most specific combination of its input arguments. Before defining the function above there was no dispatch that had `IzhNeuron` in its signature so Neuroblox defaulted to the connection we saw above.
# Now that we have defined a specialized equation, we can connect the same two Bloxs in a new way.

connection_equations(lif, izh)
connection_equations(lif, izh, weight=1, connection_rule="basic")

# Notice how the equation has changed compared to above and it is equal to our latest `connection_equations` dispatch.
# > **_NOTE_:** When we define a new `connection_equations` dispatch we need to include three positional arguments, the source Blox, the destination Blox and a symbolic weight parameter that is generated internally in Neuroblox and assigned to a specific connection.
Expand Down

0 comments on commit 91218e4

Please sign in to comment.