Title: External State
1External State
- Kerry Barnes
- Gedae, Inc.
- www.gedae.com
- 856-231-4458
2Controlling Segment Reset
- During Segment Reset all boxes call their Reset
methods - All Primitive Local state variables are set to
their initial state - What if the algorithm requires state to be
persistent between segments? - Done using external state
3Persistent State
- Moving state out of subgraph controlled by
segmenter makes the state persistent across
segment boundaries
segmenter
proc1
in
out
in
out
S
State input S
state
K
out
4Illegal graph
- External state variables cannot be shared between
primitives - Sharing would possibly change the algorithm when
there is a - Change in granularity
- Change in primitive firing order
segmenter
proc1
proc2
in
out
in
out
in
out
S
S
State inputs
state
K
out
5Legal graph
- One writer and multiple readers of state can be
implemented by having state input box output
state values
segmenter
proc1
proc2
in
out
in
out
in
out
s
S
s
State input
state
Value follows state input
K
out
6Controlling Reset Level
- State variable is reset by toplevel segmenter but
not second level segmenter
segmenter
proc1
segmenter
in
out
in
out
in
out
S
State input S
state
K
out
7Low Pass Filter with Internal State Informational
and Data Fields
- Name lpf
- Type static
- Input
- stream float in
- float A
-
- Local
- float fb
-
- Output
- stream float out
8Low Pass Filter with Internal State Methods
- Reset
- fb 0
-
- Apply
- int i
- out0 fb A(in0-fb)
- for (i1 iltgranularity i)
- outi outi-1 A(ini- outi-1)
-
- fb outgranularity-1
9Low Pass Filter with State Input
- Name lpf_s
- Type static
- Input
- stream float in
- float A
- state float fb
-
- Output
- stream float out
-
- Apply
- int i
- out0 fb A(in0-fb)
- for (i1 iltgranularity i)
- outi outi-1 A(ini-outi-1)
-
- fb outgranularity-1
Removed Reset and Local state variable fb and
replaced with state input fb.
State input fb declared with state keyword
Previous value of state variable can be used in
the Apply method
Apply method must set the final value of the
state variable before it exits
10State Primitive
- Name float_state
- Type state
- Input
- float K
-
- Output
- float out
-
- Init
- K 0
-
- Reset
- out K
-
Type of box is state
May have input parameters
Outputs are the external state variables that can
be connected to primitive state inputs
Reset method called at segment Reset
11Example 1
- Internal state interior to subgraph gives
identical results to normal lpf box - Transients are still seen on segment boundaries
12Example 1 Trace Table
- The float_state Reset method is called at the
beginning of every segment
13Example 2 Trace Table
- The float_state box is only Reset at the
beginning of flowgraph execution
14Example 2
- Moving state out of filterS box causes it to be
persistent between segment boundaries - Transients no longer observed on segment
boundaries
15Example 3
- Filter state reset at toplevel segment boundaries
- Not reset by second level segment boundaries
16Example 3
17Exercise 1
- Load graph
- gedae file training/segmentation/lect5/Exercise1
pa default gr default tr - Run graph and observe output
- Change filterX1.integrate to use external state
- Add float_state box to filterX1 and connect to
integrate - Run graph and observe similar behavior
- View trace table and note when the float_state
resets occur
18Exercise 2
- Load graph
- gedae file training/segmentation/lect5/Exercise2
pa default gr default tr - Run graph and observe output
- Replace filterX2.integrate with integrate box
created in previous example - Add an input S to filterX2 and connect to the
integrate state
19Exercise 2(continued)
- Add float_state box to toplevel graph and connect
to filterX2ltS - Run graph and observe no reset on segment
boundaries - View trace table and note when the float_state
resets occur