[SciPy-User] How to tell a domain to fmin

Chris Weisiger cweisiger at msg.ucsf.edu
Sat Apr 16 17:06:40 EDT 2011


You are in control of the cost function passed to fmin. If it wants a value
outside the domain, you can simply return a very high cost. That should
effectively constrain the search space to only values inside the desired
domain. E.g.

def costFunc(coordinates):
    x, y = coordinates
    if x < 0 or x > 1 or x < 0 or x > 1:
        return 10 ** 10
    return g(x, y)

2011/4/16 亀田馬志 <masashi.kameda at gmail.com>

> Hello, there.
> I'm a newbie to scypi, and have stuck around it for a week. Please give me
> some advice.
>
> Suppose I have a formula, geometric mean with logarithm. Let's say I have
> something like
>
> g(x, y) = 0.35*ln|1+4*x+2*y|+0.35*ln|1-x+2*y|+0.3*ln|1-x-y|
>
> and want to find its maximum. fmin seems estimated to calculate the
> minimum, so I just give
> this formula with negative sign to fmin.
> fmin told the minimum(actually maximum) of the function. It gives me the
> result:
>
> Out[4]: array([ -5.30653193e-09,   4.00000010e-01])
>
> The first element is the negative one. But this is not what I want to get.
> To be honest, I want to know the maximum in a certain domain, for instance,
> x >= 0, y >= 0, x + y < 1
> ; however I don't know how to tell the domain to fmin.
>
> I tested some similar geometric means given to fmin, and it sometimes gives
> "math domain error" or
> "maximum function evaluates exceeded" because fmin calculates over the area
> where I estimated, or domain.
>
> Please tell me how to tell domain to fmin.
>
>
> --
> 亀田馬志
> Masahi Kameda
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110416/81d12ba6/attachment.html>


More information about the SciPy-User mailing list