Issue
93 April 1998
Picaro:
A Stamp-like Interpreted Controller
by
Tom Napier
For
years, Toms been itching to control the instruction
sets of processors. Using a PIC, some memory, and
an interpreter, he bypasses the processor hurdle
and writes his own language. He shows you how to
do it, too.
At
this point, it may seem like the PLU was relatively
easy to construct. Unfortunately, the algorithm is still
not very smart.
Even
though it can "predict" the arrival of occupants
with some success, it records and acts on any and all
patterns that arise, regardless of how atypical they
may be. To build a sturdy machine that only recognizes
"typical" patterns, a more complex mechanism
is required.
The
software approach that transcends the basic PLU is a
sophisticated "fuzzy" recognizer that verifies
the ordinariness of a pattern before committing it to
memory. Note that the term "fuzzy" is used
here loosely and does not refer to the use of fuzzy
logic as an engineering approach. In this context, "fuzzy"
means that the software is able to recognize patterns
even when patterns don't match exactly.
The
algorithm also has the ability to recognize when the
building is unoccupied for an extended period (vacation
detection) and suspends all pattern recording and anticipation
until the building becomes normally occupied again.
The original patterns are retained until they are needed
again.
The
fuzzy recognizers basic approach is a series of
comparisons that each days record is put through
in an attempt to gauge its validity. Figure 4 shows
how previous records are stored in memory.
Long-term
memory (LTM) is a permanent record, one week long. If
a current record passes muster, it can replace the existing
record for that particular weekday in LTM.
Additionally,
there are five slots for temporary records. These are
records that did not match anything at the time they
appeared. The temporary records are key in the process
of learning new patterns. Anytime a current pattern
matches the same temporary pattern for two weeks running,
the system assumes that its seeing a new schedule
for that weekday.
Figure
5 shows a block diagram of the matching process. Each
days record is compared to the same days
record in LTM using a pattern-matching process. As shown
in Figure 6, the two patterns are compared bit by bit
with the total number of like bits being noted.
Clearly,
if all 24 bits are the same, the patterns are exactly
alike. The tricky part is recognizing patterns that
are very similar but not exactly alike.
The
approach used here was to shift the patterns one bit
position relative to each other and then measure the
score again. This technique tells us if the patterns
are similar except for being offset somewhat.
As
you can see in Figures 6a and 6b, the shifting process
can yield higher scores for patterns that really are
similar, while producing nothing for patterns that arent
all that much alike. Shifting both to the left and to
the right and then looking for a score of at least 23
out of 24 gives a good assurance of a similar pattern.
If
the record is not deemed similar enough to the LTM record
for that weekday, then it is compared to the five different
temporary records. The comparison with the temporary
records is similar to that for LTM records, except that
the shifting process is not employed and the current
record is compared to all five temporary records with
the score of each comparison being noted.
The
highest-scoring comparison that scores at least 18 is
taken as a match. A current record that fails to match
any record is deemed a new temporary record, overwriting
the oldest one in memory.
If
a given record does match a temporary record, a quick
check is performed to see if the same thing happened
last week. If so (i.e., the record has matched the same
miscellaneous record for two weeks running), then that
record wins a place as the new permanent memory (i.e.,
LTM) for that weekday.
I
should note here that the algorithm also checks for
a completely unoccupied state during the current records
24-h period. Whenever there is a match with the unoccupied
profile, a counter is incremented. If this happens for
three consecutive days, then all system learning is
suspended (i.e., vacation detection).
Through
this pattern-matching process, a delicate balance is
created. If a pattern is similar to patterns for that
weekday in the past, then the new pattern is immediately
adopted as permanent. This system allows for quick adjustment
to changes like Daylight Savings Time.
If
the pattern is not similar enough to adopt immediately,
then it is compared to previous unusual patterns. If
there is a match with one of these for at least two
weeks running, then that pattern is taken as the permanent
record.
The
result of this process is that slight changes to patterns
are adopted immediately, while anomalous patterns are
ignored, unless they persist for several weeks. In that
case, they are adopted as the new permanent record.