Re: [Jprogramming] Euclidean Distance

2017-10-29 Thread Louis de Forcrand
I believe you can easily plot points in 3D space with lines betweens pairs of 
points:

require 'plot'
plot (; 2 ; 1) i:10j100

Cheers,
Louis

> On 28 Oct 2017, at 15:12, 'Skip Cave' via Programming 
>  wrote:
> 
> Thanks to Raul & Esa for their very clear instructions and examples for
> plotting points in 2D space.
> 
> I originally thought that my plot post was overlooked, so I re-posted it
> under a more descriptive
> title. Then I saw Raul & Esa's posts, so you can ignore that post.
> In any case, Raul & Esa's answers have resolved part of my requirements.
> 
> However, I need to plot 3D point plots as well. So I may need to look at GNU
> Plot, or
> perhaps Mathematica, to do the 3D plots. I also need to draw lines between
> the pairs of points
> (between each left argument point and it's corresponding right argument
> point) in both 2D & 3D plots.
> 
> I might be willing to pay for someone to update the J plot package to
> handle point plots and lines
> between point pairs. Anyone interested?
> 
> Skip
> 
> <<< >>>
> 
>> On Sat, Oct 28, 2017 at 1:53 AM, Raul Miller  wrote:
>> 
>> I had to study the plot docs, and experiment a little. The page
>> http://code.jsoftware.com/wiki/Plot/Data is probably the most
>> important to understand.
>> 
>> For your item 1, something like this might work (change the pensize to
>> change the size of the dots - the default size is too small for a
>> graph with only a few dots):
>> 
>>  'type dot;pensize 5' plot ;/|:0 0, 2 _3, _1 2, 1 1,_1 _2,: 3 4
>> 
>> Note, especially, that I used ,: between the last pair of points so
>> these would form into a matrix rather than a long vector. (And then I
>> flipped the matrix on its side with |: and broke it into x and y
>> elements using ;/ so that plot would recognize the data in the way you
>> wanted it to.)
>> 
>> For your item 2, I just now saw Lippu Esa post what looks like a good
>> answer while I was composing this message.
>> 
>> For your item 4 ..  according to
>> http://code.jsoftware.com/wiki/Plot/Types plot currently does not
>> support dot plots for 3d data. I sometimes struggle understanding
>> plot's limitations, but since I have not been prepared to rewrite it,
>> I mostly just accept them as they are. Still, we could use a stick
>> plot:
>> 
>>'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1
>> 1 1,_1 _2 3,: 3 4 2
>> 
>> Sadly, it looks like a stick plot does not adequately show some
>> points. We could work around that by adding another point to force a
>> different bounding box:
>> 
>>  'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1 1
>> 1,_1 _2 3,: 3 4 2
>> 
>> There might be a better way?
>> 
>> For your item 5, you can also set the observer viewpoint:
>> 
>>'type stick; pensize 5; viewpoint _1.6 _2.4 1.5' plot ;/|:0 0 0, 2
>> _3 1, _1 2 0, 1 1 1,_1 _2 3,: 3 4  2
>> 
>> And, finally, for your item 6, you would probably want to break up
>> this one-liner into a sequence of commands, as was illustrated in
>> Lippu Esa's post. (You do get a sequence of commands separated by ; in
>> the left hand argument to plot, but to break up the data and issue
>> commands for different chunks of data you need to work with a sequence
>> of pd statements.)
>> 
>> Thanks,
>> 
>> --
>> Raul
>> 
>> 
>> 
>> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Euclidean Distance

2017-10-28 Thread 'Skip Cave' via Programming
Thanks to Raul & Esa for their very clear instructions and examples for
plotting points in 2D space.

I originally thought that my plot post was overlooked, so I re-posted it
under a more descriptive
title. Then I saw Raul & Esa's posts, so you can ignore that post.
In any case, Raul & Esa's answers have resolved part of my requirements.

However, I need to plot 3D point plots as well. So I may need to look at GNU
Plot, or
perhaps Mathematica, to do the 3D plots. I also need to draw lines between
the pairs of points
(between each left argument point and it's corresponding right argument
point) in both 2D & 3D plots.

I might be willing to pay for someone to update the J plot package to
handle point plots and lines
between point pairs. Anyone interested?

Skip

<<< >>>

On Sat, Oct 28, 2017 at 1:53 AM, Raul Miller  wrote:

