Last active
June 25, 2018 13:35
-
-
Save hugohadfield/7577011e2e73250edd59e4e836c9d6cc to your computer and use it in GitHub Desktop.
Cartans.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from clifford.tools import orthoFrames2Verser as cartan\nfrom clifford.tools.g3c import * \nfrom clifford.tools.g3 import generate_rotation_rotor\nfrom scipy import e,rand\nimport numpy as np", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def cartans_lines(line_list_a, line_list_b):\n V_found,rs = cartan(A=line_list_a,B=line_list_b)\n e123inf =e123*einf \n theta = ((V_found*~V_found)*e1234)(0)\n V_found = e**(-theta/2*e123inf)*V_found\n return V_found", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "n_objects_used = 5\n\ncomponent_errors = []\nfor i in range(1000):\n\n line_list_a = [random_line() for i in range(n_objects_used)]\n r = generate_translation_rotor(random_euc_mv())*generate_rotation_rotor(np.random.randn(),random_euc_mv().normal(), random_euc_mv().normal())\n line_list_b = [(r*l*~r).normal() for l in line_list_a]\n V_found = cartans_lines(line_list_a, line_list_b)\n line_list_c = [(V_found*l*~V_found).normal() for l in line_list_a]\n for b,c in zip(line_list_b,line_list_c):\n component_errors.append(np.max(np.abs(b.value - c.value)))", | |
"execution_count": 36, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(max(component_errors))\nprint(np.mean(component_errors))", | |
"execution_count": 37, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "0.5888467065055061\n0.002065627867944979\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": 19, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "0\n0\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%%prun -s cumulative\nfor i in range(10000):\n cartans_lines(line_list_a, line_list_b)", | |
"execution_count": 38, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": " ", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"pygments_lexer": "ipython3", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"version": "3.5.2", | |
"mimetype": "text/x-python", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "7577011e2e73250edd59e4e836c9d6cc", | |
"data": { | |
"description": "Cartans.ipynb", | |
"public": true | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/7577011e2e73250edd59e4e836c9d6cc" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment