Skip to content

Instantly share code, notes, and snippets.

@neworderofjamie
Created November 4, 2016 13:21
Show Gist options
  • Save neworderofjamie/f7897f1f58d0e44a87410c07f476201b to your computer and use it in GitHub Desktop.
Save neworderofjamie/f7897f1f58d0e44a87410c07f476201b to your computer and use it in GitHub Desktop.
maximum_matrix_size_estimate
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import math\n",
"import numpy as np\n",
"import scipy.stats as stats\n",
"\n",
"mean = 1.6\n",
"sd = 0.75\n",
"\n",
"max_row_length = 1024\n",
"num_rows = 1000\n",
"max_delay = 0.7\n",
"\n",
"dist = stats.truncnorm\n",
"params = {\"loc\": mean, \"scale\": sd, \"a\": (0.1 - mean) / sd, \"b\": (np.inf - mean) / sd}"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probabity in first sub-row:0.094469, maximum synapses:149\n"
]
}
],
"source": [
"prob_first_sub_row = dist.cdf(max_delay, **params)\n",
"row_probability = 0.9999 ** (1.0 / float(num_rows))\n",
"max_first_sub_row_synapses = stats.binom.ppf(row_probability, max_row_length, prob_first_sub_row)\n",
"print \"Probabity in first sub-row:%f, maximum synapses:%u\" % (prob_first_sub_row, max_first_sub_row_synapses)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Subsequent sub-row maximum synapses:972\n"
]
}
],
"source": [
"max_subsequent_sub_row_synapses = stats.binom.ppf(row_probability, max_row_length, 1.0 - prob_first_sub_row)\n",
"print \"Subsequent sub-row maximum synapses:%u\" % (max_subsequent_sub_row_synapses)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extension delay range:5.398744, max sub rows:8, max sub row length:121\n"
]
}
],
"source": [
"# If any sub-rows are required\n",
"if max_subsequent_sub_row_synapses > 0:\n",
" # Calculate the maximum range of delays\n",
" # this many synapses is likely to have\n",
" max_probability = 0.9999 ** (1.0 / float(max_subsequent_sub_row_synapses))\n",
" extension_delay_range = dist.ppf(max_probability, **params) -\\\n",
" dist.ppf(1.0 - max_probability, **params)\n",
"\n",
" # Convert this to a maximum number of sub-rows\n",
" max_sub_rows = max(1, int(math.ceil(extension_delay_range /\n",
" 0.7)))\n",
"\n",
" # Divide mean number of synapses in row evenly between sub-rows\n",
" max_sub_row_length = max_subsequent_sub_row_synapses // max_sub_rows\n",
"\n",
" print(\"Extension delay range:%f, max sub rows:%u, max sub row length:%u\"\n",
" % (extension_delay_range, max_sub_rows, max_sub_row_length))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment