(* A simple network of excitatory and inhibitory neurons *) component ExcInhNetwork = struct binding construct_diagram V t gL vL Isyn C theta tspike spike Vreset trefractory refractory_end tstep = binding subthreshold_eq = [ D (V t) = (((- gL) * (V - vL)) + Isyn) / C ] val threshold_detect = [ spike = (V >= theta) ] val tspike_assignment = [ tspike = if spike then t else tspike ] val subthreshold_regime = Diagram.SEQUENCE subthreshold_eq (Diagram.SEQUENCE threshold_detect tspike_assignment) val refractory_eq = [ V = Vreset ] val refractory_regime = [ [ V = Vreset ] [ refractory_end = (t >= (tspike + trefractory)) ] [ t = t + tstep ] ] return Diagram.RTRANSITION subthreshold_regime refractory_regime spike refractory_end binding construct_network N_exc N_inh D_exc D_inh P = (* a graph to represent the excitatory population *) binding I_exc = Interval.closed_interval 0d1 N_exc binding excitatory_population = Graph.set_node_interval_property (Graph.nodes (N_exc)) I_exc `synapticPrototype D_exc (* a graph to represent the inhibitory population *) binding I_inh = Interval.closed_interval 0d1 N_inh binding inhibitory_population = Graph.set_node_interval_property (Graph.nodes (N_inh)) I_inh `synapticPrototype D_inh (* disjoint union of the two populations *) binding populations = Graph.disjoint_union excitatory_population inhibitory_population (* random graph G(N,P) *) binding P = 0.02 binding connections = Graph.gnp_graph (N_exc + N_inh) P (* graph union: node attributes take precedence from left to right *) binding populations_and_connections = Graph.union populations connections (* this procedure determines the synapse prototype for a connection: *) binding synapse_prototype G S D = Graph.node_property G S `synapticPrototype (* final network *) binding I_network = Interval.closed_interval 0d1 (N_exc + N_inh) binding network = Graph.set_edge_interval_property populations_and_connections I_network I_network `synapticPrototype synapse_prototype return network end