in reply to Can I speed this up? (repetitively scanning ranges in a large array)
I trying to approach your problem in a quite different way, which means that my calculations aren't just a refactoring of your code, but worked out from scratch. I've been producing results broadly similar to yours for a while, and I get identical results for the 3-point/max 10 dataset.
For the larger test-set, I always get some discrepancies, and have been attributing them to errors in my algorithm. But I could never work out were I was going wrong.
I'm now convinced that your algorithm above is wrong! (Or I'm misunderstanding the question completely?)
Given the following set of points with a MAX of 35:
[ 25, 1 ][ 31, 1 ][ 29, 9 ][ 35, 9 ][ 28, 10 ][ 28, 10 ][ 31, 11 ] [ 34, 18 ][ 35, 20 ][ 21, 35 ][ 22, 35 ][ 13, 31 ][ 19, 31 ][ 21, 31 ] [ 30, 31 ][ 22, 30 ][ 19, 26 ][ 24, 26 ][ 7, 25 ][ 7, 24 ][ 16, 24 ] [ 17, 22 ][ 19, 22 ][ 1, 20 ][ 6, 20 ][ 10, 16 ][ 10, 16 ][ 14, 16 ] [ 2, 15 ][ 1, 13 ][ 4, 12 ][ 11, 12 ][ 6, 10 ][ 1, 9 ][ 5, 6 ]
The OP code produces this set of half-distances:
9 9 8 8 7 8 9 10 10 11 10 9 8 8 9 10 9 8 7 8 9 10 9 8 7 6 7 8 7 6 6 5 +6 7 8
In order to test this hypothesis, I knocked up a script to produce a diagram similar to your ascii art in the OP, for any given data&results set, so that I could manually verify the results. This is what it produces for the above:
c:\test>868765-plot -MAX=35 -S=20 -R=35 -DIST=op.results 1234567890123456789012345678901234567890 *|||||||||||||||||||||||***********|[ 25, 1 ] *|||||||||||||||||||||||||||||*****|[ 31, 1 ] *********|||||||||||||||||||*******|[ 29, 9 ] *********|||||||||||||||||||||||||*|[ 35, 9 ] **********|||||||||||||||||********|[ 28, 10 ] **********|||||||||||||||||********|[ 28, 10 ] ***********|||||||||||||||||||*****|[ 31, 11 ] ******************|||||||||||||||**|[ 34, 18 ] ********************||||||||||||||*|[ 35, 20 ] ||||||||||||||||||||***************|[ 21, 35 ] |||||||||||||||||||||**************|[ 22, 35 ] ||||||||||||*******************|||||[ 13, 31 ] ||||||||||||||||||*************|||||[ 19, 31 ] ||||||||||||||||||||***********|||||[ 21, 31 ] |||||||||||||||||||||||||||||**|||||[ 30, 31 ] |||||||||||||||||||||*********||||||[ 22, 30 ] ||||||||||||||||||********||||||||||[ 19, 26 ] |||||||||||||||||||||||***||||||||||[ 24, 26 ] ||||||*******************|||||||||||[ 7, 25 ] ||||||******************||||||||||||[ 7, 24 ] |||||||||||||||*********||||||||||||[ 16, 24 ] ||||||||||||||||******||||||||||||||[ 17, 22 ] ||||||||||||||||||****||||||||||||||[ 19, 22 ] ********************||||||||||||||||[ 1, 20 ] |||||***************||||||||||||||||[ 6, 20 ] |||||||||*******||||||||||||||||||||[ 10, 16 ] |||||||||*******||||||||||||||||||||[ 10, 16 ] |||||||||||||***||||||||||||||||||||[ 14, 16 ] |**************|||||||||||||||||||||[ 2, 15 ] *************|||||||||||||||||||||||[ 1, 13 ] |||*********||||||||||||||||||||||||[ 4, 12 ] ||||||||||**||||||||||||||||||||||||[ 11, 12 ] |||||*****||||||||||||||||||||||||||[ 6, 10 ] *********|||||||||||||||||||||||||||[ 1, 9 ] ||||**||||||||||||||||||||||||||||||[ 5, 6 ] +-------->||||||||||||||||<--------| 9 -+-------->||||||||||||||||<-------| 9 --+------->||||||||||||||||||<-----| 8 ---+------->||||||||||||||||||<----| 8 ----+------>||||||||||||||||||||<--| 7 -----+------->||||||||||||||||||<--| 8 ------+-------->||||||||||||||||<--| 9 -------+--------->||||||||||||||<--| 10 --------+--------->||||||||||||||<-| 10 ---------+---------->||||||||||||<-| 11 <---------+--------->||||||||||||||| 10 ||<--------+-------->||||||||||||||| 9 ||||<-------+------->||||||||||||||| 8 |||||<-------+------->|||||||||||||| 8 |||||<--------+-------->|||||||||||| 9 |||||<---------+--------->|||||||||| 10 |||||||<--------+-------->|||||||||| 9 |||||||||<-------+------->|||||||||| 8 |||||||||||<------+------>|||||||||| 7 |||||||||||<-------+------->|||||||| 8 |||||||||||<--------+-------->|||||| 9 |||||||||||<---------+--------->|||| 10 |||||||||||||<--------+-------->|||| 9 |||||||||||||||<-------+------->|||| 8 |||||||||||||||||<------+------>|||| 7 |||||||||||||||||||<-----+----->|||| 6 |||||||||||||||||||<------+------>|| 7 >||||||||||||||||||<-------+-------| 8 >||||||||||||||||||||<------+------| 7 >||||||||||||||||||||||<-----+-----| 6 ->||||||||||||||||||||||<-----+----| 6 ->||||||||||||||||||||||||<----+---| 5 --->||||||||||||||||||||||<-----+--| 6 ----->||||||||||||||||||||<------+-| 7 ------->||||||||||||||||||<-------+| 8
If you consider position 1.
Which would be a half-distance of 20.
Which is a half-distance of 12.
Which means the final half-distance for position 1 should be 12; not 9 as produced by the OP code.
Similarly, considering position 35
Which would be a half-distance of 21.
Which is a half-distance of 11.
Which means the final half-distance for position 1 should be 11; not 8 as produced by the OP code.
You can work the other out for yourself.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I speed this up? (Algorithm error)
by daverave (Scribe) on Nov 03, 2010 at 20:11 UTC | |
by BrowserUk (Patriarch) on Nov 03, 2010 at 20:37 UTC |