Package to compute geodesic given a Riemannian metric - python

I'm looking for a code/package which given a starting point $x_o$ and ending point $x_1$ to compute equally spaced points on the geodesic between $x_0$ and $x_1$ given a function which returns the Riemannian metric tensor at any point. This does not seem to be a trivial task since you need to solve some form of a differential equation. Is anyone aware of any such materials?

You can compute minimal geodesics by solving the Eikonal equation using the Fast Marching Method, which is implemented in Python in Jason Furtney's scikit-fmm. It may be ok for Riemannian metrics with weak anisotropy. If not, it's at least a place to start.
Update 2019/01: Jean-Marie Mirebeau has a rather more complex package of code implementing his fast-marching method for solving the eikonal equation with Riemannian metrics. The code includes tools for computing geodesics. It's non-trivial to install and run, but I've had some success after persevering.

Related

Solving a se(3) optimization problem using SciPy?

I want to use scipy.optimize package to solve a rigid body optimization problem (finding optimal translation and rotation of a object).
A way to parametrize this problem is through lie group theory and the lie algebra se(3) (often called twist coordinates). This means the state vector is composed of 6 parameters (i.e. pose = [rho_x, rho_y, rho_z, theta_0, theta_1, theta_3]) from which the SE(3) Transformation matrix (a composition of translation vector and rotation matrix) can be obtained through the so called 'wedge' or 'hat' operator and the matrix exponentiation. (I found this cheat-sheet to be an excellent overview)
Now my question: Can scipy be used to optimize a 3D pose that is parametrized by the twist coordinates? I read somewhere that such problems require 'on manifold optimization' methods. So can I use scipy's least_square() or minimize(method="BFGS") for this? or do these only work for flat euclidean spaces?
Alternatively it would also help me a lot if anyone knows of any example where scipy is used to solve a 3D pose optimization problem. I have been looking for examples for the last couple of days but without much success.
This question is a implementation specific part of a more general question I posted on the robotics stackexchange here.

How to evaluate a Hamiltonian (Quantum Mechanics) in Python

I'm working on this project where I've been tasked to model the band structure of various potentials, I've worked through all of the math on paper and have had success hard coding some results, but I'm looking to be able to produce results from scratch providing only the eigenvector, Hamiltonian, and potential being explored, I'm working in Python by the way.
So far I've been able to represent the components of my Hamiltonian that are just dependent on the (-h_bar^2/2m)(d^2/dx^2). I'm using Numpy to represent my bra's as arrays and then using Numpy's inner product function to evaluate the components of my Hamiltonian that are just dependent on the second derivative and its respective constants. Issues arise when I go to try and evaluate the components of the Hamiltonian that are potential dependent (seeing that the full Hamiltonian operator is (-h_bar^2/2m)(d^2/dx^2) + V(x)).
I'm not quite sure how to complete this part. I've tried evaluating the inner product in its integral form using SciPy, but I keep running into issues when trying to evaluate these integrals that have complex components (SciPy doesn't like that).
To get a more solid idea of what I'm doing, here's the PDF I'm working out of:https://era.library.ualberta.ca/items/4835014b-1dbc-48e1-bbec-c175c87c9b03/view/000b36c4-55ba-471b-aaf8-d9d1c5f5ee06/Pavelich_Robert_L_201609_MSc.pdf (page 19-22 as written in the actual document)
Any help would be much appreciated, I'm fairly new to Quantum Mechanics as a whole and even greener when it comes to modeling it. Thanks a lot!
The other way to compute Hamiltonian with your given Potential can be evaluated using Finite difference method where you can diagonalize your Hamiltonian and calculate eigen value and eigen states, Therefore could obtain the spectrum .
This code might be helpful https://github.com/mholtrop/QMPython/blob/master/Finite%20Well%20Bound%20States.ipynb

Computing intersection of a function with a specific interval using scipy

I'm stuck trying to get functions that are existent in scipy (or sympy) for the following task:
Suppose we are given the following function:
f(A,B,C) = k1-A*sin(B*k2-C)
for each of the axis A,B,C of the space we have a specific interval, like [a_lb, a_ub], [b_lb, b_ub], [c_lb, c_ub], [d_lb, d_ub].
Which functions of scipy can be used to compute if the space encompassed by the boundaries is intersected by the given function? I thought of like e.g. computing the Hessian matrix.
Thank you for hints
Best regards
If I understand correctly, what you are looking for is an answer to whether f(A,B,C) bounded in the domain [a_l,a_u]x[b_l,b_u]x[c_l,c_u] has a value within [d_l,d_u]. You can try using scipy.optimize.minimize for this.
If you run scipy.optimize.minimize on f with the bounds [a_l,a_u]x[b_l,b_u]x[c_l,c_u], you should get the minimal value of f in the domain. Similarly, minimizing -f will give you the maximal value of f in the domain. f intersects the given boundary if and only if the interval [fmin, fmax] intersects the interval [d_l,d_u].
Note that scipy.optimize.minimize is a non-linear optimization and therefore requires an initial guess. The middle point of the domain box is a natural choice, but since the non-linear optimization may encounter a local minimum (or not converge), you may want to try several other initial guesses as well. scipy.optimize.minimize has many (optional) parameters so I recommend you read its documentation and play with them to fine-tune your usage to your needs.

Multilateration Algorithm

I'm trying to call upon the famous multilateration algorithm in order to pinpoint a radiation emission source given a set of arrival times for various detectors. I have the necessary data, but I'm still having trouble implementing this calculation; I am relatively new with Python.
I know that, if I were to do this by hand, I would use matrices and carry out elementary row operations in order to find my 3 unknowns (x,y,z), but I'm not sure how to code this. Is there a way to have Python implement ERO, or is there a better way to carry out my computation?
Depending on your needs, you could try:
NumPy if your interested in numerical solutions. As far as I remember, it could solve linear equations. Don't know how it deals with non-linear resolution.
SymPy for symbolic math. It solves symbolically linear equations ... according to their main page.
The two above are "generic" math packages. I doubt you will find (easily) any dedicated (and maintained) library for your specific need. Their was already a question on that topic here: Multilateration of GPS Coordinates

Newton-Raphson linearization? Second-Order Nonlinear ODE numpy-scipy Python

I am try to solve the next equation more than one week:
I have to use Newton-Raphson Method for getting the approximate solution of u. I have the script to do that, but I need to "linearize" this non linear ODE. The k1-k4 are not constants. On each grid point (x=1-100) they get a different value which is calculated. The initial condition is u(0)=0.
Is this a homework assignment?
Also, is it a boundary value problem or an ODE? From what you write, it sounds like BVP. Also, your boundary condition at u(0) is not enough.
If BVP, you can just use scikits.bvp_solver or scikits.bvp1lg which do the difficult parts for you.
If ODE, write the problem as a first order system, and use scipy.integrate.odeint or scipy.integrate.ode.
Regarding linearization (assuming this is a BVP): in practice it is usually enough to compute the partial derivative required for the Newton method via numerical differentiation.

Categories