May be it's not really the type of solution you have in mind, but I'll
give it a try.

If the domain of the args is i.n , then this is more efficient for:

LHA with 'large' gaps,  and 10 ( much < ) # RHA

trap17=: 4 : 0
  'u h d' =. 2 -~/\ x
  'lz dr' =. 0 >. x (-&{.,-~&{.) y
  (#y){. dr}. (lz$0), ((%*i.)u), (1$~h+1), (%...@-)d
)

   200 400 480 600 (trap-:trap17) i.1e3
1

   5 ts '200 400 480 600 trap i.1e3'
0.0083002 219776
   5 ts '200 400 480 600 trap17 i.1e3'
8.74e_5 45696

   6j2 ": 0.0083002 219776 % 8.74e_5 45696
 94.97  4.81



Hallo Brian Schott, je schreef op 27-04-09 06:50:
>       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
>
>
>   

-- 
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to