Title: Gedae Advanced Course Trigger and Eval Boxes
1Gedae Advanced CourseTrigger and Eval Boxes
- James W. Steed
- William I. Lundgren
- (856) 231-4458
- gedae_at_gedae.com
2Overview
- Eval Boxes
- Using an Eval Box to Implement a Database
- Trigger Boxes
- Using Trigger Boxes to Implement a State Machine
- Description of Laboratory
- Laboratory time
- Solution
3Eval Boxes
- Parameter inputs and parameter outputs only
- Methods Input, Output, Include, Init, Eval
- Eval method replaces Apply method of stream boxes
Name V_Sum Type eval Input float
InN Output float Out Eval int
i Out 0.0 for (i0 iltN i) Out
Ini
4Eval BoxesInitializing Structure Parameters
- Eval box can be used to initialize a structure
parameter - Memory is allocated, and a pointer to the memory
is passed as an output parameter - Values in the structure can be initialized
Name CreateDB Type eval Input int
N Output Database Out Include . .
. Eval Out (Database ) malloc(.
. .) Out-gtN N Out-gtDB . . .
5Example Hash Table-Based Database
- The Database Structure
- struct _Database
- int N / size of array /
- OList DB / array of lists /
-
- typedef struct _Database Database
An OList is the list structure used in GEDAE
based on LISP lists
DB
Add data with ID Id to list DBHash(Id) where
Hash(Id) Id N
0
1
2
3
Id 61 . . .
4
Id 7 . . .
5
Id 40 . . .
6Example Hash Table-Based Database (continued)
- Take tokens off a stream and insert them in the
database - Database was formed by an Eval box
Name addDB Type static Input stream DBElem
in Database DB Include . . . Apply
int i for (i0 iltgranularity i)
int indexini-gtid DB-gtN DBindex-gtDB
Ocons(ini, DBindex-gtDB)
Assume the DBElem structure has an id field and
a data field
Ocons(a,L) adds element a to the front of list L.
Note this does not check to see if the element is
already in the database
7Example Hash Table-Based Database(continued)
- Dump database to stream
- Return at most Max elements
Apply int i, j, cnt 0 for (i0
iltgranularity i) int cnt_i 0 OList
L for (j0 jltDB-gtN cnt_iltMax
j) for (LDB-gtDBj L cnt_iltMax
LOcdr(L)) DBElem elem
Ocar(L) outcnt elem-gtdata
cnt_i produce(out,cnt)
Name getDB Type static Input Database
DB int Max Output dynamic stream
void out(Max) Include . . .
Copy the data field from each element to the
output
8Trigger Boxes
Name AddK Type trigger Input trigger float
in float K Output float out Init
K 1 Trigger out in K
push(out)
- Triggers announce changes to values, informing
downstream boxes to also update their values - Trigger inputs, parameter inputs, and parameter
outputs only - Methods Input, Local, Output, Include, Init,
Callback (name can vary), Reset, Trigger,
Destroy, Save, Restore - Trigger method replaces Apply method of stream
boxes called whenever inputs pushed from another
box
9Trigger BoxesExample
- New inputs entered through the GUI
- Triggers push values down the graph, each AddK
trigger box re-calculating its output based on
its new trigger input value
17
17
Does AddK_4 execute before AddK_2?
10Trigger BoxesUtility Functions
- void push(. . .)
- Push listed parameters, signifying to downstream
Trigger boxes that the value has been updated - If more than one input, synchronously pushed
- int dirty(input i)
- True if input i has been pushed by an upstream
box since the last execution
11Trigger BoxesSpecial Methods
- Destroy
- Code to be run when the graph is terminated
- Free memory, release resources
- Callback
- Registers a callback function that can be used by
other methods - Can have any name many callbacks can be
registered - Creates function called as CallbackName(self,calld
ata) - Save Restore
- Includes values in parameter file save restore
- To restore, call functions restore_type(type
var) - To save, call functions save_type(type var)
12Example State Machine
- A state in a state machine is just a trigger box
with the following behavior - If dirty(in), then set hereTrue, set Tempin,
and push(here) - If here and dirty(c), then set outTemp, set
hereFalse, push(out), and push(here)
start
A
B
D
C
13Laboratory Assignment
- Assume we have a set of target black white
images (Tp). We are given a stream of candidate
images (C(q)) and must report for each candidate
which target is the closest match. We can define
the confidence of a match to be Sum(Tpij
C(q)ij) over all i, j, e.g.,
1 1 0 0
1 1 0 1
Confidence( , ) 2
14Laboratory Assignment (continued)
- Use graph training/Advanced/match/match as a
starting point. - A state machine is used to control the mode of
the graph (forming the target database or
actively matching candidates to targets). Write
a state primitive as described in the lecture.
Form this state machine (GUI.p0 and GUI.p1 are
trigger outputs of the GUI box in the
stateMachine subgraph) - A database of target images is created. Fill in
primitives addDB, mi_getDB, and CreateDB to
complete this section.
GUI.p1
Form DB
start
Match
GUI.p0
15Laboratory Assignment (continued)
- addDB For each token on the input stream, add
the token to the database if it is not already
there. - If the token is not there, determine which list
in the database it should be placed in (DB id
mod (size of DB array)), and put it there. - If the token is already there, free the structure
in the input stream. - CreateDB Create and initialize the structure
for the database. - Allocate the Database structure
- Initialize its fields
- Allocate the array of lists
16Laboratory Assignment (continued)
- mi_getDB For each element in the input stream
in, dump the database to the dbout output stream - Copy the in input tokens to the out output stream
so that they are paired with each element in the
database - Set up the control stream c to be 1 at the last
element of the dumped database and 0 otherwise
1 0 0 0
1 0 0 0
1 0 0 0
1 0 0 0
in
out
1 1 0 1
0 0 0 1
1 1 1 1
1 1 0 1
0 0 0 1
1 1 1 1
Elements in DB
dbout
17Solution to Laboratory Assignment Follows
18Solution to Laboratory Assignment
Scan database, pair each candidate with every
target in the database
Scan database, if id is found, do not add and
free memory, otherwise add to the appropriate list
19Solution to Laboratory Assignment (continued)
20Results of Solution
A random stream of candidate images and their
matching target images are displayed after
pressing the Match button