473,414 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Pattern Search...?

Hi

I'm stuck due to lack of knowledge.

Problem: I'm scanning through Array1[1000][1000] to find the closest match
to Array2[50][50] within Array1. At the moment I'm using a method that can
best be described as "brute force"..I'm literally scanning through the
entire Array1 using the entire Array2. The routine quits if a match conforms
to a threshhold cut-off. The problem is: *it's slow!*

Please could someone point me in the right direction? A name of a method or
algorythm that I could implement?

Appreciated!
Jul 22 '05 #1
6 1924
"cybit friendly" <rooivalk at sa-military plop co plop za> wrote
Hi

I'm stuck due to lack of knowledge.

Problem: I'm scanning through Array1[1000][1000] to find the closest match
to Array2[50][50] within Array1. At the moment I'm using a method that can
best be described as "brute force"..I'm literally scanning through the
entire Array1 using the entire Array2. The routine quits if a match conforms
to a threshhold cut-off. The problem is: *it's slow!*

Please could someone point me in the right direction? A name of a method or
algorythm that I could implement?


Since you don't define "closest match", my advice is likely to be off base, but
bits are cheap, so...

Try to create a "digest" of Array2 such that if the digest of another array of
the same size is numerically close, the two arrays are probably close matches.
You can then compute digests of the subarrays of Array1 and compare them to the
pre-computed digest of Array2. If you design your digest such that you can
recompute it by removing elements and adding new ones, you can then quickly scan
Array1 by doing S-shaped sweeps, thereby minimizing the changes to the current
digest.

Claudio Puviani
Jul 22 '05 #2
Hi Claudio

The problem is that Array1[1000][1000] is for all intents and purposes an
array of random numbers, I have neither preconception of nor control over
the contents of Array1. On the other hand, Array2[50][50] is also an array
of random numbers, the only difference is that I know the value and location
of each number in that matrix. My goal is to determine whether the pattern
of numbers in Array2 occurs somewhere in Array1, and if it does not, which
50x50 region in Array1 will contain an array which is most similar to
Array2. That is to say, of all the possible 50x50 arrays in the original
1000x1000 array, which is the most similar to Array2. It can be safely
assumed that a perfect 100% match will never occur.

The most obvious way to determine this is to physically break Array1 up into
50x50 arrays. Starting at (0,0)(50,50), then to (1,0)(51,50)...all the way
to (950,950)(1000,1000), I compare each one od these 50x50 'subarrays' with
Array2. The one with the least difference is considered the 'closest match'.
If, however, the difference is more than a certain threshhold (say more than
25%), it is not considered similar enough and then no match is defined.

I am looking for a better, more optimized method of performing this search.
One way (which is best avoided) is to do what I do, but using assembly.

ciao

cybit

"Claudio Puviani" <pu*****@hotmail.com> wrote in message
news:jz*********************@news4.srv.hcvlny.cv.n et...
"cybit friendly" <rooivalk at sa-military plop co plop za> wrote
Hi
<snip>
Since you don't define "closest match", my advice is likely to be off base, but bits are cheap, so...

Try to create a "digest" of Array2 such that if the digest of another array of the same size is numerically close, the two arrays are probably close matches. You can then compute digests of the subarrays of Array1 and compare them to the pre-computed digest of Array2. If you design your digest such that you can
recompute it by removing elements and adding new ones, you can then quickly scan Array1 by doing S-shaped sweeps, thereby minimizing the changes to the current digest.

Claudio Puviani

Jul 22 '05 #3
"cybit friendly" <rooivalk at sa-military plop co plop za> wrote
Hi Claudio

The problem is that Array1[1000][1000] is for all intents and purposes an
array of random numbers, I have neither preconception of nor control over
the contents of Array1. On the other hand, Array2[50][50] is also an array
of random numbers, the only difference is that I know the value and location
of each number in that matrix. My goal is to determine whether the pattern
of numbers in Array2 occurs somewhere in Array1, and if it does not, which
50x50 region in Array1 will contain an array which is most similar to
Array2. That is to say, of all the possible 50x50 arrays in the original
1000x1000 array, which is the most similar to Array2. It can be safely
assumed that a perfect 100% match will never occur.

The most obvious way to determine this is to physically break Array1 up into
50x50 arrays. Starting at (0,0)(50,50), then to (1,0)(51,50)...all the way
to (950,950)(1000,1000), I compare each one od these 50x50 'subarrays' with
Array2. The one with the least difference is considered the 'closest match'.
If, however, the difference is more than a certain threshhold (say more than
25%), it is not considered similar enough and then no match is defined.

I am looking for a better, more optimized method of performing this search.
One way (which is best avoided) is to do what I do, but using assembly.

ciao

cybit


Actually reading my previous answer might help.

Claudio Puviani
Jul 22 '05 #4
Firstly, what do you mean by "digest"?

If I understand you correctly, you're suggesting that I create a unique
numeric "ID" for Array2 (by using its contents), and then creating similar
IDs for similarly sized arrays in Array1, and then comparing IDs...?
However, unless I scan every 50x50 subarray in Array1, I might miss a
possible match.

Please elaborate!

"Claudio Puviani" <pu*****@hotmail.com> wrote in message
news:RY*********************@news4.srv.hcvlny.cv.n et...

Actually reading my previous answer might help.

Claudio Puviani

Jul 22 '05 #5
cybit friendly wrote:
The most obvious way to determine this is to physically break Array1 up into
50x50 arrays. Starting at (0,0)(50,50), then to (1,0)(51,50)...all the way
to (950,950)(1000,1000), I compare each one od these 50x50 'subarrays' with
Array2. The one with the least difference is considered the 'closest match'.
If, however, the difference is more than a certain threshhold (say more than
25%), it is not considered similar enough and then no match is defined.

I am looking for a better, more optimized method of performing this search.
One way (which is best avoided) is to do what I do, but using assembly.


Hi!

Maybe a stupid idea, but I mention it anyway:

Calculate sums of the rows and columns in the (50,50) Matrix.

Then compare these sums with sums over the 50 elements of
the big matrix. Since the sum over each 50 element range
differ only in the the values of two elements it should be
rather cheap to calculate.

If the sums are nearly equal the matrix will be "equal" with
a high probability. So you can maybe do a presearch and get
several small areas that you can search afterwards.

In case your values are truly random this wont get you far.

And probably sum isn't the right thing to do. But, even
applying a more complex metric should be much cheaper than
comparing all values...

hth

Christoph

P.S.: Please dont toppost.
Jul 22 '05 #6
"cybit friendly" <rooivalk at sa-military plop co plop za> wrote:
Problem: I'm scanning through Array1[1000][1000] to find the closest match
to Array2[50][50] within Array1. At the moment I'm using a method that can
best be described as "brute force"..I'm literally scanning through the
entire Array1 using the entire Array2. The routine quits if a match conforms to a threshhold cut-off. The problem is: *it's slow!*


I am not sure what the definition of "closest match" is; do you mean
something like this:

Find (x, y) such that the sum of the absolute values of (Array2[a][b] -
Array1[x+a][y+b]) for all 0 <= a < 50, 0 <= b < 50 is minimised.

What is the application ? If this is for image recognition, there may be
better ways ...

David F
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dariusz | last post by:
Despite looking at a number of tutorials in books and online examples on pattern matching - I can't quite get my head around it to work... so need some help. What I have now is a variable that...
2
by: BalyanM | last post by:
Hi, I am new to python.I am using it on redhat linux 9. I am interested to run python on a sun machine(SunE420R,os=solaris) with 4 cpu's for a pattern discovery/search program on biological...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
2
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
1
by: Eric | last post by:
I use RegEx to search pattern. Script works fine in the situation when there is a colon after each word and it fetch the rest of the word from that line. Now the pattern is in square bracket and i...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
3
by: mercuryshipzz | last post by:
#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.