Exemple #1
0
    def get_delta_root( arg, dir, par_at_min ):

        my_neg_pos = ConfBracket.neg_pos[ dir ]

        if is_iterable( arg ):
            return arg
            #return map( lambda x: my_neg_pos * abs( x - par_at_min ), arg )
        elif None != arg:
            arg -= par_at_min
            return my_neg_pos * abs( arg )
        else:
            return arg
Exemple #2
0
    def get_delta_root(arg, dir, par_at_min):

        my_neg_pos = ConfBracket.neg_pos[dir]

        if is_iterable(arg):
            return arg
            # return map( lambda x: my_neg_pos * abs( x - par_at_min ), arg )
        elif None != arg:
            arg -= par_at_min
            return my_neg_pos * abs(arg)
        else:
            return arg
Exemple #3
0
        def myformat( hfmt, str, lowstr, lownum, highstr, highnum ):
            str += hfmt % ('Param', 'Best-Fit', 'Lower Bound', 'Upper Bound')
            str += hfmt % ('-'*5, '-'*8, '-'*11, '-'*11)

            for name, val, lower, upper in izip(self.parnames, self.parvals,
                                                self.parmins, self.parmaxes):

                str += '\n   %-12s %12g ' % (name, val)
                if is_iterable( lower ):
                    str += ' '
                    str += list_to_open_interval( lower )
                elif (lower is None):
                    str += lowstr % '-----'
                else:
                    str += lownum % lower
                if is_iterable( upper ):
                    str += '  '
                    str += list_to_open_interval( upper )
                elif (upper is None):
                    str += highstr % '-----'
                else:
                    str += highnum % upper

            return str
Exemple #4
0
    def print_status( myblog, verbose, prefix, answer, lock ):

        if lock is not None:
            lock.acquire()

        if 0 == verbose:
            msg = '%s\t' % prefix.lstrip()
        else:
            msg = '%s\t' % prefix

        if is_iterable( answer ):
            msg += list_to_open_interval( answer )
        elif answer is None:
            msg += '-----'
        else:
            msg += '%g' % answer
        myblog( msg )

        if lock is not None:
            lock.release()
Exemple #5
0
    def print_status(myblog, verbose, prefix, answer, lock):

        if lock is not None:
            lock.acquire()

        if 0 == verbose:
            msg = '%s\t' % prefix.lstrip()
        else:
            msg = '%s\t' % prefix

        if is_iterable(answer):
            msg += list_to_open_interval(answer)
        elif answer is None:
            msg += '-----'
        else:
            msg += '%g' % answer
        myblog(msg)

        if lock is not None:
            lock.release()
Exemple #6
0
def optneldermead(
    afcn,
    x0,
    xmin,
    xmax,
    ftol=EPSILON,
    maxfev=None,
    initsimplex=0,
    finalsimplex=None,
    step=None,
    multicore=False,
    verbose=None,
):

    x, xmin, xmax = _check_args(x0, xmin, xmax)

    nfev, fcn = func_counter(afcn)

    if step is None or (numpy.iterable(step) and len(step) != len(x)):
        step = 1.2 * numpy.ones(x.shape, numpy.float_, numpy.isfortran(x))
    elif numpy.isscalar(step):
        step = step * numpy.ones(x.shape, numpy.float_, numpy.isfortran(x))

    if maxfev is None:
        maxfev = 1024 * len(x)

    if finalsimplex is None:
        finalsimplex = [0, 2]

    if False == is_iterable(finalsimplex):
        finalsimplex = [finalsimplex]

    # For internal use only:
    debug = True

    def myloop(xxx, mymaxfev, mystep):

        nms = classicNelderMead(fcn)
        mynfev = 0
        for myfinalsimplex in finalsimplex:
            starttime = time.time()
            result = nms(
                xxx, xmin, xmax, mymaxfev - mynfev, ftol, mystep, initsimplex, myfinalsimplex, multicore, verbose
            )
            mynfev += result[3]
            if 0 != result[0]:
                return result[0], result[1], result[2], mynfev
            if debug:
                print "neldermead::myloop: result = ", result, " took ", time.time() - starttime, " secs"
        if multicore:
            return result[0], result[1], result[2], mynfev + nfev[0]
        else:
            return result[0], result[1], result[2], mynfev

    def myneldermead(xxx, mymaxfev, mystep, fold=numpy.float_(numpy.finfo(numpy.float_).max)):
        result = myloop(xxx, mymaxfev, mystep)
        mynfev = result[3]
        fnew = result[2]
        if (
            fnew < fold * 0.995
            and 0 == Knuth_close(fnew, fold, ftol)
            and 0 == Knuth_close(fnew, fold, ftol)
            and 0 == result[0]
            and mynfev < mymaxfev
        ):
            if debug:
                print "neldermead: fnew = ", fnew, "\tfold = ", fold, "\tx = ", result[1]
            result = myneldermead(result[1], mymaxfev - mynfev, step, fold=fnew)
            mynfev += result[3]
        return result[0], result[1], result[2], mynfev

    # result = myneldermead( x, maxfev, step )
    result = myloop(x, maxfev, step)
    return get_result(result, maxfev)