> I had to study the plot docs, and experiment a little. The page
> http://code.jsoftware.com/wiki/Plot/Data is probably the most
> important to understand.
>
> For your item 1, something like this might work (change the pensize to
> change the size of the dots - the default size is too small for a
> graph with only a few dots):
>
>   'type dot;pensize 5' plot ;/|:0 0, 2 _3, _1 2, 1 1,_1 _2,: 3 4
>
> Note, especially, that I used ,: between the last pair of points so
> these would form into a matrix rather than a long vector. (And then I
> flipped the matrix on its side with |: and broke it into x and y
> elements using ;/ so that plot would recognize the data in the way you
> wanted it to.)
>
> For your item 2, I just now saw Lippu Esa post what looks like a good
> answer while I was composing this message.
>
> For your item 4 ..  according to
> http://code.jsoftware.com/wiki/Plot/Types plot currently does not
> support dot plots for 3d data. I sometimes struggle understanding
> plot's limitations, but since I have not been prepared to rewrite it,
> I mostly just accept them as they are. Still, we could use a stick
> plot:
>
> 'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1
> 1 1,_1 _2 3,: 3 4 2
>
> Sadly, it looks like a stick plot does not adequately show some
> points. We could work around that by adding another point to force a
> different bounding box:
>
>   'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1 1
> 1,_1 _2 3,: 3 4 2
>
> There might be a better way?
>
> For your item 5, you can also set the observer viewpoint:
>
> 'type stick; pensize 5; viewpoint _1.6 _2.4 1.5' plot ;/|:0 0 0, 2
> _3 1, _1 2 0, 1 1 1,_1 _2 3,: 3 4  2
>
> And, finally, for your item 6, you would probably want to break up
> this one-liner into a sequence of commands, as was illustrated in
> Lippu Esa's post. (You do get a sequence of commands separated by ; in
> the left hand argument to plot, but to break up the data and issue
> commands for different chunks of data you need to work with a sequence
> of pd statements.)
>
> Thanks,
>
> --
> Raul
>
>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Euclidean Distance

2017-10-28 Thread Raul Miller
I had to study the plot docs, and experiment a little. The page
http://code.jsoftware.com/wiki/Plot/Data is probably the most
important to understand.

For your item 1, something like this might work (change the pensize to
change the size of the dots - the default size is too small for a
graph with only a few dots):

  'type dot;pensize 5' plot ;/|:0 0, 2 _3, _1 2, 1 1,_1 _2,: 3 4

Note, especially, that I used ,: between the last pair of points so
these would form into a matrix rather than a long vector. (And then I
flipped the matrix on its side with |: and broke it into x and y
elements using ;/ so that plot would recognize the data in the way you
wanted it to.)

For your item 2, I just now saw Lippu Esa post what looks like a good
answer while I was composing this message.

For your item 4 ..  according to
http://code.jsoftware.com/wiki/Plot/Types plot currently does not
support dot plots for 3d data. I sometimes struggle understanding
plot's limitations, but since I have not been prepared to rewrite it,
I mostly just accept them as they are. Still, we could use a stick
plot:

'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1
1 1,_1 _2 3,: 3 4 2

Sadly, it looks like a stick plot does not adequately show some
points. We could work around that by adding another point to force a
different bounding box:

  'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1 1
1,_1 _2 3,: 3 4 2

There might be a better way?

For your item 5, you can also set the observer viewpoint:

'type stick; pensize 5; viewpoint _1.6 _2.4 1.5' plot ;/|:0 0 0, 2
_3 1, _1 2 0, 1 1 1,_1 _2 3,: 3 4  2

And, finally, for your item 6, you would probably want to break up
this one-liner into a sequence of commands, as was illustrated in
Lippu Esa's post. (You do get a sequence of commands separated by ; in
the left hand argument to plot, but to break up the data and issue
commands for different chunks of data you need to work with a sequence
of pd statements.)

Thanks,

-- 
Raul



On Fri, Oct 27, 2017 at 11:32 PM, 'Skip Cave' via Programming
 wrote:
