Considering that I have a matrix (mXn) like this:
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 0 | 1 | 1 | 2 | 1 | 1 | 0 | 0 | 0 0 | 1 | 4 | 9 | 4 | 1 | 0 | 0 | 0 1 | 2 | 9 | # | 9 | 2 | 1 | 0 | 0 0 | 1 | 4 | 9 | 4 | 1 | 0 | 0 | 0 0 | 1 | 1 | 2 | 1 | 1 | 0 | 0 | 0 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0
Where there is a spot #
randomly set. The values near that, are affected in a form of wave. The closer to that spot, closer the value gets to 10.
Which algorithm would work well on finding #
, assuming it will be used on larger scales?
EDIT: I am more interested on how to find the the first non-zero number, than find #
itself, which is the purpose, but not the real problem. Imagine a huge matrix full of zero and somewhere that #
is hiding. The exhaustive part of the algorithm is to find the first non-zero.
Finding the first non-zero value only works when the signal is symmetric and contain no rotation. Consider the following example borrowed from Internet (zero = blue, max = red), note the first-non-zero value is somewhere by the top right corner:
(source: mathworks.com)
You might want to have a look at gradient descent. The general algorithm is defined for continuous functions (yours is discrete), but you can still use it.
It basically gets initialized somewhere in your matrix, looks for the gradient at that point and moves in that direction, then repeat until it converges. You can initialize it by sampling randomly (pick a random cell until you get to a non-zero value, you could expect this to be faster than traversing and finding a non zero value in average, naturally depending on your matrix and signal size)
Some properties:
Limitations:
This might be an overkill for you, it might be appropriate, I don't know, you don't provide more detail but it might be worth it to have a look at it. Note that there's a whole family of algorithms, with many variations and optimizations. Have a look at the Wikipedia article first ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With