[Numpy-discussion] quadratic function

Brennan Williams brennan.williams at visualreservoir.com
Thu Oct 28 13:47:36 EDT 2010


  On 29/10/2010 6:35 a.m., Robert Kern wrote:
> On Thu, Oct 28, 2010 at 12:33, Brennan Williams
> <brennan.williams at visualreservoir.com>  wrote:
>>   On 29/10/2010 2:34 a.m., Robert Kern wrote:
>>> On Thu, Oct 28, 2010 at 06:38, Brennan Williams
>>> <brennan.williams at visualreservoir.com>    wrote:
>>>>    I have used both linear least squares and radial basis functions as a
>>>> proxy equation, calculated from the results of computer simulations
>>>> which are calculating some objective function value based on a number of
>>>> varied input parameters.
>>>>
>>>> As an alternative option I want to add a quadratic function so if there
>>>> are parameters/variables x,y,z then rather than just having a linear
>>>> function f=a+bx+cy+dz I'll have f=a+bx+cx**2 + dxy + .... I'd like to
>>>> have the option not to include all the different second order terms.
>>> A = np.column_stack([
>>>       np.ones_like(x),
>>>       x, y, z,
>>>       x*x, y*y, z*z,
>>>       x*y, y*z, x*z,
>>> ])
>>> x, res, rank, s = np.linalg.lstsq(A, f)
>>>
>> OK, so in other words, you can use linalg.lstsq for whatever higher
>> order terms you want to include or exclude. Very nice. Thanks.
> Right. Just as long as the problem is linear in the coefficients, the
> design matrix can be derived however you like.
>
So I could optionally put log terms in if I thought it was linear in 
log(x) for example?
>> On a related topic I also use the Rbf radial basis function as a proxy
>> equation. I have one set of data that it fails to return an Rbf for and
>> I've just realised that in my set of simulations that are used to build
>> the proxy equation I have some duplicate equations. I'm wondering if Rbf
>> doesn't like duplicate points? It obviously doesn't affect linalg.lstsq.
> Rbf doesn't like duplicate points. :-)
OK, fair enough, I just need to add a bit of housekeeping to remove 
duplicate simulations.
Thanks for the confirmation.





More information about the NumPy-Discussion mailing list