~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to cogent/maths/scipy_optimisers.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
import numpy
 
2
 
 
3
from __future__ import division
 
4
import numpy, time, math
3
5
from cogent.maths.scipy_optimize import fmin_bfgs, fmin_powell, fmin, brent
4
 
from optimiser import OptimiserBase
5
 
import time
 
6
from cogent.maths.optimiser import OptimiserBase
6
7
 
7
8
__author__ = "Peter Maxwell and Gavin Huttley"
8
9
__copyright__ = "Copyright 2007-2009, The Cogent Project"
9
10
__credits__ = ["Peter Maxwell", "Gavin Huttley"]
10
11
__license__ = "GPL"
11
 
__version__ = "1.4.1"
 
12
__version__ = "1.5.0"
12
13
__maintainer__ = "Gavin Huttley"
13
14
__email__ = "gavin.huttley@anu.edu.au"
14
15
__status__ = "Production"
51
52
    
52
53
    Since these are local optimisers, we sometimes restart them to
53
54
    check the result is stable.  Cost is less than 2-fold slowdown"""
 
55
    label = "local"
54
56
    
55
57
    default_max_restarts = 0
56
58
    # These are minimisers
67
69
        if tolerance is not None:
68
70
            self.ftol = tolerance
69
71
        self.max_evaluations = max_evaluations
70
 
    
71
 
    def runInner(self, function, xopt, show_progress, random_series=None):
 
72
 
 
73
    def runInner(self, function, xopt, show_remaining, random_series=None):
72
74
        # random_series isn't used - these optimisers are deterministic -
73
75
        # but optimiser_base doesn't know that.
74
76
        fval_last = fval = numpy.inf
77
79
        if len(xopt) == 0:
78
80
            return function(xopt), xopt, 1, time.time() - t0
79
81
        template = "\tNumber of function evaluations = %d; current F = %f"
80
 
        if show_progress:
 
82
        if show_remaining:
81
83
            def _callback(fcalls, x, fval, delta):
82
 
                print template % (fcalls, fval)
83
 
            _callback(1, xopt, function(xopt), None)
 
84
                remaining = math.log(max(abs(delta)/self.ftol, 1.0))
 
85
                show_remaining(remaining, -fval, delta, fcalls)
84
86
        else:
85
87
            _callback = None
86
88
        for i in range((self.max_restarts + 1)):
87
89
            (xopt, fval, iterations, func_calls, warnflag) = self._minimise(
88
 
                    function, xopt, disp=show_progress, callback=_callback, 
 
90
                    function, xopt, disp=False, callback=_callback, 
89
91
                    ftol=self.ftol, full_output=True,
90
92
                    maxfun=self.max_evaluations)
91
93
            xopt = numpy.atleast_1d(xopt) # unsqueeze incase only one param