{"id":13570871,"url":"https://github.com/cjekel/similarity_measures","last_synced_at":"2025-05-15T08:06:27.818Z","repository":{"id":35063887,"uuid":"133959367","full_name":"cjekel/similarity_measures","owner":"cjekel","description":"Quantify the difference between two arbitrary curves in space","archived":false,"fork":false,"pushed_at":"2025-01-12T18:39:47.000Z","size":1699,"stargazers_count":255,"open_issues_count":14,"forks_count":41,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-07T03:15:44.965Z","etag":null,"topics":["curve","distance","dtw","dynamic-time-warping","fr-chet-distance","frechet-distance","measure","python","similarity-measures","warping"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cjekel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-18T13:40:16.000Z","updated_at":"2025-03-21T15:56:24.000Z","dependencies_parsed_at":"2024-01-14T03:51:45.814Z","dependency_job_id":"d93e08a3-2ea6-488b-92ae-f5a1e99539db","html_url":"https://github.com/cjekel/similarity_measures","commit_stats":{"total_commits":184,"total_committers":7,"mean_commits":"26.285714285714285","dds":"0.17391304347826086","last_synced_commit":"9dcc9fde8132a9976b6bf2974ce0d16c72c11208"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjekel%2Fsimilarity_measures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjekel%2Fsimilarity_measures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjekel%2Fsimilarity_measures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjekel%2Fsimilarity_measures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cjekel","download_url":"https://codeload.github.com/cjekel/similarity_measures/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248889854,"owners_count":21178308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curve","distance","dtw","dynamic-time-warping","fr-chet-distance","frechet-distance","measure","python","similarity-measures","warping"],"created_at":"2024-08-01T14:00:55.930Z","updated_at":"2025-04-14T13:41:06.792Z","avatar_url":"https://github.com/cjekel.png","language":"Jupyter Notebook","funding_links":[],"categories":["📦 Packages"],"sub_categories":["Python"],"readme":"# similaritymeasures\n\n![Downloads a month](https://img.shields.io/pypi/dm/similaritymeasures.svg) ![similaritymeasures ci](https://github.com/cjekel/similarity_measures/workflows/similaritymeasures%20ci/badge.svg) [![codecov](https://codecov.io/gh/cjekel/similarity_measures/branch/master/graph/badge.svg?token=nwuIhL8r3C)](https://codecov.io/gh/cjekel/similarity_measures) ![PyPI version](https://img.shields.io/pypi/v/similaritymeasures) \n\n# Quantify the difference between two arbitrary curves\n\nCurves in this case are:\n- discretized by inidviudal data points\n- ordered from a beginning to an ending\n\nConsider the following two curves. We want to quantify how different the Numerical curve is from the Experimental curve. Notice how there are no concurrent Stress or Strain values in the two curves. Additionally one curve has more data points than the other curves.\n\n![Image of two different curves](https://raw.githubusercontent.com/cjekel/similarity_measures/master/images/TwoCurves.png)\n\nIn the ideal case the Numerical curve would match the Experimental curve exactly. This means that the two curves would appear directly on top of each other. Our measures of similarity would return a *zero* distance between two curves that were on top of each other.\n\n# Methods covered\nThis library includes the following methods to quantify the difference (or similarity) between two curves:\n\n- **Partial Curve Mapping**\u003csup\u003ex\u003c/sup\u003e (PCM) method: Matches the area of a subset between the two curves [1]\n- **Area method**\u003csup\u003ex\u003c/sup\u003e: An algorithm for calculating the Area between two curves in 2D space [2]\n- **Discrete Frechet distance**\u003csup\u003ey\u003c/sup\u003e: The shortest distance in-between two curves, where you are allowed to very the speed at which you travel along each curve independently (walking dog problem) [3, 4, 5, 6, 7, 8]\n- **Curve Length**\u003csup\u003ex\u003c/sup\u003e method: Assumes that the only true independent variable of the curves is the arc-length distance along the curve from the origin [9, 10]\n- **Dynamic Time Warping**\u003csup\u003ey\u003c/sup\u003e (DTW): A non-metric distance between two time-series curves that has been proven useful for a variety of applications [11, 12, 13, 14, 15, 16]\n- **Mean absolute error**\u003csup\u003ey,z\u003c/sup\u003e (MAE): A L1 error that requires curves to have the same number of data points and dimensions. See [this](https://en.wikipedia.org/wiki/Mean_absolute_error) wiki page.\n- **Mean squared error**\u003csup\u003ey,z\u003c/sup\u003e (MSE): A L2 error that requires curves to have the same number of data points and dimensions. See [this](https://en.wikipedia.org/wiki/Mean_squared_error) wiki page.\n\n\u003csup\u003ex\u003c/sup\u003e denotes methods created specifically for material parameter identification\n\n\u003csup\u003ey\u003c/sup\u003e denotes that the method implemented in this library supports N-D data!\n\n\u003csup\u003ez\u003c/sup\u003e denotes that the method requires each curve to have the same number of data points\n\n# Installation \nInstall with pip\n\n```\npython -m pip install similaritymeasures\n```\nor clone and install from source.\n```\ngit clone https://github.com/cjekel/similarity_measures\npython -m pip install ./similarity_measures\n```\n\n# Example usage\nThis shows you how to compute the various similarity measures\n```python\nimport numpy as np\nimport similaritymeasures\nimport matplotlib.pyplot as plt\n\n# Generate random experimental data\nx = np.random.random(100)\ny = np.random.random(100)\nexp_data = np.zeros((100, 2))\nexp_data[:, 0] = x\nexp_data[:, 1] = y\n\n# Generate random numerical data\nx = np.random.random(100)\ny = np.random.random(100)\nnum_data = np.zeros((100, 2))\nnum_data[:, 0] = x\nnum_data[:, 1] = y\n\n# quantify the difference between the two curves using PCM\npcm = similaritymeasures.pcm(exp_data, num_data)\n\n# quantify the difference between the two curves using\n# Discrete Frechet distance\ndf = similaritymeasures.frechet_dist(exp_data, num_data)\n\n# quantify the difference between the two curves using\n# area between two curves\narea = similaritymeasures.area_between_two_curves(exp_data, num_data)\n\n# quantify the difference between the two curves using\n# Curve Length based similarity measure\ncl = similaritymeasures.curve_length_measure(exp_data, num_data)\n\n# quantify the difference between the two curves using\n# Dynamic Time Warping distance\ndtw, d = similaritymeasures.dtw(exp_data, num_data)\n\n# mean absolute error\nmae = similaritymeasures.mae(exp_data, num_data)\n\n# mean squared error\nmse = similaritymeasures.mse(exp_data, num_data)\n\n# print the results\nprint(pcm, df, area, cl, dtw, mae, mse)\n\n# plot the data\nplt.figure()\nplt.plot(exp_data[:, 0], exp_data[:, 1])\nplt.plot(num_data[:, 0], num_data[:, 1])\nplt.show()\n```\n\nIf you are interested in setting up an optimization problem using these measures, check out [this Jupyter Notebook](https://github.com/cjekel/similarity_measures/blob/master/Examples_of_Similarity_Measures.ipynb) which replicates Section 3.2 from [2].\n\n# Changelog\nVersion 0.3.0: Frechet distance now supports N-D data! See [CHANGELOG.md](https://github.com/cjekel/similarity_measures/blob/master/CHANGELOG.md) for full details.\n\n# Documenation\nEach function includes a descriptive docstring, which you can view online [here](https://jekel.me/similarity_measures/index.html).\n\n# References\n[1] Katharina Witowski and Nielen Stander. Parameter Identification of Hysteretic Models\nUsing Partial Curve Mapping. 12th AIAA Aviation Technology, Integration, and Op-\nerations (ATIO) Conference and 14th AIAA/ISSMO Multidisciplinary Analysis and\nOptimization Conference, sep 2012. doi: doi:10.2514/6.2012-5580.\n\n[2] Jekel, C. F., Venter, G., Venter, M. P., Stander, N., \u0026 Haftka, R. T. (2018). Similarity measures for identifying material parameters from hysteresis loops using inverse analysis. International Journal of Material Forming. https://doi.org/10.1007/s12289-018-1421-8\n\n[3] M Maurice Frechet. Sur quelques points du calcul fonctionnel. Rendiconti del Circol\nMatematico di Palermo (1884-1940), 22(1):1–72, 1906.\n\n[4] Thomas Eiter and Heikki Mannila. Computing discrete Frechet distance. Technical\nreport, 1994.\n\n[5] Anne Driemel, Sariel Har-Peled, and Carola Wenk. Approximating the Frechet Distance\nfor Realistic Curves in Near Linear Time. Discrete \u0026 Computational Geometry, 48(1):\n94–127, 2012. ISSN 1432-0444. doi: 10.1007/s00454-012-9402-z. URL http://dx.doi.org/10.1007/s00454-012-9402-z.\n\n[6] K Bringmann. Why Walking the Dog Takes Time: Frechet Distance Has No Strongly\nSubquadratic Algorithms Unless SETH Fails, 2014.\n\n[7] Sean L Seyler, Avishek Kumar, M F Thorpe, and Oliver Beckstein. Path Similarity\nAnalysis: A Method for Quantifying Macromolecular Pathways. PLOS Computational\nBiology, 11(10):1–37, 2015. doi: 10.1371/journal.pcbi.1004568. URL https://doi.org/10.1371/journal.pcbi.1004568.\n\n[8] Helmut Alt and Michael Godau. Computing the Frechet Distance Between Two Polyg-\nonal Curves. International Journal of Computational Geometry \u0026 Applications, 05\n(01n02):75–91, 1995. doi: 10.1142/S0218195995000064.\n\n[9] A Andrade-Campos, R De-Carvalho, and R A F Valente. Novel criteria for determina-\ntion of material model parameters. International Journal of Mechanical Sciences, 54\n(1):294–305, 2012. ISSN 0020-7403. doi: https://doi.org/10.1016/j.ijmecsci.2011.11.010.\nURL http://www.sciencedirect.com/science/article/pii/S0020740311002451.\n\n[10] J Cao and J Lin. A study on formulation of objective functions for determin-\ning material models. International Journal of Mechanical Sciences, 50(2):193–204,\n2008. ISSN 0020-7403. doi: https://doi.org/10.1016/j.ijmecsci.2007.07.003. URL\nhttp://www.sciencedirect.com/science/article/pii/S0020740307001178.\n\n[11] Donald J Berndt and James Clifford. Using Dynamic Time Warping to Find Pat-\nterns in Time Series. In Proceedings of the 3rd International Conference on Knowledge\nDiscovery and Data Mining, AAAIWS’94, pages 359–370. AAAI Press, 1994. URL\nhttp://dl.acm.org/citation.cfm?id=3000850.3000887.\n\n[12] François Petitjean, Alain Ketterlin, and Pierre Gançarski. A global averaging method for dynamic time warping, with applications to clustering. Pattern Recognition, 44 (3):678–693, 2011. ISSN 0031-3203. doi: https://doi.org/10.1016/j.patcog.2010.09.013.\nURL http://www.sciencedirect.com/science/article/pii/S003132031000453X.\n\n[13] Toni Giorgino. Computing and Visualizing Dynamic Time Warping Alignments in R:\nThe dtw Package. Journal of Statistical Software; Vol 1, Issue 7 (2009), aug 2009. URL\nhttp://dx.doi.org/10.18637/jss.v031.i07.\n\n[14] Stan Salvador and Philip Chan. Toward Accurate Dynamic Time Warping in Linear\nTime and Space. Intell. Data Anal., 11(5):561–580, oct 2007. ISSN 1088-467X. URL\nhttp://dl.acm.org/citation.cfm?id=1367985.1367993.\n\n[15] Paolo Tormene, Toni Giorgino, Silvana Quaglini, and Mario Stefanelli. Matching\nincomplete time series with dynamic time warping: an algorithm and an applica-\ntion to post-stroke rehabilitation. Artificial Intelligence in Medicine, 45(1):11–34,\n2009. ISSN 0933-3657. doi: https://doi.org/10.1016/j.artmed.2008.11.007. URL\nhttp://www.sciencedirect.com/science/article/pii/S0933365708001772.\n\n[16] Senin, P., 2008. Dynamic time warping algorithm review. Information and \nComputer Science Department University of Hawaii at Manoa Honolulu, USA, 855, pp.1-23.\nhttp://seninp.github.io/assets/pubs/senin_dtw_litreview_2008.pdf\n\n# Contributions welcome!\n\nThis is by no means a complete list of all possible similarity measures. For instance the SciPy [Hausdorff distance](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.directed_hausdorff.html) is an alternative similarity measure useful if you don't know the beginning and ending of each curve. There are many more possible functions out there. Feel free to send PRs for other functions in literature!\n\nRequirements for adding new method to this library:\n - all methods should be able to quantify the difference between two curves\n - method must support the case where each curve may have a different number of data points\n - follow the style of existing functions\n - reference to method details, or descriptive docstring of the method\n - include test(s) for your new method\n - minimum Python dependencies (try to stick to SciPy/numpy functions if possible)\n\n# Please cite\nIf you've found this information or library helpful please cite the following paper. You should also cite the papers of any methods that you have used.\n\nJekel, C. F., Venter, G., Venter, M. P., Stander, N., \u0026 Haftka, R. T. (2018). Similarity measures for identifying material parameters from hysteresis loops using inverse analysis. International Journal of Material Forming. https://doi.org/10.1007/s12289-018-1421-8\n\n```\n@article{Jekel2019,\nauthor = {Jekel, Charles F and Venter, Gerhard and Venter, Martin P and Stander, Nielen and Haftka, Raphael T},\ndoi = {10.1007/s12289-018-1421-8},\nissn = {1960-6214},\njournal = {International Journal of Material Forming},\nmonth = {may},\ntitle = {{Similarity measures for identifying material parameters from hysteresis loops using inverse analysis}},\nurl = {https://doi.org/10.1007/s12289-018-1421-8},\nyear = {2019}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjekel%2Fsimilarity_measures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcjekel%2Fsimilarity_measures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjekel%2Fsimilarity_measures/lists"}