GithubHelp home page GithubHelp logo

discrete-frechet's Introduction

discrete-frechet

A dive into the discrete Fréchet distance calculation, from the naïve approach to high-speed and memory-efficient optimizations.

The discrete Fréchet distance measures the similarity between two polygonal curves or polylines.

This repository contains four different implementations of the discrete Fréchet distance calculation.

Medium Articles

How long should your dog leash be?

Fast Discrete Fréchet Distance

Using the Code

The DFD classes live in the distances package. They are:

  • DiscreteFrechet: The classic dynamic programming implementation using recursion and a NumPy array to store the distance data.
  • LinarDiscreteFrechet: The linearized implementation of the previous algorithm avoiding recursion.
  • FastDiscreteFrechetSparse: Implements the improved algorithm and uses a sparse array to store the distance data. The sparse array is implemented as a dictionary.
  • FastDiscreteFrechetMatrix: Same as above but uses a full-sized NumPy array to store the distance data. This is the fastest implementation of all.

To use the code, select the class to instantiate and initialize it with one of the following distance functions:

  • euclidean: Standard euclidean distance
  • haversine: Haversine distance on a unit sphere
  • earth_haversine: Calculates the haversine distance on the Earth's surface in meters

All distance functions take the point parameters as NumPy arrays and return the distance as a single float. The haversine distance functions reverse the parameter indexing order. Instead of (x, y), they take (lat, lon). The hearth_haversine function takes its inputs in decimal degrees.

Use the distance function of your selected class to calculate the DFD.

discrete-frechet's People

Contributors

dependabot[bot] avatar joaofig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discrete-frechet's Issues

Extension to 3 dimensions

Hello,
This is really helpful. Thanks!
I wanted to know if there is an easy extension to 3 Dimensional points?

Problem computing the diagonal for a 3 x 9 matrix

Dear Joao Paulo
Many thanks for this amazing work ! I have found a problem when computing the _bresenham_pairs for a 3 x 9 matrix. I simply used these values

    p = np.array([[80.0644976552576, 50.6552672944963],
                  [71.4585771784186, 63.2156178820878],
                  [19.9234400875866, 12.8415436018258]])

    q = np.array([[5.88378887623549, 11.4293440245092],
                  [84.2895035166293, 67.4984930083156],
                  [90.9000392071903, 36.4088270813227],
                  [34.2789062298834, 0.568102905526757],
                  [43.9584670122713, 75.5553565453738],
                  [24.4398877490312, 30.7297872845083],
                  [35.2576361969113, 39.8860249202698],
                  [62.438058713451, 44.4697478786111],
                  [38.4228205773979, 66.4192265830934]])

and I obtained the following error

$ python discrete.py
Slow : 9.959999988495838e-05
83.9133518061399
Linear : 7.949999962875154e-05
83.9133518061399
Traceback (most recent call last):
  File "discrete.py", line 667, in <module>
    main()
  File "discrete.py", line 625, in main
    distance = sparse_frechet.distance(p, q)
  File "discrete.py", line 484, in distance
    ca = _fdfd_sparse(p, q, self.dist_func)
  File "discrete.py", line 436, in _fdfd_sparse
    ca = _fast_distance_sparse(p, q, diagonal, dist_func)
  File "discrete.py", line 283, in _fast_distance_sparse
    d = dist_func(p[i0], q[j0])
IndexError: index 3 is out of bounds for axis 0 with size 3
$

return aligned points between two curve or trajectory

Hi, i'm using LinearDiscreteFrechet(euclidean) for calculating similarity distance between two array. i was wondering is there any way to get all aligned and matched points between two compared trajectory or curves.

thank you very much.

Different results from the for fast versions

Hi,

I'm trying to use your algorithm and actually implemented it in Matlab but I noticed for the following input the fast versions have different results:

p = [[62785, 5],
     [62821, 5],
     [62822, 5],
     [62819, 5],
     [62819, 5]]
                
q = [[44324, 1],
     [44386, 1],
     [44652, 1],
     [44680, 2],
     [40438, 2],
     [42577, 2],
     [42554, 2]]

Output:

Slow : 9.14999982342124e-05
22347.000201369312
Linear : 1.7583020962774754e-05
22347.000201369312
Sparse : 3.716698847711086e-05
22381.0002010634
Fast : 0.13922633399488404
22381.0002010634

Here's how the matrix looks like at the end for the Fast version:

[[18461.0004 18461.0004 18461.0004 18461.0004 22347.0002 22347.0002  22347.0002]
 [18497.0004 18461.0004 18461.0004 18461.0004        inf        inf         inf]
 [18498.0004 18461.0004 18461.0004 18461.0004        inf        inf         inf]
 [18498.0004 18461.0004 18461.0004 18461.0004 22381.0002 22381.0002  22381.0002]
 [18498.0004 18461.0004 18461.0004 18461.0004        inf 22381.0002  22381.0002]]

Here's how the matrix looks like for the linear version:

[[18461.0004 18461.0004 18461.0004 18461.0004 22347.0002 22347.0002  22347.0002]
 [18497.0004 18461.0004 18461.0004 18461.0004 22383.0002 22347.0002  22347.0002]
 [18498.0004 18461.0004 18461.0004 18461.0004 22384.0002 22347.0002  22347.0002]
 [18498.0004 18461.0004 18461.0004 18461.0004 22381.0002 22347.0002  22347.0002]
 [18498.0004 18461.0004 18461.0004 18461.0004 22381.0002 22347.0002  22347.0002]]

Thanks a lot though, I learned a lot going through your blog post and reading your code.

typos in README.md

In the README.md file, change 'iss' to 'is' and 'Instad' to 'Instead'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.