Members of the Forum:

If I plot the points of a sine curve thusly

   'type point;pensize 5' plot 1 o. 8%~i:49

I get a nice graph but, due the nature of the sine function, points near the
inflection points are more closely spaced than those further away.  How can
I adjust my input points to get more evenly-spaced (for simplicity, on the
X-axis) outputs?  I'd like a method I could use for any arbitrary function.

Here's a simple attempt wherein I try to remove the point closest to the one
before it and insert a point midway between the two most widely separated
points:

NB.* evenOut: adjust inputs to fnc so outputs more evenly spaced.
evenOut=: 1 : 0
   diffs=. |2-~/\u y
   'whi wlo'=. diffs i. (>./,<./)diffs
   wlo=. wlo-wlo=<:#y   NB. Don't remove endpoint
   y=. (0 (>:whi)}1$~>:#y)#^:_1 y
   y=. (u -:+/y{~whi+0 2) (>:whi)}y
   y=. (<<<>:wlo){y
)

evenOut_test_=: 3 : 0
   tsts=. 0 1 10,0 10 11,:0 5 10
   assert. (] evenOut"1 tsts)-:(5.5 5 5) 1}&.|:tsts
)

If I could get a satisfactory version of this two-point substituter, it
might work to apply it repeatedly until the point differences stabilize.
 I'm satisfied with the result for these simple test cases:

   ]tsts=. 0 1 10,0 10 11,:0 5 10
0 1 10
0 10 11
0 5 10
   ] evenOut"1 tsts
0 5.5 10
0 5 11
0 5 10

(Testing with verb "]" for simplicity).  However, this result

    ] evenOut 0 2 4 5
0 1 2 5

isn't as good; a result like "0 2 3
5" might be better in this case.  We could define a measure of evenness:

   msrEveness=: 13 : '%:+/*:2-/\|2-/\y'

to quantify this preference (where a lower measure is better).  This shows
us that of the three possibilities,

   msrEveness ] evenOut 0 2 4 5
2
   msrEveness 0 2 4 5
1
   msrEveness 0 2 3 5
1.4142136

the initial arrangement is best.  An arrangement like this

    msrEveness 0 5r3 10r3 5
0

is optimal in this case (we want to retain the endpoints unchanged).

Any ideas on how to approach this?







-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to