Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Modelling early organogenesis as a sphere packing process
import autograd.numpy as np
from autograd import grad
def U(x):
definition of the symmetric potential function
return (x-50.0)**2
def net_potential(x,y):
A function that allows us to calculate the sum of N-1 potentials.
D = np.sum(np.square(x-y),axis=1)
return np.sum([U(d) for d in D])
## partial derivative of the net potential wrt a particular cell
NP_gradient = grad(net_potential,0)
def sphere_packing(N,iters):
i = 0
points = 5*(2*np.random.rand(N,3)-1.0)
while i < iters:
## update the positions of each point:
for k in range(N):
## define x:
x = points[k]
## compute the net potential gradient of x wrt other points:
ind = np.ones((N,), bool) ## define indices of points
ind[k] = False
y = points[ind]
## update the kth point:
points[k] -= 0.0001*NP_gradient(x,y)
return points
## the case of the tetrahedron:
P = sphere_packing(4,100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment