├── .DS_Store ├── Makefile ├── README.md ├── build ├── doctrees │ ├── datasets.doctree │ ├── environment.pickle │ ├── features.doctree │ ├── ham10000.doctree │ └── index.doctree └── html │ ├── .buildinfo │ ├── .nojekyll │ ├── _images │ └── balls.gif │ ├── _sources │ ├── datasets.rst.txt │ ├── features.rst.txt │ ├── ham10000.rst.txt │ └── index.rst.txt │ ├── _static │ ├── _sphinx_javascript_frameworks_compat.js │ ├── alabaster.css │ ├── basic.css │ ├── custom.css │ ├── doctools.js │ ├── documentation_options.js │ ├── file.png │ ├── jquery-3.6.0.js │ ├── jquery.js │ ├── language_data.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore-1.13.1.js │ └── underscore.js │ ├── datasets.html │ ├── features.html │ ├── genindex.html │ ├── ham10000.html │ ├── index.html │ ├── objects.inv │ ├── search.html │ └── searchindex.js ├── config.json ├── datasets ├── HAM10000 │ ├── ham10000_data_preprocessing.py │ ├── ham10000_data_preprocessing_parallel.py │ ├── ham10000_modeling_estimates_parallel.py │ └── machine_learning_ham10000_subsampling.ipynb ├── mnist │ ├── .ipynb_checkpoints │ │ ├── machine_learning_mnist-checkpoint.ipynb │ │ └── sweep_computations-checkpoint 2.ipynb │ ├── kernel_gpu_computation.py │ ├── machine_learning_mnist.ipynb │ └── mnist_modeling_results_parallel.py ├── mpeg7 │ ├── .gitignore │ ├── .ipynb_checkpoints │ │ ├── contour_plots-checkpoint.ipynb │ │ ├── machine_learning_mpeg7-checkpoint.ipynb │ │ ├── machine_learning_mpeg7_example-checkpoint.ipynb │ │ ├── machine_learning_mpeg7_four_classes-checkpoint.ipynb │ │ └── machine_learning_mpeg7_timings-checkpoint.ipynb │ ├── mpeg7.tar.gz │ └── mpeg7_data_preprocessing.py ├── protein │ ├── .ipynb_checkpoints │ │ ├── Untitled-checkpoint.ipynb │ │ ├── machine_learning_protein-checkpoint.ipynb │ │ ├── machine_learning_protein_timings-checkpoint.ipynb │ │ └── protein_charts-checkpoint.ipynb │ ├── machine_learning_protein.ipynb │ ├── protein_data.tar.gz │ ├── protein_data_preprocessing.py │ ├── protein_parallel_kernel.py │ ├── protein_parallel_no_kernel.py │ └── protein_parallel_runs.py └── shrec14 │ ├── .ipynb_checkpoints │ └── machine_learning_shrec14-checkpoint.ipynb │ ├── machine_learning_shrec14.ipynb │ ├── schrec14_parallel_runs.py │ ├── shrec14.tar.gz │ └── shrec14_data_preprocessing.py ├── docs ├── .buildinfo ├── .doctrees │ ├── datasets.doctree │ ├── environment.pickle │ ├── features.doctree │ ├── ham10000.doctree │ └── index.doctree ├── .nojekyll ├── _images │ └── balls.gif ├── _sources │ ├── datasets.rst.txt │ ├── features.rst.txt │ ├── ham10000.rst.txt │ └── index.rst.txt ├── _static │ ├── _sphinx_javascript_frameworks_compat.js │ ├── alabaster.css │ ├── basic.css │ ├── custom.css │ ├── doctools.js │ ├── documentation_options.js │ ├── file.png │ ├── jquery-3.6.0.js │ ├── jquery.js │ ├── language_data.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore-1.13.1.js │ └── underscore.js ├── datasets.html ├── features.html ├── genindex.html ├── ham10000.html ├── index.html ├── objects.inv ├── search.html └── searchindex.js ├── mlforpers └── persistence_methods │ ├── ATS.py │ ├── __init__.py │ ├── __pycache__ │ └── __init__.cpython-37.pyc │ ├── persistence_methods.py │ ├── persistence_methods_cuda.py │ ├── persistence_methods_numba.py │ └── persistence_methods_timings.py ├── persistence_methods └── __pycache__ │ └── ATS.cpython-38.pyc └── source ├── .DS_Store ├── _figures ├── ball.png ├── balls.gif ├── create_balls_gif.py ├── mnist.png └── pi_1.png ├── conf.py ├── datasets.rst ├── features.rst ├── ham10000.rst └── index.rst /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/.DS_Store -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # You can set these variables from the command line, and also 2 | # from the environment for the first two. 3 | 4 | SPHINXOPTS ?= 5 | SPHINXBUILD ?= sphinx-build 6 | SOURCEDIR = source 7 | BUILDDIR = build 8 | .PHONY: tests, docs 9 | 10 | help: 11 | @Echo clean: runs autopep to improve formatting of code 12 | @Echo reqs: replace requirements.txt file for use by collaborators to create virtual environments and for use in documentation 13 | @Echo tests: runs unit tests 14 | @Echo docs: clears files from docs folder, rebuilds docs from source folder 15 | @Echo release: runs build to create tar and wheel for distribution 16 | @Echo all: runs clean build and docs folders, creates new html folders in build, moves relevant files to docs, and runs unittests and autopep. 17 | 18 | reqs: 19 | @pip freeze > requirements.txt 20 | 21 | clean: 22 | # Running autopep8 23 | @autopep8 -r --in-place teaspoon/ 24 | 25 | tests: 26 | # Running unittests 27 | @python -m unittest 28 | 29 | release: 30 | python setup.py sdist bdist_wheel 31 | 32 | docs: 33 | @mkdir $(shell pwd)/build/temp 34 | # Removing all files from build folder. 35 | @rm -rf $(shell pwd)/build/ 36 | @mkdir $(shell pwd)/build/ 37 | @mkdir $(shell pwd)/docs/temp 38 | # Removing all files from docs folder. 39 | @rm -rf $(shell pwd)/docs/ 40 | @mkdir $(shell pwd)/docs/ 41 | # Running sphinx-build to build html files in build folder. 42 | sphinx-build -M html source build 43 | @mkdir $(shell pwd)/docs/.doctrees 44 | @cp -a $(shell pwd)/build/doctrees/. $(shell pwd)/docs/.doctrees/ 45 | @cp -a $(shell pwd)/build/html/. $(shell pwd)/docs/ 46 | 47 | all: 48 | # Cleaning build folder 49 | @mkdir $(shell pwd)/build/temp 50 | @rm -rf $(shell pwd)/build/ 51 | @mkdir $(shell pwd)/build/ 52 | 53 | # Cleaning docs folder 54 | @mkdir $(shell pwd)/docs/temp 55 | @rm -rf $(shell pwd)/docs/ 56 | @mkdir $(shell pwd)/docs/ 57 | 58 | # Running sphinx-build to build html files. 59 | @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 60 | 61 | # Copying over contents of build/html to docs 62 | @mkdir $(shell pwd)/docs/.doctrees 63 | @cp -a $(shell pwd)/build/doctrees/. $(shell pwd)/docs/.doctrees/ 64 | @cp -a $(shell pwd)/build/html/. $(shell pwd)/docs/ 65 | 66 | # Running autopep8 67 | @autopep8 -r --in-place teaspoon/ 68 | 69 | # Running unittests 70 | @python -m unittest 71 | 72 | 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # machine_learning_for_persistence 2 | 3 | Download HAM10000 Dataset here: https://persistencedata.s3.us-east-2.amazonaws.com/ham10000_images.tar 4 | 5 | Download HAM10000 Persistence diagrams here: https://persistencedata.s3.us-east-2.amazonaws.com/persistence.zip 6 | -------------------------------------------------------------------------------- /build/doctrees/datasets.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/doctrees/datasets.doctree -------------------------------------------------------------------------------- /build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/doctrees/environment.pickle -------------------------------------------------------------------------------- /build/doctrees/features.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/doctrees/features.doctree -------------------------------------------------------------------------------- /build/doctrees/ham10000.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/doctrees/ham10000.doctree -------------------------------------------------------------------------------- /build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/doctrees/index.doctree -------------------------------------------------------------------------------- /build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 2d201253a4f5482e65e583586e8ed0ad 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /build/html/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/.nojekyll -------------------------------------------------------------------------------- /build/html/_images/balls.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/_images/balls.gif -------------------------------------------------------------------------------- /build/html/_sources/datasets.rst.txt: -------------------------------------------------------------------------------- 1 | Datasets 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | HAM10000 8 | -------------------------------------------------------------------------------- /build/html/_sources/features.rst.txt: -------------------------------------------------------------------------------- 1 | Features 2 | ******************* 3 | -------------------------------------------------------------------------------- /build/html/_sources/ham10000.rst.txt: -------------------------------------------------------------------------------- 1 | HAM10000 2 | ******************* 3 | -------------------------------------------------------------------------------- /build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. Machine Learning Library for TDA documentation master file, created by 2 | sphinx-quickstart on Fri Aug 5 12:22:23 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Machine Learning Library for TDA's documentation! 7 | ============================================================ 8 | 9 | Welcome! You're on the associated page for our repository for our paper, `A Comparative Study of Machine Learning Methods for Persistence Diagrams `_ 10 | 11 | .. image:: _figures/balls.gif 12 | :width: 600 px 13 | 14 | Table of Contents 15 | ******************* 16 | 17 | .. toctree:: 18 | :maxdepth: 4 19 | :numbered: 20 | 21 | Featurization 22 | Datasets 23 | -------------------------------------------------------------------------------- /build/html/_static/_sphinx_javascript_frameworks_compat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * _sphinx_javascript_frameworks_compat.js 3 | * ~~~~~~~~~~ 4 | * 5 | * Compatability shim for jQuery and underscores.js. 6 | * 7 | * WILL BE REMOVED IN Sphinx 6.0 8 | * xref RemovedInSphinx60Warning 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | 18 | /** 19 | * small helper function to urldecode strings 20 | * 21 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL 22 | */ 23 | jQuery.urldecode = function(x) { 24 | if (!x) { 25 | return x 26 | } 27 | return decodeURIComponent(x.replace(/\+/g, ' ')); 28 | }; 29 | 30 | /** 31 | * small helper function to urlencode strings 32 | */ 33 | jQuery.urlencode = encodeURIComponent; 34 | 35 | /** 36 | * This function returns the parsed url parameters of the 37 | * current request. Multiple values per key are supported, 38 | * it will always return arrays of strings for the value parts. 39 | */ 40 | jQuery.getQueryParameters = function(s) { 41 | if (typeof s === 'undefined') 42 | s = document.location.search; 43 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 44 | var result = {}; 45 | for (var i = 0; i < parts.length; i++) { 46 | var tmp = parts[i].split('=', 2); 47 | var key = jQuery.urldecode(tmp[0]); 48 | var value = jQuery.urldecode(tmp[1]); 49 | if (key in result) 50 | result[key].push(value); 51 | else 52 | result[key] = [value]; 53 | } 54 | return result; 55 | }; 56 | 57 | /** 58 | * highlight a given string on a jquery object by wrapping it in 59 | * span elements with the given class name. 60 | */ 61 | jQuery.fn.highlightText = function(text, className) { 62 | function highlight(node, addItems) { 63 | if (node.nodeType === 3) { 64 | var val = node.nodeValue; 65 | var pos = val.toLowerCase().indexOf(text); 66 | if (pos >= 0 && 67 | !jQuery(node.parentNode).hasClass(className) && 68 | !jQuery(node.parentNode).hasClass("nohighlight")) { 69 | var span; 70 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 71 | if (isInSVG) { 72 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 73 | } else { 74 | span = document.createElement("span"); 75 | span.className = className; 76 | } 77 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 78 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 79 | document.createTextNode(val.substr(pos + text.length)), 80 | node.nextSibling)); 81 | node.nodeValue = val.substr(0, pos); 82 | if (isInSVG) { 83 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 84 | var bbox = node.parentElement.getBBox(); 85 | rect.x.baseVal.value = bbox.x; 86 | rect.y.baseVal.value = bbox.y; 87 | rect.width.baseVal.value = bbox.width; 88 | rect.height.baseVal.value = bbox.height; 89 | rect.setAttribute('class', className); 90 | addItems.push({ 91 | "parent": node.parentNode, 92 | "target": rect}); 93 | } 94 | } 95 | } 96 | else if (!jQuery(node).is("button, select, textarea")) { 97 | jQuery.each(node.childNodes, function() { 98 | highlight(this, addItems); 99 | }); 100 | } 101 | } 102 | var addItems = []; 103 | var result = this.each(function() { 104 | highlight(this, addItems); 105 | }); 106 | for (var i = 0; i < addItems.length; ++i) { 107 | jQuery(addItems[i].parent).before(addItems[i].target); 108 | } 109 | return result; 110 | }; 111 | 112 | /* 113 | * backward compatibility for jQuery.browser 114 | * This will be supported until firefox bug is fixed. 115 | */ 116 | if (!jQuery.browser) { 117 | jQuery.uaMatch = function(ua) { 118 | ua = ua.toLowerCase(); 119 | 120 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 121 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 122 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 123 | /(msie) ([\w.]+)/.exec(ua) || 124 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 125 | []; 126 | 127 | return { 128 | browser: match[ 1 ] || "", 129 | version: match[ 2 ] || "0" 130 | }; 131 | }; 132 | jQuery.browser = {}; 133 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 134 | } 135 | -------------------------------------------------------------------------------- /build/html/_static/alabaster.css: -------------------------------------------------------------------------------- 1 | @import url("basic.css"); 2 | 3 | /* -- page layout ----------------------------------------------------------- */ 4 | 5 | body { 6 | font-family: Georgia, serif; 7 | font-size: 17px; 8 | background-color: #fff; 9 | color: #000; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | 15 | div.document { 16 | width: 940px; 17 | margin: 30px auto 0 auto; 18 | } 19 | 20 | div.documentwrapper { 21 | float: left; 22 | width: 100%; 23 | } 24 | 25 | div.bodywrapper { 26 | margin: 0 0 0 220px; 27 | } 28 | 29 | div.sphinxsidebar { 30 | width: 220px; 31 | font-size: 14px; 32 | line-height: 1.5; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #fff; 41 | color: #3E4349; 42 | padding: 0 30px 0 30px; 43 | } 44 | 45 | div.body > .section { 46 | text-align: left; 47 | } 48 | 49 | div.footer { 50 | width: 940px; 51 | margin: 20px auto 30px auto; 52 | font-size: 14px; 53 | color: #888; 54 | text-align: right; 55 | } 56 | 57 | div.footer a { 58 | color: #888; 59 | } 60 | 61 | p.caption { 62 | font-family: inherit; 63 | font-size: inherit; 64 | } 65 | 66 | 67 | div.relations { 68 | display: none; 69 | } 70 | 71 | 72 | div.sphinxsidebar a { 73 | color: #444; 74 | text-decoration: none; 75 | border-bottom: 1px dotted #999; 76 | } 77 | 78 | div.sphinxsidebar a:hover { 79 | border-bottom: 1px solid #999; 80 | } 81 | 82 | div.sphinxsidebarwrapper { 83 | padding: 18px 10px; 84 | } 85 | 86 | div.sphinxsidebarwrapper p.logo { 87 | padding: 0; 88 | margin: -10px 0 0 0px; 89 | text-align: center; 90 | } 91 | 92 | div.sphinxsidebarwrapper h1.logo { 93 | margin-top: -10px; 94 | text-align: center; 95 | margin-bottom: 5px; 96 | text-align: left; 97 | } 98 | 99 | div.sphinxsidebarwrapper h1.logo-name { 100 | margin-top: 0px; 101 | } 102 | 103 | div.sphinxsidebarwrapper p.blurb { 104 | margin-top: 0; 105 | font-style: normal; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: Georgia, serif; 111 | color: #444; 112 | font-size: 24px; 113 | font-weight: normal; 114 | margin: 0 0 5px 0; 115 | padding: 0; 116 | } 117 | 118 | div.sphinxsidebar h4 { 119 | font-size: 20px; 120 | } 121 | 122 | div.sphinxsidebar h3 a { 123 | color: #444; 124 | } 125 | 126 | div.sphinxsidebar p.logo a, 127 | div.sphinxsidebar h3 a, 128 | div.sphinxsidebar p.logo a:hover, 129 | div.sphinxsidebar h3 a:hover { 130 | border: none; 131 | } 132 | 133 | div.sphinxsidebar p { 134 | color: #555; 135 | margin: 10px 0; 136 | } 137 | 138 | div.sphinxsidebar ul { 139 | margin: 10px 0; 140 | padding: 0; 141 | color: #000; 142 | } 143 | 144 | div.sphinxsidebar ul li.toctree-l1 > a { 145 | font-size: 120%; 146 | } 147 | 148 | div.sphinxsidebar ul li.toctree-l2 > a { 149 | font-size: 110%; 150 | } 151 | 152 | div.sphinxsidebar input { 153 | border: 1px solid #CCC; 154 | font-family: Georgia, serif; 155 | font-size: 1em; 156 | } 157 | 158 | div.sphinxsidebar hr { 159 | border: none; 160 | height: 1px; 161 | color: #AAA; 162 | background: #AAA; 163 | 164 | text-align: left; 165 | margin-left: 0; 166 | width: 50%; 167 | } 168 | 169 | div.sphinxsidebar .badge { 170 | border-bottom: none; 171 | } 172 | 173 | div.sphinxsidebar .badge:hover { 174 | border-bottom: none; 175 | } 176 | 177 | /* To address an issue with donation coming after search */ 178 | div.sphinxsidebar h3.donation { 179 | margin-top: 10px; 180 | } 181 | 182 | /* -- body styles ----------------------------------------------------------- */ 183 | 184 | a { 185 | color: #004B6B; 186 | text-decoration: underline; 187 | } 188 | 189 | a:hover { 190 | color: #6D4100; 191 | text-decoration: underline; 192 | } 193 | 194 | div.body h1, 195 | div.body h2, 196 | div.body h3, 197 | div.body h4, 198 | div.body h5, 199 | div.body h6 { 200 | font-family: Georgia, serif; 201 | font-weight: normal; 202 | margin: 30px 0px 10px 0px; 203 | padding: 0; 204 | } 205 | 206 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 207 | div.body h2 { font-size: 180%; } 208 | div.body h3 { font-size: 150%; } 209 | div.body h4 { font-size: 130%; } 210 | div.body h5 { font-size: 100%; } 211 | div.body h6 { font-size: 100%; } 212 | 213 | a.headerlink { 214 | color: #DDD; 215 | padding: 0 4px; 216 | text-decoration: none; 217 | } 218 | 219 | a.headerlink:hover { 220 | color: #444; 221 | background: #EAEAEA; 222 | } 223 | 224 | div.body p, div.body dd, div.body li { 225 | line-height: 1.4em; 226 | } 227 | 228 | div.admonition { 229 | margin: 20px 0px; 230 | padding: 10px 30px; 231 | background-color: #EEE; 232 | border: 1px solid #CCC; 233 | } 234 | 235 | div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { 236 | background-color: #FBFBFB; 237 | border-bottom: 1px solid #fafafa; 238 | } 239 | 240 | div.admonition p.admonition-title { 241 | font-family: Georgia, serif; 242 | font-weight: normal; 243 | font-size: 24px; 244 | margin: 0 0 10px 0; 245 | padding: 0; 246 | line-height: 1; 247 | } 248 | 249 | div.admonition p.last { 250 | margin-bottom: 0; 251 | } 252 | 253 | div.highlight { 254 | background-color: #fff; 255 | } 256 | 257 | dt:target, .highlight { 258 | background: #FAF3E8; 259 | } 260 | 261 | div.warning { 262 | background-color: #FCC; 263 | border: 1px solid #FAA; 264 | } 265 | 266 | div.danger { 267 | background-color: #FCC; 268 | border: 1px solid #FAA; 269 | -moz-box-shadow: 2px 2px 4px #D52C2C; 270 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 271 | box-shadow: 2px 2px 4px #D52C2C; 272 | } 273 | 274 | div.error { 275 | background-color: #FCC; 276 | border: 1px solid #FAA; 277 | -moz-box-shadow: 2px 2px 4px #D52C2C; 278 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 279 | box-shadow: 2px 2px 4px #D52C2C; 280 | } 281 | 282 | div.caution { 283 | background-color: #FCC; 284 | border: 1px solid #FAA; 285 | } 286 | 287 | div.attention { 288 | background-color: #FCC; 289 | border: 1px solid #FAA; 290 | } 291 | 292 | div.important { 293 | background-color: #EEE; 294 | border: 1px solid #CCC; 295 | } 296 | 297 | div.note { 298 | background-color: #EEE; 299 | border: 1px solid #CCC; 300 | } 301 | 302 | div.tip { 303 | background-color: #EEE; 304 | border: 1px solid #CCC; 305 | } 306 | 307 | div.hint { 308 | background-color: #EEE; 309 | border: 1px solid #CCC; 310 | } 311 | 312 | div.seealso { 313 | background-color: #EEE; 314 | border: 1px solid #CCC; 315 | } 316 | 317 | div.topic { 318 | background-color: #EEE; 319 | } 320 | 321 | p.admonition-title { 322 | display: inline; 323 | } 324 | 325 | p.admonition-title:after { 326 | content: ":"; 327 | } 328 | 329 | pre, tt, code { 330 | font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 331 | font-size: 0.9em; 332 | } 333 | 334 | .hll { 335 | background-color: #FFC; 336 | margin: 0 -12px; 337 | padding: 0 12px; 338 | display: block; 339 | } 340 | 341 | img.screenshot { 342 | } 343 | 344 | tt.descname, tt.descclassname, code.descname, code.descclassname { 345 | font-size: 0.95em; 346 | } 347 | 348 | tt.descname, code.descname { 349 | padding-right: 0.08em; 350 | } 351 | 352 | img.screenshot { 353 | -moz-box-shadow: 2px 2px 4px #EEE; 354 | -webkit-box-shadow: 2px 2px 4px #EEE; 355 | box-shadow: 2px 2px 4px #EEE; 356 | } 357 | 358 | table.docutils { 359 | border: 1px solid #888; 360 | -moz-box-shadow: 2px 2px 4px #EEE; 361 | -webkit-box-shadow: 2px 2px 4px #EEE; 362 | box-shadow: 2px 2px 4px #EEE; 363 | } 364 | 365 | table.docutils td, table.docutils th { 366 | border: 1px solid #888; 367 | padding: 0.25em 0.7em; 368 | } 369 | 370 | table.field-list, table.footnote { 371 | border: none; 372 | -moz-box-shadow: none; 373 | -webkit-box-shadow: none; 374 | box-shadow: none; 375 | } 376 | 377 | table.footnote { 378 | margin: 15px 0; 379 | width: 100%; 380 | border: 1px solid #EEE; 381 | background: #FDFDFD; 382 | font-size: 0.9em; 383 | } 384 | 385 | table.footnote + table.footnote { 386 | margin-top: -15px; 387 | border-top: none; 388 | } 389 | 390 | table.field-list th { 391 | padding: 0 0.8em 0 0; 392 | } 393 | 394 | table.field-list td { 395 | padding: 0; 396 | } 397 | 398 | table.field-list p { 399 | margin-bottom: 0.8em; 400 | } 401 | 402 | /* Cloned from 403 | * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 404 | */ 405 | .field-name { 406 | -moz-hyphens: manual; 407 | -ms-hyphens: manual; 408 | -webkit-hyphens: manual; 409 | hyphens: manual; 410 | } 411 | 412 | table.footnote td.label { 413 | width: .1px; 414 | padding: 0.3em 0 0.3em 0.5em; 415 | } 416 | 417 | table.footnote td { 418 | padding: 0.3em 0.5em; 419 | } 420 | 421 | dl { 422 | margin: 0; 423 | padding: 0; 424 | } 425 | 426 | dl dd { 427 | margin-left: 30px; 428 | } 429 | 430 | blockquote { 431 | margin: 0 0 0 30px; 432 | padding: 0; 433 | } 434 | 435 | ul, ol { 436 | /* Matches the 30px from the narrow-screen "li > ul" selector below */ 437 | margin: 10px 0 10px 30px; 438 | padding: 0; 439 | } 440 | 441 | pre { 442 | background: #EEE; 443 | padding: 7px 30px; 444 | margin: 15px 0px; 445 | line-height: 1.3em; 446 | } 447 | 448 | div.viewcode-block:target { 449 | background: #ffd; 450 | } 451 | 452 | dl pre, blockquote pre, li pre { 453 | margin-left: 0; 454 | padding-left: 30px; 455 | } 456 | 457 | tt, code { 458 | background-color: #ecf0f3; 459 | color: #222; 460 | /* padding: 1px 2px; */ 461 | } 462 | 463 | tt.xref, code.xref, a tt { 464 | background-color: #FBFBFB; 465 | border-bottom: 1px solid #fff; 466 | } 467 | 468 | a.reference { 469 | text-decoration: none; 470 | border-bottom: 1px dotted #004B6B; 471 | } 472 | 473 | /* Don't put an underline on images */ 474 | a.image-reference, a.image-reference:hover { 475 | border-bottom: none; 476 | } 477 | 478 | a.reference:hover { 479 | border-bottom: 1px solid #6D4100; 480 | } 481 | 482 | a.footnote-reference { 483 | text-decoration: none; 484 | font-size: 0.7em; 485 | vertical-align: top; 486 | border-bottom: 1px dotted #004B6B; 487 | } 488 | 489 | a.footnote-reference:hover { 490 | border-bottom: 1px solid #6D4100; 491 | } 492 | 493 | a:hover tt, a:hover code { 494 | background: #EEE; 495 | } 496 | 497 | 498 | @media screen and (max-width: 870px) { 499 | 500 | div.sphinxsidebar { 501 | display: none; 502 | } 503 | 504 | div.document { 505 | width: 100%; 506 | 507 | } 508 | 509 | div.documentwrapper { 510 | margin-left: 0; 511 | margin-top: 0; 512 | margin-right: 0; 513 | margin-bottom: 0; 514 | } 515 | 516 | div.bodywrapper { 517 | margin-top: 0; 518 | margin-right: 0; 519 | margin-bottom: 0; 520 | margin-left: 0; 521 | } 522 | 523 | ul { 524 | margin-left: 0; 525 | } 526 | 527 | li > ul { 528 | /* Matches the 30px from the "ul, ol" selector above */ 529 | margin-left: 30px; 530 | } 531 | 532 | .document { 533 | width: auto; 534 | } 535 | 536 | .footer { 537 | width: auto; 538 | } 539 | 540 | .bodywrapper { 541 | margin: 0; 542 | } 543 | 544 | .footer { 545 | width: auto; 546 | } 547 | 548 | .github { 549 | display: none; 550 | } 551 | 552 | 553 | 554 | } 555 | 556 | 557 | 558 | @media screen and (max-width: 875px) { 559 | 560 | body { 561 | margin: 0; 562 | padding: 20px 30px; 563 | } 564 | 565 | div.documentwrapper { 566 | float: none; 567 | background: #fff; 568 | } 569 | 570 | div.sphinxsidebar { 571 | display: block; 572 | float: none; 573 | width: 102.5%; 574 | margin: 50px -30px -20px -30px; 575 | padding: 10px 20px; 576 | background: #333; 577 | color: #FFF; 578 | } 579 | 580 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 581 | div.sphinxsidebar h3 a { 582 | color: #fff; 583 | } 584 | 585 | div.sphinxsidebar a { 586 | color: #AAA; 587 | } 588 | 589 | div.sphinxsidebar p.logo { 590 | display: none; 591 | } 592 | 593 | div.document { 594 | width: 100%; 595 | margin: 0; 596 | } 597 | 598 | div.footer { 599 | display: none; 600 | } 601 | 602 | div.bodywrapper { 603 | margin: 0; 604 | } 605 | 606 | div.body { 607 | min-height: 0; 608 | padding: 0; 609 | } 610 | 611 | .rtd_doc_footer { 612 | display: none; 613 | } 614 | 615 | .document { 616 | width: auto; 617 | } 618 | 619 | .footer { 620 | width: auto; 621 | } 622 | 623 | .footer { 624 | width: auto; 625 | } 626 | 627 | .github { 628 | display: none; 629 | } 630 | } 631 | 632 | 633 | /* misc. */ 634 | 635 | .revsys-inline { 636 | display: none!important; 637 | } 638 | 639 | /* Make nested-list/multi-paragraph items look better in Releases changelog 640 | * pages. Without this, docutils' magical list fuckery causes inconsistent 641 | * formatting between different release sub-lists. 642 | */ 643 | div#changelog > div.section > ul > li > p:only-child { 644 | margin-bottom: 0; 645 | } 646 | 647 | /* Hide fugly table cell borders in ..bibliography:: directive output */ 648 | table.docutils.citation, table.docutils.citation td, table.docutils.citation th { 649 | border: none; 650 | /* Below needed in some edge cases; if not applied, bottom shadows appear */ 651 | -moz-box-shadow: none; 652 | -webkit-box-shadow: none; 653 | box-shadow: none; 654 | } 655 | 656 | 657 | /* relbar */ 658 | 659 | .related { 660 | line-height: 30px; 661 | width: 100%; 662 | font-size: 0.9rem; 663 | } 664 | 665 | .related.top { 666 | border-bottom: 1px solid #EEE; 667 | margin-bottom: 20px; 668 | } 669 | 670 | .related.bottom { 671 | border-top: 1px solid #EEE; 672 | } 673 | 674 | .related ul { 675 | padding: 0; 676 | margin: 0; 677 | list-style: none; 678 | } 679 | 680 | .related li { 681 | display: inline; 682 | } 683 | 684 | nav#rellinks { 685 | float: right; 686 | } 687 | 688 | nav#rellinks li+li:before { 689 | content: "|"; 690 | } 691 | 692 | nav#breadcrumbs li+li:before { 693 | content: "\00BB"; 694 | } 695 | 696 | /* Hide certain items when printing */ 697 | @media print { 698 | div.related { 699 | display: none; 700 | } 701 | } -------------------------------------------------------------------------------- /build/html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Base JavaScript utilities for all Sphinx HTML documentation. 6 | * 7 | * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | "use strict"; 12 | 13 | const _ready = (callback) => { 14 | if (document.readyState !== "loading") { 15 | callback(); 16 | } else { 17 | document.addEventListener("DOMContentLoaded", callback); 18 | } 19 | }; 20 | 21 | /** 22 | * highlight a given string on a node by wrapping it in 23 | * span elements with the given class name. 24 | */ 25 | const _highlight = (node, addItems, text, className) => { 26 | if (node.nodeType === Node.TEXT_NODE) { 27 | const val = node.nodeValue; 28 | const parent = node.parentNode; 29 | const pos = val.toLowerCase().indexOf(text); 30 | if ( 31 | pos >= 0 && 32 | !parent.classList.contains(className) && 33 | !parent.classList.contains("nohighlight") 34 | ) { 35 | let span; 36 | 37 | const closestNode = parent.closest("body, svg, foreignObject"); 38 | const isInSVG = closestNode && closestNode.matches("svg"); 39 | if (isInSVG) { 40 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 41 | } else { 42 | span = document.createElement("span"); 43 | span.classList.add(className); 44 | } 45 | 46 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 47 | parent.insertBefore( 48 | span, 49 | parent.insertBefore( 50 | document.createTextNode(val.substr(pos + text.length)), 51 | node.nextSibling 52 | ) 53 | ); 54 | node.nodeValue = val.substr(0, pos); 55 | 56 | if (isInSVG) { 57 | const rect = document.createElementNS( 58 | "http://www.w3.org/2000/svg", 59 | "rect" 60 | ); 61 | const bbox = parent.getBBox(); 62 | rect.x.baseVal.value = bbox.x; 63 | rect.y.baseVal.value = bbox.y; 64 | rect.width.baseVal.value = bbox.width; 65 | rect.height.baseVal.value = bbox.height; 66 | rect.setAttribute("class", className); 67 | addItems.push({ parent: parent, target: rect }); 68 | } 69 | } 70 | } else if (node.matches && !node.matches("button, select, textarea")) { 71 | node.childNodes.forEach((el) => _highlight(el, addItems, text, className)); 72 | } 73 | }; 74 | const _highlightText = (thisNode, text, className) => { 75 | let addItems = []; 76 | _highlight(thisNode, addItems, text, className); 77 | addItems.forEach((obj) => 78 | obj.parent.insertAdjacentElement("beforebegin", obj.target) 79 | ); 80 | }; 81 | 82 | /** 83 | * Small JavaScript module for the documentation. 84 | */ 85 | const Documentation = { 86 | init: () => { 87 | Documentation.highlightSearchWords(); 88 | Documentation.initDomainIndexTable(); 89 | Documentation.initOnKeyListeners(); 90 | }, 91 | 92 | /** 93 | * i18n support 94 | */ 95 | TRANSLATIONS: {}, 96 | PLURAL_EXPR: (n) => (n === 1 ? 0 : 1), 97 | LOCALE: "unknown", 98 | 99 | // gettext and ngettext don't access this so that the functions 100 | // can safely bound to a different name (_ = Documentation.gettext) 101 | gettext: (string) => { 102 | const translated = Documentation.TRANSLATIONS[string]; 103 | switch (typeof translated) { 104 | case "undefined": 105 | return string; // no translation 106 | case "string": 107 | return translated; // translation exists 108 | default: 109 | return translated[0]; // (singular, plural) translation tuple exists 110 | } 111 | }, 112 | 113 | ngettext: (singular, plural, n) => { 114 | const translated = Documentation.TRANSLATIONS[singular]; 115 | if (typeof translated !== "undefined") 116 | return translated[Documentation.PLURAL_EXPR(n)]; 117 | return n === 1 ? singular : plural; 118 | }, 119 | 120 | addTranslations: (catalog) => { 121 | Object.assign(Documentation.TRANSLATIONS, catalog.messages); 122 | Documentation.PLURAL_EXPR = new Function( 123 | "n", 124 | `return (${catalog.plural_expr})` 125 | ); 126 | Documentation.LOCALE = catalog.locale; 127 | }, 128 | 129 | /** 130 | * highlight the search words provided in the url in the text 131 | */ 132 | highlightSearchWords: () => { 133 | const highlight = 134 | new URLSearchParams(window.location.search).get("highlight") || ""; 135 | const terms = highlight.toLowerCase().split(/\s+/).filter(x => x); 136 | if (terms.length === 0) return; // nothing to do 137 | 138 | // There should never be more than one element matching "div.body" 139 | const divBody = document.querySelectorAll("div.body"); 140 | const body = divBody.length ? divBody[0] : document.querySelector("body"); 141 | window.setTimeout(() => { 142 | terms.forEach((term) => _highlightText(body, term, "highlighted")); 143 | }, 10); 144 | 145 | const searchBox = document.getElementById("searchbox"); 146 | if (searchBox === null) return; 147 | searchBox.appendChild( 148 | document 149 | .createRange() 150 | .createContextualFragment( 151 | '" 155 | ) 156 | ); 157 | }, 158 | 159 | /** 160 | * helper function to hide the search marks again 161 | */ 162 | hideSearchWords: () => { 163 | document 164 | .querySelectorAll("#searchbox .highlight-link") 165 | .forEach((el) => el.remove()); 166 | document 167 | .querySelectorAll("span.highlighted") 168 | .forEach((el) => el.classList.remove("highlighted")); 169 | const url = new URL(window.location); 170 | url.searchParams.delete("highlight"); 171 | window.history.replaceState({}, "", url); 172 | }, 173 | 174 | /** 175 | * helper function to focus on search bar 176 | */ 177 | focusSearchBar: () => { 178 | document.querySelectorAll("input[name=q]")[0]?.focus(); 179 | }, 180 | 181 | /** 182 | * Initialise the domain index toggle buttons 183 | */ 184 | initDomainIndexTable: () => { 185 | const toggler = (el) => { 186 | const idNumber = el.id.substr(7); 187 | const toggledRows = document.querySelectorAll(`tr.cg-${idNumber}`); 188 | if (el.src.substr(-9) === "minus.png") { 189 | el.src = `${el.src.substr(0, el.src.length - 9)}plus.png`; 190 | toggledRows.forEach((el) => (el.style.display = "none")); 191 | } else { 192 | el.src = `${el.src.substr(0, el.src.length - 8)}minus.png`; 193 | toggledRows.forEach((el) => (el.style.display = "")); 194 | } 195 | }; 196 | 197 | const togglerElements = document.querySelectorAll("img.toggler"); 198 | togglerElements.forEach((el) => 199 | el.addEventListener("click", (event) => toggler(event.currentTarget)) 200 | ); 201 | togglerElements.forEach((el) => (el.style.display = "")); 202 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) togglerElements.forEach(toggler); 203 | }, 204 | 205 | initOnKeyListeners: () => { 206 | // only install a listener if it is really needed 207 | if ( 208 | !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS && 209 | !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS 210 | ) 211 | return; 212 | 213 | const blacklistedElements = new Set([ 214 | "TEXTAREA", 215 | "INPUT", 216 | "SELECT", 217 | "BUTTON", 218 | ]); 219 | document.addEventListener("keydown", (event) => { 220 | if (blacklistedElements.has(document.activeElement.tagName)) return; // bail for input elements 221 | if (event.altKey || event.ctrlKey || event.metaKey) return; // bail with special keys 222 | 223 | if (!event.shiftKey) { 224 | switch (event.key) { 225 | case "ArrowLeft": 226 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 227 | 228 | const prevLink = document.querySelector('link[rel="prev"]'); 229 | if (prevLink && prevLink.href) { 230 | window.location.href = prevLink.href; 231 | event.preventDefault(); 232 | } 233 | break; 234 | case "ArrowRight": 235 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 236 | 237 | const nextLink = document.querySelector('link[rel="next"]'); 238 | if (nextLink && nextLink.href) { 239 | window.location.href = nextLink.href; 240 | event.preventDefault(); 241 | } 242 | break; 243 | case "Escape": 244 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 245 | Documentation.hideSearchWords(); 246 | event.preventDefault(); 247 | } 248 | } 249 | 250 | // some keyboard layouts may need Shift to get / 251 | switch (event.key) { 252 | case "/": 253 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 254 | Documentation.focusSearchBar(); 255 | event.preventDefault(); 256 | } 257 | }); 258 | }, 259 | }; 260 | 261 | // quick alias for translations 262 | const _ = Documentation.gettext; 263 | 264 | _ready(Documentation.init); 265 | -------------------------------------------------------------------------------- /build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '.1', 4 | LANGUAGE: 'en', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false, 12 | SHOW_SEARCH_SUMMARY: true, 13 | ENABLE_SEARCH_SHORTCUTS: true, 14 | }; -------------------------------------------------------------------------------- /build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/_static/file.png -------------------------------------------------------------------------------- /build/html/_static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; 14 | 15 | 16 | /* Non-minified version is copied as a separate JS file, is available */ 17 | 18 | /** 19 | * Porter Stemmer 20 | */ 21 | var Stemmer = function() { 22 | 23 | var step2list = { 24 | ational: 'ate', 25 | tional: 'tion', 26 | enci: 'ence', 27 | anci: 'ance', 28 | izer: 'ize', 29 | bli: 'ble', 30 | alli: 'al', 31 | entli: 'ent', 32 | eli: 'e', 33 | ousli: 'ous', 34 | ization: 'ize', 35 | ation: 'ate', 36 | ator: 'ate', 37 | alism: 'al', 38 | iveness: 'ive', 39 | fulness: 'ful', 40 | ousness: 'ous', 41 | aliti: 'al', 42 | iviti: 'ive', 43 | biliti: 'ble', 44 | logi: 'log' 45 | }; 46 | 47 | var step3list = { 48 | icate: 'ic', 49 | ative: '', 50 | alize: 'al', 51 | iciti: 'ic', 52 | ical: 'ic', 53 | ful: '', 54 | ness: '' 55 | }; 56 | 57 | var c = "[^aeiou]"; // consonant 58 | var v = "[aeiouy]"; // vowel 59 | var C = c + "[^aeiouy]*"; // consonant sequence 60 | var V = v + "[aeiou]*"; // vowel sequence 61 | 62 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/_static/minus.png -------------------------------------------------------------------------------- /build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/_static/plus.png -------------------------------------------------------------------------------- /build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #f8f8f8; } 8 | .highlight .c { color: #8f5902; font-style: italic } /* Comment */ 9 | .highlight .err { color: #a40000; border: 1px solid #ef2929 } /* Error */ 10 | .highlight .g { color: #000000 } /* Generic */ 11 | .highlight .k { color: #004461; font-weight: bold } /* Keyword */ 12 | .highlight .l { color: #000000 } /* Literal */ 13 | .highlight .n { color: #000000 } /* Name */ 14 | .highlight .o { color: #582800 } /* Operator */ 15 | .highlight .x { color: #000000 } /* Other */ 16 | .highlight .p { color: #000000; font-weight: bold } /* Punctuation */ 17 | .highlight .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */ 18 | .highlight .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */ 19 | .highlight .cp { color: #8f5902 } /* Comment.Preproc */ 20 | .highlight .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */ 21 | .highlight .c1 { color: #8f5902; font-style: italic } /* Comment.Single */ 22 | .highlight .cs { color: #8f5902; font-style: italic } /* Comment.Special */ 23 | .highlight .gd { color: #a40000 } /* Generic.Deleted */ 24 | .highlight .ge { color: #000000; font-style: italic } /* Generic.Emph */ 25 | .highlight .gr { color: #ef2929 } /* Generic.Error */ 26 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 27 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 28 | .highlight .go { color: #888888 } /* Generic.Output */ 29 | .highlight .gp { color: #745334 } /* Generic.Prompt */ 30 | .highlight .gs { color: #000000; font-weight: bold } /* Generic.Strong */ 31 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 32 | .highlight .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */ 33 | .highlight .kc { color: #004461; font-weight: bold } /* Keyword.Constant */ 34 | .highlight .kd { color: #004461; font-weight: bold } /* Keyword.Declaration */ 35 | .highlight .kn { color: #004461; font-weight: bold } /* Keyword.Namespace */ 36 | .highlight .kp { color: #004461; font-weight: bold } /* Keyword.Pseudo */ 37 | .highlight .kr { color: #004461; font-weight: bold } /* Keyword.Reserved */ 38 | .highlight .kt { color: #004461; font-weight: bold } /* Keyword.Type */ 39 | .highlight .ld { color: #000000 } /* Literal.Date */ 40 | .highlight .m { color: #990000 } /* Literal.Number */ 41 | .highlight .s { color: #4e9a06 } /* Literal.String */ 42 | .highlight .na { color: #c4a000 } /* Name.Attribute */ 43 | .highlight .nb { color: #004461 } /* Name.Builtin */ 44 | .highlight .nc { color: #000000 } /* Name.Class */ 45 | .highlight .no { color: #000000 } /* Name.Constant */ 46 | .highlight .nd { color: #888888 } /* Name.Decorator */ 47 | .highlight .ni { color: #ce5c00 } /* Name.Entity */ 48 | .highlight .ne { color: #cc0000; font-weight: bold } /* Name.Exception */ 49 | .highlight .nf { color: #000000 } /* Name.Function */ 50 | .highlight .nl { color: #f57900 } /* Name.Label */ 51 | .highlight .nn { color: #000000 } /* Name.Namespace */ 52 | .highlight .nx { color: #000000 } /* Name.Other */ 53 | .highlight .py { color: #000000 } /* Name.Property */ 54 | .highlight .nt { color: #004461; font-weight: bold } /* Name.Tag */ 55 | .highlight .nv { color: #000000 } /* Name.Variable */ 56 | .highlight .ow { color: #004461; font-weight: bold } /* Operator.Word */ 57 | .highlight .w { color: #f8f8f8; text-decoration: underline } /* Text.Whitespace */ 58 | .highlight .mb { color: #990000 } /* Literal.Number.Bin */ 59 | .highlight .mf { color: #990000 } /* Literal.Number.Float */ 60 | .highlight .mh { color: #990000 } /* Literal.Number.Hex */ 61 | .highlight .mi { color: #990000 } /* Literal.Number.Integer */ 62 | .highlight .mo { color: #990000 } /* Literal.Number.Oct */ 63 | .highlight .sa { color: #4e9a06 } /* Literal.String.Affix */ 64 | .highlight .sb { color: #4e9a06 } /* Literal.String.Backtick */ 65 | .highlight .sc { color: #4e9a06 } /* Literal.String.Char */ 66 | .highlight .dl { color: #4e9a06 } /* Literal.String.Delimiter */ 67 | .highlight .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */ 68 | .highlight .s2 { color: #4e9a06 } /* Literal.String.Double */ 69 | .highlight .se { color: #4e9a06 } /* Literal.String.Escape */ 70 | .highlight .sh { color: #4e9a06 } /* Literal.String.Heredoc */ 71 | .highlight .si { color: #4e9a06 } /* Literal.String.Interpol */ 72 | .highlight .sx { color: #4e9a06 } /* Literal.String.Other */ 73 | .highlight .sr { color: #4e9a06 } /* Literal.String.Regex */ 74 | .highlight .s1 { color: #4e9a06 } /* Literal.String.Single */ 75 | .highlight .ss { color: #4e9a06 } /* Literal.String.Symbol */ 76 | .highlight .bp { color: #3465a4 } /* Name.Builtin.Pseudo */ 77 | .highlight .fm { color: #000000 } /* Name.Function.Magic */ 78 | .highlight .vc { color: #000000 } /* Name.Variable.Class */ 79 | .highlight .vg { color: #000000 } /* Name.Variable.Global */ 80 | .highlight .vi { color: #000000 } /* Name.Variable.Instance */ 81 | .highlight .vm { color: #000000 } /* Name.Variable.Magic */ 82 | .highlight .il { color: #990000 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /build/html/datasets.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 2. Datasets — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 35 |
36 | 37 |
38 |

