Exemplo n.º 1
0
def minimize_f(fi, K=None, method=None, eps=None, accrual=None):
    """
    Minimize the ``fi`` function instance.  Returns the number of minimization
    iterations performed and method finding the optimum (if any).
    """
    f = fi.f
    optmethod = None

    pop = Population(
        fi, K,
        [MinimizeMethod(name, fi) for name in string.split(method, ',')])
    # Credit Assignment does not matter for us as long as it's order-invariant
    popcredit = PopulationCredit(pop, "raw", accrual)

    stop = False

    # Initial iterations - evaluate each function once.
    for i in range(K):
        (x, y) = pop.step_one(i)
        #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
        if y < f.ftarget:
            optmethod = pop.minimizers[i].minmethod.name
            stop = True
            break  # stop immediately, no point in going on
        pop.end_iter()
        popcredit.update()

    # Main set of iterations - explore/exploit.
    while not stop and f.evaluations < fi.maxfunevals:
        if np.random.rand() < eps:
            # Explore
            i = np.random.randint(K)
        else:
            # Exploit
            i = popcredit.credit.argmin()

        (x, y) = pop.step_one(i)
        #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
        if y < f.ftarget:
            optmethod = pop.minimizers[i].minmethod.name
            stop = True
            break  # stop immediately, no point in going on
        pop.end_iter()
        popcredit.update()

    pop.stop()

    return (pop.total_iters, optmethod)
Exemplo n.º 2
0
def minimize_f(fi, K=None, method=None):
    """
    Minimize the ``fi`` function instance.  Returns the number of minimization
    iterations performed and method finding the optimum (if any).
    """
    f = fi.f
    optmethod = None

    pop = Population(
        fi, K,
        [XMinimizeMethod(name, fi) for name in string.split(method, ',')])

    # Iterate; make a full iteration even in case maxfunevals is reached.
    stop = False
    while not stop:
        for i in range(K):
            (x, y) = pop.step_one(i)
            #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
            if y < f.ftarget:
                optmethod = pop.minimizers[i].minmethod.name
                stop = True
                break  # stop immediately, no point in going on

        if f.evaluations > fi.maxfunevals:
            stop = True
        pop.end_iter()

    pop.stop()

    return (pop.total_iters, optmethod)
Exemplo n.º 3
0
def minimize_f(fi, K = None, method = None, eps = None, accrual = None):
    """
    Minimize the ``fi`` function instance.  Returns the number of minimization
    iterations performed and method finding the optimum (if any).
    """
    f = fi.f
    optmethod = None

    pop = Population(fi, K, [MinimizeMethod(name, fi) for name in string.split(method, ',')])
    # Credit Assignment does not matter for us as long as it's order-invariant
    popcredit = PopulationCredit(pop, "raw", accrual)

    stop = False

    # Initial iterations - evaluate each function once.
    for i in range(K):
        (x, y) = pop.step_one(i)
        #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
        if y < f.ftarget:
            optmethod = pop.minimizers[i].minmethod.name
            stop = True
            break # stop immediately, no point in going on
        pop.end_iter()
        popcredit.update()

    # Main set of iterations - explore/exploit.
    while not stop and f.evaluations < fi.maxfunevals:
        if np.random.rand() < eps:
            # Explore
            i = np.random.randint(K)
        else:
            # Exploit
            i = popcredit.credit.argmin()

        (x, y) = pop.step_one(i)
        #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
        if y < f.ftarget:
            optmethod = pop.minimizers[i].minmethod.name
            stop = True
            break # stop immediately, no point in going on
        pop.end_iter()
        popcredit.update()

    pop.stop()

    return (pop.total_iters, optmethod)
Exemplo n.º 4
0
def minimize_f(fi, K = None, method = None):
    """
    Minimize the ``fi`` function instance.  Returns the number of minimization
    iterations performed and method finding the optimum (if any).
    """
    f = fi.f
    optmethod = None

    pop = Population(fi, K, [XMinimizeMethod(name, fi) for name in string.split(method, ',')])

    # Iterate; make a full iteration even in case maxfunevals is reached.
    stop = False
    while not stop:
        for i in range(K):
            (x, y) = pop.step_one(i)
            #print("[%d] #%d %s=%s" % (pop.total_iters, i, x, y))
            if y < f.ftarget:
                optmethod = pop.minimizers[i].minmethod.name
                stop = True
                break # stop immediately, no point in going on

        if f.evaluations > fi.maxfunevals:
            stop = True
        pop.end_iter()

    pop.stop()

    return (pop.total_iters, optmethod)