Henry, Brian,
thanks, it works now. I now have a 0-20% speedup compared to the previous
version.
Jan.

On Mon, Dec 21, 2009 at 12:02 AM, Henry Rich <henryhr...@nc.rr.com> wrote:

> I think Brian is right, and the fix would be to replace that line with
>
> z=. <./\&.(-&iz) (>: <. (j ~: b)&[ + |.!.j_index) z
>
> (untested)
>
> Henry Rich
>
> Jan Jacobs wrote:
> > Henry,
> > I tried this in J5.04 (changed x y into x. y.) but it returned a syntax
> > error (e.g. 'aap' LevDist5 'taap')
> > ³syntax error: LevDist5
> > ³   z=.<./\&.(-&iz)(    >:<.(j~:b)+|.!.j_index)z
> > What's wrong?
> > J6 works fine.
> > Jan.
> >
> > On Sun, Dec 20, 2009 at 5:37 PM, Henry Rich <henryhr...@nc.rr.com>
> wrote:
> >
> >> Well, let me give you my final version then:
> >>
> >> levdist=: 4 : 0"1
> >> 'a b'=. (/: #&>)x;y
> >> z=. >: iz =. i.#b
> >> for_j. a do.
> >>   z=. <./\&.(-&iz) (>: <. (j ~: b) + |.!.j_index) z
> >> end.
> >> {:z
> >> )
> >>
> >> No way is this ever going to be a J primitive.  And J does not allow
> >> overloading primitive names with user code.  You'll have to give it a
> >> name and use it.
> >>
> >> I've not heard of Tanimoto distance, but we can work on that next.
> >>
> >> Henry Rich
> >>
> >> Jan Jacobs wrote:
> >>> Henry,
> >>> very good. For longer strings it is more than double so fast as the
> >> previous
> >>> version. In my test cases it even consumes less memory.
> >>> Is it possible to include this as a native function in J (e.g.
> >> overloading
> >>> -. or s:)?
> >>> Same question but now for Tanimoto distance?
> >>> Jan.
> >>>
> >>>
> >>> On 12/19/09, R.E. Boss <r.e.b...@planet.nl> wrote:
> >>>> Smart analysis. Chapeau!
> >>>>
> >>>>
> >>>> R.E. Boss
> >>>>
> >>>>
> >>>> -----Oorspronkelijk bericht-----
> >>>> Van: programming-boun...@jsoftware.com
> >>>> [mailto:programming-boun...@jsoftware.com] Namens Henry Rich
> >>>> Verzonden: zaterdag 19 december 2009 3:00
> >>>> Aan: Programming forum
> >>>> Onderwerp: [Jprogramming] Levenshtein distance
> >>>>
> >>>> I was working with R. E.'s compact implementation of the Levenshtein
> >>>> distance and I found an interesting equivalence:
> >>>>
> >>>> (<. >:)/\.&.|.
> >>>>
> >>>> can be replaced by
> >>>>
> >>>> (<./\@:- + ]) i...@#
> >>>>
> >>>> which uses a little more space but is quite a bit faster for large
> >>>> operands.  So now I have the version:
> >>>>
> >>>> NB. Levenshtein distance between two strings
> >>>> levdist=: 4 : 0
> >>>> 'a b'=. (/: #&>)x;y
> >>>> z=. i.>:#b
> >>>> for_j. a do.
> >>>> z=. ((<./\@:- + ]) i...@#) ((j ~: b) + }:z) ({...@] , (<. }.)) >:z
> >>>> end.
> >>>> {:z
> >>>> )
> >>>>
> >>>>
> >>>> Henry Rich
> >>>> ----------------------------------------------------------------------
> >>>> For information about J forums see
> http://www.jsoftware.com/forums.htm
> >>>>
> >>>> ----------------------------------------------------------------------
> >>>> For information about J forums see
> http://www.jsoftware.com/forums.htm
> >>>>
> >>>
> >>>
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >>
> >
> >
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Jan Jacobs
Esdoornstraat 33
5995AN Kessel
T: +31 77 462 1887
M: +31 6 23 82 55 21
E: jan.jac...@sommaps.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to