On Wed, Mar 3, 2010 at 10:28 PM, Zsbán Ambrus <[email protected]> wrote:
>   conv=: +//.@:(*/)
>   deconv=: 4 :('r=.$0'; 'while. x<:&#y'; 'do. r=.r,t=.y%&{.x';
> 'y=.}.y-/@:,:t*x'; 'end.'; 'r')
>   deconv2=: 4 :('r=.i.0 0'; 'while. x<:&#y'; 'do. r=.r,t=.x
> deconv&:{.y'; 'y=.}.y-/@:,:t conv"1 x'; 'end.'; 'r')

Of course this two dimensional deconvolution verb in my previous mail
only works for right arguments that are actually convolutions of the
left argument, it gives spectacularly bad results for right arguments
that aren't.

   conv2=: 4 :'+//."2 +//. x */"1"1 2 y'
   ]b=: 1 1,:1 0
1 1
1 0
   ]c=: 1$~6 7
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
   b deconv2 c
1  0  1   0   1   0
0  1 _1   2  _2   3
1 _1  3  _4   7  _9
0  2 _4   9 _15  25
1 _2  7 _15  31 _55
   b conv2 b deconv2 c
1  1 1   1  1   1   0
1  1 1   1  1   1   3
1  1 1   1  1   1  _9
1  1 1   1  1   1  25
1  1 1   1  1   1 _55
1 _2 7 _15 31 _55   0

For this case, I recommend the following solution instead.

   decv2 =: 4 :'z $ (,y) %. |:,"_1 (-(#:,@:i.) z=.y>:@-&$x) |. ($y){.x'
   b decv2 c
0.748737 0.370301 0.577096 0.474212 0.502546 0.641338
0.383489 0.179775 0.244423 0.253298 0.123513 0.449928
0.550721 0.334645 0.447706 0.447706 0.334645 0.550721
0.449928 0.123513 0.253298 0.244423 0.179775 0.383489
0.641338 0.502546 0.474212 0.577096 0.370301 0.748737
   b conv2 b decv2 c
0.748737  1.11904 0.947397  1.05131 0.976759  1.14388 0.641338
 1.13223 0.933565  1.00129 0.971933 0.879358  1.21478 0.449928
 0.93421  1.06514  1.02677  1.14871 0.905864  1.33529 0.550721
 1.00065 0.908086 0.824517 0.945426 0.758842  1.11399 0.383489
 1.09127   1.2674  1.23006  1.29573  1.12717  1.50253 0.748737
0.641338 0.502546 0.474212 0.577096 0.370301 0.748737        0

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

Reply via email to