> As part of my NLP project, I need a way to plot 2D & 3D point cluster plots.
> Let's take the example in my previous email:
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
> In that distance calculation, their are 6 coordinate pairs, representing 6
> points in x & y.
> The six points are:
>
>  0 0, 2 _3, _1 2, 1 1,_1 _2, 3 4
>
> I want to see a plot of those 6 points.
>
> 1. How do I make a 2D plot that shows these 6 points as small dots on an xy
> graph.
> 2. How can I make the first three points red dots, and the last three
> points blue dots?
> 3. Now assume I have 6 more points, but they are in three dimensions:
>
> 0 0 0, 2 _3 1, _1 2 0, 1 1 1,_1 _2 3, 3 4  2
>
> 4. How do I make a 3D plot that shows these 6 points as small dots in a 3D
> xyz perspective view graph
> 5. How do I rotate the view?
> 6. How can I make the first three points red dots, and the last three
> points blue dots?
>
> Skip
>
> <<<>>>
>
>
> On Fri, Oct 27, 2017 at 9:48 PM, Skip Cave  wrote:
>
>> Raul,
>>
>> Yes, rank was the problem. It hit me while I was eating dinner
>> but your solution was different than what I expected (they usually are):
>>
>> Raul:
>>
>>  dis =.4 :'%:+/*:x-y' "1
>>
>>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>>
>> 1.41421 3.16228 4.47214
>>
>>
>>0 0 dis 1 1,_1 _2,:3 4
>>
>> 1.41421 2.23607 5
>>
>>
>> I need to study this more. My solution was:
>>
>>  dis =. 4 :'%:+/"1 *:x-y'
>>
>>
>>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>>
>> 1.41421 3.16228 4.47214
>>
>>
>>  0 0 dis 1 1,_1 _2,:3 4
>>
>> |length error: dis
>>
>> | %:+/"1*:x -y
>>
>>
>> So my scheme doesn't work for one-to-many. It just works on one-to-one
>>
>> & many-to-many (both nouns must be the same size).
>>
>> I had no idea you could put the rank operator outside the quotes!
>>
>> Where does the language description doc discuss this trick?
>>
>>
>> Skip
>>
>> Skip Cave
>> Cave Consulting LLC
>>
>> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller 
>> wrote:
>>
>>> The items that dis is expecting are rank 1 vectors. So it might make
>>> sense to include a rank 1 specification in its definition:
>>>
>>>dis =: 4 :'%:+/*:x-y'"1
>>>
>>> Does that work for this example?
>>>
>>>0 0 dis 1 1,_1 _2,:3 4
>>> 1.41421 2.23607 5
>>>
>>> ... seems so ...
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>>>  wrote:
>>> > In the 2014-11-11 NYCJUG meeting
>>> >  there was a
>>> discussion
>>> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>>> > calculate the Euclidean distance between two vectors.
>>> >
>>> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>>> 2-D
>>> > points 1 1 _1 _2 3 4 0 0 

Re: [Jprogramming] Euclidean Distance

2017-10-28 Thread Lippu Esa
Hi Skip

For the tasks 1. and 2. you can write:

require 'plot'
]a=.0 0, 2 _3, _1 2, 1 1,_1 _2,: 3 4
pd 'reset;type marker;color red'
pd <"1|: 3{.a
pd 'color blue'
pd <"1|: 3}.a
pd 'show'

but I don't know how to plot points in 3D in J. I have done rotating only in 2D 
and played in 3D by rotating surface plots by crudely changing viewpoint.

Maybe you could prep the data in J and feed it to GNU Plot or something 
similar? This might not be very smooth, though.

Best Regards

Esa

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of 'Skip Cave' via Programming
Sent: Saturday, October 28, 2017 6:32 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Euclidean Distance

As part of my NLP project, I need a way to plot 2D & 3D point cluster plots.
Let's take the example in my previous email:

 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214

In that distance calculation, their are 6 coordinate pairs, representing 6
points in x & y.
The six points are:

 0 0, 2 _3, _1 2, 1 1,_1 _2, 3 4

I want to see a plot of those 6 points.

1. How do I make a 2D plot that shows these 6 points as small dots on an xy
graph.
2. How can I make the first three points red dots, and the last three
points blue dots?
3. Now assume I have 6 more points, but they are in three dimensions:

0 0 0, 2 _3 1, _1 2 0, 1 1 1,_1 _2 3, 3 4  2

4. How do I make a 3D plot that shows these 6 points as small dots in a 3D
xyz perspective view graph
5. How do I rotate the view?
6. How can I make the first three points red dots, and the last three
points blue dots?

​Skip

​<<<>>>​


On Fri, Oct 27, 2017 at 9:48 PM, Skip Cave <s...@caveconsulting.com> wrote:

