Efficient least squares fit of 2D polynomials to data?
I have some data on a regular 2D grid that I would like to decompose into an orthogonal basis function set. What is the most efficient way to do the fit?
Here's some sample code:
import numpy as np
sze = (128,128)
x, y = np.linspace(1, 1, sze[1]), np.linspace(1, 1, sze[0])
xv, yv = np.meshgrid(x, y)
rho = np.sqrt(xv**2 + yv**2)
phi = np.arctan2(yv, xv)
data = (rho * np.cos(phi))
data[rho > 1] = 0
# now have some synthetic data  need to fit to a basis function set that has singleindex members:
# 0: 1
# 1: rho * cos(phi)
# 2: rho * sin(phi)
# ...
# 24: 70 rho^8  140 rho^6 + 90 rho^4  20 rho^2 + 1
See also questions close to this topic

django F ceil divison
I'm making annotate expression, and I don't know how to realize what I expect. The model has 3 integer fields "AA","BB","CC" and my goal is to calculate those 3 like
int(math.ceil(float(AA) / (BB)) *CC)
If AA=4,BB=2,CC=3, then the answer is 6. *case1
And AA=5,BB=2,CC=3, it takes 9. *case2
annotate(ans=F("AA")/F("BB")*("CC"))
This is enough for case1 because AA/BB is not rounded off,
but in case2, the answer takes 6.
I looked up this solution and found some ways. But I couldn't make it...

How do I make a multiplayer concurrent game in Django?
Noob here. I'm trying to create a multiplayer game, in each team there would be 3 people. Person B submits after Person A and Person C after Person B. How do I achieve this? Preferably in python (Django).

Differ between integer and float in an array
I have an assignment where I'm handed an array with numbers, integers, floats and possibly strings. I then have to identify which of the elements are contained in another array with pure integers and which are not. Those which are not contained in the array with integers must be printed and the user must change the element to a value that is contained in the array with integers. Though I have the problem that if the element in the element in the given array is a float, the output from the user's input also becomes a float, (Unless the input is a value from the array with integers.) The same problem also occurs if the element in the given array is an integer and the user's input is a float. Then the float rounds down to an integer. Can anyone give any tips how I should change this code, so the script runs flawless?
grades = np.array([3,10.5,0,7,4,8,4,7,10,5]) SevenGradeScale = np.array([3, 0, 2, 4, 7, 10, 12]) SevenGradeScale = SevenGradeScale.astype(int) for i in range(np.size(grades)): if grades[i] not in SevenGradeScale: while True: if grades[i] in SevenGradeScale: grades = grades.astype(int) print("The grade has been changed to {:d}. ".format(grades[i])) break elif type(grades[i]) is np.float64: print("\n{:.1f} is not a valid grade. The grade must be an integer.".format(grades[i])) elif type(grades[i]) is np.int32: print("\n{:d} is not within the seven grade scale.".format(grades[i])) elif type(grades[i]) is str: type("\n{:s} is not a valid grade.".format(grades[i])) try: grades[i] = float(input("Insert new grade: ")) except ValueError: pass
You would probably comment the "float(input())" but this somehow helped my script. Though I don't know if there are other possibilities.
When running the code and typing random inputs, I get following results
 10.5 is not a valid grade. The grade must be an integer. Insert new grade: 10.7 10.7 is not a valid grade. The grade must be an integer. Insert new grade: 10 The grade has been changed to 10. 8 is not within the seven grade scale. Insert new grade: 7.5 The grade has been changed to 7. 5 is not within the seven grade scale. Insert new grade: 5.5 5 is not within the seven grade scale. Insert new grade: string 5 is not within the seven grade scale. Insert new grade: 0 The grade has been changed to 0.

How does matlab lognfit work?
Does lognfit bin the data before fitting? If so, how does it determine the number of bins, the bin width, and pick the binned data points that get fitted? If not, how does it do the fit?

R Non linear mixed effect model fitting
I am trying to use a nlme to fit a rather simple function but I can't make it works. Could you tell me why? Thanks.
In the following example I would like to fit a to b. When b < a0 the relationship is random while > a0 the relationship follows a=ux+v
library(nlme) #Data simulation b=runif(100);c=sample(3,100,replace=T) a=jitter(ifelse(c==1,2*b1,ifelse(c==2,3*b+2,4*b+3)),amount=0.1) a[b<.5]=runif(length(which(b<.5))) dft=data.frame(a=a,b=b,c=c) dft2=groupedData( a ~ b  c,dft) #Fitting function fn=function(x,u=1,v=1,a0=.5) return(ifelse(x<a0,0,u*x+v)) l4=nlme(a~fn(b,u,v,a0),data=dft2,fixed=u+v+a0~1,random=u+v+a0~1,start=c(u=2,v=0,a0=.5)) #Error in chol.default((value + t(value))/2) : # The leading minor of order 3 is not positive definite

Fit plane to N dimensional points in MATLAB
I have a set of
N
points ink
dimensions as a matrix of sizeN X k
.How can I find the best fitting line through these points? The line will be a plane (hyerpplane) in
k
dimensions. It will havek
coefficients and one bias term.Existing functions like
fit
seem to be usable only for points in 2 or 3 dimension. 
Universal basis for graph analog of Boolean circuits?
The NAND gate is universal for Boolean circuits. That means that any function 2^n > 2 can be built out of NAND gates.
Let Omega be the subgraph classifier, the graph with two vertices t,f and five edges
in:t>t, out1:t>t, out2:t>f, out3:f>t, out4:f>f.
There's obviously a finite set of operations that covers all graph homomorphisms from Omega^n to Omega, because the set of all operations of that form is finite. But how small can that set be? I'd be satisfied with a formula parametric in n, but surprised if it actually depends on n; I'd expect it to be a finite set of binary operations.

Map an xyz coordinate inside a hexahedron to normalized 01 space
The problem I am trying to solve is as follows:
I have 8 coordinates in a 3D space that define a hexahedron (a distorted cube).
Next, I have a new arbitrary 3D coordinate in that space.
How do I map this new coordinate into the hexahedron's space where 01 defines the space inside the hexahedron in each axis?
Research I have done leads me to think the answer lies in matrix math "change of basis" operations. However, since it appears that the solution would need to account for a nonlinear transformation (the coordinates of any face of the hexahedron could form a trapezoid, for example) I am not sure where to look next. It seems the solution should be a fairly straightforward matrix math... but what? I am not sure where to even look next.