Ok...

I was also thinking of using an adverb or a conjunction, to handle the
extra arguments.

Here's what dwtL looks like as an adverb:

dwtL=: 1 : 0
:
 'yn wn'=. m dwt y
 wn; ((<:x)&(m dwtL)^:(x>1) yn)
)

(Note that I got rid of the & on the left side of dwt - that was unnecessary.)

Note that dwtL's usage changes:

wavelets =: 4 'db4' dwtL yvals

Next, it bothers me that wn is on the right side of the result from
dwt and on the left side of the result from dwtL. So let's change
that:

dwt=: 4 : 0
  'hpf lpf'=.wdict x
  yvals=. hpf&oddx y
  (yvals +/ . * hpf);(yvals +/ . * lpf)
)

dwtL=: 1 : 0
:
  'wn yn'=. m dwt y
  wn; ((<:x)&(m dwtL)^:(x>1) yn)
)

Next, let's start cleaning up the parenthesis like you asked. The
right hand argument of a verb has an implicit parenthesis around it,
so we can take advantage of that. Also, none of instances of & are
necessary here:

dwt=: 4 : 0
  'hpf lpf'=.wdict x
  yvals=. hpf oddx y
  (yvals +/ . * hpf); yvals +/ . * lpf
)

dwtL=: 1 : 0
:
  'wn yn'=. m dwt y
  wn; (<:x) (m dwtL)^:(x>1) yn
)

You may prefer the symmetry of the parenthesis in dwt, and leave them there?

And, now that the & is gone, I no longer need to parenthesize the
verb-building stage of the use of the dwtL adverb:

dwtL=: 1 : 0
:
  'wn yn'=. m dwt y
  wn; (<:x) m dwtL^:(x>1) yn
)

But that might be getting too obscure?

It might also be reasonable to fold dwtL and dwt into a single
definition, but I'm not sure enough about that (what does the L stand
for in 'dwtL'?). Would you feel uncomfortable if the body of dwt were
brought into dwtL?

Thanks,

-- 
Raul

On Mon, Oct 27, 2014 at 11:50 PM, Scott Locklin <[email protected]> wrote:
> Hit the send button too soon:
>
> Just FYI; the level value here is completely arbitrary; the 4 is not
> associated in any way with the fact that I picked the 'db4' mother wavelet;
> 1,2,3,5,6, etc, are equally valid. Or you could use (4;'db6').
>
> wavelets =. (4;'db4')dwtL yvals
>
> -SL
>
>
> On 10/27/2014 08:45 PM, Scott Locklin wrote:
>>
>> My apologies guys: I should have included the other bits, but I thought
>> something might pop out immediately, and I didn't want to spam up the list
>> with lots of code. Adverbs and conjunctions, I am still a bit intimidated
>> by; wouldn't have thought of that. FWIIW, I have to think about higher
>> dimensions: I think you'd need different verbs for images. For images,
>> you'll almost certainly want to use "max overlap DWT" which takes arbitrary
>> size inputs.
>>
>> Interesting, small use case (the output may or may not be informative, but
>> it is correct):
>>
>> yvals =.  ((0 1 2 _1 #~ 4 %~ ]) + (1 o. i.) + 1 o. (o. 1) %~ i.) 256 NB.
>> this number must be 2^N
>> wavelets =. (4;'db4')dwtL yvals
>>
>> dwtL=: 4 : 0
>>  'lev k'=.x
>>  'yn wn'=. k&dwt y
>>  wn; (((<:lev);k)&dwtL^:(lev>1) yn)
>> )
>>
>>
>> Here is what I have for dwt:
>>
>> oddx=: ] {~ ([: (] #~ 0 1 $~ #) [: i. [: # ]) -/ [: i. [: # [
>> dwt=: 4 : 0
>> 'hpf lpf'=.wdict x
>>  yvals=. hpf&oddx y
>> (yvals +/ . * lpf);(yvals +/ . * hpf)
>> )
>>
>> wdict is a bunch of constants for the different kinds of wavelets, which I
>> will abbreviate to just the Daubechies wavelets:
>>
>>
>> NB. get the high pass from the low pass, return a box list of both
>> HpLp =: ] ;~ |. * _1 ^ [: i. #
>>
>> wdict=: 3 : 0
>>  select. y
>>   case. 'db4' do.
>>    HpLp 0.482962913144534, 0.836516303737808, 0.224143868042013,
>> _0.12940952255126
>>   case. 'db6' do.
>>    HpLp 0.332670552950083, 0.806891509311093, 0.459877502118491,
>> _0.135011020010255, _0.0854412738820267, 0.0352262918857096
>>   case. 'db8' do.
>>    HpLp 0.230377813307443, 0.714846570548406, 0.630880767935879,
>> _0.0279837694166834, _0.187034811717913, 0.0308413818353661,
>> 0.0328830116666778, _0.0105974017850021
>>   case. 'db16' do.
>>    HpLp 0.0544158422431049, 0.312871590914303, 0.67563073629729,
>> 0.585354683654191, _0.0158291052563816, _0.28401554296157,
>> 0.0004724845739124, 0.128747426620484, _0.0173693010018083,
>> _0.0440882539307952, 0.0139810279173995, 0.0087460940474061,
>> _0.0048703529934518, _0.000391740373377, 0.0006754494064506,
>> _0.0001174767841248
>>  end.
>> )
>>
>>
>> >It's indeed difficult to suggest things if we can not try it out.
>>>
>>> Conceptually, I'd say things which don't change in one  invocation are
>>> prime
>>> candidates for being changed into adverb arguments.
>>> Eg. fixing thewavelet type as "u" would eliminate the need for boxes in
>>> the left argument, something along the lines of:
>>
>>
>>> dwtL2=: 1 : 0
>>> 'yn wn'=. u&dwt y
>>> wn; ((<:x)&dwtL2^:(x>1) yn)
>>> )
>>
>>
>>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to