2. Datasets

39 |
40 | 43 |
44 |
45 | 46 | 47 |
48 | 49 |
50 |
51 | 100 |
101 |
102 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /build/html/features.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1. Features — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 35 |
36 | 37 |
38 |

1. Features

39 |
40 | 41 | 42 |
43 | 44 |
45 |
46 | 92 |
93 |
94 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Index — Machine Learning Library for TDA .1 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
30 | 31 | 32 |
33 | 34 | 35 |

Index

36 | 37 |
38 | 39 |
40 | 41 | 42 |
43 | 44 |
45 |
46 | 90 |
91 |
92 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /build/html/ham10000.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 2.1. HAM10000 — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

2.1. HAM10000

38 |
39 | 40 | 41 |
42 | 43 |
44 |
45 | 95 |
96 |
97 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Welcome to Machine Learning Library for TDA’s documentation! — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

Welcome to Machine Learning Library for TDA’s documentation!

38 |

Welcome! You’re on the associated page for our repository for our paper, A Comparative Study of Machine Learning Methods for Persistence Diagrams

39 | _images/balls.gif 40 |
41 |

Table of Contents

42 |
43 | 50 |
51 |
52 |
53 | 54 | 55 |
56 | 57 |
58 |
59 | 104 |
105 |
106 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/build/html/objects.inv -------------------------------------------------------------------------------- /build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Search — Machine Learning Library for TDA .1 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 |
35 |
36 | 37 | 38 |
39 | 40 |

Search

41 | 42 | 50 | 51 | 52 |

53 | Searching for multiple words only shows matches that contain 54 | all words. 55 |

56 | 57 | 58 |
59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 |
67 | 68 |
69 | 70 | 71 |
72 | 73 |
74 |
75 | 109 |
110 |
111 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({"docnames": ["datasets", "features", "ham10000", "index"], "filenames": ["datasets.rst", "features.rst", "ham10000.rst", "index.rst"], "titles": ["2. Datasets", "1. Features", "2.1. HAM10000", "Welcome to Machine Learning Library for TDA\u2019s documentation!"], "terms": {"ham10000": [0, 3], "you": 3, "re": 3, "associ": 3, "page": 3, "our": 3, "repositori": 3, "paper": 3, "A": 3, "compar": 3, "studi": 3, "method": 3, "persist": 3, "diagram": 3, "featur": 3, "dataset": 3}, "objects": {}, "objtypes": {}, "objnames": {}, "titleterms": {"dataset": 0, "featur": 1, "ham10000": 2, "welcom": 3, "machin": 3, "learn": 3, "librari": 3, "tda": 3, "": 3, "document": 3, "tabl": 3, "content": 3}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 6, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.intersphinx": 1, "sphinx.ext.todo": 2, "sphinx.ext.viewcode": 1, "sphinx": 56}}) -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | {"fp": "/Users/barnesd8/Documents/git/machine_learning_persistence/", 2 | "mpeg7data": "mpeg7/data/", 3 | "mpeg7pers": "mpeg7/persistence/", 4 | "mpeg7contours": "mpeg7/contours/", 5 | "proteindata":"protein/data/", 6 | "proteinpers":"protein/persistence/", 7 | "ham10000data":"ham10000/data/", 8 | "ham10000pers":"ham10000/persistence/", 9 | "ham10000data_test":"ham10000/data_test/", 10 | "ham10000pers_test":"ham10000/persistence_test/"} -------------------------------------------------------------------------------- /datasets/HAM10000/ham10000_data_preprocessing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import os 4 | import os.path 5 | import matplotlib.image as mpimg 6 | import cv2 7 | import pickle 8 | import PIL 9 | import csv 10 | import matplotlib.pyplot as plt 11 | import matplotlib.gridspec as gridspec 12 | import skimage 13 | 14 | from scipy.spatial.distance import cdist 15 | from skimage.morphology import convex_hull_image 16 | from scipy import sparse 17 | from ripser import ripser, lower_star_img 18 | 19 | import json 20 | import copy 21 | 22 | np.set_printoptions(precision=2) 23 | 24 | # -------------- FUNCTIONS ---------------------------------------------------- 25 | 26 | def getImageFiltration(I, T, filtration, a=None): 27 | ''' 28 | This function computes a filtration of binary images for a given image I. 29 | Each step in the filtration is defined by the following following formula for a fixed T and a. 30 | 31 | .. math:: 32 | I^*_t(i,j) = \begin{cases} 33 | 0 & \mbox{if } I^*(i,j) > a(1 - t/T) 34 | 255 & \mbox{if } I^*(i,j) \leq a(1 - t/T) 35 | \end{cases} 36 | 37 | where $T^*$ is the the image I after being converted to gray scale. 38 | 39 | :type I: numpy.array 40 | :param I: n x m image. 41 | 42 | :type T: float 43 | :param T: End point for the filtration. 44 | 45 | :type filtration: list or numpy.array 46 | :param filtration: Collection of values 0 <= t <= T that will be used to build the filtration of binary images I^*_t 47 | 48 | :type a: float 49 | :param a: Default = None. Scale for the filtration. If the value is None this implementation uses the mean pixel intensity as the scale for the filtration. 50 | 51 | :retrun: numpy.array - 3D array representing the filtration of binary images. The dimensions correspond to height x width x step_in_filtration. 52 | ''' 53 | 54 | # Make sure input is an array 55 | 56 | image = np.array(I) 57 | 58 | # Make the original images gray scale 59 | if I.ndim > 2: 60 | img_grey = np.asarray(PIL.Image.fromarray(image).convert('L')) 61 | 62 | # my_img_grey = np.remainder((1/3)*(image[:,:,0] + image[:,:,1] + image[:,:,2]), 255) 63 | else: 64 | img_grey = image 65 | 66 | #the filtration calues can not go over T 67 | if np.max(filtration) > T: 68 | print('ERROR: The filtration value excedes the maximum T') 69 | return 70 | 71 | # Lets compute the filtration of binary images 72 | 73 | # If not scale value a for the filtration is provided, well use the average pixel value in the gray scale image. 74 | if a==None: 75 | a = np.mean(np.mean(img_grey)) 76 | 77 | # Initialize array to store filtration 78 | F = np.zeros((img_grey.shape[0], img_grey.shape[1], len(filtration))) 79 | 80 | for i in range(len(filtration)): 81 | tresh = a*(1 - filtration[i]/T) 82 | 83 | temp = np.zeros((img_grey.shape[0], img_grey.shape[1])) 84 | 85 | temp[img_grey <= tresh] = 255 86 | 87 | F[:,:,i] = temp 88 | 89 | # Now we need to compute the lifetime of each point 90 | 91 | lifetimes = np.zeros((img_grey.shape[0], img_grey.shape[1])) 92 | 93 | S_1 = np.column_stack((np.where(F[:,:,1] == 255)[0], np.where(F[:,:,1] == 255)[1])) 94 | 95 | for j in range(S_1.shape[0]): 96 | if np.where(F[S_1[j,0], S_1[j,1], :] == 0)[0].size > 0: 97 | lifetimes[S_1[j,0], S_1[j,1]] = np.where(F[S_1[j,0], S_1[j,1], :] == 0)[0][0]-1 98 | else: 99 | lifetimes[S_1[j,0], S_1[j,1]] = len(F[S_1[j,0], S_1[j,1], :]) 100 | 101 | # fig, ax = plt.subplots(1,1, figsize=(10,10)) 102 | 103 | # im = ax.imshow(lifetimes) 104 | # fig.colorbar(im, ax=ax) 105 | 106 | # plt.savefig('lifetimes.png') 107 | 108 | return F, lifetimes 109 | 110 | def getSegmentation(F): 111 | ''' 112 | This function computes the step in the filtration of binary images that we will use later onto find a suitable mask. 113 | 114 | :type F: numpy.array 115 | :param F: 3D array representing the filtration of binary images. The dimensions correspond to height x width x step_in_filtration. 116 | 117 | :retrun: numpy.array - Binary image that will be used to compute the mask.3 118 | ''' 119 | 120 | if F.ndim != 3: 121 | print('ERROR: The parameter F must be a 3D-array.') 122 | return 123 | 124 | 125 | prev_num_connected_componnets = img.shape[0]*img.shape[1] 126 | T2 = 0 127 | for i in range(F.shape[2]): 128 | 129 | # Compute 0-dim persistence 130 | dgm = lower_star_img(F[:,:,i]) 131 | # We need to clear out results since nany point with persistence (-0,infy) is point that never was part of the diagram. 132 | # ind_of_zeros = np.where(dgm[:,0] == 0)[0] 133 | # dgm = np.delete(dgm, ind_of_zeros, axis=0) 134 | 135 | # The stopping condition comes whenever S_{t+1} has more connected components than S_t 136 | 137 | if dgm.shape[0] <= prev_num_connected_componnets: 138 | 139 | prev_num_connected_componnets = dgm.shape[0] 140 | else: 141 | 142 | T2 = i-1 143 | break 144 | 145 | T1 = int(1 + np.floor(T2/4)) 146 | 147 | selected = F[:,:,T1] 148 | 149 | return selected 150 | 151 | def getMask(img, lifetime): 152 | ''' 153 | This function computes mas of an image, based on a binary image img and with the lifetime of each pixel in the filtration. 154 | 155 | To accomplish this goal we compute the life score of each connected component C given by 156 | 157 | .. math:: 158 | LS(C) = \frac{ (1 + d(C,o))^3 \sum\limits_{(x,y)\in C} L(x,y) }{ (1 + d(C,b)^3 } 159 | 160 | where $d(C,o)$ is the distance from the component $C$ to the midpoint $o$ and $d(C,d)$ is the distance form the component $C$ to the boundary of the image. 161 | 162 | :type img: numpy.array 163 | :param F: 2D array binary image. 164 | 165 | :type lifetime: numpy.array 166 | :param lifetime: 2D array that contains the lifetime for each pixel in a filtration if binary images. 167 | 168 | :retrun: numpy.array - Mask for the image. 169 | ''' 170 | 171 | # This package return the connected components of a binary image pretty fast. 172 | labeled_image, num_objects = skimage.measure.label(img, connectivity=1, return_num=True) 173 | 174 | # compute mid point of the image 175 | mid_point = np.array([int(img.shape[0]/2), int(img.shape[1]/2)]).reshape(1,2) 176 | 177 | # find boundary of the image 178 | top = np.column_stack((np.zeros(img.shape[1]), np.arange(0, img.shape[1]))) 179 | 180 | botom = np.column_stack(((img.shape[0]-1)*np.ones(img.shape[1]), np.arange(0, img.shape[1]))) 181 | 182 | left = np.column_stack((np.arange(1, img.shape[0]-1), np.zeros(img.shape[0]-2))) 183 | 184 | right = np.column_stack((np.arange(1, img.shape[0]-1), (img.shape[1]-1)*np.ones(img.shape[0]-2))) 185 | 186 | boudnary = np.row_stack((top, botom, left, right)) 187 | 188 | LC = [] 189 | for i in range(1,num_objects+1): 190 | # Points in a given connected component. 191 | C = np.column_stack((np.where(labeled_image == i)[0], np.where(labeled_image == i)[1])) 192 | 193 | # distance from connected component C to midpoint 194 | matrix_distance_C_midpont = cdist(mid_point, C, 'minkowski', p=1) 195 | 196 | distance_C_midpont = np.min(matrix_distance_C_midpont) 197 | 198 | # distance from connected component C to boundary 199 | matrix_distance_C_boundary = cdist(mid_point, C,'minkowski', p=1) 200 | 201 | distance_C_boundary = max(np.max(np.min(matrix_distance_C_boundary, axis=0)), np.max(np.min(matrix_distance_C_boundary, axis=1))) 202 | 203 | # Compute Life Score for the current connected component 204 | LC.append((np.power(1 + distance_C_boundary, 3)*np.sum(lifetime[labeled_image == i]))/np.power(1 + distance_C_midpont, 3)) 205 | 206 | mean_LC = np.mean(LC) 207 | 208 | choosen_componenets = np.arange(1,num_objects+1)[LC > mean_LC] 209 | 210 | clean_image = np.zeros((img.shape[0], img.shape[1])) 211 | for j in choosen_componenets: 212 | clean_image[labeled_image == j] = 255 213 | 214 | # fig, ax = plt.subplots(1,1, figsize=(10,10)) 215 | 216 | # ax.imshow(clean_image, cmap='gray') 217 | 218 | # plt.savefig('segmented_clean.png') 219 | 220 | chull = skimage.img_as_ubyte(convex_hull_image(clean_image)) 221 | 222 | return chull 223 | 224 | 225 | # -------------- IMPORT DATA -------------------------------------------------- 226 | 227 | # Decompres data set, this line is specific for linux! 228 | ### Need to add to check if there is a .gitignore already 229 | if os.path.exists("data/"): 230 | print("Data already unzipped") 231 | else: 232 | os.system('tar -xzvf ham10000_images.tar') 233 | os.system('mv images data') 234 | os.system('touch data/.gitignore') 235 | os.system('echo "*" >> data/.gitignore') 236 | 237 | # Load after file is unzipped 238 | with open("../config.json") as json_config_file: 239 | filepaths= json.load(json_config_file) 240 | fp = filepaths['fp'] 241 | data = fp + filepaths['ham10000data'] 242 | pers = fp + filepaths['ham10000pers'] 243 | 244 | # ----------------------------------------------------------------------------- 245 | # Load labels 246 | # 0 - MEL: “Melanoma” diagnosis confidence 247 | # 1 - NV: “Melanocytic nevus” diagnosis confidence 248 | # 2 - BCC: “Basal cell carcinoma” diagnosis confidence 249 | # 3 - AKIEC: “Actinic keratosis / Bowen’s disease (intraepithelial carcinoma)” diagnosis confidence 250 | # 4 - BKL: “Benign keratosis (solar lentigo / seborrheic keratosis / lichen planus-like keratosis)” diagnosis confidence 251 | # 5 - DF: “Dermatofibroma” diagnosis confidence 252 | # 6 - VASC: “Vascular lesion” diagnosis confidence 253 | 254 | image_ids = [] 255 | original_labels = [] 256 | 257 | with open("HAM10000_metadata.csv", newline='') as csvfile: 258 | csvreader = csv.reader(csvfile, delimiter=',') #csv reader 259 | next(csvreader) # skip first row / header 260 | for row in csvreader: 261 | image_ids.append(row[1]) 262 | original_labels.append(row[2]) 263 | 264 | original_labels = [0 if x=='mel' else x for x in original_labels] 265 | original_labels = [1 if x=='nv' else x for x in original_labels] 266 | original_labels = [2 if x=='bcc' else x for x in original_labels] 267 | original_labels = [3 if x=='akiec' else x for x in original_labels] 268 | original_labels = [4 if x=='bkl' else x for x in original_labels] 269 | original_labels = [5 if x=='df' else x for x in original_labels] 270 | original_labels = [6 if x=='vasc' else x for x in original_labels] 271 | 272 | # ----------------------------------------------------------------------------- 273 | 274 | l = os.listdir(data) 275 | l.remove('.gitignore') 276 | 277 | dgm_R_rgb = [] 278 | dgm_G_rgb = [] 279 | dgm_B_rgb = [] 280 | 281 | dgm_H_hsv = [] 282 | dgm_S_hsv = [] 283 | dgm_V_hsv = [] 284 | 285 | dgm_X_xyz = [] 286 | dgm_Y_xyz = [] 287 | dgm_Z_xyz = [] 288 | 289 | labels = [] 290 | 291 | plt.ioff() 292 | 293 | for file in l: 294 | filename = os.fsdecode(data + file) 295 | 296 | img = mpimg.imread(filename) 297 | 298 | # This function returns a filtration of binary images as a 3D-array. 299 | Fill, lifetimes = getImageFiltration(img, T=50, filtration=np.linspace(0,50,20)) 300 | 301 | 302 | 303 | # fig, ax = plt.subplots(4,5, figsize=(25,10)) 304 | 305 | # ax = ax.ravel() 306 | 307 | # for i in range(20): 308 | # ax[i].imshow(Fill[:,:,i], cmap='gray') 309 | 310 | # plt.savefig('filtration.png') 311 | 312 | 313 | 314 | segmented_image = getSegmentation(Fill) 315 | 316 | 317 | 318 | # fig, ax = plt.subplots(1,1, figsize=(10,10)) 319 | 320 | # ax.imshow(segmented_image, cmap='gray') 321 | 322 | # plt.savefig('segmented.png') 323 | 324 | 325 | 326 | mask = getMask(segmented_image, lifetimes) 327 | 328 | 329 | 330 | # fig, ax = plt.subplots(1,1, figsize=(10,10)) 331 | 332 | # ax.imshow(mask, cmap='gray') 333 | 334 | # plt.savefig('mask.png') 335 | 336 | 337 | 338 | # Apply mask to image 339 | 340 | masked_img = cv2.bitwise_and(img, img, mask = mask) 341 | 342 | 343 | 344 | # fig, ax = plt.subplots(1,1, figsize=(10,10)) 345 | 346 | # ax.imshow(masked_img, cmap='gray') 347 | 348 | # plt.savefig('masked_img.png') 349 | 350 | 351 | # RGB 352 | 353 | dgm_R_rgb.append( lower_star_img(-masked_img[:,:,0]) ) 354 | dgm_G_rgb.append( lower_star_img(-masked_img[:,:,1]) ) 355 | dgm_B_rgb.append( lower_star_img(-masked_img[:,:,2]) ) 356 | 357 | # HSV 358 | 359 | masked_img_hsv = skimage.color.rgb2hsv(masked_img) 360 | 361 | dgm_H_hsv.append( lower_star_img(-masked_img_hsv[:,:,0]) ) 362 | dgm_S_hsv.append( lower_star_img(-masked_img_hsv[:,:,1]) ) 363 | dgm_V_hsv.append( lower_star_img(-masked_img_hsv[:,:,2]) ) 364 | 365 | # XYZ 366 | 367 | masked_img_xyz = skimage.color.rgb2xyz(masked_img) 368 | 369 | dgm_X_xyz.append( lower_star_img(-masked_img_xyz[:,:,0]) ) 370 | dgm_Y_xyz.append( lower_star_img(-masked_img_xyz[:,:,1]) ) 371 | dgm_Z_xyz.append( lower_star_img(-masked_img_xyz[:,:,2]) ) 372 | 373 | 374 | # Now lets find the correct label 375 | 376 | labels.append(original_labels[image_ids.index(file[:-4])]) 377 | 378 | print('Processed file ', filename) 379 | 380 | diagrams = pd.DataFrame(index=range(len(labels))) 381 | 382 | diagrams['dgm_R_rgb'] = dgm_R_rgb 383 | diagrams['dgm_G_rgb'] = dgm_G_rgb 384 | diagrams['dgm_B_rgb'] = dgm_B_rgb 385 | 386 | diagrams['dgm_H_hsv'] = dgm_H_hsv 387 | diagrams['dgm_S_hsv'] = dgm_S_hsv 388 | diagrams['dgm_V_hsv'] = dgm_V_hsv 389 | 390 | diagrams['dgm_X_xyz'] = dgm_X_xyz 391 | diagrams['dgm_Y_xyz'] = dgm_Y_xyz 392 | diagrams['dgm_Z_xyz'] = dgm_Z_xyz 393 | 394 | diagrams['labels'] = labels 395 | 396 | print(diagrams.head()) 397 | 398 | # Save with pickle 399 | os.system('mkdir ' + pers) 400 | os.system('touch persistence/.gitignore') 401 | os.system('echo "*" >> persistence/.gitignore') 402 | with open(pers + 'diagrams.pickle', 'wb') as handle: 403 | pickle.dump(diagrams, handle, protocol=pickle.HIGHEST_PROTOCOL) -------------------------------------------------------------------------------- /datasets/mnist/kernel_gpu_computation.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import itertools 3 | import os 4 | import hdbscan 5 | import sys 6 | import time 7 | import pandas as pd 8 | import itertools 9 | import pickle 10 | import warnings 11 | 12 | from keras.datasets import mnist 13 | from copy import deepcopy 14 | from ripser import ripser 15 | from persim import plot_diagrams 16 | from matplotlib.patches import Ellipse 17 | from numba import jit, njit, prange 18 | from sklearn.model_selection import train_test_split, cross_val_score 19 | from sklearn.linear_model import RidgeClassifier, LogisticRegression 20 | from sklearn.preprocessing import PolynomialFeatures 21 | from sklearn.svm import LinearSVC, SVC, NuSVC 22 | from sklearn.kernel_ridge import KernelRidge 23 | from sklearn import mixture 24 | import dionysus as d 25 | import math 26 | from sklearn.preprocessing import scale 27 | 28 | import matplotlib.pyplot as plt 29 | 30 | from gudhi.representations.vector_methods import Landscape 31 | 32 | from persim import PersImage 33 | from persim import heat 34 | 35 | sys.path.append('../persistence_methods') 36 | import ATS 37 | from persistence_methods_numba import reshape_persistence_diagrams 38 | from persistence_methods_cuda import create_index 39 | from persistence_methods_cuda import cuda_kernel_features_train 40 | from persistence_methods_cuda import cuda_kernel_features_test 41 | 42 | warnings.simplefilter("ignore") 43 | 44 | 45 | (train_X, train_y), (test_X, test_y) = mnist.load_data() 46 | 47 | def directional_transform(img): 48 | z = np.array([0,1]) 49 | z = z.reshape([1,2]) 50 | left_to_right = np.zeros((28,28)) 51 | for i in range(0,28): 52 | for j in range(0,28): 53 | if img[i,j] != 0: 54 | left_to_right[i,j] = np.inner([i,j],z) 55 | else: 56 | left_to_right[i,j] = 0 57 | 58 | z = np.array([0,-1]) 59 | z = z.reshape([1,2]) 60 | right_to_left = np.zeros((28,28)) 61 | for i in range(0,28): 62 | for j in range(0,28): 63 | if img[i,j] != 0: 64 | right_to_left[i,j] = abs(28 + np.inner([i,j],z)) 65 | else: 66 | right_to_left[i,j] = 0 67 | 68 | z = np.array([1,0]) 69 | z = z.reshape([1,2]) 70 | bottom_to_top = np.zeros((28,28)) 71 | for i in range(0,28): 72 | for j in range(0,28): 73 | if img[i,j] != 0: 74 | bottom_to_top[i,j] = np.inner([i,j],z) 75 | else: 76 | bottom_to_top[i,j] = 0 77 | 78 | z = np.array([-1,0]) 79 | z = z.reshape([1,2]) 80 | top_to_bottom = np.zeros((28,28)) 81 | for i in range(0,28): 82 | for j in range(0,28): 83 | if img[i,j] != 0: 84 | top_to_bottom[i,j] = abs(28 + np.inner([i,j],z)) 85 | else: 86 | top_to_bottom[i,j] = 0 87 | imgs = [left_to_right, right_to_left, bottom_to_top, top_to_bottom] 88 | return imgs 89 | 90 | def compute_persistence(directional_transform): 91 | f_lower_star = d.fill_freudenthal(directional_transform, reverse = True) 92 | p = d.homology_persistence(f_lower_star) 93 | dgms_lower = d.init_diagrams(p, f_lower_star) 94 | return dgms_lower 95 | 96 | def append_dim_list(dgms, dim_list): 97 | jth_pt = [] 98 | for k in range(0, len(dgms)): 99 | if dgms[k].death - dgms[k].birth >=0: 100 | birth = dgms[k].birth 101 | death = dgms[k].death 102 | else: 103 | birth = dgms[k].death 104 | death = dgms[k].birth 105 | if math.isinf(death): 106 | b = 50 107 | else: 108 | b = death 109 | t = [birth, b] 110 | jth_pt.append(t) 111 | dim_list.append(np.array(jth_pt)) 112 | 113 | def fill_missing(dim_1): 114 | for i in range(0, len(dim_1)): 115 | if len(dim_1[i])== 0: 116 | dim_1[i] = np.array([[0,.01]]) 117 | else: 118 | dim_1[i] = dim_1[i] 119 | return dim_1 120 | 121 | 122 | n = len(train_y) 123 | obs = np.arange(0,n) 124 | obs, unused_obs = train_test_split(obs, random_state = 12, test_size = .8, stratify = train_y) 125 | train_y = train_y[obs] 126 | zero_dim_0 = [] 127 | zero_dim_1 = [] 128 | zero_dim_2 = [] 129 | zero_dim_3 = [] 130 | one_dim_0 = [] 131 | one_dim_1 = [] 132 | one_dim_2 = [] 133 | one_dim_3 = [] 134 | for i in obs: 135 | print("Transforming Image ", i) 136 | img = train_X[i] 137 | imgs = directional_transform(img) 138 | for j in range(0,4): 139 | dgms_lower= compute_persistence(imgs[j]) 140 | if j == 0: 141 | append_dim_list(dgms_lower[0], zero_dim_0) 142 | append_dim_list(dgms_lower[1], one_dim_0) 143 | if j == 1: 144 | append_dim_list(dgms_lower[0], zero_dim_1) 145 | append_dim_list(dgms_lower[1], one_dim_1) 146 | if j == 2: 147 | append_dim_list(dgms_lower[0], zero_dim_2) 148 | append_dim_list(dgms_lower[1], one_dim_2) 149 | if j == 3: 150 | append_dim_list(dgms_lower[0], zero_dim_3) 151 | append_dim_list(dgms_lower[1], one_dim_3) 152 | 153 | one_dim_0 = fill_missing(one_dim_0) 154 | one_dim_1 = fill_missing(one_dim_1) 155 | one_dim_2 = fill_missing(one_dim_2) 156 | one_dim_3 = fill_missing(one_dim_3) 157 | 158 | 159 | n = len(train_y) 160 | obs = np.arange(0,n) 161 | state = int(sys.argv[1]) 162 | 163 | train_index, test_index, y_train, y_test = train_test_split(obs, train_y, random_state = state, test_size = .2, stratify = train_y) 164 | 165 | zero_dim_ltr_train = np.array(zero_dim_0)[train_index] 166 | zero_dim_rtl_train = np.array(zero_dim_1)[train_index] 167 | zero_dim_ttb_train = np.array(zero_dim_2)[train_index] 168 | zero_dim_btt_train = np.array(zero_dim_3)[train_index] 169 | 170 | zero_dim_ltr_test = np.array(zero_dim_0)[test_index] 171 | zero_dim_rtl_test = np.array(zero_dim_1)[test_index] 172 | zero_dim_ttb_test = np.array(zero_dim_2)[test_index] 173 | zero_dim_btt_test = np.array(zero_dim_3)[test_index] 174 | 175 | one_dim_ltr_train = np.array(one_dim_0)[train_index] 176 | one_dim_rtl_train = np.array(one_dim_1)[train_index] 177 | one_dim_ttb_train = np.array(one_dim_2)[train_index] 178 | one_dim_btt_train = np.array(one_dim_3)[train_index] 179 | 180 | one_dim_ltr_test = np.array(one_dim_0)[test_index] 181 | one_dim_rtl_test = np.array(one_dim_1)[test_index] 182 | one_dim_ttb_test = np.array(one_dim_2)[test_index] 183 | one_dim_btt_test = np.array(one_dim_3)[test_index] 184 | 185 | ### Kernel Features 186 | print('Starting Kernel Features') 187 | start = time.time() 188 | dummy_train = np.arange(len(y_train), dtype=np.float64) 189 | dummy_test = np.arange(len(y_test), dtype=np.float64) 190 | 191 | s = 1.2 192 | zero_dim_ltr_train_ = reshape_persistence_diagrams(zero_dim_ltr_train) 193 | zero_dim_rtl_train_ = reshape_persistence_diagrams(zero_dim_rtl_train) 194 | zero_dim_ttb_train_ = reshape_persistence_diagrams(zero_dim_ttb_train) 195 | zero_dim_btt_train_ = reshape_persistence_diagrams(zero_dim_btt_train) 196 | 197 | one_dim_ltr_train_ = reshape_persistence_diagrams(one_dim_ltr_train) 198 | one_dim_rtl_train_ = reshape_persistence_diagrams(one_dim_rtl_train) 199 | one_dim_ttb_train_ = reshape_persistence_diagrams(one_dim_ttb_train) 200 | one_dim_btt_train_ = reshape_persistence_diagrams(one_dim_btt_train) 201 | 202 | zero_dim_ltr_test_ = reshape_persistence_diagrams(zero_dim_ltr_test) 203 | zero_dim_rtl_test_ = reshape_persistence_diagrams(zero_dim_rtl_test) 204 | zero_dim_ttb_test_ = reshape_persistence_diagrams(zero_dim_ttb_test) 205 | zero_dim_btt_test_ = reshape_persistence_diagrams(zero_dim_btt_test) 206 | 207 | one_dim_ltr_test_ = reshape_persistence_diagrams(one_dim_ltr_test) 208 | one_dim_rtl_test_ = reshape_persistence_diagrams(one_dim_rtl_test) 209 | one_dim_ttb_test_ = reshape_persistence_diagrams(one_dim_ttb_test) 210 | one_dim_btt_test_ = reshape_persistence_diagrams(one_dim_btt_test) 211 | 212 | index_train_0_ltr = create_index(zero_dim_ltr_train_, dummy_train) 213 | index_test_0_ltr = create_index(zero_dim_ltr_test_, dummy_test) 214 | index_train_0_rtl = create_index(zero_dim_rtl_train_, dummy_train) 215 | index_test_0_rtl = create_index(zero_dim_rtl_test_, dummy_test) 216 | index_train_0_ttb = create_index(zero_dim_ttb_train_, dummy_train) 217 | index_test_0_ttb = create_index(zero_dim_ttb_test_, dummy_test) 218 | index_train_0_btt = create_index(zero_dim_btt_train_, dummy_train) 219 | index_test_0_btt = create_index(zero_dim_btt_test_, dummy_test) 220 | 221 | 222 | index_train_1_ltr = create_index(one_dim_ltr_train_, dummy_train) 223 | index_test_1_ltr = create_index(one_dim_ltr_test_, dummy_test) 224 | index_train_1_rtl = create_index(one_dim_rtl_train_, dummy_train) 225 | index_test_1_rtl = create_index(one_dim_rtl_test_, dummy_test) 226 | index_train_1_ttb = create_index(one_dim_ttb_train_, dummy_train) 227 | index_test_1_ttb = create_index(one_dim_ttb_test_, dummy_test) 228 | index_train_1_btt = create_index(one_dim_btt_train_, dummy_train) 229 | index_test_1_btt = create_index(one_dim_btt_test_, dummy_test) 230 | 231 | X_train_features_0_ltr_kernel = cuda_kernel_features_train(zero_dim_ltr_train_, index_train_0_ltr,s) 232 | X_train_features_0_rtl_kernel = cuda_kernel_features_train(zero_dim_rtl_train_, index_train_0_rtl,s) 233 | X_train_features_0_ttb_kernel = cuda_kernel_features_train(zero_dim_ttb_train_, index_train_0_ttb,s) 234 | X_train_features_0_btt_kernel = cuda_kernel_features_train(zero_dim_btt_train_, index_train_0_btt,s) 235 | 236 | X_train_features_1_ltr_kernel = cuda_kernel_features_train(one_dim_ltr_train_, index_train_1_ltr,s) 237 | X_train_features_1_rtl_kernel = cuda_kernel_features_train(one_dim_rtl_train_, index_train_1_rtl,s) 238 | X_train_features_1_ttb_kernel = cuda_kernel_features_train(one_dim_ttb_train_, index_train_1_ttb,s) 239 | X_train_features_1_btt_kernel = cuda_kernel_features_train(one_dim_btt_train_, index_train_1_btt,s) 240 | 241 | X_test_features_0_ltr_kernel = cuda_kernel_features_test(zero_dim_ltr_train_, zero_dim_ltr_test_, index_train_0_ltr,index_test_0_ltr,s) 242 | X_test_features_0_rtl_kernel = cuda_kernel_features_test(zero_dim_rtl_train_, zero_dim_rtl_test_, index_train_0_rtl,index_test_0_rtl,s) 243 | X_test_features_0_ttb_kernel = cuda_kernel_features_test(zero_dim_ttb_train_, zero_dim_ttb_test_, index_train_0_ttb,index_test_0_ttb, s) 244 | X_test_features_0_btt_kernel = cuda_kernel_features_test(zero_dim_btt_train_, zero_dim_btt_test_, index_train_0_btt,index_test_0_btt, s) 245 | 246 | X_test_features_1_ltr_kernel = cuda_kernel_features_test(one_dim_ltr_train_, one_dim_ltr_test_, index_train_1_ltr,index_test_1_ltr,s) 247 | X_test_features_1_rtl_kernel = cuda_kernel_features_test(one_dim_rtl_train_, one_dim_rtl_test_, index_train_1_rtl,index_test_1_rtl,s) 248 | X_test_features_1_ttb_kernel = cuda_kernel_features_test(one_dim_ttb_train_, one_dim_ttb_test_, index_train_1_ttb,index_test_1_ttb,s) 249 | X_test_features_1_btt_kernel = cuda_kernel_features_test(one_dim_btt_train_, one_dim_btt_test_, index_train_1_btt,index_test_1_btt,s) 250 | 251 | print("Cuda time: ", time.time()-start) 252 | 253 | train_kernel = X_train_features_1_btt_kernel + X_train_features_1_ttb_kernel + X_train_features_1_rtl_kernel + X_train_features_1_ltr_kernel + X_train_features_0_btt_kernel + X_train_features_0_ttb_kernel + X_train_features_0_rtl_kernel + X_train_features_0_ltr_kernel 254 | test_kernel = X_test_features_1_btt_kernel + X_test_features_1_ttb_kernel + X_test_features_1_rtl_kernel + X_test_features_1_ltr_kernel + X_test_features_0_btt_kernel + X_test_features_0_ttb_kernel + X_test_features_0_rtl_kernel + X_test_features_0_ltr_kernel 255 | 256 | svc_model = NuSVC(kernel='precomputed') 257 | svc_model.fit(train_kernel, y_train) 258 | 259 | kernel_numba_train_accuracy_svm = svc_model.score(train_kernel, y_train) 260 | print("score numba train:", svc_model.score(train_kernel, y_train)) 261 | kernel_numba_test_accuracy_svm = svc_model.score(test_kernel, y_test) 262 | print("score numba test:",svc_model.score(test_kernel, y_test)) 263 | 264 | kernel_numba_train_accuracy_svm = np.array(kernel_numba_train_accuracy_svm) 265 | kernel_numba_train_accuracy_svm = np.reshape(kernel_numba_train_accuracy_svm, newshape=(-1,1)) 266 | kernel_numba_train_mean = np.mean(kernel_numba_train_accuracy_svm) 267 | kernel_numba_train_std = np.std(kernel_numba_train_accuracy_svm) 268 | 269 | kernel_numba_test_accuracy_svm = np.array(kernel_numba_test_accuracy_svm) 270 | kernel_numba_test_accuracy_svm = np.reshape(kernel_numba_test_accuracy_svm, newshape=(-1,1)) 271 | kernel_numba_test_mean = np.mean(kernel_numba_test_accuracy_svm) 272 | kernel_numba_test_std = np.std(kernel_numba_test_accuracy_svm) 273 | 274 | print("kernel_numba Features - svm Model") 275 | print("Mean Training Accuracy: ", kernel_numba_train_mean, "Mean Testing Accuracy: ", kernel_numba_test_mean, "Std Dev Training Accuracy: ", kernel_numba_train_std, "Std Dev Testing Accuracy: ", kernel_numba_test_std) 276 | 277 | 278 | -------------------------------------------------------------------------------- /datasets/mpeg7/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/datasets/mpeg7/.gitignore -------------------------------------------------------------------------------- /datasets/mpeg7/.ipynb_checkpoints/contour_plots-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /datasets/mpeg7/mpeg7.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/datasets/mpeg7/mpeg7.tar.gz -------------------------------------------------------------------------------- /datasets/mpeg7/mpeg7_data_preprocessing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import os 4 | import os.path 5 | import matplotlib.image as mpimg 6 | import cv2 7 | import pickle 8 | from scipy.spatial import distance 9 | import math 10 | 11 | from scipy import sparse 12 | from cv2 import findContours 13 | from scipy.ndimage import binary_erosion, binary_dilation 14 | from scipy.ndimage.morphology import binary_fill_holes 15 | from ripser import ripser 16 | 17 | import json 18 | 19 | np.set_printoptions(precision=2) 20 | 21 | # -------------- IMPORT DATA -------------------------------------------------- 22 | 23 | # Decompres data set, this line is specific for linux! 24 | ### Need to add to check if there is a .gitignore already 25 | if os.path.exists("data/"): 26 | print("Data already unzipped") 27 | else: 28 | os.system('tar -xzvf mpeg7.tar.gz') 29 | os.system('mv mpeg7 data') 30 | os.system('touch data/.gitignore') 31 | os.system('echo "*" >> data/.gitignore') 32 | 33 | # Load after file is unzipped 34 | with open("../config.json") as json_config_file: 35 | filepaths= json.load(json_config_file) 36 | fp = filepaths['fp'] 37 | data = fp + filepaths['mpeg7data'] 38 | pers = fp + filepaths['mpeg7pers'] 39 | contours = fp + filepaths['mpeg7contours'] 40 | os.system('mkdir ' + contours) 41 | os.system('touch contours/.gitignore') 42 | os.system('echo "*" >> contours/.gitignore') 43 | 44 | 45 | # ----------------------------------------------------------------------------- 46 | # Importante notes: 47 | # The implementatio nhere used to compute contours was made by Sarah Tymochko. 48 | 49 | def get_contour(img): 50 | 51 | # Very hacky image processing to get rid of outlying pixels and fill holes in region 52 | img = binary_erosion(img) 53 | img = binary_dilation(img) 54 | img = binary_fill_holes(img)*1 55 | 56 | # Necessary to get data in right format for findContours 57 | img = np.ascontiguousarray(img, dtype=np.uint8) 58 | 59 | # Get the outline of the shapes 60 | # _, contours, _ = findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 61 | contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 62 | 63 | # Reformat contour 64 | pt_cloud = np.array([list(i[0]) for i in contours[0]]) 65 | 66 | return pt_cloud 67 | 68 | def get_dist_curve(pt_cloud): 69 | center = [np.mean(pt_cloud[:,0]), np.mean(pt_cloud[:,1])] 70 | 71 | return np.sqrt([np.sum((pt_cloud[i]-center)**2) for i in range(len(pt_cloud))]) 72 | 73 | def scale_time(df): 74 | max_t = max([len(dlist) for dlist in df['DistCurve']]) 75 | 76 | for i in df.index: 77 | df.loc[i,'t'] = list(np.linspace(0,len(df.loc[i,'DistCurve'])/max_t,len(df.loc[i,'DistCurve']))) 78 | 79 | return df 80 | 81 | l = os.listdir(data) 82 | l.remove('.gitignore') 83 | 84 | point_clouds = [] 85 | distance_curves = [] 86 | 87 | subsampling_countours = 500 88 | 89 | 90 | for file in l: 91 | #for i in range(198,210): 92 | # file = l[i] 93 | filename = os.fsdecode(file) 94 | 95 | img = mpimg.imread(data+filename) 96 | 97 | if len(np.shape(img)) == 3: 98 | img = img[:,:,0] 99 | 100 | pt_cloud = get_contour(img) 101 | pt_cloud_filename = contours + filename[:-3] + "csv" 102 | np.savetxt(pt_cloud_filename, pt_cloud, delimiter = ",") 103 | 104 | if pt_cloud.shape[0] > subsampling_countours: 105 | ind = np.random.choice(np.arange(pt_cloud.shape[0]), subsampling_countours) 106 | ind.sort() 107 | 108 | pt_cloud = pt_cloud[ind,:] 109 | 110 | point_clouds.append(pt_cloud) 111 | 112 | distance_curves.append(get_dist_curve(pt_cloud)) 113 | 114 | # Compute persistent diagrams 115 | diagrams = pd.DataFrame(index=range(len(point_clouds)), columns=['Name', 'Outline', 'DistCurve', 'persistence_outline', 'lower_star_persistence']) 116 | 117 | 118 | for j in range(len(point_clouds)): 119 | print(j) 120 | d = ripser(point_clouds[j], maxdim=1, do_cocycles=False)['dgms'] 121 | 122 | file = l[j] 123 | filename = os.fsdecode(file) 124 | name = filename[:-4] 125 | 126 | # SUBLEVEL SET PERSISTENCE 127 | 128 | N = len(distance_curves[j]) 129 | 130 | I = np.arange(N-1) 131 | J = np.arange(1, N) 132 | V = np.maximum(distance_curves[j][0:-1], distance_curves[j][1::]) 133 | # Add vertex birth times along the diagonal of the distance matrix 134 | I = np.concatenate((I, np.arange(N))) 135 | J = np.concatenate((J, np.arange(N))) 136 | V = np.concatenate((V, distance_curves[j])) 137 | #Create the sparse distance matrix 138 | D = sparse.coo_matrix((V, (I, J)), shape=(N, N)).tocsr() 139 | dgm0 = ripser(D, maxdim=0, distance_matrix=True)['dgms'][0] 140 | 141 | diagrams.loc[j] = [name, point_clouds[j], distance_curves[j], d, dgm0] 142 | 143 | 144 | # Save with pickle 145 | os.system('mkdir ' + pers) 146 | os.system('touch persistence/.gitignore') 147 | os.system('echo "*" >> persistence/.gitignore') 148 | with open(pers + 'diagrams.pickle', 'wb') as handle: 149 | pickle.dump(diagrams, handle, protocol=pickle.HIGHEST_PROTOCOL) -------------------------------------------------------------------------------- /datasets/protein/.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /datasets/protein/.ipynb_checkpoints/protein_charts-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /datasets/protein/protein_data.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/datasets/protein/protein_data.tar.gz -------------------------------------------------------------------------------- /datasets/protein/protein_data_preprocessing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | import pickle 4 | import json 5 | 6 | from ripser import ripser 7 | from persim import plot_diagrams 8 | 9 | # -------------- IMPORT DATA -------------------------------------------------- 10 | 11 | # Importante notes: 12 | # 13 | # This data set was provided to me by Dr. Kelin Xia's lab. It was orignally 14 | # used in A topological approach for protein classification by Zixuan Cang, 15 | # Lin Mu, Kedi Wu, Kristopher Opron, Kelin Xia, and Guo-Wei Wei. 16 | 17 | # ----------------------------------------------------------------------------- 18 | 19 | # Decompres data set, this line is specific for linux! 20 | ### Need to add to check if there is a .gitignore already 21 | os.system('tar -xzvf protein_data.tar.gz') 22 | os.system('mv protein_data data') 23 | os.system('touch data/.gitignore') 24 | os.system('echo "*" >> data/.gitignore') 25 | 26 | # Load after file is unzipped 27 | with open("../config.json") as json_config_file: 28 | filepaths= json.load(json_config_file) 29 | fp = filepaths['fp'] 30 | data = fp + filepaths['proteindata'] 31 | pers = fp + filepaths['proteinpers'] 32 | 33 | # Compute persisitent diagrams 34 | diagrams = [] 35 | 36 | j = 0 37 | for file in os.listdir(data + 'SCOP40mini/'): 38 | filename = os.fsdecode(file) 39 | 40 | open_file = open(data + 'SCOP40mini/' + filename) 41 | lines = open_file.read().splitlines() 42 | 43 | coordinates = [] 44 | 45 | # This loop read the coordinate data in R^3 46 | for i in range(12, len(lines)-3): 47 | line = lines[i] 48 | 49 | if line.split()[0]=='ATOM': 50 | x = float(line[32:38]) 51 | y = float(line[38:46]) 52 | z = float(line[46:54]) 53 | 54 | coordinates.append([x, y, z]) 55 | 56 | 57 | coordinates = np.array(coordinates) 58 | 59 | # Persistent homology computation using ripser 60 | if len(coordinates)>500: 61 | d = ripser(coordinates, maxdim=1, do_cocycles=False, n_perm=500)['dgms'] 62 | else: 63 | d = ripser(coordinates, maxdim=1, do_cocycles=False)['dgms'] 64 | 65 | name = filename[:-4] 66 | 67 | temp = {} 68 | 69 | temp['name'] = name 70 | temp['h0'] = d[0] 71 | temp['h1'] = d[1] 72 | 73 | diagrams.append(temp) 74 | 75 | print(j) 76 | j += 1 77 | 78 | # Save with pickle 79 | os.system('mkdir ' + pers) 80 | os.system('touch persistence/.gitignore') 81 | os.system('echo "*" >> persistence/.gitignore') 82 | with open(pers + 'diagrams.pickle', 'wb') as handle: 83 | pickle.dump(diagrams, handle, protocol=pickle.HIGHEST_PROTOCOL) 84 | 85 | 86 | # IMPORTANT NOTICE: 87 | # 88 | # This script was provided to me by Dr. Zixuan Cang. 89 | # 90 | # It parses the data and creates the training and testing sets as used in A 91 | # topological approach for protein classification by Zixuan Cang, Lin Mu, 92 | # Kedi Wu, Kristopher Opron, Kelin Xia, and Guo-Wei Wei. 93 | 94 | 95 | # 1: +train 2: -train 3: +test 4:-test 96 | # http://pongor.itk.ppke.hu/benchmark/#/Benchmark_data_formats 97 | import numpy as np 98 | import os 99 | 100 | os.system('mkdir data/Index') 101 | 102 | mat = np.empty([1357,55], int) 103 | infile = open('data/CAST.txt') 104 | lines = infile.read().splitlines() 105 | for i in range(len(lines)): 106 | line = lines[i] 107 | a = line[7:].split() 108 | for j in range(55): 109 | mat[i,j] = int(a[j]) 110 | 111 | for i in range(55): 112 | print(i+1) 113 | TrainIndex = [] 114 | TestIndex = [] 115 | TrainLabel = [] 116 | TestLabel = [] 117 | for j in range(1357): 118 | if mat[j,i] == 1 or mat[j,i] == 2: 119 | TrainIndex.append(j) 120 | if mat[j,i] == 1: 121 | TrainLabel.append(1) 122 | elif mat[j,i] == 2: 123 | TrainLabel.append(-1) 124 | if mat[j,i] == 3 or mat[j,i] == 4: 125 | TestIndex.append(j) 126 | if mat[j,i] == 3: 127 | TestLabel.append(1) 128 | elif mat[j,i] == 4: 129 | TestLabel.append(-1) 130 | 131 | TrainIndex = np.asarray(TrainIndex, int) 132 | TestIndex = np.asarray(TestIndex, int) 133 | TrainLabel = np.asarray(TrainLabel, int) 134 | TestLabel = np.asarray(TestLabel, int) 135 | 136 | print(len(TrainIndex), np.sum(TrainLabel), len(TestIndex), np.sum(TestLabel), len(TrainIndex)+len(TestIndex)) 137 | 138 | outfile = open('data/Index/TrainIndex'+str(i+1)+'.npy','wb') 139 | np.save(outfile, TrainIndex) 140 | outfile.close() 141 | outfile = open('data/Index/TrainLabel'+str(i+1)+'.npy','wb') 142 | np.save(outfile, TrainLabel) 143 | outfile.close() 144 | outfile = open('data/Index/TestIndex'+str(i+1)+'.npy','wb') 145 | np.save(outfile, TestIndex) 146 | outfile.close() 147 | outfile = open('data/Index/TestLabel'+str(i+1)+'.npy','wb') 148 | np.save(outfile, TestLabel) 149 | outfile.close() 150 | -------------------------------------------------------------------------------- /datasets/shrec14/shrec14.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/datasets/shrec14/shrec14.tar.gz -------------------------------------------------------------------------------- /datasets/shrec14/shrec14_data_preprocessing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import os 4 | import json 5 | 6 | np.set_printoptions(precision=2) 7 | 8 | # -------------- IMPORT DATA -------------------------------------------------- 9 | 10 | # Importante notes: 11 | # This data set was provided to me by Dr. Elizabeth Munch's lab. 12 | # This data set was originally provided by Dr. Ulrich Bauer and it corresponds 13 | # the data used in A Stable Multi-Scale Kernel for Topological Machine Learnin 14 | # by Jan Reininghaus, Stefan Huber, Ulrich Bauer, Roland Kwit 15 | 16 | # ----------------------------------------------------------------------------- 17 | 18 | # Decompres data set, this line is specific for linux! 19 | os.system('tar -xzvf shrec14.tar.gz') 20 | os.system('mv shrec14 data') 21 | os.system('touch data/.gitignore') 22 | os.system('echo "*" >> data/.gitignore') 23 | 24 | Data = pd.read_csv('data/Uli_data.csv') 25 | 26 | # Code to reshape the data in the groupby command below 27 | def reshapeVec(g): 28 | A = np.array([g.dim,g.birth,g.death]) 29 | A = A.T 30 | return A 31 | 32 | DgmsDF = Data.groupby(['freq', 'trial']).apply(reshapeVec) 33 | DgmsDF = DgmsDF.reset_index() 34 | DgmsDF = DgmsDF.rename(columns = {0:'CollectedDgm'}) 35 | 36 | def getDgm(A, dim = 0): 37 | if type(dim) != str: 38 | if dim == 0: 39 | A = A[np.where(np.logical_or(A[:,0] == dim, A[:,0] == -1))[0],1:] 40 | 41 | if dim == 1: 42 | A = A[np.where(np.logical_or(A[:,0] == dim, A[:,0] == -2))[0],1:] 43 | 44 | return(A) 45 | 46 | DgmsDF['Dgm1'] = DgmsDF.CollectedDgm.apply(lambda x: getDgm(x, dim = 1)) 47 | DgmsDF['Dgm0'] = DgmsDF.CollectedDgm.apply(lambda x: getDgm(x, dim = 0)) 48 | 49 | 50 | def label(index): 51 | if 0 <= index <= 19: 52 | return 'male_neutral' 53 | elif 20<= index <=39: 54 | return 'male_bodybuilder' 55 | elif 40<= index <=59: 56 | return 'male_fat' 57 | elif 60<= index <=79: 58 | return 'male_thin' 59 | elif 80<= index <=99: 60 | return 'male_average' 61 | elif 100<= index <=119: 62 | return 'female_neutral' 63 | elif 120<= index <=139: 64 | return 'female_bodybuilder' 65 | elif 140<= index <=159: 66 | return 'female_fat' 67 | elif 160<= index <=179: 68 | return 'female_thin' 69 | elif 180<= index <=199: 70 | return 'female_average' 71 | elif 200<= index <=219: 72 | return 'child_neutral' 73 | elif 220<= index <=239: 74 | return 'child_bodybuilder' 75 | elif 240<= index <=259: 76 | return 'child_fat' 77 | elif 260<= index <=279: 78 | return 'child_thin' 79 | elif 280<= index <=299: 80 | return 'child_average' 81 | else: 82 | print('What are you giving me?') 83 | 84 | DgmsDF['TrainingLabel'] = DgmsDF.freq.apply(label) 85 | DgmsDF= DgmsDF.sample(frac=1) 86 | 87 | # This part of the code is just testing the correct readin gof the data 88 | 89 | for i in range(1,11): 90 | 91 | freq = i 92 | 93 | SampleDF = DgmsDF[DgmsDF.trial == freq].sample(frac=1) 94 | 95 | print(SampleDF.head(5)) 96 | -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 2d201253a4f5482e65e583586e8ed0ad 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/.doctrees/datasets.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.doctrees/datasets.doctree -------------------------------------------------------------------------------- /docs/.doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/.doctrees/features.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.doctrees/features.doctree -------------------------------------------------------------------------------- /docs/.doctrees/ham10000.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.doctrees/ham10000.doctree -------------------------------------------------------------------------------- /docs/.doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.doctrees/index.doctree -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/.nojekyll -------------------------------------------------------------------------------- /docs/_images/balls.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/_images/balls.gif -------------------------------------------------------------------------------- /docs/_sources/datasets.rst.txt: -------------------------------------------------------------------------------- 1 | Datasets 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | HAM10000 8 | -------------------------------------------------------------------------------- /docs/_sources/features.rst.txt: -------------------------------------------------------------------------------- 1 | Features 2 | ******************* 3 | -------------------------------------------------------------------------------- /docs/_sources/ham10000.rst.txt: -------------------------------------------------------------------------------- 1 | HAM10000 2 | ******************* 3 | -------------------------------------------------------------------------------- /docs/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. Machine Learning Library for TDA documentation master file, created by 2 | sphinx-quickstart on Fri Aug 5 12:22:23 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Machine Learning Library for TDA's documentation! 7 | ============================================================ 8 | 9 | Welcome! You're on the associated page for our repository for our paper, `A Comparative Study of Machine Learning Methods for Persistence Diagrams `_ 10 | 11 | .. image:: _figures/balls.gif 12 | :width: 600 px 13 | 14 | Table of Contents 15 | ******************* 16 | 17 | .. toctree:: 18 | :maxdepth: 4 19 | :numbered: 20 | 21 | Featurization 22 | Datasets 23 | -------------------------------------------------------------------------------- /docs/_static/_sphinx_javascript_frameworks_compat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * _sphinx_javascript_frameworks_compat.js 3 | * ~~~~~~~~~~ 4 | * 5 | * Compatability shim for jQuery and underscores.js. 6 | * 7 | * WILL BE REMOVED IN Sphinx 6.0 8 | * xref RemovedInSphinx60Warning 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | 18 | /** 19 | * small helper function to urldecode strings 20 | * 21 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL 22 | */ 23 | jQuery.urldecode = function(x) { 24 | if (!x) { 25 | return x 26 | } 27 | return decodeURIComponent(x.replace(/\+/g, ' ')); 28 | }; 29 | 30 | /** 31 | * small helper function to urlencode strings 32 | */ 33 | jQuery.urlencode = encodeURIComponent; 34 | 35 | /** 36 | * This function returns the parsed url parameters of the 37 | * current request. Multiple values per key are supported, 38 | * it will always return arrays of strings for the value parts. 39 | */ 40 | jQuery.getQueryParameters = function(s) { 41 | if (typeof s === 'undefined') 42 | s = document.location.search; 43 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 44 | var result = {}; 45 | for (var i = 0; i < parts.length; i++) { 46 | var tmp = parts[i].split('=', 2); 47 | var key = jQuery.urldecode(tmp[0]); 48 | var value = jQuery.urldecode(tmp[1]); 49 | if (key in result) 50 | result[key].push(value); 51 | else 52 | result[key] = [value]; 53 | } 54 | return result; 55 | }; 56 | 57 | /** 58 | * highlight a given string on a jquery object by wrapping it in 59 | * span elements with the given class name. 60 | */ 61 | jQuery.fn.highlightText = function(text, className) { 62 | function highlight(node, addItems) { 63 | if (node.nodeType === 3) { 64 | var val = node.nodeValue; 65 | var pos = val.toLowerCase().indexOf(text); 66 | if (pos >= 0 && 67 | !jQuery(node.parentNode).hasClass(className) && 68 | !jQuery(node.parentNode).hasClass("nohighlight")) { 69 | var span; 70 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 71 | if (isInSVG) { 72 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 73 | } else { 74 | span = document.createElement("span"); 75 | span.className = className; 76 | } 77 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 78 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 79 | document.createTextNode(val.substr(pos + text.length)), 80 | node.nextSibling)); 81 | node.nodeValue = val.substr(0, pos); 82 | if (isInSVG) { 83 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 84 | var bbox = node.parentElement.getBBox(); 85 | rect.x.baseVal.value = bbox.x; 86 | rect.y.baseVal.value = bbox.y; 87 | rect.width.baseVal.value = bbox.width; 88 | rect.height.baseVal.value = bbox.height; 89 | rect.setAttribute('class', className); 90 | addItems.push({ 91 | "parent": node.parentNode, 92 | "target": rect}); 93 | } 94 | } 95 | } 96 | else if (!jQuery(node).is("button, select, textarea")) { 97 | jQuery.each(node.childNodes, function() { 98 | highlight(this, addItems); 99 | }); 100 | } 101 | } 102 | var addItems = []; 103 | var result = this.each(function() { 104 | highlight(this, addItems); 105 | }); 106 | for (var i = 0; i < addItems.length; ++i) { 107 | jQuery(addItems[i].parent).before(addItems[i].target); 108 | } 109 | return result; 110 | }; 111 | 112 | /* 113 | * backward compatibility for jQuery.browser 114 | * This will be supported until firefox bug is fixed. 115 | */ 116 | if (!jQuery.browser) { 117 | jQuery.uaMatch = function(ua) { 118 | ua = ua.toLowerCase(); 119 | 120 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 121 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 122 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 123 | /(msie) ([\w.]+)/.exec(ua) || 124 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 125 | []; 126 | 127 | return { 128 | browser: match[ 1 ] || "", 129 | version: match[ 2 ] || "0" 130 | }; 131 | }; 132 | jQuery.browser = {}; 133 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 134 | } 135 | -------------------------------------------------------------------------------- /docs/_static/alabaster.css: -------------------------------------------------------------------------------- 1 | @import url("basic.css"); 2 | 3 | /* -- page layout ----------------------------------------------------------- */ 4 | 5 | body { 6 | font-family: Georgia, serif; 7 | font-size: 17px; 8 | background-color: #fff; 9 | color: #000; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | 15 | div.document { 16 | width: 940px; 17 | margin: 30px auto 0 auto; 18 | } 19 | 20 | div.documentwrapper { 21 | float: left; 22 | width: 100%; 23 | } 24 | 25 | div.bodywrapper { 26 | margin: 0 0 0 220px; 27 | } 28 | 29 | div.sphinxsidebar { 30 | width: 220px; 31 | font-size: 14px; 32 | line-height: 1.5; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #fff; 41 | color: #3E4349; 42 | padding: 0 30px 0 30px; 43 | } 44 | 45 | div.body > .section { 46 | text-align: left; 47 | } 48 | 49 | div.footer { 50 | width: 940px; 51 | margin: 20px auto 30px auto; 52 | font-size: 14px; 53 | color: #888; 54 | text-align: right; 55 | } 56 | 57 | div.footer a { 58 | color: #888; 59 | } 60 | 61 | p.caption { 62 | font-family: inherit; 63 | font-size: inherit; 64 | } 65 | 66 | 67 | div.relations { 68 | display: none; 69 | } 70 | 71 | 72 | div.sphinxsidebar a { 73 | color: #444; 74 | text-decoration: none; 75 | border-bottom: 1px dotted #999; 76 | } 77 | 78 | div.sphinxsidebar a:hover { 79 | border-bottom: 1px solid #999; 80 | } 81 | 82 | div.sphinxsidebarwrapper { 83 | padding: 18px 10px; 84 | } 85 | 86 | div.sphinxsidebarwrapper p.logo { 87 | padding: 0; 88 | margin: -10px 0 0 0px; 89 | text-align: center; 90 | } 91 | 92 | div.sphinxsidebarwrapper h1.logo { 93 | margin-top: -10px; 94 | text-align: center; 95 | margin-bottom: 5px; 96 | text-align: left; 97 | } 98 | 99 | div.sphinxsidebarwrapper h1.logo-name { 100 | margin-top: 0px; 101 | } 102 | 103 | div.sphinxsidebarwrapper p.blurb { 104 | margin-top: 0; 105 | font-style: normal; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: Georgia, serif; 111 | color: #444; 112 | font-size: 24px; 113 | font-weight: normal; 114 | margin: 0 0 5px 0; 115 | padding: 0; 116 | } 117 | 118 | div.sphinxsidebar h4 { 119 | font-size: 20px; 120 | } 121 | 122 | div.sphinxsidebar h3 a { 123 | color: #444; 124 | } 125 | 126 | div.sphinxsidebar p.logo a, 127 | div.sphinxsidebar h3 a, 128 | div.sphinxsidebar p.logo a:hover, 129 | div.sphinxsidebar h3 a:hover { 130 | border: none; 131 | } 132 | 133 | div.sphinxsidebar p { 134 | color: #555; 135 | margin: 10px 0; 136 | } 137 | 138 | div.sphinxsidebar ul { 139 | margin: 10px 0; 140 | padding: 0; 141 | color: #000; 142 | } 143 | 144 | div.sphinxsidebar ul li.toctree-l1 > a { 145 | font-size: 120%; 146 | } 147 | 148 | div.sphinxsidebar ul li.toctree-l2 > a { 149 | font-size: 110%; 150 | } 151 | 152 | div.sphinxsidebar input { 153 | border: 1px solid #CCC; 154 | font-family: Georgia, serif; 155 | font-size: 1em; 156 | } 157 | 158 | div.sphinxsidebar hr { 159 | border: none; 160 | height: 1px; 161 | color: #AAA; 162 | background: #AAA; 163 | 164 | text-align: left; 165 | margin-left: 0; 166 | width: 50%; 167 | } 168 | 169 | div.sphinxsidebar .badge { 170 | border-bottom: none; 171 | } 172 | 173 | div.sphinxsidebar .badge:hover { 174 | border-bottom: none; 175 | } 176 | 177 | /* To address an issue with donation coming after search */ 178 | div.sphinxsidebar h3.donation { 179 | margin-top: 10px; 180 | } 181 | 182 | /* -- body styles ----------------------------------------------------------- */ 183 | 184 | a { 185 | color: #004B6B; 186 | text-decoration: underline; 187 | } 188 | 189 | a:hover { 190 | color: #6D4100; 191 | text-decoration: underline; 192 | } 193 | 194 | div.body h1, 195 | div.body h2, 196 | div.body h3, 197 | div.body h4, 198 | div.body h5, 199 | div.body h6 { 200 | font-family: Georgia, serif; 201 | font-weight: normal; 202 | margin: 30px 0px 10px 0px; 203 | padding: 0; 204 | } 205 | 206 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 207 | div.body h2 { font-size: 180%; } 208 | div.body h3 { font-size: 150%; } 209 | div.body h4 { font-size: 130%; } 210 | div.body h5 { font-size: 100%; } 211 | div.body h6 { font-size: 100%; } 212 | 213 | a.headerlink { 214 | color: #DDD; 215 | padding: 0 4px; 216 | text-decoration: none; 217 | } 218 | 219 | a.headerlink:hover { 220 | color: #444; 221 | background: #EAEAEA; 222 | } 223 | 224 | div.body p, div.body dd, div.body li { 225 | line-height: 1.4em; 226 | } 227 | 228 | div.admonition { 229 | margin: 20px 0px; 230 | padding: 10px 30px; 231 | background-color: #EEE; 232 | border: 1px solid #CCC; 233 | } 234 | 235 | div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { 236 | background-color: #FBFBFB; 237 | border-bottom: 1px solid #fafafa; 238 | } 239 | 240 | div.admonition p.admonition-title { 241 | font-family: Georgia, serif; 242 | font-weight: normal; 243 | font-size: 24px; 244 | margin: 0 0 10px 0; 245 | padding: 0; 246 | line-height: 1; 247 | } 248 | 249 | div.admonition p.last { 250 | margin-bottom: 0; 251 | } 252 | 253 | div.highlight { 254 | background-color: #fff; 255 | } 256 | 257 | dt:target, .highlight { 258 | background: #FAF3E8; 259 | } 260 | 261 | div.warning { 262 | background-color: #FCC; 263 | border: 1px solid #FAA; 264 | } 265 | 266 | div.danger { 267 | background-color: #FCC; 268 | border: 1px solid #FAA; 269 | -moz-box-shadow: 2px 2px 4px #D52C2C; 270 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 271 | box-shadow: 2px 2px 4px #D52C2C; 272 | } 273 | 274 | div.error { 275 | background-color: #FCC; 276 | border: 1px solid #FAA; 277 | -moz-box-shadow: 2px 2px 4px #D52C2C; 278 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 279 | box-shadow: 2px 2px 4px #D52C2C; 280 | } 281 | 282 | div.caution { 283 | background-color: #FCC; 284 | border: 1px solid #FAA; 285 | } 286 | 287 | div.attention { 288 | background-color: #FCC; 289 | border: 1px solid #FAA; 290 | } 291 | 292 | div.important { 293 | background-color: #EEE; 294 | border: 1px solid #CCC; 295 | } 296 | 297 | div.note { 298 | background-color: #EEE; 299 | border: 1px solid #CCC; 300 | } 301 | 302 | div.tip { 303 | background-color: #EEE; 304 | border: 1px solid #CCC; 305 | } 306 | 307 | div.hint { 308 | background-color: #EEE; 309 | border: 1px solid #CCC; 310 | } 311 | 312 | div.seealso { 313 | background-color: #EEE; 314 | border: 1px solid #CCC; 315 | } 316 | 317 | div.topic { 318 | background-color: #EEE; 319 | } 320 | 321 | p.admonition-title { 322 | display: inline; 323 | } 324 | 325 | p.admonition-title:after { 326 | content: ":"; 327 | } 328 | 329 | pre, tt, code { 330 | font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 331 | font-size: 0.9em; 332 | } 333 | 334 | .hll { 335 | background-color: #FFC; 336 | margin: 0 -12px; 337 | padding: 0 12px; 338 | display: block; 339 | } 340 | 341 | img.screenshot { 342 | } 343 | 344 | tt.descname, tt.descclassname, code.descname, code.descclassname { 345 | font-size: 0.95em; 346 | } 347 | 348 | tt.descname, code.descname { 349 | padding-right: 0.08em; 350 | } 351 | 352 | img.screenshot { 353 | -moz-box-shadow: 2px 2px 4px #EEE; 354 | -webkit-box-shadow: 2px 2px 4px #EEE; 355 | box-shadow: 2px 2px 4px #EEE; 356 | } 357 | 358 | table.docutils { 359 | border: 1px solid #888; 360 | -moz-box-shadow: 2px 2px 4px #EEE; 361 | -webkit-box-shadow: 2px 2px 4px #EEE; 362 | box-shadow: 2px 2px 4px #EEE; 363 | } 364 | 365 | table.docutils td, table.docutils th { 366 | border: 1px solid #888; 367 | padding: 0.25em 0.7em; 368 | } 369 | 370 | table.field-list, table.footnote { 371 | border: none; 372 | -moz-box-shadow: none; 373 | -webkit-box-shadow: none; 374 | box-shadow: none; 375 | } 376 | 377 | table.footnote { 378 | margin: 15px 0; 379 | width: 100%; 380 | border: 1px solid #EEE; 381 | background: #FDFDFD; 382 | font-size: 0.9em; 383 | } 384 | 385 | table.footnote + table.footnote { 386 | margin-top: -15px; 387 | border-top: none; 388 | } 389 | 390 | table.field-list th { 391 | padding: 0 0.8em 0 0; 392 | } 393 | 394 | table.field-list td { 395 | padding: 0; 396 | } 397 | 398 | table.field-list p { 399 | margin-bottom: 0.8em; 400 | } 401 | 402 | /* Cloned from 403 | * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 404 | */ 405 | .field-name { 406 | -moz-hyphens: manual; 407 | -ms-hyphens: manual; 408 | -webkit-hyphens: manual; 409 | hyphens: manual; 410 | } 411 | 412 | table.footnote td.label { 413 | width: .1px; 414 | padding: 0.3em 0 0.3em 0.5em; 415 | } 416 | 417 | table.footnote td { 418 | padding: 0.3em 0.5em; 419 | } 420 | 421 | dl { 422 | margin: 0; 423 | padding: 0; 424 | } 425 | 426 | dl dd { 427 | margin-left: 30px; 428 | } 429 | 430 | blockquote { 431 | margin: 0 0 0 30px; 432 | padding: 0; 433 | } 434 | 435 | ul, ol { 436 | /* Matches the 30px from the narrow-screen "li > ul" selector below */ 437 | margin: 10px 0 10px 30px; 438 | padding: 0; 439 | } 440 | 441 | pre { 442 | background: #EEE; 443 | padding: 7px 30px; 444 | margin: 15px 0px; 445 | line-height: 1.3em; 446 | } 447 | 448 | div.viewcode-block:target { 449 | background: #ffd; 450 | } 451 | 452 | dl pre, blockquote pre, li pre { 453 | margin-left: 0; 454 | padding-left: 30px; 455 | } 456 | 457 | tt, code { 458 | background-color: #ecf0f3; 459 | color: #222; 460 | /* padding: 1px 2px; */ 461 | } 462 | 463 | tt.xref, code.xref, a tt { 464 | background-color: #FBFBFB; 465 | border-bottom: 1px solid #fff; 466 | } 467 | 468 | a.reference { 469 | text-decoration: none; 470 | border-bottom: 1px dotted #004B6B; 471 | } 472 | 473 | /* Don't put an underline on images */ 474 | a.image-reference, a.image-reference:hover { 475 | border-bottom: none; 476 | } 477 | 478 | a.reference:hover { 479 | border-bottom: 1px solid #6D4100; 480 | } 481 | 482 | a.footnote-reference { 483 | text-decoration: none; 484 | font-size: 0.7em; 485 | vertical-align: top; 486 | border-bottom: 1px dotted #004B6B; 487 | } 488 | 489 | a.footnote-reference:hover { 490 | border-bottom: 1px solid #6D4100; 491 | } 492 | 493 | a:hover tt, a:hover code { 494 | background: #EEE; 495 | } 496 | 497 | 498 | @media screen and (max-width: 870px) { 499 | 500 | div.sphinxsidebar { 501 | display: none; 502 | } 503 | 504 | div.document { 505 | width: 100%; 506 | 507 | } 508 | 509 | div.documentwrapper { 510 | margin-left: 0; 511 | margin-top: 0; 512 | margin-right: 0; 513 | margin-bottom: 0; 514 | } 515 | 516 | div.bodywrapper { 517 | margin-top: 0; 518 | margin-right: 0; 519 | margin-bottom: 0; 520 | margin-left: 0; 521 | } 522 | 523 | ul { 524 | margin-left: 0; 525 | } 526 | 527 | li > ul { 528 | /* Matches the 30px from the "ul, ol" selector above */ 529 | margin-left: 30px; 530 | } 531 | 532 | .document { 533 | width: auto; 534 | } 535 | 536 | .footer { 537 | width: auto; 538 | } 539 | 540 | .bodywrapper { 541 | margin: 0; 542 | } 543 | 544 | .footer { 545 | width: auto; 546 | } 547 | 548 | .github { 549 | display: none; 550 | } 551 | 552 | 553 | 554 | } 555 | 556 | 557 | 558 | @media screen and (max-width: 875px) { 559 | 560 | body { 561 | margin: 0; 562 | padding: 20px 30px; 563 | } 564 | 565 | div.documentwrapper { 566 | float: none; 567 | background: #fff; 568 | } 569 | 570 | div.sphinxsidebar { 571 | display: block; 572 | float: none; 573 | width: 102.5%; 574 | margin: 50px -30px -20px -30px; 575 | padding: 10px 20px; 576 | background: #333; 577 | color: #FFF; 578 | } 579 | 580 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 581 | div.sphinxsidebar h3 a { 582 | color: #fff; 583 | } 584 | 585 | div.sphinxsidebar a { 586 | color: #AAA; 587 | } 588 | 589 | div.sphinxsidebar p.logo { 590 | display: none; 591 | } 592 | 593 | div.document { 594 | width: 100%; 595 | margin: 0; 596 | } 597 | 598 | div.footer { 599 | display: none; 600 | } 601 | 602 | div.bodywrapper { 603 | margin: 0; 604 | } 605 | 606 | div.body { 607 | min-height: 0; 608 | padding: 0; 609 | } 610 | 611 | .rtd_doc_footer { 612 | display: none; 613 | } 614 | 615 | .document { 616 | width: auto; 617 | } 618 | 619 | .footer { 620 | width: auto; 621 | } 622 | 623 | .footer { 624 | width: auto; 625 | } 626 | 627 | .github { 628 | display: none; 629 | } 630 | } 631 | 632 | 633 | /* misc. */ 634 | 635 | .revsys-inline { 636 | display: none!important; 637 | } 638 | 639 | /* Make nested-list/multi-paragraph items look better in Releases changelog 640 | * pages. Without this, docutils' magical list fuckery causes inconsistent 641 | * formatting between different release sub-lists. 642 | */ 643 | div#changelog > div.section > ul > li > p:only-child { 644 | margin-bottom: 0; 645 | } 646 | 647 | /* Hide fugly table cell borders in ..bibliography:: directive output */ 648 | table.docutils.citation, table.docutils.citation td, table.docutils.citation th { 649 | border: none; 650 | /* Below needed in some edge cases; if not applied, bottom shadows appear */ 651 | -moz-box-shadow: none; 652 | -webkit-box-shadow: none; 653 | box-shadow: none; 654 | } 655 | 656 | 657 | /* relbar */ 658 | 659 | .related { 660 | line-height: 30px; 661 | width: 100%; 662 | font-size: 0.9rem; 663 | } 664 | 665 | .related.top { 666 | border-bottom: 1px solid #EEE; 667 | margin-bottom: 20px; 668 | } 669 | 670 | .related.bottom { 671 | border-top: 1px solid #EEE; 672 | } 673 | 674 | .related ul { 675 | padding: 0; 676 | margin: 0; 677 | list-style: none; 678 | } 679 | 680 | .related li { 681 | display: inline; 682 | } 683 | 684 | nav#rellinks { 685 | float: right; 686 | } 687 | 688 | nav#rellinks li+li:before { 689 | content: "|"; 690 | } 691 | 692 | nav#breadcrumbs li+li:before { 693 | content: "\00BB"; 694 | } 695 | 696 | /* Hide certain items when printing */ 697 | @media print { 698 | div.related { 699 | display: none; 700 | } 701 | } -------------------------------------------------------------------------------- /docs/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /docs/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Base JavaScript utilities for all Sphinx HTML documentation. 6 | * 7 | * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | "use strict"; 12 | 13 | const _ready = (callback) => { 14 | if (document.readyState !== "loading") { 15 | callback(); 16 | } else { 17 | document.addEventListener("DOMContentLoaded", callback); 18 | } 19 | }; 20 | 21 | /** 22 | * highlight a given string on a node by wrapping it in 23 | * span elements with the given class name. 24 | */ 25 | const _highlight = (node, addItems, text, className) => { 26 | if (node.nodeType === Node.TEXT_NODE) { 27 | const val = node.nodeValue; 28 | const parent = node.parentNode; 29 | const pos = val.toLowerCase().indexOf(text); 30 | if ( 31 | pos >= 0 && 32 | !parent.classList.contains(className) && 33 | !parent.classList.contains("nohighlight") 34 | ) { 35 | let span; 36 | 37 | const closestNode = parent.closest("body, svg, foreignObject"); 38 | const isInSVG = closestNode && closestNode.matches("svg"); 39 | if (isInSVG) { 40 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 41 | } else { 42 | span = document.createElement("span"); 43 | span.classList.add(className); 44 | } 45 | 46 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 47 | parent.insertBefore( 48 | span, 49 | parent.insertBefore( 50 | document.createTextNode(val.substr(pos + text.length)), 51 | node.nextSibling 52 | ) 53 | ); 54 | node.nodeValue = val.substr(0, pos); 55 | 56 | if (isInSVG) { 57 | const rect = document.createElementNS( 58 | "http://www.w3.org/2000/svg", 59 | "rect" 60 | ); 61 | const bbox = parent.getBBox(); 62 | rect.x.baseVal.value = bbox.x; 63 | rect.y.baseVal.value = bbox.y; 64 | rect.width.baseVal.value = bbox.width; 65 | rect.height.baseVal.value = bbox.height; 66 | rect.setAttribute("class", className); 67 | addItems.push({ parent: parent, target: rect }); 68 | } 69 | } 70 | } else if (node.matches && !node.matches("button, select, textarea")) { 71 | node.childNodes.forEach((el) => _highlight(el, addItems, text, className)); 72 | } 73 | }; 74 | const _highlightText = (thisNode, text, className) => { 75 | let addItems = []; 76 | _highlight(thisNode, addItems, text, className); 77 | addItems.forEach((obj) => 78 | obj.parent.insertAdjacentElement("beforebegin", obj.target) 79 | ); 80 | }; 81 | 82 | /** 83 | * Small JavaScript module for the documentation. 84 | */ 85 | const Documentation = { 86 | init: () => { 87 | Documentation.highlightSearchWords(); 88 | Documentation.initDomainIndexTable(); 89 | Documentation.initOnKeyListeners(); 90 | }, 91 | 92 | /** 93 | * i18n support 94 | */ 95 | TRANSLATIONS: {}, 96 | PLURAL_EXPR: (n) => (n === 1 ? 0 : 1), 97 | LOCALE: "unknown", 98 | 99 | // gettext and ngettext don't access this so that the functions 100 | // can safely bound to a different name (_ = Documentation.gettext) 101 | gettext: (string) => { 102 | const translated = Documentation.TRANSLATIONS[string]; 103 | switch (typeof translated) { 104 | case "undefined": 105 | return string; // no translation 106 | case "string": 107 | return translated; // translation exists 108 | default: 109 | return translated[0]; // (singular, plural) translation tuple exists 110 | } 111 | }, 112 | 113 | ngettext: (singular, plural, n) => { 114 | const translated = Documentation.TRANSLATIONS[singular]; 115 | if (typeof translated !== "undefined") 116 | return translated[Documentation.PLURAL_EXPR(n)]; 117 | return n === 1 ? singular : plural; 118 | }, 119 | 120 | addTranslations: (catalog) => { 121 | Object.assign(Documentation.TRANSLATIONS, catalog.messages); 122 | Documentation.PLURAL_EXPR = new Function( 123 | "n", 124 | `return (${catalog.plural_expr})` 125 | ); 126 | Documentation.LOCALE = catalog.locale; 127 | }, 128 | 129 | /** 130 | * highlight the search words provided in the url in the text 131 | */ 132 | highlightSearchWords: () => { 133 | const highlight = 134 | new URLSearchParams(window.location.search).get("highlight") || ""; 135 | const terms = highlight.toLowerCase().split(/\s+/).filter(x => x); 136 | if (terms.length === 0) return; // nothing to do 137 | 138 | // There should never be more than one element matching "div.body" 139 | const divBody = document.querySelectorAll("div.body"); 140 | const body = divBody.length ? divBody[0] : document.querySelector("body"); 141 | window.setTimeout(() => { 142 | terms.forEach((term) => _highlightText(body, term, "highlighted")); 143 | }, 10); 144 | 145 | const searchBox = document.getElementById("searchbox"); 146 | if (searchBox === null) return; 147 | searchBox.appendChild( 148 | document 149 | .createRange() 150 | .createContextualFragment( 151 | '" 155 | ) 156 | ); 157 | }, 158 | 159 | /** 160 | * helper function to hide the search marks again 161 | */ 162 | hideSearchWords: () => { 163 | document 164 | .querySelectorAll("#searchbox .highlight-link") 165 | .forEach((el) => el.remove()); 166 | document 167 | .querySelectorAll("span.highlighted") 168 | .forEach((el) => el.classList.remove("highlighted")); 169 | const url = new URL(window.location); 170 | url.searchParams.delete("highlight"); 171 | window.history.replaceState({}, "", url); 172 | }, 173 | 174 | /** 175 | * helper function to focus on search bar 176 | */ 177 | focusSearchBar: () => { 178 | document.querySelectorAll("input[name=q]")[0]?.focus(); 179 | }, 180 | 181 | /** 182 | * Initialise the domain index toggle buttons 183 | */ 184 | initDomainIndexTable: () => { 185 | const toggler = (el) => { 186 | const idNumber = el.id.substr(7); 187 | const toggledRows = document.querySelectorAll(`tr.cg-${idNumber}`); 188 | if (el.src.substr(-9) === "minus.png") { 189 | el.src = `${el.src.substr(0, el.src.length - 9)}plus.png`; 190 | toggledRows.forEach((el) => (el.style.display = "none")); 191 | } else { 192 | el.src = `${el.src.substr(0, el.src.length - 8)}minus.png`; 193 | toggledRows.forEach((el) => (el.style.display = "")); 194 | } 195 | }; 196 | 197 | const togglerElements = document.querySelectorAll("img.toggler"); 198 | togglerElements.forEach((el) => 199 | el.addEventListener("click", (event) => toggler(event.currentTarget)) 200 | ); 201 | togglerElements.forEach((el) => (el.style.display = "")); 202 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) togglerElements.forEach(toggler); 203 | }, 204 | 205 | initOnKeyListeners: () => { 206 | // only install a listener if it is really needed 207 | if ( 208 | !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS && 209 | !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS 210 | ) 211 | return; 212 | 213 | const blacklistedElements = new Set([ 214 | "TEXTAREA", 215 | "INPUT", 216 | "SELECT", 217 | "BUTTON", 218 | ]); 219 | document.addEventListener("keydown", (event) => { 220 | if (blacklistedElements.has(document.activeElement.tagName)) return; // bail for input elements 221 | if (event.altKey || event.ctrlKey || event.metaKey) return; // bail with special keys 222 | 223 | if (!event.shiftKey) { 224 | switch (event.key) { 225 | case "ArrowLeft": 226 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 227 | 228 | const prevLink = document.querySelector('link[rel="prev"]'); 229 | if (prevLink && prevLink.href) { 230 | window.location.href = prevLink.href; 231 | event.preventDefault(); 232 | } 233 | break; 234 | case "ArrowRight": 235 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 236 | 237 | const nextLink = document.querySelector('link[rel="next"]'); 238 | if (nextLink && nextLink.href) { 239 | window.location.href = nextLink.href; 240 | event.preventDefault(); 241 | } 242 | break; 243 | case "Escape": 244 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 245 | Documentation.hideSearchWords(); 246 | event.preventDefault(); 247 | } 248 | } 249 | 250 | // some keyboard layouts may need Shift to get / 251 | switch (event.key) { 252 | case "/": 253 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 254 | Documentation.focusSearchBar(); 255 | event.preventDefault(); 256 | } 257 | }); 258 | }, 259 | }; 260 | 261 | // quick alias for translations 262 | const _ = Documentation.gettext; 263 | 264 | _ready(Documentation.init); 265 | -------------------------------------------------------------------------------- /docs/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '.1', 4 | LANGUAGE: 'en', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false, 12 | SHOW_SEARCH_SUMMARY: true, 13 | ENABLE_SEARCH_SHORTCUTS: true, 14 | }; -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; 14 | 15 | 16 | /* Non-minified version is copied as a separate JS file, is available */ 17 | 18 | /** 19 | * Porter Stemmer 20 | */ 21 | var Stemmer = function() { 22 | 23 | var step2list = { 24 | ational: 'ate', 25 | tional: 'tion', 26 | enci: 'ence', 27 | anci: 'ance', 28 | izer: 'ize', 29 | bli: 'ble', 30 | alli: 'al', 31 | entli: 'ent', 32 | eli: 'e', 33 | ousli: 'ous', 34 | ization: 'ize', 35 | ation: 'ate', 36 | ator: 'ate', 37 | alism: 'al', 38 | iveness: 'ive', 39 | fulness: 'ful', 40 | ousness: 'ous', 41 | aliti: 'al', 42 | iviti: 'ive', 43 | biliti: 'ble', 44 | logi: 'log' 45 | }; 46 | 47 | var step3list = { 48 | icate: 'ic', 49 | ative: '', 50 | alize: 'al', 51 | iciti: 'ic', 52 | ical: 'ic', 53 | ful: '', 54 | ness: '' 55 | }; 56 | 57 | var c = "[^aeiou]"; // consonant 58 | var v = "[aeiouy]"; // vowel 59 | var C = c + "[^aeiouy]*"; // consonant sequence 60 | var V = v + "[aeiou]*"; // vowel sequence 61 | 62 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /docs/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/_static/minus.png -------------------------------------------------------------------------------- /docs/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/_static/plus.png -------------------------------------------------------------------------------- /docs/_static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #f8f8f8; } 8 | .highlight .c { color: #8f5902; font-style: italic } /* Comment */ 9 | .highlight .err { color: #a40000; border: 1px solid #ef2929 } /* Error */ 10 | .highlight .g { color: #000000 } /* Generic */ 11 | .highlight .k { color: #004461; font-weight: bold } /* Keyword */ 12 | .highlight .l { color: #000000 } /* Literal */ 13 | .highlight .n { color: #000000 } /* Name */ 14 | .highlight .o { color: #582800 } /* Operator */ 15 | .highlight .x { color: #000000 } /* Other */ 16 | .highlight .p { color: #000000; font-weight: bold } /* Punctuation */ 17 | .highlight .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */ 18 | .highlight .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */ 19 | .highlight .cp { color: #8f5902 } /* Comment.Preproc */ 20 | .highlight .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */ 21 | .highlight .c1 { color: #8f5902; font-style: italic } /* Comment.Single */ 22 | .highlight .cs { color: #8f5902; font-style: italic } /* Comment.Special */ 23 | .highlight .gd { color: #a40000 } /* Generic.Deleted */ 24 | .highlight .ge { color: #000000; font-style: italic } /* Generic.Emph */ 25 | .highlight .gr { color: #ef2929 } /* Generic.Error */ 26 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 27 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 28 | .highlight .go { color: #888888 } /* Generic.Output */ 29 | .highlight .gp { color: #745334 } /* Generic.Prompt */ 30 | .highlight .gs { color: #000000; font-weight: bold } /* Generic.Strong */ 31 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 32 | .highlight .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */ 33 | .highlight .kc { color: #004461; font-weight: bold } /* Keyword.Constant */ 34 | .highlight .kd { color: #004461; font-weight: bold } /* Keyword.Declaration */ 35 | .highlight .kn { color: #004461; font-weight: bold } /* Keyword.Namespace */ 36 | .highlight .kp { color: #004461; font-weight: bold } /* Keyword.Pseudo */ 37 | .highlight .kr { color: #004461; font-weight: bold } /* Keyword.Reserved */ 38 | .highlight .kt { color: #004461; font-weight: bold } /* Keyword.Type */ 39 | .highlight .ld { color: #000000 } /* Literal.Date */ 40 | .highlight .m { color: #990000 } /* Literal.Number */ 41 | .highlight .s { color: #4e9a06 } /* Literal.String */ 42 | .highlight .na { color: #c4a000 } /* Name.Attribute */ 43 | .highlight .nb { color: #004461 } /* Name.Builtin */ 44 | .highlight .nc { color: #000000 } /* Name.Class */ 45 | .highlight .no { color: #000000 } /* Name.Constant */ 46 | .highlight .nd { color: #888888 } /* Name.Decorator */ 47 | .highlight .ni { color: #ce5c00 } /* Name.Entity */ 48 | .highlight .ne { color: #cc0000; font-weight: bold } /* Name.Exception */ 49 | .highlight .nf { color: #000000 } /* Name.Function */ 50 | .highlight .nl { color: #f57900 } /* Name.Label */ 51 | .highlight .nn { color: #000000 } /* Name.Namespace */ 52 | .highlight .nx { color: #000000 } /* Name.Other */ 53 | .highlight .py { color: #000000 } /* Name.Property */ 54 | .highlight .nt { color: #004461; font-weight: bold } /* Name.Tag */ 55 | .highlight .nv { color: #000000 } /* Name.Variable */ 56 | .highlight .ow { color: #004461; font-weight: bold } /* Operator.Word */ 57 | .highlight .w { color: #f8f8f8; text-decoration: underline } /* Text.Whitespace */ 58 | .highlight .mb { color: #990000 } /* Literal.Number.Bin */ 59 | .highlight .mf { color: #990000 } /* Literal.Number.Float */ 60 | .highlight .mh { color: #990000 } /* Literal.Number.Hex */ 61 | .highlight .mi { color: #990000 } /* Literal.Number.Integer */ 62 | .highlight .mo { color: #990000 } /* Literal.Number.Oct */ 63 | .highlight .sa { color: #4e9a06 } /* Literal.String.Affix */ 64 | .highlight .sb { color: #4e9a06 } /* Literal.String.Backtick */ 65 | .highlight .sc { color: #4e9a06 } /* Literal.String.Char */ 66 | .highlight .dl { color: #4e9a06 } /* Literal.String.Delimiter */ 67 | .highlight .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */ 68 | .highlight .s2 { color: #4e9a06 } /* Literal.String.Double */ 69 | .highlight .se { color: #4e9a06 } /* Literal.String.Escape */ 70 | .highlight .sh { color: #4e9a06 } /* Literal.String.Heredoc */ 71 | .highlight .si { color: #4e9a06 } /* Literal.String.Interpol */ 72 | .highlight .sx { color: #4e9a06 } /* Literal.String.Other */ 73 | .highlight .sr { color: #4e9a06 } /* Literal.String.Regex */ 74 | .highlight .s1 { color: #4e9a06 } /* Literal.String.Single */ 75 | .highlight .ss { color: #4e9a06 } /* Literal.String.Symbol */ 76 | .highlight .bp { color: #3465a4 } /* Name.Builtin.Pseudo */ 77 | .highlight .fm { color: #000000 } /* Name.Function.Magic */ 78 | .highlight .vc { color: #000000 } /* Name.Variable.Class */ 79 | .highlight .vg { color: #000000 } /* Name.Variable.Global */ 80 | .highlight .vi { color: #000000 } /* Name.Variable.Instance */ 81 | .highlight .vm { color: #000000 } /* Name.Variable.Magic */ 82 | .highlight .il { color: #990000 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/datasets.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 2. Datasets — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 35 |
36 | 37 |
38 |

2. Datasets

39 |
40 | 43 |
44 |
45 | 46 | 47 |
48 | 49 |
50 |
51 | 100 |
101 |
102 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /docs/features.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1. Features — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 35 |
36 | 37 |
38 |

1. Features

39 |
40 | 41 | 42 |
43 | 44 |
45 |
46 | 92 |
93 |
94 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Index — Machine Learning Library for TDA .1 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
30 | 31 | 32 |
33 | 34 | 35 |

Index

36 | 37 |
38 | 39 |
40 | 41 | 42 |
43 | 44 |
45 |
46 | 90 |
91 |
92 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /docs/ham10000.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 2.1. HAM10000 — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

2.1. HAM10000

38 |
39 | 40 | 41 |
42 | 43 |
44 |
45 | 95 |
96 |
97 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Welcome to Machine Learning Library for TDA’s documentation! — Machine Learning Library for TDA .1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

Welcome to Machine Learning Library for TDA’s documentation!

38 |

Welcome! You’re on the associated page for our repository for our paper, A Comparative Study of Machine Learning Methods for Persistence Diagrams

39 | _images/balls.gif 40 |
41 |

Table of Contents

42 |
43 | 50 |
51 |
52 |
53 | 54 | 55 |
56 | 57 |
58 |
59 | 104 |
105 |
106 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/docs/objects.inv -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Search — Machine Learning Library for TDA .1 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 |
35 |
36 | 37 | 38 |
39 | 40 |

Search

41 | 42 | 50 | 51 | 52 |

53 | Searching for multiple words only shows matches that contain 54 | all words. 55 |

56 | 57 | 58 |
59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 |
67 | 68 |
69 | 70 | 71 |
72 | 73 |
74 |
75 | 109 |
110 |
111 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /docs/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({"docnames": ["datasets", "features", "ham10000", "index"], "filenames": ["datasets.rst", "features.rst", "ham10000.rst", "index.rst"], "titles": ["2. Datasets", "1. Features", "2.1. HAM10000", "Welcome to Machine Learning Library for TDA\u2019s documentation!"], "terms": {"ham10000": [0, 3], "you": 3, "re": 3, "associ": 3, "page": 3, "our": 3, "repositori": 3, "paper": 3, "A": 3, "compar": 3, "studi": 3, "method": 3, "persist": 3, "diagram": 3, "featur": 3, "dataset": 3}, "objects": {}, "objtypes": {}, "objnames": {}, "titleterms": {"dataset": 0, "featur": 1, "ham10000": 2, "welcom": 3, "machin": 3, "learn": 3, "librari": 3, "tda": 3, "": 3, "document": 3, "tabl": 3, "content": 3}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 6, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.intersphinx": 1, "sphinx.ext.todo": 2, "sphinx.ext.viewcode": 1, "sphinx": 56}}) -------------------------------------------------------------------------------- /mlforpers/persistence_methods/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/mlforpers/persistence_methods/__init__.py -------------------------------------------------------------------------------- /mlforpers/persistence_methods/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/mlforpers/persistence_methods/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /mlforpers/persistence_methods/persistence_methods.py: -------------------------------------------------------------------------------- 1 | from persim import heat 2 | import numpy as np 3 | import ATS 4 | import time 5 | from sklearn import mixture 6 | import multidim 7 | from multidim.covertree import CoverTree 8 | from multidim.models import CDER 9 | import hdbscan 10 | from gudhi.representations.vector_methods import Landscape 11 | from persim import PersImage 12 | from sklearn.neighbors import DistanceMetric 13 | 14 | def kernel_features(train, test, s): 15 | n_train = len(train) 16 | n_test = len(test) 17 | X_train_features = np.zeros((n_train, n_train)) 18 | X_test_features = np.zeros((n_test, n_train)) 19 | 20 | start = time.time() 21 | for i in range(0,n_train): 22 | for j in range(0,i): 23 | print("train: ", j) 24 | dgm0 = train[i] 25 | dgm1 = train[j] 26 | hk = heat(dgm0, dgm1, sigma = s) 27 | X_train_features[i,j] = hk 28 | X_train_features[j,i] = hk 29 | for j in range(0,n_test): 30 | print("test: ", j) 31 | dgm0 = train[i] 32 | dgm1 = test[j] 33 | hk = heat(dgm0, dgm1, sigma = s) 34 | X_test_features[j,i] = hk 35 | 36 | print(time.time()-start) 37 | return X_train_features, X_test_features 38 | 39 | def tent_features(X_train, X_test, d=5, padding=.05): 40 | centers, delta = ATS.box_centers(X_train, d, padding) 41 | 42 | start = time.time() 43 | 44 | X_train_features = ATS.get_all_features_boxes(X_train, centers, delta) 45 | 46 | X_test_features = ATS.get_all_features_boxes(X_test, centers, delta) 47 | 48 | end = time.time() 49 | print('Computing features took (seconds):{}'.format(end-start)) 50 | return X_train_features, X_test_features 51 | 52 | def adaptive_features(X_train, X_test, model, y_train, d=25): 53 | if model == "gmm": 54 | print('Begin GMM...') 55 | start = time.time() 56 | X_train_temp = np.vstack(X_train) 57 | gmm_f_train=[] 58 | for i in range(len(X_train)): 59 | gmm_f_train.append(y_train[i]*np.ones(len(X_train[i]))) 60 | gmm_f_train = np.concatenate(gmm_f_train) 61 | 62 | gmm = mixture.BayesianGaussianMixture(n_components=d, covariance_type='full', max_iter=int(10e4)).fit(X_train_temp, gmm_f_train) 63 | 64 | ellipses = [] 65 | for i in range(len(gmm.means_)): 66 | L, v = np.linalg.eig(gmm.covariances_[i]) 67 | temp = {'mean':gmm.means_[i], 'std':np.sqrt(L), 'rotation':v.transpose(), 'radius':max(np.sqrt(L)), 'entropy':gmm.weights_[i]} 68 | temp['std'] = 3*temp['std'] 69 | ellipses.append(temp) 70 | 71 | X_train_features = ATS.get_all_features(X_train, ellipses, ATS.f_ellipse) 72 | 73 | X_test_features = ATS.get_all_features(X_test, ellipses, ATS.f_ellipse) 74 | 75 | end = time.time() 76 | print('Computing gmm features took (seconds):{}'.format(end-start)) 77 | 78 | elif model == "hdb": 79 | print('Begin HDBSCAN...') 80 | start = time.time() 81 | X_train_temp = np.vstack(X_train) 82 | 83 | clusterer = hdbscan.HDBSCAN() 84 | 85 | clusterer.fit(X_train_temp) 86 | 87 | num_clusters = clusterer.labels_.max() 88 | 89 | ellipses = [] 90 | for i in range(num_clusters): 91 | cluster_i = X_train_temp[clusterer.labels_ == i] 92 | 93 | en = np.mean(clusterer.probabilities_[clusterer.labels_ == i]) 94 | 95 | mean = np.mean(cluster_i, axis=0) 96 | cov_matrix = np.cov(cluster_i.transpose()) 97 | 98 | L,v = np.linalg.eig(cov_matrix) 99 | 100 | temp = {'mean':mean, 'std':np.sqrt(L), 'rotation':v.transpose(), 'radius':max(np.sqrt(L)), 'entropy':en} 101 | temp['std'] = 2*temp['std'] 102 | ellipses.append(temp) 103 | 104 | X_train_features = ATS.get_all_features(X_train, ellipses, ATS.f_ellipse) 105 | 106 | X_test_features = ATS.get_all_features(X_test, ellipses, ATS.f_ellipse) 107 | 108 | end = time.time() 109 | print('Computing hdbscan features took (seconds):{}'.format(end-start)) 110 | 111 | elif model == "cder": 112 | 113 | y_train_cder = y_train.copy() 114 | 115 | print('Begin CDER...') 116 | start = time.time() 117 | 118 | pc_train = multidim.PointCloud.from_multisample_multilabel(X_train, y_train_cder) 119 | ct_train = CoverTree(pc_train) 120 | 121 | cder = CDER(parsimonious=True) 122 | 123 | cder.fit(ct_train) 124 | 125 | cder_result = cder.gaussians 126 | 127 | ellipses = [] 128 | for c in cder_result: 129 | temp = {key:c[key] for key in ['mean', 'std', 'rotation', 'radius', 'entropy']} 130 | temp['std'] = 3*temp['std'] 131 | ellipses.append(temp) 132 | 133 | X_train_features = ATS.get_all_features(X_train, ellipses, ATS.f_ellipse) 134 | 135 | X_test_features = ATS.get_all_features(X_test, ellipses, ATS.f_ellipse) 136 | 137 | end = time.time() 138 | print('Computing features from H_1 took (seconds):{}'.format(end-start)) 139 | 140 | else: 141 | print("Not a valid model type") 142 | return X_train_features, X_test_features 143 | 144 | def carlsson_coordinates(X_train, X_test): 145 | n = len(X_train) 146 | X_train_features_cc1 = np.zeros(n) 147 | X_train_features_cc2 = np.zeros(n) 148 | X_train_features_cc3 = np.zeros(n) 149 | X_train_features_cc4 = np.zeros(n) 150 | start = time.time() 151 | ymax = 0 152 | for i in range(0,n): 153 | if len(X_train[i])>0: 154 | b = np.max(X_train[i][:,1]) 155 | else: 156 | b = ymax 157 | if ymax < b: 158 | ymax = b 159 | else: 160 | ymax = ymax 161 | print(ymax) 162 | for i in range(0,n): 163 | if len(X_train[i])>0: 164 | x = X_train[i][:,0] 165 | y = X_train[i][:,1] 166 | X_train_features_cc1[i] = sum(x*(y-x)) 167 | X_train_features_cc2[i] = sum((ymax - y)*(y-x)) 168 | X_train_features_cc3[i] = sum(x**2*(y-x)**4) 169 | X_train_features_cc4[i] = sum((ymax-y)**2*(y-x)**4) 170 | else: 171 | X_train_features_cc1[i] = 0 172 | X_train_features_cc2[i] = 0 173 | X_train_features_cc3[i] = 0 174 | X_train_features_cc4[i] = 0 175 | 176 | n = len(X_test) 177 | X_test_features_cc1 = np.zeros(n) 178 | X_test_features_cc2 = np.zeros(n) 179 | X_test_features_cc3 = np.zeros(n) 180 | X_test_features_cc4 = np.zeros(n) 181 | ymax = 0 182 | for i in range(0,n): 183 | if len(X_test[i])>0: 184 | b = np.max(X_test[i][:,1]) 185 | else: 186 | b = ymax 187 | if ymax < b: 188 | ymax = b 189 | else: 190 | ymax = ymax 191 | for i in range(0,n): 192 | if len(X_test[i])>0: 193 | x = X_test[i][:,0] 194 | y = X_test[i][:,1] 195 | X_test_features_cc1[i] = sum(x*(y-x)) 196 | X_test_features_cc2[i] = sum((ymax - y)*(y-x)) 197 | X_test_features_cc3[i] = sum(x**2*(y-x)**4) 198 | X_test_features_cc4[i] = sum((ymax-y)**2*(y-x)**4) 199 | else: 200 | X_test_features_cc1[i] = 0 201 | X_test_features_cc2[i] = 0 202 | X_test_features_cc3[i] = 0 203 | X_test_features_cc4[i] = 0 204 | print("Total Time (Carlsson Coordinates): ", time.time()-start) 205 | return X_train_features_cc1, X_train_features_cc2, X_train_features_cc3, X_train_features_cc4, X_test_features_cc1, X_test_features_cc2, X_test_features_cc3, X_test_features_cc4 206 | 207 | def landscape_features(X_train, X_test, num_landscapes=5, resolution=100): 208 | start = time.time() 209 | landscapes = Landscape(num_landscapes, resolution) 210 | lr = landscapes.fit(X_train) 211 | X_train_features = lr.transform(X_train) 212 | X_test_features = lr.transform(X_test) 213 | print("Total Time (Landscape Features): ", time.time()-start) 214 | return X_train_features, X_test_features 215 | 216 | def persistence_image_features(X_train, X_test, pixels=[20,20], spread=1): 217 | start = time.time() 218 | pim = PersImage(pixels=pixels, spread=spread) 219 | imgs_train = pim.transform(X_train) 220 | X_train_features = np.array([img.flatten() for img in imgs_train]) 221 | pim = PersImage(pixels=pixels, spread=spread) 222 | imgs_test = pim.transform(X_test) 223 | X_test_features = np.array([img.flatten() for img in imgs_test]) 224 | print("Total Time (Persistence Images): ", time.time()-start) 225 | return X_train_features, X_test_features 226 | 227 | def fast_hk(dgm0,dgm1,sigma=.4): 228 | dist = DistanceMetric.get_metric('euclidean') 229 | dist1 = (dist.pairwise(dgm0,dgm1))**2 230 | Qc = dgm1[:,1::-1] 231 | dist2 = (dist.pairwise(dgm0,Qc))**2 232 | exp_dist1 = sum(sum(np.exp(-dist1/(8*sigma)))) 233 | exp_dist2 = sum(sum(np.exp(-dist2/(8*sigma)))) 234 | hk = (exp_dist1-exp_dist2)/(8*np.pi*sigma) 235 | return(hk) 236 | 237 | def heat_kernel_approx(dgm0, dgm1, sigma=.4): 238 | return np.sqrt(fast_hk(dgm0, dgm0, sigma) + fast_hk(dgm1, dgm1, sigma) - 2*fast_hk(dgm0, dgm1, sigma)) 239 | 240 | def fast_kernel_features(train, test, s): 241 | n_train = len(train) 242 | n_test = len(test) 243 | X_train_features = np.zeros((n_train, n_train)) 244 | X_test_features = np.zeros((n_test, n_train)) 245 | 246 | start = time.time() 247 | for i in range(0,n_train): 248 | if i % 5 == 0: 249 | print("Iteration: ", i) 250 | print("Total Time: ", time.time() - start) 251 | print("Iterations left: " , n_train - i) 252 | for j in range(0,i): 253 | dgm0 = train[i] 254 | dgm1 = train[j] 255 | hka = heat_kernel_approx(dgm0, dgm1, sigma = s) 256 | X_train_features[i,j] = hka 257 | X_train_features[j,i] = hka 258 | for j in range(0,n_test): 259 | dgm0 = train[i] 260 | dgm1 = test[j] 261 | hka = heat_kernel_approx(dgm0, dgm1, sigma = s) 262 | X_test_features[j,i] = hka 263 | 264 | print("Total Time (Kernel): ", time.time()-start) 265 | return X_train_features, X_test_features 266 | 267 | 268 | -------------------------------------------------------------------------------- /mlforpers/persistence_methods/persistence_methods_cuda.py: -------------------------------------------------------------------------------- 1 | from persim import heat 2 | import numpy as np 3 | import ATS 4 | import time 5 | from sklearn import mixture 6 | import multidim 7 | from multidim.covertree import CoverTree 8 | from multidim.models import CDER 9 | import hdbscan 10 | from gudhi.representations.vector_methods import Landscape 11 | from persim import PersImage 12 | from sklearn.neighbors import DistanceMetric 13 | from numba import guvectorize 14 | import math 15 | 16 | def reshape_persistence_diagrams(dgm): 17 | dgm_reshape = np.array([]) 18 | n = len(dgm) 19 | print(n) 20 | for i in range(0,n): 21 | t = np.repeat(i, len(dgm[i])) 22 | t = t.reshape(len(dgm[i]),1) 23 | t1 = np.concatenate((t,dgm[i]),1) 24 | if i == 0: 25 | dgm_reshape = t1 26 | else: 27 | dgm_reshape = np.append(dgm_reshape, t1, 0) 28 | return dgm_reshape 29 | 30 | def create_index(dgm, dummy): 31 | n = dummy.shape[0] 32 | index = np.zeros((n,2)) 33 | arr = dgm[:,0] 34 | for i in range(0,n): 35 | t = np.where(arr==i) 36 | index[i,0] = min(t[0]) 37 | index[i,1] = max(t[0])+1 38 | return index 39 | 40 | @guvectorize(["void(float64[:,:], float64[:,:], float64, float64[:,:])",],"(m,n),(p,r),()->(p,p)", target="cuda") 41 | def cuda_kernel_features_train(train, index, s, result): 42 | n_train = index.shape[0] 43 | for i in range(n_train): 44 | for j in range(i): 45 | dgm0 = train[int(index[i,0]):int(index[i,1]),1:3] 46 | dgm1 = train[int(index[j,0]):int(index[j,1]),1:3] 47 | kSigma0 = 0 48 | kSigma1 = 0 49 | kSigma2 = 0 50 | sigma = s 51 | for k in range(dgm0.shape[0]): 52 | p = dgm0[k,0:2] 53 | for l in range(dgm0.shape[0]): 54 | q = dgm0[l,0:2] 55 | qc = dgm0[l, 1::-1] 56 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 57 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 58 | kSigma0 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 59 | for k in range(dgm1.shape[0]): 60 | p = dgm1[k,0:2] 61 | for l in range(dgm1.shape[0]): 62 | q = dgm1[l,0:2] 63 | qc = dgm1[l, 1::-1] 64 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 65 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 66 | kSigma1 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 67 | for k in range(dgm0.shape[0]): 68 | p = dgm0[k,0:2] 69 | for l in range(dgm1.shape[0]): 70 | q = dgm1[l,0:2] 71 | qc = dgm1[l, 1::-1] 72 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 73 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 74 | kSigma2 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 75 | 76 | kSigma0 = kSigma0/(8 * np.pi * sigma) 77 | kSigma1 = kSigma1/(8 * np.pi * sigma) 78 | kSigma2 = kSigma2/(8 * np.pi * sigma) 79 | result[i,j] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) 80 | result[j,i] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) 81 | 82 | @guvectorize(["void(float64[:,:], float64[:,:], float64[:,:], float64[:,:],float64 ,float64[:,:])",],"(m,n),(l,n),(p,r),(q,r), ()->(q,p)", target="cuda") 83 | def cuda_kernel_features_test(train, test, index_train, index_test, s, result): 84 | n_train = index_train.shape[0] 85 | n_test = index_test.shape[0] 86 | for i in range(n_train): 87 | for j in range(n_test): 88 | dgm0 = train[int(index_train[i,0]):int(index_train[i,1]),1:3] 89 | dgm1 = test[int(index_test[j,0]):int(index_test[j,1]),1:3] 90 | kSigma0 = 0 91 | kSigma1 = 0 92 | kSigma2 = 0 93 | sigma = s 94 | for k in range(dgm0.shape[0]): 95 | p = dgm0[k,0:2] 96 | for l in range(dgm0.shape[0]): 97 | q = dgm0[l,0:2] 98 | qc = dgm0[l, 1::-1] 99 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 100 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 101 | kSigma0 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 102 | for k in range(dgm1.shape[0]): 103 | p = dgm1[k,0:2] 104 | for l in range(dgm1.shape[0]): 105 | q = dgm1[l,0:2] 106 | qc = dgm1[l, 1::-1] 107 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 108 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 109 | kSigma1 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 110 | for k in range(dgm0.shape[0]): 111 | p = dgm0[k,0:2] 112 | for l in range(dgm1.shape[0]): 113 | q = dgm1[l,0:2] 114 | qc = dgm1[l, 1::-1] 115 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 116 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 117 | kSigma2 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 118 | 119 | kSigma0 = kSigma0/(8 * np.pi * sigma) 120 | kSigma1 = kSigma1/(8 * np.pi * sigma) 121 | kSigma2 = kSigma2/(8 * np.pi * sigma) 122 | result[j,i] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) -------------------------------------------------------------------------------- /mlforpers/persistence_methods/persistence_methods_numba.py: -------------------------------------------------------------------------------- 1 | from persim import heat 2 | import numpy as np 3 | import ATS 4 | import time 5 | from sklearn import mixture 6 | import multidim 7 | from multidim.covertree import CoverTree 8 | from multidim.models import CDER 9 | import hdbscan 10 | from gudhi.representations.vector_methods import Landscape 11 | from persim import PersImage 12 | from sklearn.neighbors import DistanceMetric 13 | from numba import guvectorize 14 | import math 15 | 16 | def reshape_persistence_diagrams(dgm): 17 | dgm_reshape = np.array([]) 18 | n = len(dgm) 19 | print(n) 20 | for i in range(0,n): 21 | t = np.repeat(i, len(dgm[i])) 22 | t = t.reshape(len(dgm[i]),1) 23 | t1 = np.concatenate((t,dgm[i]),1) 24 | if i == 0: 25 | dgm_reshape = t1 26 | else: 27 | dgm_reshape = np.append(dgm_reshape, t1, 0) 28 | return dgm_reshape 29 | 30 | @guvectorize(["void(float64[:,:], float64[:], float64, float64[:,:])",],"(m,n),(p),()->(p,p)") 31 | def numba_kernel_features_train(train, dummy, s, result): 32 | n_train = len(dummy) 33 | for i in range(n_train): 34 | print("train features", i) 35 | for j in range(i): 36 | dgm0 = train[train[:,0]==i,1:3] 37 | dgm1 = train[train[:,0]==j,1:3] 38 | kSigma0 = 0 39 | kSigma1 = 0 40 | kSigma2 = 0 41 | sigma = s 42 | for k in range(dgm0.shape[0]): 43 | p = dgm0[k,0:2] 44 | for l in range(dgm0.shape[0]): 45 | q = dgm0[l,0:2] 46 | qc = dgm0[l, 1::-1] 47 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 48 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 49 | kSigma0 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 50 | for k in range(dgm1.shape[0]): 51 | p = dgm1[k,0:2] 52 | for l in range(dgm1.shape[0]): 53 | q = dgm1[l,0:2] 54 | qc = dgm1[l, 1::-1] 55 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 56 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 57 | kSigma1 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 58 | for k in range(dgm0.shape[0]): 59 | p = dgm0[k,0:2] 60 | for l in range(dgm1.shape[0]): 61 | q = dgm1[l,0:2] 62 | qc = dgm1[l, 1::-1] 63 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 64 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 65 | kSigma2 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 66 | 67 | kSigma0 = kSigma0/(8 * np.pi * sigma) 68 | kSigma1 = kSigma1/(8 * np.pi * sigma) 69 | kSigma2 = kSigma2/(8 * np.pi * sigma) 70 | result[i,j] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) 71 | result[j,i] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) 72 | 73 | @guvectorize(["void(float64[:,:], float64[:,:], float64[:], float64[:],float64,float64[:,:])",],"(m,n),(l,n),(p),(q), ()->(q,p)") 74 | def numba_kernel_features_test(train, test, dummy_train, dummy_test, s, result): 75 | n_train = len(dummy_train) 76 | n_test = len(dummy_test) 77 | for i in range(n_train): 78 | print("test features:", i) 79 | for j in range(n_test): 80 | dgm0 = train[train[:,0]==i,1:3] 81 | dgm1 = test[test[:,0]==j,1:3] 82 | kSigma0 = 0 83 | kSigma1 = 0 84 | kSigma2 = 0 85 | sigma = s 86 | for k in range(dgm0.shape[0]): 87 | p = dgm0[k,0:2] 88 | for l in range(dgm0.shape[0]): 89 | q = dgm0[l,0:2] 90 | qc = dgm0[l, 1::-1] 91 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 92 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 93 | kSigma0 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 94 | for k in range(dgm1.shape[0]): 95 | p = dgm1[k,0:2] 96 | for l in range(dgm1.shape[0]): 97 | q = dgm1[l,0:2] 98 | qc = dgm1[l, 1::-1] 99 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 100 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 101 | kSigma1 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 102 | for k in range(dgm0.shape[0]): 103 | p = dgm0[k,0:2] 104 | for l in range(dgm1.shape[0]): 105 | q = dgm1[l,0:2] 106 | qc = dgm1[l, 1::-1] 107 | pq = (p[0] - q[0])**2 + (p[1] - q[1])**2 108 | pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2 109 | kSigma2 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma)) 110 | 111 | kSigma0 = kSigma0/(8 * np.pi * sigma) 112 | kSigma1 = kSigma1/(8 * np.pi * sigma) 113 | kSigma2 = kSigma2/(8 * np.pi * sigma) 114 | result[j,i] = math.sqrt(kSigma1 + kSigma0-2*kSigma2) -------------------------------------------------------------------------------- /mlforpers/persistence_methods/persistence_methods_timings.py: -------------------------------------------------------------------------------- 1 | from persim import heat 2 | import numpy as np 3 | import ATS 4 | import time 5 | from sklearn import mixture 6 | import multidim 7 | from multidim.covertree import CoverTree 8 | from multidim.models import CDER 9 | import hdbscan 10 | from gudhi.representations.vector_methods import Landscape 11 | from persim import PersImage 12 | from sklearn.neighbors import DistanceMetric 13 | 14 | def tent_features(X_train, d=5, padding=.05): 15 | centers, delta = ATS.box_centers(X_train, d, padding) 16 | start = time.time() 17 | X_train_features = ATS.get_all_features_boxes(X_train, centers, delta) 18 | end = time.time() 19 | timing = end - start 20 | return timing 21 | 22 | def adaptive_features(X_train, model, y_train, d=25): 23 | if model == "gmm": 24 | print('Begin GMM...') 25 | start = time.time() 26 | X_train_temp = np.vstack(X_train) 27 | gmm_f_train=[] 28 | for i in range(len(X_train)): 29 | gmm_f_train.append(y_train[i]*np.ones(len(X_train[i]))) 30 | gmm_f_train = np.concatenate(gmm_f_train) 31 | 32 | gmm = mixture.BayesianGaussianMixture(n_components=d, covariance_type='full', max_iter=int(10e4)).fit(X_train_temp, gmm_f_train) 33 | 34 | ellipses = [] 35 | for i in range(len(gmm.means_)): 36 | L, v = np.linalg.eig(gmm.covariances_[i]) 37 | temp = {'mean':gmm.means_[i], 'std':np.sqrt(L), 'rotation':v.transpose(), 'radius':max(np.sqrt(L)), 'entropy':gmm.weights_[i]} 38 | temp['std'] = 3*temp['std'] 39 | ellipses.append(temp) 40 | 41 | X_train_features = ATS.get_all_features(X_train, ellipses, ATS.f_ellipse) 42 | end = time.time() 43 | timing = end - start 44 | 45 | elif model == "cder": 46 | 47 | y_train_cder = y_train.copy() 48 | 49 | print('Begin CDER...') 50 | start = time.time() 51 | 52 | pc_train = multidim.PointCloud.from_multisample_multilabel(X_train, y_train_cder) 53 | ct_train = CoverTree(pc_train) 54 | 55 | cder = CDER(parsimonious=True) 56 | 57 | cder.fit(ct_train) 58 | 59 | cder_result = cder.gaussians 60 | 61 | ellipses = [] 62 | for c in cder_result: 63 | temp = {key:c[key] for key in ['mean', 'std', 'rotation', 'radius', 'entropy']} 64 | temp['std'] = 3*temp['std'] 65 | ellipses.append(temp) 66 | 67 | X_train_features = ATS.get_all_features(X_train, ellipses, ATS.f_ellipse) 68 | end = time.time() 69 | timing = end - start 70 | return timing 71 | 72 | def carlsson_coordinates(X_train): 73 | n = len(X_train) 74 | X_train_features_cc1 = np.zeros(n) 75 | X_train_features_cc2 = np.zeros(n) 76 | X_train_features_cc3 = np.zeros(n) 77 | X_train_features_cc4 = np.zeros(n) 78 | start = time.time() 79 | ymax = 0 80 | for i in range(0,n): 81 | if len(X_train[i])>0: 82 | b = np.max(X_train[i][:,1]) 83 | else: 84 | b = ymax 85 | if ymax < b: 86 | ymax = b 87 | else: 88 | ymax = ymax 89 | print(ymax) 90 | for i in range(0,n): 91 | if len(X_train[i])>0: 92 | x = X_train[i][:,0] 93 | y = X_train[i][:,1] 94 | X_train_features_cc1[i] = sum(x*(y-x)) 95 | X_train_features_cc2[i] = sum((ymax - y)*(y-x)) 96 | X_train_features_cc3[i] = sum(x**2*(y-x)**4) 97 | X_train_features_cc4[i] = sum((ymax-y)**2*(y-x)**4) 98 | else: 99 | X_train_features_cc1[i] = 0 100 | X_train_features_cc2[i] = 0 101 | X_train_features_cc3[i] = 0 102 | X_train_features_cc4[i] = 0 103 | 104 | timing = time.time()-start 105 | return timing 106 | 107 | def landscape_features(X_train, num_landscapes=5, resolution=100): 108 | start = time.time() 109 | landscapes = Landscape(num_landscapes, resolution) 110 | lr = landscapes.fit(X_train) 111 | X_train_features = lr.transform(X_train) 112 | timing = time.time()-start 113 | return timing 114 | 115 | def persistence_image_features(X_train, pixels=[20,20], spread=1): 116 | start = time.time() 117 | pim = PersImage(pixels=pixels, spread=spread) 118 | imgs_train = pim.transform(X_train) 119 | X_train_features = np.array([img.flatten() for img in imgs_train]) 120 | timing = time.time()-start 121 | return timing 122 | 123 | def fast_hk(dgm0,dgm1,sigma=.4): 124 | dist = DistanceMetric.get_metric('euclidean') 125 | dist1 = (dist.pairwise(dgm0,dgm1))**2 126 | Qc = dgm1[:,1::-1] 127 | dist2 = (dist.pairwise(dgm0,Qc))**2 128 | exp_dist1 = sum(sum(np.exp(-dist1/(8*sigma)))) 129 | exp_dist2 = sum(sum(np.exp(-dist2/(8*sigma)))) 130 | hk = (exp_dist1-exp_dist2)/(8*np.pi*sigma) 131 | return(hk) 132 | 133 | def heat_kernel_approx(dgm0, dgm1, sigma=.4): 134 | return np.sqrt(fast_hk(dgm0, dgm0, sigma) + fast_hk(dgm1, dgm1, sigma) - 2*fast_hk(dgm0, dgm1, sigma)) 135 | 136 | def fast_kernel_features(train, s): 137 | n_train = len(train) 138 | X_train_features = np.zeros((n_train, n_train)) 139 | 140 | start = time.time() 141 | for i in range(0,n_train): 142 | for j in range(0,i): 143 | dgm0 = train[i] 144 | dgm1 = train[j] 145 | hka = heat_kernel_approx(dgm0, dgm1, sigma = s) 146 | X_train_features[i,j] = hka 147 | X_train_features[j,i] = hka 148 | 149 | timing = time.time()-start 150 | return timing 151 | 152 | 153 | -------------------------------------------------------------------------------- /persistence_methods/__pycache__/ATS.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/persistence_methods/__pycache__/ATS.cpython-38.pyc -------------------------------------------------------------------------------- /source/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/source/.DS_Store -------------------------------------------------------------------------------- /source/_figures/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/source/_figures/ball.png -------------------------------------------------------------------------------- /source/_figures/balls.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/source/_figures/balls.gif -------------------------------------------------------------------------------- /source/_figures/create_balls_gif.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageDraw 2 | from sklearn import datasets 3 | import matplotlib.pyplot as plt 4 | import io 5 | 6 | def create_data(): 7 | n_samples = 100 8 | noisy_circles = datasets.make_circles(n_samples=n_samples, factor=0.5, noise=0.05) 9 | X,y = noisy_circles 10 | OC = X[y==0] 11 | return OC 12 | 13 | def balls(r, OC): 14 | fig, ax = plt.subplots() # note we must use plt.subplots, not plt.subplot 15 | ax.set_xlim([-1.5,1.5]) 16 | ax.set_ylim([-1.5,1.5]) 17 | ax.scatter(OC[:, 0], OC[:, 1], s=10, c='black', marker=".") 18 | n = OC.shape[0] 19 | for i in range(0, n): 20 | circle = plt.Circle(OC[i], radius=r/2, color='purple', alpha=.25) 21 | ax.add_patch(circle) 22 | 23 | plt.axis('off') 24 | return fig 25 | 26 | def make_gif(): 27 | frames = [] 28 | OC = create_data() 29 | radii = [.05, .075, .1, .125, .15,.175, .2,.225, .25,.275, .3,.325, .35,.375, .4,.425, .45,.475, .5, .475, .45, .425, .4, .375, .35, .325, .3, .275, .25, .225, .2, .175, .15, .125, .1, .075, .05] 30 | for r in radii: 31 | img_buf = io.BytesIO() 32 | balls(r, OC).savefig(img_buf, format='png') 33 | im = Image.open(img_buf) 34 | frames.append(im) 35 | 36 | frame_one = frames[0] 37 | frame_one.save("balls.gif", format="GIF", append_images=frames, 38 | save_all=True, duration=100, loop=0) 39 | 40 | if __name__ == "__main__": 41 | make_gif() -------------------------------------------------------------------------------- /source/_figures/mnist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/source/_figures/mnist.png -------------------------------------------------------------------------------- /source/_figures/pi_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnesd8/machine_learning_for_persistence/8fd38d419051e4be38e5de14f2191b8232b9b4ba/source/_figures/pi_1.png -------------------------------------------------------------------------------- /source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | # import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'Machine Learning Library for TDA' 21 | copyright = '2022, Danielle Barnes' 22 | author = 'Danielle Barnes' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '.1' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = ['sphinx.ext.autodoc', 34 | 'sphinx.ext.coverage', 35 | 'sphinx.ext.napoleon', 36 | 'matplotlib.sphinxext.mathmpl', 37 | 'matplotlib.sphinxext.plot_directive', 38 | 'sphinx.ext.autosummary', 39 | 'sphinx.ext.doctest', 40 | 'sphinx.ext.intersphinx', 41 | 'sphinx.ext.todo', 42 | 'sphinx.ext.mathjax', 43 | 'sphinx.ext.ifconfig', 44 | 'sphinx.ext.viewcode', 45 | 'sphinx.ext.githubpages',] 46 | 47 | # Add any paths that contain templates here, relative to this directory. 48 | templates_path = ['_templates'] 49 | 50 | # List of patterns, relative to source directory, that match files and 51 | # directories to ignore when looking for source files. 52 | # This pattern also affects html_static_path and html_extra_path. 53 | exclude_patterns = [] 54 | 55 | 56 | # -- Options for HTML output ------------------------------------------------- 57 | 58 | # The theme to use for HTML and HTML Help pages. See the documentation for 59 | # a list of builtin themes. 60 | # 61 | html_theme = 'alabaster' 62 | 63 | # Add any paths that contain custom static files (such as style sheets) here, 64 | # relative to this directory. They are copied after the builtin static files, 65 | # so a file named "default.css" will overwrite the builtin "default.css". 66 | html_static_path = ['_static'] 67 | -------------------------------------------------------------------------------- /source/datasets.rst: -------------------------------------------------------------------------------- 1 | Datasets 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | HAM10000 8 | -------------------------------------------------------------------------------- /source/features.rst: -------------------------------------------------------------------------------- 1 | Features 2 | ******************* 3 | -------------------------------------------------------------------------------- /source/ham10000.rst: -------------------------------------------------------------------------------- 1 | HAM10000 2 | ******************* 3 | -------------------------------------------------------------------------------- /source/index.rst: -------------------------------------------------------------------------------- 1 | .. Machine Learning Library for TDA documentation master file, created by 2 | sphinx-quickstart on Fri Aug 5 12:22:23 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Machine Learning Library for TDA's documentation! 7 | ============================================================ 8 | 9 | Welcome! You're on the associated page for our repository for our paper, `A Comparative Study of Machine Learning Methods for Persistence Diagrams `_ 10 | 11 | .. image:: _figures/balls.gif 12 | :width: 600 px 13 | 14 | Table of Contents 15 | ******************* 16 | 17 | .. toctree:: 18 | :maxdepth: 4 19 | :numbered: 20 | 21 | Featurization 22 | Datasets 23 | --------------------------------------------------------------------------------