Add dynamics%.
This commit is contained in:
parent
811df5fe1e
commit
8c89bf810a
2 changed files with 72 additions and 3 deletions
39
networks.rkt
39
networks.rkt
|
@ -1,7 +1,7 @@
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(module typed typed/racket
|
(module typed typed/racket
|
||||||
(require "utils.rkt" "functions.rkt"
|
(require "utils.rkt" "functions.rkt" "dynamics.rkt"
|
||||||
typed/graph racket/random)
|
typed/graph racket/random)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
build-interaction-graph/form build-signed-interaction-graph
|
build-interaction-graph/form build-signed-interaction-graph
|
||||||
build-signed-interaction-graph/form
|
build-signed-interaction-graph/form
|
||||||
|
|
||||||
Modality Mode
|
Modality Mode dynamics%
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-type (State a) (VariableMapping a))
|
(define-type (State a) (VariableMapping a))
|
||||||
|
@ -512,6 +512,41 @@
|
||||||
|
|
||||||
(define-type Modality (Listof Variable))
|
(define-type Modality (Listof Variable))
|
||||||
(define-type Mode (Listof Modality))
|
(define-type Mode (Listof Modality))
|
||||||
|
|
||||||
|
(define dynamics%
|
||||||
|
;; TODO: Fix the parameter of State when Typed Racket supports
|
||||||
|
;; passing type parameters to the parent.
|
||||||
|
(class (inst dds% (State Any) Modality)
|
||||||
|
#:forall (a)
|
||||||
|
(super-new)
|
||||||
|
|
||||||
|
(init-field [network : (Network a) network]
|
||||||
|
[mode : Mode mode])
|
||||||
|
|
||||||
|
(: step/annotated (-> (State a) (Listof (Pairof Modality (State a)))))
|
||||||
|
(define/override (step/annotated s)
|
||||||
|
(for/list ([m mode])
|
||||||
|
(cons m (update network s m))))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "dynamics%"
|
||||||
|
(define n1 : (Network Boolean)
|
||||||
|
(forms->boolean-network (hash 'x '(not y)
|
||||||
|
'y 'x
|
||||||
|
'z '(and y z))))
|
||||||
|
(define syn : Mode '((x y z)))
|
||||||
|
(define asyn : Mode '((x) (y) (z)))
|
||||||
|
(define dyn-syn (new (inst dynamics% Boolean) [network n1] [mode syn]))
|
||||||
|
(define dyn-asyn (new (inst dynamics% Boolean) [network n1] [mode asyn]))
|
||||||
|
|
||||||
|
(define s1 (hash 'x #f 'y #f 'z #f))
|
||||||
|
(check-equal? (send dyn-syn step/annotated s1)
|
||||||
|
'(((x y z) . #hash((x . #t) (y . #f) (z . #f)))))
|
||||||
|
(check-equal? (send dyn-asyn step/annotated s1)
|
||||||
|
'(((x) . #hash((x . #t) (y . #f) (z . #f)))
|
||||||
|
((y) . #hash((x . #f) (y . #f) (z . #f)))
|
||||||
|
((z) . #hash((x . #f) (y . #f) (z . #f)))))
|
||||||
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require 'typed)
|
(require 'typed)
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
(for-label typed/racket/base
|
(for-label typed/racket/base
|
||||||
graph
|
graph
|
||||||
(only-in typed/graph Graph)
|
(only-in typed/graph Graph)
|
||||||
|
(only-in racket/class send)
|
||||||
(submod "../networks.rkt" typed)
|
(submod "../networks.rkt" typed)
|
||||||
"../utils.rkt"
|
"../utils.rkt"
|
||||||
"../functions.rkt"))
|
"../functions.rkt"
|
||||||
|
"../dynamics.rkt"))
|
||||||
|
|
||||||
@(define networks-evaluator
|
@(define networks-evaluator
|
||||||
(parameterize ([sandbox-output 'string]
|
(parameterize ([sandbox-output 'string]
|
||||||
|
@ -376,6 +378,38 @@ A mode is a list of modalities. This is a synonym of @racket[(Listof Modality)]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defclass[dynamics% dds% ()]{
|
||||||
|
|
||||||
|
A model of dynamics of a network is a @racket[Network] with a @racket[Mode].
|
||||||
|
|
||||||
|
@defconstructor[([network (Network a)] [mode Mode])]{
|
||||||
|
|
||||||
|
Creates a new instance of @racket[dynamics%] from a @racket[network] and
|
||||||
|
a @racket[mode]. Both are available as public fields of the class.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@defmethod[(step/annotated [st (State a)]) (Listof (Pairof Modality (State a)))]{
|
||||||
|
|
||||||
|
Apply the network stored in this class to the state @racket[st] with all
|
||||||
|
modalities of the mode stored in this class.
|
||||||
|
|
||||||
|
This is the only method of @racket[dds%] overridden in this class.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(let* ([n (forms->boolean-network (hash 'a '(and a b)
|
||||||
|
'b '(not b)))]
|
||||||
|
[syn '((a) (b))]
|
||||||
|
[syn-dynamics (new (inst dynamics% Boolean) [network n] [mode syn])]
|
||||||
|
[st (hash 'a #f 'b #f)])
|
||||||
|
(send syn-dynamics step/annotated st))
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@section{Inferring interaction graphs}
|
@section{Inferring interaction graphs}
|
||||||
|
|
||||||
This section provides inference of both unsigned and signed interaction graphs.
|
This section provides inference of both unsigned and signed interaction graphs.
|
||||||
|
|
Loading…
Reference in a new issue