[SciPy-User] Value that compare two

denis denis-bz-py@t-online...
Wed Apr 3 03:51:41 CDT 2013

Florian Lindner <mailinglists <at> xgm.de> writes:
> Hello,
> this is not exactly a scipy question... but I want to implement it with scipy. 
> I have two datasets of shape: (n, 2), each row consists of a coordinate and a 
> pressure value from experiments or simulations.
> I want to compare these two sets and get some kind of integral distance value.
> delta = abs(data2 - data1)
> delta[:,0] = data1[:,0] # I don't want to delta the coordinates ??

  to compare two curves,
you could first interpolate both to the same fine grid,
say np.linspace( lo, hi, 1000 ).
Untested --

    from __future__ import division
    import numpy as np
    import pylab as pl

    plot = 1

    def compare_ab( A, B, xfine ):
        """ compare A, B n x 2 on the same fine grid """
        Ax, Ay = A.T
        Bx, By = B.T
        Afine = np.interp( xfine, Ax, Ay )
        Bfine = np.interp( xfine, Bx, By )
        absdiff = np.fabs( Afine - Bfine )
        print "av |A - B|: %.3g" % absdiff.mean()
        rms = np.sqrt( ((Afine - Bfine) ** 2) .mean() )
        print "rms |A - B|: %.3g" % rms
        if plot:
            pl.plot( xfine, Afine, label="A" )
            pl.plot( xfine, Bfine, label="B" )

Which metric to use ? I don't know of *a priori* reasons
for choosing L1 vs L2 vs Lmax.
For distributions, you might ask on stats.stackexchange.com; and see

  -- denis

More information about the SciPy-User mailing list