Jump to content

help with pattern matching


Rutger83
 Share

Recommended Posts

Hi everyone,

I am new to autoit and am working on my first script, and I am hoping someone can help me a bit ahead.

The situation is like this: I have serveral predefined charts as this:

local $pattern[12][2]=[ _
      ["a","2,8,4,3,2,4"], _
      ["b","1"], _
      ["c","8,2,2,2,8"], _
      ["d","1,1,10"], _
      ["e","3,3,3,3,4"], _
      ["f","2,2,3,3,7"], _
      ["g","2,2,3,2,10,1"], _
      ["h","7,3,3,3,6"], _
      ["i","8,3,3,3,6"], _
      ["j","1,4,3,3,2"], _
      ["k","7,3,3,3,7"], _
      ["l","6,3,3,3,8"]
]

Each digit in the string repesents a bar.

Now is my goal to match a pattern like this one:

["2, 2.5, 8, 7.5, 4.2, 4, 3, 3, 2, 2, 2, 4, 4.7"]

which should be closed to the pattern "a" out of the array, because it sort of flows in the same lines, but with bigger steps.

I have searched the forums and have read a lot of post about pattern matching but I havent been able to get anything working, which is also due to my lack of math and pattern matching. Thus if anyone is willing to explain how this should be done I would be very gratefull :)

Greetings,

Rutger

Edited by Rutger83
Link to comment
Share on other sites

The input pattern you give offers a few ways to solve this, but I doubt the obvious ones would work in other cases than the example you gave.

To give any sensible advise we'd need to know what sort of input patterns to expect.

Obviously the example has more numbers than the output pattern is resolves to. These are the things I would need to know:

There are two numbers for nearly all numbers in the pattern, and three for one of them.

*How many doubles can there be in the input pattern for each number in the output pattern? (or does it just get increasingly unlikely for each additional double?)

*Does each number always occur twice at minimum?

In your example 4.7 gets resolved to 4. making for a difference of 0.7.

*how big can we realistically expect this number to be, before it makes sense to disqualify a match?

I was writing an example, but ran out of time. Basically what I propose is that for each number in your chart, you iterate through the numbers in the input pattern.

The first number in the input pattern should represent the first number in the chart pattern.

The second number in the input pattern could represent the first, or second number in the chart pattern, so check which it is closest to.

Once you have all the numbers in the Input pattern that represent the first number of the chart pattern, average them out and calculate the difference to the number you are comparing to.

If this is bigger than a threshold value, you can disqualify the pattern and go to the next pattern on the chart, otherwise you continue to the next number in the chart pattern.

Add the difference for the each number in the chart pattern together. This gives you a number that indicates your match quality. The lower the number the higher the quality.

Like this you calculate the quality for each pattern on the chart. The pattern with the lowest number should be your match.

You have to make a workaround for chart patterns with very few numbers as they will always have a high quality match, but like I said. I have no time any more.

Link to comment
Share on other sites

If I understand your need correctly you want to correlate curves defined by series of points irregularly spread, something more or less close to varying sampling rate in signal processing parlance.

Could you frst confirm you're looking along these lines.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

If I understand your need correctly you want to correlate curves defined by series of points irregularly spread, something more or less close to varying sampling rate in signal processing parlance.

Could you frst confirm you're looking along these lines.

Hi jchd that is a Confirm :)

But its not irregularly spread, either all the points are spread or all may even be shrinked causing some points to drop.

Thanks tvern for your reply.

The input pattern you give offers a few ways to solve this, but I doubt the obvious ones would work in other cases than the example you gave.

To give any sensible advise we'd need to know what sort of input patterns to expect.

Obviously the example has more numbers than the output pattern is resolves to. These are the things I would need to know:

There are two numbers for nearly all numbers in the pattern, and three for one of them.

*How many doubles can there be in the input pattern for each number in the output pattern? (or does it just get increasingly unlikely for each additional double?)

*Does each number always occur twice at minimum?

In your example 4.7 gets resolved to 4. making for a difference of 0.7.

*how big can we realistically expect this number to be, before it makes sense to disqualify a match?

...

Actualy a lot of the patterns to match are smaller in length, the example i gave was possibly the longest possible, but I probally wont encounter something like that.

To give some more accurate examples:

["a","2,8,4,3,2,4"], _

                  ["a","2,6,4,4,4,4,4"], _
                  ["a","2,8,4,3,4"], _


                  ["b","3,3,3,3,4"], _

                  ["b","2,3,3,4,4"], _
                  ["b","2,3,3,4"], _


                  ["c","2,2,3,2,10,1"], _

                  ["c","2,3,3,10,1"], _
                  ["c","2,3,10"], _


                  ["d","4,4,3,3,6"], _

                  ["d","4,4,3,3,5"], _
                  ["d","4,3,6"], _

                
                  ["e","2,8,4,3,2,4"], _

                  ["e","2,6,4,4,4,4,4"], _

Thank you for suggesting a way to tackle this.

Edited by Rutger83
Link to comment
Share on other sites

The problem is with irregular sampling. Dropped points are going to be a problem anyway.

BTW, do you mean that points can be dropped at (X-axis index, whatever that means) 2, 5, 6, 9, only leaving significant values at indexes 1, 3, 4, 7, 8.

Or on the contrary do you mean that only the end points can be missing?

In the latter case something relatively accurate can be done. But in the former case you'll probably have to go through interpolation thru splines (choose your spline type!) and from there interpolate missing points.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...