Skip to content

Instantly share code, notes, and snippets.

@kescobo
Created December 13, 2017 21:27
Show Gist options
  • Save kescobo/48ef708c932f2cd9894cdebbea75b487 to your computer and use it in GitHub Desktop.
Save kescobo/48ef708c932f2cd9894cdebbea75b487 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"using Clustering\n",
"using Distances\n",
"using BenchmarkTools;"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5000×5000 Array{Float64,2}:\n",
" 0.0 0.343369 0.34366 0.340141 … 0.336091 0.338619 0.333748\n",
" 0.343369 0.0 0.331632 0.335547 0.335049 0.338414 0.339493\n",
" 0.34366 0.331632 0.0 0.335141 0.339824 0.34027 0.338529\n",
" 0.340141 0.335547 0.335141 0.0 0.322269 0.327231 0.340499\n",
" 0.338945 0.335581 0.342374 0.332958 0.330955 0.325538 0.328526\n",
" 0.343973 0.340117 0.344257 0.33879 … 0.337204 0.316357 0.32182 \n",
" 0.327998 0.333916 0.335018 0.334355 0.340203 0.335612 0.334887\n",
" 0.326519 0.337853 0.346471 0.344228 0.327721 0.334557 0.319285\n",
" 0.330871 0.329097 0.348236 0.33656 0.332745 0.334408 0.33932 \n",
" 0.339208 0.347929 0.335793 0.346454 0.330397 0.340416 0.336861\n",
" 0.341503 0.345218 0.331044 0.323576 … 0.325335 0.33884 0.332917\n",
" 0.322232 0.330622 0.330086 0.328989 0.334396 0.336174 0.317607\n",
" 0.339902 0.342281 0.342619 0.347962 0.333823 0.351439 0.338163\n",
" ⋮ ⋱ \n",
" 0.330957 0.347526 0.331785 0.335055 0.342946 0.338383 0.341168\n",
" 0.327584 0.334309 0.324169 0.321827 0.331287 0.335389 0.318614\n",
" 0.327557 0.32448 0.328454 0.329129 … 0.339167 0.344099 0.338294\n",
" 0.335319 0.34019 0.330957 0.340505 0.330014 0.338275 0.323959\n",
" 0.32913 0.32356 0.332591 0.336012 0.335383 0.334236 0.321879\n",
" 0.340549 0.33668 0.350206 0.333848 0.32995 0.345196 0.325663\n",
" 0.32749 0.329868 0.332984 0.337432 0.33624 0.334221 0.328347\n",
" 0.33659 0.329371 0.333425 0.338162 … 0.338806 0.328651 0.341408\n",
" 0.335656 0.332368 0.341622 0.342993 0.332729 0.346547 0.337752\n",
" 0.336091 0.335049 0.339824 0.322269 0.0 0.336087 0.323557\n",
" 0.338619 0.338414 0.34027 0.327231 0.336087 0.0 0.32873 \n",
" 0.333748 0.339493 0.338529 0.340499 0.323557 0.32873 0.0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = rand(1000, 5000)\n",
"dm = pairwise(BrayCurtis(), m)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 289.31 MiB\n",
" allocs estimate: 201803\n",
" --------------\n",
" minimum time: 1.016 s (10.77% GC)\n",
" median time: 1.038 s (10.54% GC)\n",
" mean time: 1.067 s (10.66% GC)\n",
" maximum time: 1.139 s (12.37% GC)\n",
" --------------\n",
" samples: 5\n",
" evals/sample: 1"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark hcl = hclust(dm, :single)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5000-element Array{Int64,1}:\n",
" 2700\n",
" 682\n",
" 4876\n",
" 4870\n",
" 2919\n",
" 253\n",
" 1916\n",
" 2757\n",
" 4303\n",
" 3086\n",
" 1046\n",
" 3008\n",
" 2071\n",
" ⋮\n",
" 4858\n",
" 2674\n",
" 3959\n",
" 4513\n",
" 3780\n",
" 3829\n",
" 3388\n",
" 1216\n",
" 3249\n",
" 4103\n",
" 3213\n",
" 4250"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hcl = hclust(dm, :single)\n",
"hcl.order"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 25.01 MiB\n",
" allocs estimate: 51788\n",
" --------------\n",
" minimum time: 43.757 ms (3.91% GC)\n",
" median time: 48.536 ms (4.61% GC)\n",
" mean time: 49.039 ms (4.86% GC)\n",
" maximum time: 59.522 ms (5.77% GC)\n",
" --------------\n",
" samples: 102\n",
" evals/sample: 1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark optimalorder(hcl, dm)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5000-element Array{Int64,1}:\n",
" 2700\n",
" 543\n",
" 4250\n",
" 4653\n",
" 4195\n",
" 4825\n",
" 4561\n",
" 2784\n",
" 2874\n",
" 634\n",
" 398\n",
" 3020\n",
" 2250\n",
" ⋮\n",
" 860\n",
" 1967\n",
" 2408\n",
" 4268\n",
" 3121\n",
" 1469\n",
" 2071\n",
" 3008\n",
" 3086\n",
" 253\n",
" 4870\n",
" 4876"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"optimalorder(hcl, dm)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.1",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment