Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Algorithm inspiration required.

by bliako (Monsignor)
on Jun 18, 2018 at 13:36 UTC ( [id://1216857]=note: print w/replies, xml ) Need Help??


in reply to Algorithm inspiration required.

Make a Finite State Automaton (what a mouthful) as a chain of nodes where, in this particular case, each node can only move to the next node in the chain. The length of the chain is equal to the length of the pattern you try to detect. Also, i^th node knows about the i^th data point (DP) in your pattern in order to compare whatever data it is holding and make a response if same.

Generally this is how it works:

First DP in the stream enters the 1st node. That node checks if entered DP is the same as the DP from your pattern it knows. Depending on yes/no, it turns a bit on/off in a global message buffer (buffer is of length equal to your pattern's). Then pass the DP to the next node of the chain and load next DP from the stream.

As a new DP is extracted from the stream, it enters the 1st node, that node does the check and propagates the DP to the second node. Second node does the same until the DP comes out from the last node.

In the meantime, someone keeps an eye on the message buffer and if/when all bits are on, you got a pattern detected.

Sometimes you will get 90% of the bits on, this is when a partial pattern match occured. Set a minimum match percentage to trigger a response.

I think you are right to mention regex, I have just described how a regex works.

If you go that way then of course there are plenty of modules in cpan, see Finite State Automata / Transducers

Forgot to say, this is also common in electronics where data moves on a clock-pulse. Do not do any asynchronous message buffer checking, but instead follow a clock. Data moves, bits flipped, message buffer checked each new clock pulse.

hope that helps, bliako

Replies are listed 'Best First'.
Re^2: Algorithm inspiration required.
by bliako (Monsignor) on Jun 19, 2018 at 19:49 UTC

    this is not suitable for this problem because we have an "infinite" and unknown pattern to detect. The above is useful only when the pattern to detect is known in advance.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-16 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found