I have been trying to improve an old algorithm for
creating trapezoid shaped fuzzy set membership functions
using I., but problems have arisen.

        The idea is to supply a left argument to the verb
`trap` that corresponds to the ordered values
aa<:bb<:cc<:dd, which correspond to the x-ordinate of each
of the 4 (x,y) corners of the trapezoid in the following
picture, and a right argument to `trap` that specifies a
list of sample points on the x axis. The resulting output of
`trap` should be the shape of the right hand argument, as
follows (unfortunately in this case the right hand argument
is the x values on the graph, which we normally refer to as
the y value of a verb).

[Case 0]
0,  when x < aa, or when x>dd
[Case 1]
1,  when bb < x < cc
[Case 2]
a linear interpolation between 0 and 1 or between
1 and 0,  where the order 0 to 1 applies when
aa<x<bb and the order 1 to 0 when cc<x<dd

NB.     ______               y=1
NB.    /      \
NB.   /        \
NB. _/          \____        y=0
NB. aa bb    cc dd
NB.

        So for example,  the fictional inputs and results
should be like these.

   2 6 8 10 trap i. 11
0 0 0 0.25 0.5 0.75 1 1 1 0.5 0
   2 6 8 8  trap i. 11
0 0 0 0.25 0.5 0.75 1 1 1 0   0
   6 6 8 10 trap i. 11
0 0 0 0    0   0    1 1 1 0.5 0

        What I have so far is two different versions of
`trap`: trap2 and trap3 which can be combined into trap, but
I am not happy with the inefficiency of this trap and am
looking for suggestions.

Idotr =: |....@[ (#...@[-i.) ]    NB. reverses direction of I.
ntr =: interpolate =:     ({...@[-])%-/@(2&{.)@[
trap2 =: (0:`ntr`1:`(|....@[ntr])`0:@.I.   )"1 0
trap3 =: (0:`ntr`1:`(|....@[ntr])`0:@.Idotr)"1 0
trap  =: trap2>.trap3

Thank you,

--

(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to