compute all pairwise diffs

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

compute all pairwise diffs

CdeMills
Hello,

I faced the problem of finding in a vector if all components are distinct. I found an idea with the help of google, and implemented it in the enclosed file. I tried to model it as closely as possible to diff, with the ability to choose the dimension to work on for matrices.

The result for a N dim object is a N+1 dim  object, where all matrices are anti-symmetric and contains NaN on the main diagonal, in order to detect without trickery the smallest non-null difference. The algorithm is redundant, as the resulting matrix must be antisymetric, so only one half has to be computed. But I suppose that using a loop will be slower than performing twice the computations.

Comments ? Suggestion ? Could it be incorporated somewhere ?

Regards

Pascal

pwdiff.m 
Reply | Threaded
Open this post in threaded view
|

Re: compute all pairwise diffs

Claudio Belotti-3
On Fri, Jul 8, 2011 at 09:35, CdeMills <[hidden email]> wrote:

> I faced the problem of finding in a vector if all components are distinct. I
> found an idea with the help of google, and implemented it in the enclosed
> file. I tried to model it as closely as possible to diff, with the ability
> to choose the dimension to work on for matrices.
>
[...]

I think for that you could use 'unique'

Claudio
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compute all pairwise diffs

CdeMills
I wanted to look it the distance was not below some threshold. The call
unique([1 1+eps])
returns a set with two values, which doesn't make much sense in my case: such tiny difference may result from pure numerical error, and not from "real" data separation.

Regards

Pascal
Reply | Threaded
Open this post in threaded view
|

Re: compute all pairwise diffs

Claudio Belotti-3
On Fri, Jul 8, 2011 at 16:10, CdeMills <[hidden email]> wrote:
> I wanted to look it the distance was not below some threshold. The call
> unique([1 1+eps])
> returns a set with two values, which doesn't make much sense in my case:
> such tiny difference may result from pure numerical error, and not from
> "real" data separation.

I see, then you can modify unique.m to suit your needs?
I suppose you just need to change

match = (y(1:n-1) == y(2:n));
into
match = (abs(y(1:n-1) - y(2:n))<=tolerance);
to find the differences within a given tolerance
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave