Procrustes Analysis with NumPy?

I’m not aware of any pre-existing implementation in Python, but it’s easy to take a look at the MATLAB code using edit procrustes.m and port it to Numpy: def procrustes(X, Y, scaling=True, reflection=’best’): “”” A port of MATLAB’s `procrustes` function to Numpy. Procrustes analysis determines a linear transformation (translation, reflection, orthogonal rotation and scaling) of … Read more

Fast interpolation of grid data

Sure! There are two options that do different things but both exploit the regularly-gridded nature of the original data. The first is scipy.ndimage.zoom. If you just want to produce a denser regular grid based on interpolating the original data, this is the way to go. The second is scipy.ndimage.map_coordinates. If you’d like to interpolate a … Read more

Scipy.optimize Inequality Constraint – Which side of the inequality is considered?

Refer to https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html and scroll down to Constrained minimization of multivariate scalar functions (minimize), you can find that This algorithm allows to deal with constrained minimization problems of the form: where the inequalities are of the form C_j(x) >= 0. So when you define the constraint as def constraint1(x): return x[0]+x[1]+x[2]+x[3]-1 and specify the type … Read more

Fit mixture of two gaussian/normal distributions to a histogram from one set of data, python

Here a simulation with scipy tools : from pylab import * from scipy.optimize import curve_fit data=concatenate((normal(1,.2,5000),normal(2,.2,2500))) y,x,_=hist(data,100,alpha=.3,label=”data”) x=(x[1:]+x[:-1])/2 # for len(x)==len(y) def gauss(x,mu,sigma,A): return A*exp(-(x-mu)**2/2/sigma**2) def bimodal(x,mu1,sigma1,A1,mu2,sigma2,A2): return gauss(x,mu1,sigma1,A1)+gauss(x,mu2,sigma2,A2) expected=(1,.2,250,2,.2,125) params,cov=curve_fit(bimodal,x,y,expected) sigma=sqrt(diag(cov)) plot(x,bimodal(x,*params),color=”red”,lw=3,label=”model”) legend() print(params,’\n’,sigma) The data is the superposition of two normal samples, the model a sum of Gaussian curves. we obtain : And … Read more