Exemple #7
0
def optneldermead(afcn,
                  x0,
                  xmin,
                  xmax,
                  ftol=EPSILON,
                  maxfev=None,
                  initsimplex=0,
                  finalsimplex=None,
                  step=None,
                  multicore=False,
                  verbose=None):

    x, xmin, xmax = _check_args(x0, xmin, xmax)

    nfev, fcn = func_counter(afcn)

    if step is None or (numpy.iterable(step) and len(step) != len(x)):
        step = 1.2 * numpy.ones(x.shape, numpy.float_, numpy.isfortran(x))
    elif numpy.isscalar(step):
        step = step * numpy.ones(x.shape, numpy.float_, numpy.isfortran(x))

    if maxfev is None:
        maxfev = 1024 * len(x)

    if finalsimplex is None:
        finalsimplex = [0, 2]

    if False == is_iterable(finalsimplex):
        finalsimplex = [finalsimplex]

    # For internal use only:
    debug = True

    def myloop(xxx, mymaxfev, mystep):

        nms = classicNelderMead(fcn)
        mynfev = 0
        for myfinalsimplex in finalsimplex:
            starttime = time.time()
            result = nms(xxx, xmin, xmax, mymaxfev - mynfev, ftol, mystep,
                         initsimplex, myfinalsimplex, multicore, verbose)
            mynfev += result[3]
            if 0 != result[0]:
                return result[0], result[1], result[2], mynfev
            if debug:
                print 'neldermead::myloop: result = ', result, ' took ', time.time(
                ) - starttime, ' secs'
        if multicore:
            return result[0], result[1], result[2], mynfev + nfev[0]
        else:
            return result[0], result[1], result[2], mynfev

    def myneldermead(xxx,
                     mymaxfev,
                     mystep,
                     fold=numpy.float_(numpy.finfo(numpy.float_).max)):
        result = myloop(xxx, mymaxfev, mystep)
        mynfev = result[3]
        fnew = result[2]
        if fnew < fold * 0.995 and 0 == Knuth_close( fnew, fold, ftol ) and \
               0 == Knuth_close( fnew, fold, ftol ) and \
               0 == result[0] and mynfev < mymaxfev:
            if debug:
                print 'neldermead: fnew = ', fnew, '\tfold = ', fold, \
                      '\tx = ', result[ 1 ]
            result = myneldermead(result[1],
                                  mymaxfev - mynfev,
                                  step,
                                  fold=fnew)
            mynfev += result[3]
        return result[0], result[1], result[2], mynfev

    #result = myneldermead( x, maxfev, step )
    result = myloop(x, maxfev, step)
    return get_result(result, maxfev)