Picon
Picon
Favicon

Advice on Simulated Annealing (ticket #875)

Hi,

Is there anyone here who has some experience with simulated annealing?

The code at

http://scipy.org/scipy/scipy/ticket/875#comment:1

looks fragile, but I don't know how to fix it best.

Thanks
Stéfan
josef.pktd | 2 Mar 12:53
Picon

Re: Advice on Simulated Annealing (ticket #875)

On Mon, Mar 2, 2009 at 12:55 AM, Stéfan van der Walt <stefan <at> sun.ac.za> wrote:
> Hi,
>
> Is there anyone here who has some experience with simulated annealing?
>
> The code at
>
> http://scipy.org/scipy/scipy/ticket/875#comment:1
>
> looks fragile, but I don't know how to fix it best.
>
> Thanks
> Stéfan

I had looked at this ticket briefly, and, I think, following his
suggestion of building the random array xt incrementally should not
affect any other code and speed up finding a random array inside the
bounds.

The elements of xc are independently drawn, so in each iteration only
those values, for which indu or indo are true, have to be replaced,
and successfull draws can be kept. xc can be drawn for the full array
and partially discarded, since this is cheap.

something like this (use correct `or` and initialize indu and indo for
first iteration) should work

xt[indu or indo] = x0[indu or indo] + xc[indu or indo]

Josef
(Continue reading)

Sturla Molden | 2 Mar 13:52
Picon

Re: Advice on Simulated Annealing (ticket #875)

On 3/2/2009 6:55 AM, Stéfan van der Walt wrote:
> Hi,
> 
> Is there anyone here who has some experience with simulated annealing?
> 
> The code at
> 
> http://scipy.org/scipy/scipy/ticket/875#comment:1

An atrocious thing about SciPy's SA is line 188 in anneal.py that says

   schedule = eval(schedule+'_sa()')

S.M.
_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev
Sturla Molden | 2 Mar 14:54
Picon

Re: Advice on Simulated Annealing (ticket #875)

On 3/2/2009 6:55 AM, Stéfan van der Walt wrote:

> http://scipy.org/scipy/scipy/ticket/875#comment:1
> 
> looks fragile, but I don't know how to fix it best.

This ticket i bogus. There is no simple_sa in anneal.py in SVN, and line 
151 is a docstring. Google says that the simple_sa class was posted to 
this mailing list two years ago by William Ratcliff. But as far as I can 
tell it is not in SciPy.

Sturla Molden
_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev
Robert Cimrman | 2 Mar 15:14
Picon

ANN: SfePy 2009.1

I am pleased to announce the release of SfePy 2009.1.

SfePy (simple finite elements in Python) is a finite element analysis 
software based primarily on Numpy and SciPy.

Mailing lists, issue tracking, git repository: http://sfepy.org
Home page: http://sfepy.kme.zcu.cz

Major improvements:
- new solvers:
   - simple backtracking steepest descent optimization solver
   - PETSc Krylov solvers via petsc4py, sequential mode
   - LOBPCG eigenvalue solver (SciPy implementation)
- new mesh readers:
    - mesh3d (hermes3d)
    - AVS UCD ascii mesh
    - Hypermesh ascii mesh
- homogenization framework:
   - unified approach to resolve data dependencies: HomogenizationEngine 
class
- switched DVCS from mercurial to git

Applications:
- phononic materials:
   - dispersion analysis, phase velocity computation for phononic materials
   - caching of coefficients to speed up parametric runs
- schroedinger.py:
   - fixed DFT iterations, iteration plot saving
   - basic smearing around Fermi limit

(Continue reading)

william ratcliff | 2 Mar 15:43
Picon

Re: Advice on Simulated Annealing (ticket #875)

I posted a suggested patch because it would seem that the simulated annealing routine in scipy as it was would not respect bounds for the search space.  I'll try to reconstruct the test case to show where it fails.  There seemed to be a lack of interest in a version that did respect bounds (upper/lower limits on the parameters), so I've just been using my own copy.


Cheers,
William

On Mon, Mar 2, 2009 at 8:54 AM, Sturla Molden <sturla <at> molden.no> wrote:
On 3/2/2009 6:55 AM, Stéfan van der Walt wrote:

> http://scipy.org/scipy/scipy/ticket/875#comment:1
>
> looks fragile, but I don't know how to fix it best.

This ticket i bogus. There is no simple_sa in anneal.py in SVN, and line
151 is a docstring. Google says that the simple_sa class was posted to
this mailing list two years ago by William Ratcliff. But as far as I can
tell it is not in SciPy.

Sturla Molden
_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev

_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev
william ratcliff | 2 Mar 18:04
Picon

Re: Advice on Simulated Annealing (ticket #875)

Here is code that will demonstrate the failure.  Suppose you want to minimize the simple function f(x,y)=x^2+y^2, but you want to do it in a specified domain.  This will not respect the upper and lower bounds:

cheers,
William


import numpy as N
import scipy.optimize.anneal as anneal

def fcn(p):
    x,y=p  
    result=x**2+y**2
    return result


if __name__=="__main__":
    p0=N.array([3,3],'d')
    lowerm=[1,1]
    upperm=[4,4]
    myschedule='fast'
    p0,jmin=anneal(fcn,p0,\
                  schedule=myschedule,lower=lowerm,upper=upperm,\
                  maxeval=None, maxaccept=None,dwell=10,maxiter=600,T0=10000)
    print 'p0',p0,'jmin',jmin




On Mon, Mar 2, 2009 at 9:43 AM, william ratcliff <william.ratcliff <at> gmail.com> wrote:
I posted a suggested patch because it would seem that the simulated annealing routine in scipy as it was would not respect bounds for the search space.  I'll try to reconstruct the test case to show where it fails.  There seemed to be a lack of interest in a version that did respect bounds (upper/lower limits on the parameters), so I've just been using my own copy.


Cheers,
William


On Mon, Mar 2, 2009 at 8:54 AM, Sturla Molden <sturla <at> molden.no> wrote:
On 3/2/2009 6:55 AM, Stéfan van der Walt wrote:

> http://scipy.org/scipy/scipy/ticket/875#comment:1
>
> looks fragile, but I don't know how to fix it best.

This ticket i bogus. There is no simple_sa in anneal.py in SVN, and line
151 is a docstring. Google says that the simple_sa class was posted to
this mailing list two years ago by William Ratcliff. But as far as I can
tell it is not in SciPy.

Sturla Molden
_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev


_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev
josef.pktd | 2 Mar 20:04
Picon

Re: Advice on Simulated Annealing (ticket #875)

On Mon, Mar 2, 2009 at 12:04 PM, william ratcliff
<william.ratcliff <at> gmail.com> wrote:
> Here is code that will demonstrate the failure.  Suppose you want to
> minimize the simple function f(x,y)=x^2+y^2, but you want to do it in a
> specified domain.  This will not respect the upper and lower bounds:
>
> cheers,
> William
>
>
> import numpy as N
> import scipy.optimize.anneal as anneal
>
> def fcn(p):
>     x,y=p
>     result=x**2+y**2
>     return result
>
>
> if __name__=="__main__":
>     p0=N.array([3,3],'d')
>     lowerm=[1,1]
>     upperm=[4,4]
>     myschedule='fast'
>     p0,jmin=anneal(fcn,p0,\
>                   schedule=myschedule,lower=lowerm,upper=upperm,\
>                   maxeval=None,
> maxaccept=None,dwell=10,maxiter=600,T0=10000)
>     print 'p0',p0,'jmin',jmin
>
>

After looking a bit more carefully:

`upper` and `lower` in` fast_ca` are the bounds on the updating
increment, xc, not on the parameters that are estimated x0, xnew  and
in the ticket. I didn't see any constraints on the parameters
themselves in anneal.

The current bounds restrict the updating to local perturbations, while
in your case perturbations would always be global.

Rewriting anneal to incorporate bounds might be a good enhancement
but, I think, you need to distinguish between bounds on the parameters
and bounds on the update increments. Then the update increments can
easily bound by  (xbounds - x0)  and you don't need iteration to find
the updated values.

Josef
Bruce Southey | 2 Mar 20:09
Picon

Depreciating functions in scipy.stats

Hi,
I am seeing a few functions that should be made depreciated as these 
appear to duplicate Numpy or Scipy functions.

Do you want these as new or old tickets (for example, samplestd has 
ticket #81 as part of the Statistics Review)?
Would you want a large patch or one for each ticket?

These functions are just renamed functions present in scipy.special just 
with perhaps slightly more informative names:
erfc
ksprob
fprob
chisqprob
zprob
But I do not think we need these as separate functions but there is the 
issue of depreciation involved if users use these specific functions.

There are other like that should be treated as depreciated:
samplestd
samplevar

 >>> import numpy as np
 >>> import scipy.stats.stats as stats
 >>> a=np.array([[1,2,3,4,5], [6,7,8,9,10]])
 >>> np.std(a,axis=0)
array([ 2.5,  2.5,  2.5,  2.5,  2.5])
 >>> stats.samplestd(a,axis=0)
array([ 2.5,  2.5,  2.5,  2.5,  2.5])
 >>> stats.samplestd(a,axis=None)
2.8722813232690143
 >>> np.std(a,axis=None)
2.8722813232690143

Also, stats.py has the histogram and histogram2 functions where I agree 
with the comment in the code about being obsoleted by numpy.histogram.  
I would think these should be depreciated although the cumfreq and 
relfreq functions would need to be rewritten,

Thanks
Bruce
william ratcliff | 2 Mar 20:15
Picon

Re: Advice on Simulated Annealing (ticket #875)

Perhaps we could enhance the documentation so this is clear?  Also, having another module which does impose bounds on the actual values of the parameters would be useful.  My ansatz was that if the next iteration would fall outside of the bounds, stay at the current location.


Cheers,
William

On Mon, Mar 2, 2009 at 2:04 PM, <josef.pktd <at> gmail.com> wrote:
On Mon, Mar 2, 2009 at 12:04 PM, william ratcliff
> Here is code that will demonstrate the failure.  Suppose you want to
> minimize the simple function f(x,y)=x^2+y^2, but you want to do it in a
> specified domain.  This will not respect the upper and lower bounds:
>
> cheers,
> William
>
>
> import numpy as N
> import scipy.optimize.anneal as anneal
>
> def fcn(p):
>     x,y=p
>     result=x**2+y**2
>     return result
>
>
> if __name__=="__main__":
>     p0=N.array([3,3],'d')
>     lowerm=[1,1]
>     upperm=[4,4]
>     myschedule='fast'
>     p0,jmin=anneal(fcn,p0,\
>                   schedule=myschedule,lower=lowerm,upper=upperm,\
>                   maxeval=None,
> maxaccept=None,dwell=10,maxiter=600,T0=10000)
>     print 'p0',p0,'jmin',jmin
>
>

After looking a bit more carefully:

`upper` and `lower` in` fast_ca` are the bounds on the updating
increment, xc, not on the parameters that are estimated x0, xnew  and
in the ticket. I didn't see any constraints on the parameters
themselves in anneal.

The current bounds restrict the updating to local perturbations, while
in your case perturbations would always be global.

Rewriting anneal to incorporate bounds might be a good enhancement
but, I think, you need to distinguish between bounds on the parameters
and bounds on the update increments. Then the update increments can
easily bound by  (xbounds - x0)  and you don't need iteration to find
the updated values.

Josef
_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev

_______________________________________________
Scipy-dev mailing list
Scipy-dev <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev

Gmane