2020-11-29 17:43:20 +01:00
|
|
|
#lang scribble/manual
|
2022-04-27 00:10:13 +02:00
|
|
|
@(require scribble/example racket/sandbox
|
|
|
|
(for-label typed/racket/base
|
|
|
|
graph
|
|
|
|
(only-in typed/graph Graph)
|
|
|
|
(submod "../networks.rkt" typed)
|
|
|
|
"../utils.rkt"
|
|
|
|
"../functions.rkt"))
|
|
|
|
|
|
|
|
@(define networks-evaluator
|
|
|
|
(parameterize ([sandbox-output 'string]
|
|
|
|
[sandbox-error-output 'string]
|
|
|
|
[sandbox-memory-limit 50])
|
2022-04-28 23:47:37 +02:00
|
|
|
(make-evaluator 'typed/racket #:requires '((submod "networks.rkt" typed)))))
|
2022-04-27 00:10:13 +02:00
|
|
|
|
|
|
|
@(define-syntax-rule (ex . args)
|
|
|
|
(examples #:eval networks-evaluator . args))
|
2020-11-29 17:43:20 +01:00
|
|
|
|
2022-04-30 00:11:09 +02:00
|
|
|
@(define-syntax-rule (deftypeform . args)
|
|
|
|
(defform #:kind "type" . args))
|
2022-04-29 16:32:22 +02:00
|
|
|
|
|
|
|
@(define-syntax-rule (deftype . args)
|
|
|
|
(defidform #:kind "type" . args))
|
|
|
|
|
2020-11-29 17:43:20 +01:00
|
|
|
@title[#:tag "networks"]{dds/networks: Formal Dynamical Networks}
|
|
|
|
|
2022-04-27 00:10:13 +02:00
|
|
|
@defmodule[(submod dds/networks typed)]
|
2020-11-29 22:01:18 +01:00
|
|
|
|
|
|
|
This module provides definitions for and analysing network models. A network
|
|
|
|
is a set of variables which are updated according to their corresponding update
|
|
|
|
functions. The variables to be updated at each step are given by the mode.
|
|
|
|
This model can generalise Boolean networks, TBANs, multivalued networks, etc.
|
|
|
|
|
2022-04-29 15:33:46 +02:00
|
|
|
@section[#:tag "networks-basics"]{Basic types}
|
2020-11-29 22:01:18 +01:00
|
|
|
|
2022-04-30 00:11:09 +02:00
|
|
|
@deftypeform[(State a)]{
|
2022-04-27 00:10:13 +02:00
|
|
|
|
|
|
|
An immutable mapping (a hash table) assigning elements of type @racket[a] to
|
|
|
|
the variables. A synonym of @racket[VariableMapping].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:11:09 +02:00
|
|
|
@deftypeform[(UpdateFunction a)]{
|
2022-04-27 00:15:03 +02:00
|
|
|
|
|
|
|
An update function is a function computing a value from the given
|
|
|
|
state. This is a synonym of the type @racket[(-> (State a) a)].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:11:09 +02:00
|
|
|
@deftypeform[(Domain a)]{
|
2022-04-29 16:10:36 +02:00
|
|
|
|
|
|
|
A domain which is a subset of the type @racket[a].
|
|
|
|
|
|
|
|
@racket[(Domain a)] is a synonym of @racket[(Listof a)].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:11:09 +02:00
|
|
|
@deftypeform[(DomainMapping a)]{
|
2022-04-27 00:15:03 +02:00
|
|
|
|
|
|
|
A domain mapping is a hash table mapping variables to the lists of values in
|
|
|
|
their domains.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:23:38 +02:00
|
|
|
@section{Common examples}
|
|
|
|
|
|
|
|
The examples in this document often use the same definitions, which are
|
|
|
|
therefore grouped here to avoid duplicating them.
|
|
|
|
|
|
|
|
These are two functions calculating an @italic{AND} and an @italic{OR} between
|
|
|
|
the variables @racket[a] and @racket[b]:
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(: or-func (UpdateFunction Boolean))
|
|
|
|
(define (or-func s)
|
|
|
|
(or (hash-ref s 'a) (hash-ref s 'b)))
|
|
|
|
|
|
|
|
(: and-func (UpdateFunction Boolean))
|
|
|
|
(define (and-func s)
|
|
|
|
(and (hash-ref s 'a) (hash-ref s 'b)))
|
|
|
|
]
|
|
|
|
|
2022-04-30 23:17:15 +02:00
|
|
|
These are two functions calculating an @italic{AND} and an @italic{OR} between
|
|
|
|
two variables @racket[a] and @racket[b] whose values are in @tt{{0,1}}:
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(require (only-in "utils.rkt" assert-type))
|
|
|
|
|
|
|
|
(: or-func/01 (UpdateFunction (U Zero One)))
|
|
|
|
(define (or-func/01 s)
|
|
|
|
(assert-type (max (hash-ref s 'a) (hash-ref s 'b))
|
|
|
|
(U Zero One)))
|
|
|
|
|
|
|
|
(: and-func/01 (UpdateFunction (U Zero One)))
|
|
|
|
(define (and-func/01 s)
|
|
|
|
(assert-type (min (hash-ref s 'a) (hash-ref s 'b))
|
|
|
|
(U Zero One)))
|
|
|
|
]
|
|
|
|
|
2022-05-01 01:05:35 +02:00
|
|
|
@section{Utilities}
|
|
|
|
|
|
|
|
@defproc[(01->boolean/state [s (State (U Zero One))]) (State Boolean)]{
|
|
|
|
|
|
|
|
Converts the values 0 and 1 in a state to @racket[#f] and
|
|
|
|
@racket[#t] respectively.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(01->boolean/state (hash 'a 0 'b 1))
|
|
|
|
]}
|
|
|
|
|
2022-05-01 01:07:33 +02:00
|
|
|
@defproc[(make-same-domains [vars (Listof Variable)]
|
|
|
|
[domain (Domain a)])
|
|
|
|
(DomainMapping a)]{
|
|
|
|
|
|
|
|
Makes a hash set mapping all variables to a single domain.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(make-same-domains '(a b) '(1 2))
|
|
|
|
]}
|
|
|
|
|
|
|
|
@defproc[(make-boolean-domains [vars (Listof Variable)])
|
|
|
|
(DomainMapping Boolean)]{
|
|
|
|
|
|
|
|
Makes a hash set mapping all variables to the Boolean domain.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(make-boolean-domains '(a b))
|
|
|
|
]}
|
|
|
|
|
|
|
|
@defproc[(make-01-domains [vars (Listof Variable)])
|
|
|
|
(DomainMapping (U Zero One))]{
|
|
|
|
|
|
|
|
Makes a hash set mapping all variables to the Boolean domain, expressed as
|
|
|
|
@tt{{0,1}}.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(make-01-domains '(a b))
|
|
|
|
]}
|
|
|
|
|
2022-04-29 17:31:36 +02:00
|
|
|
@section{Networks}
|
|
|
|
|
2022-04-28 23:47:37 +02:00
|
|
|
@defstruct*[network ([functions (VariableMapping (UpdateFunction a))]
|
|
|
|
[domains (DomainMapping a)])]{
|
|
|
|
|
|
|
|
A network consists of a mapping from its variables to its update variables, as
|
|
|
|
a well as of a mapping from its variables to their domains.
|
|
|
|
|
|
|
|
Instances of @racket[network] have the type @racket[Network].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-02 00:22:47 +02:00
|
|
|
@deftypeform[(Network a)]{
|
2022-04-28 23:47:37 +02:00
|
|
|
|
2022-05-02 00:22:47 +02:00
|
|
|
The type of the instances of @racket[network].
|
2022-04-28 23:47:37 +02:00
|
|
|
|
|
|
|
@ex[
|
|
|
|
(network (hash 'a or-func
|
|
|
|
'b and-func)
|
|
|
|
(hash 'a '(#f #t)
|
|
|
|
'b '(#f #t)))
|
|
|
|
]}
|
|
|
|
|
2022-04-30 22:49:03 +02:00
|
|
|
@defproc[(make-boolean-network [funcs (VariableMapping (UpdateFunction Boolean))])
|
2022-04-29 15:54:15 +02:00
|
|
|
(Network Boolean)]{
|
|
|
|
|
|
|
|
Builds a Boolean network from a given hash table assigning functions to
|
|
|
|
variables by attributing Boolean domains to every variable.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(make-boolean-network (hash 'a or-func 'b and-func))
|
|
|
|
]}
|
|
|
|
|
2022-04-30 23:17:15 +02:00
|
|
|
@defproc[(make-01-network [funcs (VariableMapping (UpdateFunction (U Zero One)))])
|
|
|
|
(Network (U Zero One))]{
|
|
|
|
|
|
|
|
Build a network from a given hash table assigning functions to variables by
|
|
|
|
attributing the domain @tt{{0,1}} to every variable.
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(make-01-network (hash 'a or-func/01 'b and-func/01))
|
|
|
|
]}
|
|
|
|
|
2022-05-01 00:31:28 +02:00
|
|
|
@defproc[(update [network (Network a)] [s (State a)] [xs (Listof Variable)])
|
|
|
|
(State a)]{
|
|
|
|
|
|
|
|
Given a state @racket[s] updates all the variables of @racket[network] from
|
|
|
|
@racket[xs].
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(update (make-boolean-network (hash 'a or-func 'b and-func))
|
|
|
|
(hash 'a #f 'b #t)
|
|
|
|
'(a))
|
|
|
|
]}
|
|
|
|
|
2020-11-29 22:01:18 +01:00
|
|
|
@section{Syntactic description of networks}
|
|
|
|
|
2022-05-02 00:16:16 +02:00
|
|
|
@deftype[UpdateFunctionForm]{
|
|
|
|
|
|
|
|
An update function form is any form which can appear as a body of a function
|
|
|
|
and which can be evaluated with @racket[eval].
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(ann '(and x y (not z)) UpdateFunctionForm)
|
|
|
|
(ann '(+ 1 a (- b 10)) UpdateFunctionForm)
|
|
|
|
]
|
|
|
|
|
|
|
|
@racket[UpdateFunctionForm] is a synonym of @racket[Any].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-02 00:27:55 +02:00
|
|
|
@defstruct*[network-form ([functions (VariableMapping NetworkForm)]
|
|
|
|
[domains (DomainMapping a)])]{
|
|
|
|
|
|
|
|
A network form consists of a mapping from variables to the forms of their
|
|
|
|
update functions, together with a mapping from its variables to its
|
|
|
|
update functions.
|
|
|
|
|
|
|
|
The domain mapping does not have to assign domains to all variables (e.g., it
|
|
|
|
may be empty), but in this case the functions which need to know the domains
|
|
|
|
will not work.
|
|
|
|
|
|
|
|
Instances of @racket[network-form] have the type @racket[NetworkForm].
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@deftypeform[(NetworkForm a)]{
|
|
|
|
|
|
|
|
The type of instances of @racket[network-form].
|
|
|
|
|
|
|
|
@ex[
|
|
|
|
(network-form (hash 'a '(and a b) 'b '(or a b))
|
|
|
|
(hash 'a '(#f #t) 'b '(#f #t)))
|
|
|
|
]}
|
2022-05-02 00:16:16 +02:00
|
|
|
|
2022-05-03 21:26:36 +02:00
|
|
|
@defproc[(update-function-form->update-function/any [func UpdateFunctionForm])
|
|
|
|
(UpdateFunction Any)]{
|
2022-05-03 00:37:13 +02:00
|
|
|
|
|
|
|
Builds an update function from an update function form.
|
|
|
|
|
|
|
|
@ex[
|
2022-05-03 21:26:36 +02:00
|
|
|
(define and-from-form (update-function-form->update-function/any '(and x y)))
|
2022-05-03 00:37:13 +02:00
|
|
|
(and-from-form (hash 'x #f 'y #f))
|
|
|
|
(and-from-form (hash 'x #f 'y #t))
|
|
|
|
(and-from-form (hash 'x #t 'y #f))
|
|
|
|
(and-from-form (hash 'x #t 'y #t))
|
|
|
|
]}
|
|
|
|
|
|
|
|
|
2020-11-29 22:01:18 +01:00
|
|
|
@section{Inferring interaction graphs}
|
|
|
|
|
|
|
|
This section provides inference of both unsigned and signed interaction graphs.
|
|
|
|
Since the inference of signed interaction graphs is based on analysing the
|
|
|
|
dynamics of the networks, it may be quite resource-consuming, especially since
|
|
|
|
I allow any syntactic forms in the definitions of the functions.
|
|
|
|
|
|
|
|
Note the fine difference between @emph{syntactic} interaction graphs and
|
|
|
|
interaction graphs generated from the dynamics of the network.
|
|
|
|
Syntactic interaction graphs are based on the whether a variable appears or not
|
|
|
|
in the form of the function for another variable. On the other hand, the
|
|
|
|
normal, conventional interaction graph records the fact that one variable has
|
|
|
|
an impact on the dynamics of the other variable. Depending on the model, these
|
|
|
|
may or may not be the same.
|
|
|
|
|
|
|
|
@section{Dynamics of networks}
|
|
|
|
|
|
|
|
This section contains definitions for building and analysing the dynamics
|
|
|
|
of networks.
|
|
|
|
|
|
|
|
@section{Tabulating functions and networks}
|
|
|
|
|
|
|
|
@section{Constructing functions and networks}
|
|
|
|
|
|
|
|
@section{Random functions and networks}
|
|
|
|
|
|
|
|
@section{TBF/TBN and SBF/SBN}
|
|
|
|
|
|
|
|
This section defines threshold Boolean functions (TBF) and networks (TBN), as
|
|
|
|
well as sign Boolean functions (SBF) and networks (SBN).
|