> Raul,
>
> Yes, rank was the problem. It hit me while I was eating dinner
> but your solution was different than what I expected (they usually are):
>
> Raul:
>
>  dis =.4 :'%:+/*:x-y' "1
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>0 0 dis 1 1,_1 _2,:3 4
>
> 1.41421 2.23607 5
>
>
> I need to study this more. My solution was:
>
>  dis =. 4 :'%:+/"1 *:x-y'
>
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>  0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/"1*:x -y
>
>
> So my scheme doesn't work for one-to-many. It just works on one-to-one
>
> & many-to-many (both nouns must be the same size).
>
> I had no idea you could put the rank operator outside the quotes!
>
> Where does the language description doc discuss this trick?
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller <rauldmil...@gmail.com>
> wrote:
>
>> The items that dis is expecting are rank 1 vectors. So it might make
>> sense to include a rank 1 specification in its definition:
>>
>>dis =: 4 :'%:+/*:x-y'"1
>>
>> Does that work for this example?
>>
>>0 0 dis 1 1,_1 _2,:3 4
>> 1.41421 2.23607 5
>>
>> ... seems so ...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>> <programm...@jsoftware.com> wrote:
>> > In the 2014-11-11 NYCJUG meeting
>> > <http://code.jsoftware.com/wiki/NYCJUG/2014-11-11> there was a
>> discussion
>> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>> > calculate the Euclidean distance between two vectors.
>> >
>> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>> 2-D
>> > points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
>> > 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
>> > I have a NLP project that needs to calculate the
>> > Euclidean distance between points in a multi-dimensional
>> > space. I now the basic formula - square the differences,
>> > sum the squares, take the square root of the sum:
>> >
>> >dis =. 4 :'%:+/*:x-y'
>> >
>> >0 0 dis 1 1
>> >
>> > 1.41421
>> >  0 0 0 dis 1 1 1
>> >
>> > 1.73205
>> >
>> > Looking good
>> >
>> >0 0 dis 1 1,_1 _2,:3 4
>> >
>> > |length error: dis
>> >
>> > | %:+/*:x -y
>> >
>> > Ooops!
>> >
>> > How can I make dis handle multiple pairs of vectors?
>> >
>> > like:
>> >
>> >   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>> >
>> > 1.41421  3.16228  4.47214
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> > --
>> > 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

Re: [Jprogramming] Euclidean Distance

2017-10-28 Thread Raul Miller
Where do the docs show that you can do this? Hmm...

I suppose one strong hint is at
http://www.jsoftware.com/help/primer/rank_conjunction.htm where it
shows the left argument to the rank conjunction being a verb.

There are also books, like Henry Rich's J for C programmers which
include related examples. For example:
http://www.jsoftware.com/help/jforc/verb-definition_revisited.htm
(Chapter 13 of Learning J might be another example, though it's less
specifically obvious.)

That said, the ultimate grammar reference is probably Appendix II.E of
the dictionary - but that is so formal that most people find it
undigestible.

There is something to be said for focusing more on practical
applications and letting the grammatical details bubble up
occasionally (like here) when they turn out to have some relevance.

Thanks,

-- 
Raul




On Fri, Oct 27, 2017 at 10:48 PM, 'Skip Cave' via Programming
 wrote:
> Raul,
>
> Yes, rank was the problem. It hit me while I was eating dinner
> but your solution was different than what I expected (they usually are):
>
> Raul:
>
>  dis =.4 :'%:+/*:x-y' "1
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>0 0 dis 1 1,_1 _2,:3 4
>
> 1.41421 2.23607 5
>
>
> I need to study this more. My solution was:
>
>  dis =. 4 :'%:+/"1 *:x-y'
>
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>  0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/"1*:x -y
>
>
> So my scheme doesn't work for one-to-many. It just works on one-to-one
>
> & many-to-many (both nouns must be the same size).
>
> I had no idea you could put the rank operator outside the quotes!
>
> Where does the language description doc discuss this trick?
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller  wrote:
>
>> The items that dis is expecting are rank 1 vectors. So it might make
>> sense to include a rank 1 specification in its definition:
>>
>>dis =: 4 :'%:+/*:x-y'"1
>>
>> Does that work for this example?
>>
>>0 0 dis 1 1,_1 _2,:3 4
>> 1.41421 2.23607 5
>>
>> ... seems so ...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>>  wrote:
>> > In the 2014-11-11 NYCJUG meeting
>> >  there was a
>> discussion
>> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>> > calculate the Euclidean distance between two vectors.
>> >
>> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>> 2-D
>> > points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
>> > 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
>> > I have a NLP project that needs to calculate the
>> > Euclidean distance between points in a multi-dimensional
>> > space. I now the basic formula - square the differences,
>> > sum the squares, take the square root of the sum:
>> >
>> >dis =. 4 :'%:+/*:x-y'
>> >
>> >0 0 dis 1 1
>> >
>> > 1.41421
>> >  0 0 0 dis 1 1 1
>> >
>> > 1.73205
>> >
>> > Looking good
>> >
>> >0 0 dis 1 1,_1 _2,:3 4
>> >
>> > |length error: dis
>> >
>> > | %:+/*:x -y
>> >
>> > Ooops!
>> >
>> > How can I make dis handle multiple pairs of vectors?
>> >
>> > like:
>> >
>> >   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>> >
>> > 1.41421  3.16228  4.47214
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> > --
>> > 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

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread Lippu Esa
Hi Gilles!

Thank you for a thorough post. Sorry about my redundant message.

I should have known better to read the thread completely before responding. 
This forum works so fast, thanks to all!

Anyways, a good exercise for me.

Esa
-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Gilles Kirouac
Sent: Saturday, October 28, 2017 7:13 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Euclidean Distance

   a=:(0 0, 2 _3 ,: _1 2)
   a
 0  0
 2 _3
_1  2
   ]b=:1 1,_1 _2,:3 4
 1  1
_1 _2
 3  4

   a(4 :'+/ &.: *:x-y' "1)b    NB. Under since Square Root is obverse
(inverse) of Square
1.41421 3.16228 4.47214
   a((+/ &.: *:)@: -) "1 b NB. in a tacit way
1.41421 3.16228 4.47214
   a([: (+/ &.: *:) -) "1 b
1.41421 3.16228 4.47214
   a([: +/ &.: *: -) "1 b
1.41421 3.16228 4.47214

   a(+/ &.: *:@: -) "1 b
1.41421 3.16228 4.47214
   ((+/ &.: *:)@: -) "1        NB. Parentheses help readability but are
not needed
+/&.:*:@:-"1
   a(+/ &.: *:@: - "1 )b
1.41421 3.16228 4.47214



Le 2017-10-27 à 22:48, 'Skip Cave' via Programming a écrit :
> Raul,
>
> Yes, rank was the problem. It hit me while I was eating dinner
> but your solution was different than what I expected (they usually are):
>
> Raul:
>
>  dis =.4 :'%:+/*:x-y' "1
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>0 0 dis 1 1,_1 _2,:3 4
>
> 1.41421 2.23607 5
>
>
> I need to study this more. My solution was:
>
>  dis =. 4 :'%:+/"1 *:x-y'
>
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>  0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/"1*:x -y
>
>
> So my scheme doesn't work for one-to-many. It just works on one-to-one
>
> & many-to-many (both nouns must be the same size).
>
> I had no idea you could put the rank operator outside the quotes!
>
> Where does the language description doc discuss this trick?
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller <rauldmil...@gmail.com> wrote:
>
>> The items that dis is expecting are rank 1 vectors. So it might make
>> sense to include a rank 1 specification in its definition:
>>
>>dis =: 4 :'%:+/*:x-y'"1
>>
>> Does that work for this example?
>>
>>0 0 dis 1 1,_1 _2,:3 4
>> 1.41421 2.23607 5
>>
>> ... seems so ...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>> <programm...@jsoftware.com> wrote:
>>> In the 2014-11-11 NYCJUG meeting
>>> <http://code.jsoftware.com/wiki/NYCJUG/2014-11-11> there was a
>> discussion
>>> on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>>> calculate the Euclidean distance between two vectors.
>>>
>>> 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>> 2-D
>>> points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
>>> 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
>>> I have a NLP project that needs to calculate the
>>> Euclidean distance between points in a multi-dimensional
>>> space. I now the basic formula - square the differences,
>>> sum the squares, take the square root of the sum:
>>>
>>>dis =. 4 :'%:+/*:x-y'
>>>
>>>0 0 dis 1 1
>>>
>>> 1.41421
>>>  0 0 0 dis 1 1 1
>>>
>>> 1.73205
>>>
>>> Looking good
>>>
>>>0 0 dis 1 1,_1 _2,:3 4
>>>
>>> |length error: dis
>>>
>>> | %:+/*:x -y
>>>
>>> Ooops!
>>>
>>> How can I make dis handle multiple pairs of vectors?
>>>
>>> like:
>>>
>>>   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>>>
>>> 1.41421  3.16228  4.47214
>>>
>>> Skip Cave
>>> Cave Consulting LLC
>>> --
>>> 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
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread Lippu Esa
This is nice!

You can easily make a distance table:

 (0 0, 2 _3 ,: _1 2) dis/ 1 1,_1 _2,:3 4
1.41421 2.23607   5
4.12311 3.16228 7.07107
2.23607   4 4.47214

and reflex:

   dis/~ 1 1,_1 _2,:3 4
  0 3.60555 3.60555
3.60555   0  7.2111
3.60555  7.2111   0

The tacit version of dis:

dist=.+/&.:*:@:-"1

There is a benefit with many vectors:

  a=.?1000 1000 $ 100
   ts 'dist/~ a'
3.89076069 8424320
   ts 'dis/~ a'
11.76892645 8336600192
   (dist/~ a)-:dis/~ a
1
   
Esa (my first name, I can't get it right in the forum)
-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of 'Skip Cave' via Programming
Sent: Saturday, October 28, 2017 5:48 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Euclidean Distance

Raul,

Yes, rank was the problem. It hit me while I was eating dinner
but your solution was different than what I expected (they usually are):

Raul:

 dis =.4 :'%:+/*:x-y' "1

 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214


   0 0 dis 1 1,_1 _2,:3 4

1.41421 2.23607 5


I need to study this more. My solution was:

 dis =. 4 :'%:+/"1 *:x-y'


 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214


 0 0 dis 1 1,_1 _2,:3 4

|length error: dis

| %:+/"1*:x -y


So my scheme doesn't work for one-to-many. It just works on one-to-one

& many-to-many (both nouns must be the same size).

I had no idea you could put the rank operator outside the quotes!

Where does the language description doc discuss this trick?


Skip

Skip Cave
Cave Consulting LLC

On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller <rauldmil...@gmail.com> wrote:

> The items that dis is expecting are rank 1 vectors. So it might make
> sense to include a rank 1 specification in its definition:
>
>dis =: 4 :'%:+/*:x-y'"1
>
> Does that work for this example?
>
>0 0 dis 1 1,_1 _2,:3 4
> 1.41421 2.23607 5
>
> ... seems so ...
>
> Thanks,
>
> --
> Raul
>
>
> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
> <programm...@jsoftware.com> wrote:
> > In the 2014-11-11 NYCJUG meeting
> > <http://code.jsoftware.com/wiki/NYCJUG/2014-11-11> there was a
> discussion
> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
> > calculate the Euclidean distance between two vectors.
> >
> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
> 2-D
> > points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
> > 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
> > I have a NLP project that needs to calculate the
> > Euclidean distance between points in a multi-dimensional
> > space. I now the basic formula - square the differences,
> > sum the squares, take the square root of the sum:
> >
> >dis =. 4 :'%:+/*:x-y'
> >
> >0 0 dis 1 1
> >
> > 1.41421
> >  0 0 0 dis 1 1 1
> >
> > 1.73205
> >
> > Looking good
> >
> >0 0 dis 1 1,_1 _2,:3 4
> >
> > |length error: dis
> >
> > | %:+/*:x -y
> >
> > Ooops!
> >
> > How can I make dis handle multiple pairs of vectors?
> >
> > like:
> >
> >   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
> >
> > 1.41421  3.16228  4.47214
> >
> > Skip Cave
> > Cave Consulting LLC
> > --
> > 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

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread Gilles Kirouac
   a=:(0 0, 2 _3 ,: _1 2)
   a
 0  0
 2 _3
_1  2
   ]b=:1 1,_1 _2,:3 4
 1  1
_1 _2
 3  4

   a(4 :'+/ &.: *:x-y' "1)b    NB. Under since Square Root is obverse
(inverse) of Square
1.41421 3.16228 4.47214
   a((+/ &.: *:)@: -) "1 b NB. in a tacit way
1.41421 3.16228 4.47214
   a([: (+/ &.: *:) -) "1 b
1.41421 3.16228 4.47214
   a([: +/ &.: *: -) "1 b
1.41421 3.16228 4.47214

   a(+/ &.: *:@: -) "1 b
1.41421 3.16228 4.47214
   ((+/ &.: *:)@: -) "1        NB. Parentheses help readability but are
not needed
+/&.:*:@:-"1
   a(+/ &.: *:@: - "1 )b
1.41421 3.16228 4.47214



Le 2017-10-27 à 22:48, 'Skip Cave' via Programming a écrit :
> Raul,
>
> Yes, rank was the problem. It hit me while I was eating dinner
> but your solution was different than what I expected (they usually are):
>
> Raul:
>
>  dis =.4 :'%:+/*:x-y' "1
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>0 0 dis 1 1,_1 _2,:3 4
>
> 1.41421 2.23607 5
>
>
> I need to study this more. My solution was:
>
>  dis =. 4 :'%:+/"1 *:x-y'
>
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>  0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/"1*:x -y
>
>
> So my scheme doesn't work for one-to-many. It just works on one-to-one
>
> & many-to-many (both nouns must be the same size).
>
> I had no idea you could put the rank operator outside the quotes!
>
> Where does the language description doc discuss this trick?
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller  wrote:
>
>> The items that dis is expecting are rank 1 vectors. So it might make
>> sense to include a rank 1 specification in its definition:
>>
>>dis =: 4 :'%:+/*:x-y'"1
>>
>> Does that work for this example?
>>
>>0 0 dis 1 1,_1 _2,:3 4
>> 1.41421 2.23607 5
>>
>> ... seems so ...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>>  wrote:
>>> In the 2014-11-11 NYCJUG meeting
>>>  there was a
>> discussion
>>> on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>>> calculate the Euclidean distance between two vectors.
>>>
>>> 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>> 2-D
>>> points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
>>> 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
>>> I have a NLP project that needs to calculate the
>>> Euclidean distance between points in a multi-dimensional
>>> space. I now the basic formula - square the differences,
>>> sum the squares, take the square root of the sum:
>>>
>>>dis =. 4 :'%:+/*:x-y'
>>>
>>>0 0 dis 1 1
>>>
>>> 1.41421
>>>  0 0 0 dis 1 1 1
>>>
>>> 1.73205
>>>
>>> Looking good
>>>
>>>0 0 dis 1 1,_1 _2,:3 4
>>>
>>> |length error: dis
>>>
>>> | %:+/*:x -y
>>>
>>> Ooops!
>>>
>>> How can I make dis handle multiple pairs of vectors?
>>>
>>> like:
>>>
>>>   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>>>
>>> 1.41421  3.16228  4.47214
>>>
>>> Skip Cave
>>> Cave Consulting LLC
>>> --
>>> 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

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread 'Skip Cave' via Programming
As part of my NLP project, I need a way to plot 2D & 3D point cluster plots.
Let's take the example in my previous email:

 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214

In that distance calculation, their are 6 coordinate pairs, representing 6
points in x & y.
The six points are:

 0 0, 2 _3, _1 2, 1 1,_1 _2, 3 4

I want to see a plot of those 6 points.

1. How do I make a 2D plot that shows these 6 points as small dots on an xy
graph.
2. How can I make the first three points red dots, and the last three
points blue dots?
3. Now assume I have 6 more points, but they are in three dimensions:

0 0 0, 2 _3 1, _1 2 0, 1 1 1,_1 _2 3, 3 4  2

4. How do I make a 3D plot that shows these 6 points as small dots in a 3D
xyz perspective view graph
5. How do I rotate the view?
6. How can I make the first three points red dots, and the last three
points blue dots?

​Skip

​<<<>>>​


On Fri, Oct 27, 2017 at 9:48 PM, Skip Cave  wrote:

> Raul,
>
> Yes, rank was the problem. It hit me while I was eating dinner
> but your solution was different than what I expected (they usually are):
>
> Raul:
>
>  dis =.4 :'%:+/*:x-y' "1
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>0 0 dis 1 1,_1 _2,:3 4
>
> 1.41421 2.23607 5
>
>
> I need to study this more. My solution was:
>
>  dis =. 4 :'%:+/"1 *:x-y'
>
>
>  (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421 3.16228 4.47214
>
>
>  0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/"1*:x -y
>
>
> So my scheme doesn't work for one-to-many. It just works on one-to-one
>
> & many-to-many (both nouns must be the same size).
>
> I had no idea you could put the rank operator outside the quotes!
>
> Where does the language description doc discuss this trick?
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller 
> wrote:
>
>> The items that dis is expecting are rank 1 vectors. So it might make
>> sense to include a rank 1 specification in its definition:
>>
>>dis =: 4 :'%:+/*:x-y'"1
>>
>> Does that work for this example?
>>
>>0 0 dis 1 1,_1 _2,:3 4
>> 1.41421 2.23607 5
>>
>> ... seems so ...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>>  wrote:
>> > In the 2014-11-11 NYCJUG meeting
>> >  there was a
>> discussion
>> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
>> > calculate the Euclidean distance between two vectors.
>> >
>> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
>> 2-D
>> > points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
>> > 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
>> > I have a NLP project that needs to calculate the
>> > Euclidean distance between points in a multi-dimensional
>> > space. I now the basic formula - square the differences,
>> > sum the squares, take the square root of the sum:
>> >
>> >dis =. 4 :'%:+/*:x-y'
>> >
>> >0 0 dis 1 1
>> >
>> > 1.41421
>> >  0 0 0 dis 1 1 1
>> >
>> > 1.73205
>> >
>> > Looking good
>> >
>> >0 0 dis 1 1,_1 _2,:3 4
>> >
>> > |length error: dis
>> >
>> > | %:+/*:x -y
>> >
>> > Ooops!
>> >
>> > How can I make dis handle multiple pairs of vectors?
>> >
>> > like:
>> >
>> >   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>> >
>> > 1.41421  3.16228  4.47214
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> > --
>> > 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

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread 'Skip Cave' via Programming
Raul,

Yes, rank was the problem. It hit me while I was eating dinner
but your solution was different than what I expected (they usually are):

Raul:

 dis =.4 :'%:+/*:x-y' "1

 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214


   0 0 dis 1 1,_1 _2,:3 4

1.41421 2.23607 5


I need to study this more. My solution was:

 dis =. 4 :'%:+/"1 *:x-y'


 (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4

1.41421 3.16228 4.47214


 0 0 dis 1 1,_1 _2,:3 4

|length error: dis

| %:+/"1*:x -y


So my scheme doesn't work for one-to-many. It just works on one-to-one

& many-to-many (both nouns must be the same size).

I had no idea you could put the rank operator outside the quotes!

Where does the language description doc discuss this trick?


Skip

Skip Cave
Cave Consulting LLC

On Fri, Oct 27, 2017 at 7:03 PM, Raul Miller  wrote:

> The items that dis is expecting are rank 1 vectors. So it might make
> sense to include a rank 1 specification in its definition:
>
>dis =: 4 :'%:+/*:x-y'"1
>
> Does that work for this example?
>
>0 0 dis 1 1,_1 _2,:3 4
> 1.41421 2.23607 5
>
> ... seems so ...
>
> Thanks,
>
> --
> Raul
>
>
> On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
>  wrote:
> > In the 2014-11-11 NYCJUG meeting
> >  there was a
> discussion
> > on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
> > calculate the Euclidean distance between two vectors.
> >
> > 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of
> 2-D
> > points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
> > 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
> > I have a NLP project that needs to calculate the
> > Euclidean distance between points in a multi-dimensional
> > space. I now the basic formula - square the differences,
> > sum the squares, take the square root of the sum:
> >
> >dis =. 4 :'%:+/*:x-y'
> >
> >0 0 dis 1 1
> >
> > 1.41421
> >  0 0 0 dis 1 1 1
> >
> > 1.73205
> >
> > Looking good
> >
> >0 0 dis 1 1,_1 _2,:3 4
> >
> > |length error: dis
> >
> > | %:+/*:x -y
> >
> > Ooops!
> >
> > How can I make dis handle multiple pairs of vectors?
> >
> > like:
> >
> >   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
> >
> > 1.41421  3.16228  4.47214
> >
> > Skip Cave
> > Cave Consulting LLC
> > --
> > 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

Re: [Jprogramming] Euclidean Distance

2017-10-27 Thread Raul Miller
The items that dis is expecting are rank 1 vectors. So it might make
sense to include a rank 1 specification in its definition:

   dis =: 4 :'%:+/*:x-y'"1

Does that work for this example?

   0 0 dis 1 1,_1 _2,:3 4
1.41421 2.23607 5

... seems so ...

Thanks,

-- 
Raul


On Fri, Oct 27, 2017 at 7:11 PM, 'Skip Cave' via Programming
 wrote:
> In the 2014-11-11 NYCJUG meeting
>  there was a discussion
> on Euclidean Distance. The verb 'dis' was used to demonstrate how to to
> calculate the Euclidean distance between two vectors.
>
> 0 0 dis 1 1 NB. Euclidean distance 1.41421 1 1,_1 _2,:3 4 NB. Table of 2-D
> points 1 1 _1 _2 3 4 0 0 dis 1 1,_1 _2,:3 4 NB. Distances from origin
> 1.41421 2.23607 5 0 0 0 dis 1 1 1 NB. Handles higher dimensions 1.73205
> I have a NLP project that needs to calculate the
> Euclidean distance between points in a multi-dimensional
> space. I now the basic formula - square the differences,
> sum the squares, take the square root of the sum:
>
>dis =. 4 :'%:+/*:x-y'
>
>0 0 dis 1 1
>
> 1.41421
>  0 0 0 dis 1 1 1
>
> 1.73205
>
> Looking good
>
>0 0 dis 1 1,_1 _2,:3 4
>
> |length error: dis
>
> | %:+/*:x -y
>
> Ooops!
>
> How can I make dis handle multiple pairs of vectors?
>
> like:
>
>   (0 0, 2 _3 ,: _1 2) dis 1 1,_1 _2,:3 4
>
> 1.41421  3.16228  4.47214
>
> Skip Cave
> Cave Consulting LLC
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm