tPSO

tuning particle swarm optimiser (tPSO) for tuning optimization algorithms according to single objective. tPSO is a stripped down version of tMOPSO, which only focuses on a single OFE budget only.

class optTune.tPSO(optAlg, OFE_budget, CPV_lb, CPV_ub, CPV_validity_checks, sampleSizes, gammaBudget, N=15, w=0.4, c_g=2.0, c_p=2.0, resampling_interruption_confidence=0.9, constrain_to_initilization_bounds=False, saveTo=None, saveInterval=10, printFunction=<function to_stdout at 0x2b1de403dcf8>, printLevel=2, addtoBatch=<function _passfunction at 0x2b1ddd480230>, processBatch=<function _passfunction at 0x2b1ddd480230>, post_iteration_function=<function _passfunction at 0x2b1ddd480230>, record_X_hist=True, record_V_hist=True)

Single-objective particle swarm optimisation for tuning optimization algorithms to single OFE budget

Required Args
  • optAlg - function called with args (CPVs, OFE_budget, randomSeed) and return best solution error, (i.e f_found_opt - f_min)
  • OFE_budget - OFE budget under which optAlg is tuned
  • CPV_lb - initialization lower bound for CPV tuning, i.e. numpy.array([CPV_1_init_lb, CPV_2_init_lb, ...])
  • CPV_ub - numpy.array([CPV_1_init_ub, CPV_2_init_ub, ...])
  • CPV_validity_checks - function used to check validity of candidate CPVs. Usage CPV_validity_checks(CPV_array, OFE_budget) returns tuple (valid, msg) where msg is string of why invalid. Should be a cheap function, as candidate CPVs are regenerated if they do not satisfy it. Use to prevent negative population sizes, populations size larger then OFE_budget checks, etcetera.
  • CPV_ineq - vector which returned the amount by which each inequality constraint is violated. This should be a cheap function, as candidate CPVs are regenerated if they do not satisfy it. Use to prevent negative population sizes etcetera. Input vector of CPVs like CPV_lb
  • sampleSizes - sample sizes used to generate and refined CPV utility values. For example if the sampleSizes are [5,15,30] all candidate CPVs will be sampled 5 times, the possible not dominated CPVs are then sampled another 15 times, and if still promising another 30 times. CPV which returned performances are therefore averaged over 50 independent instances.
  • gammaBudget - the number of application layer evaluations (evaluation of the function optAlg optimizes) allocated for the tuning. NB include repeats, i.e. assessing optAlg for on OFE budget of 100 at 5 repeats, counts as a gamma of 500.
Optional Args
  • saveTo - filename used to save optimization progress (one save per itteration), use None to disable saving
  • N - tMOPSO population size
  • w - tMOPSO particle inertia factor
  • c_g - parameter controling the attraction towards the global guide
  • c_p - parameter controling the attraction towards the particles personal guide
  • resampling_interruption_confidence - re-sampling interuption confindence level used by noise stratergy
  • printLevel - 0 no printing, 1 only warnings, 2 overall info, 3 lots of info, 4 verbose (not implemented)
  • addtoBatch - args for optAlg, passed to this function before optAlg is called,
  • processBatch - function is called after all addtoBatch_function have been called. If used then optAlg, should be retrieve solutions from this functions results
  • post_iteration_function - at the end of each iteration this function is called with tPSO instance as the only arg.

Example

Pure Python example

"""
Tune the simulated annealing algorithm from the scipy package to the 5D Rosenbrock problem, for multiple objective function evaluation budgets simulatenously. The contorl parameter values (CPVs)  tuned are those which control are those which control the rate of exploration versus the rate of exploitation, namely 
 * m - control how quickly the Temperature cools down, i.e. higher m = higher exploration and lower exploitation.
        c = m * exp(-n * quench)
        T_new = T0 * exp(-c * k**quench)
 * dwell - evaluation at each tempreture
"""
import numpy
from scipy import optimize
from optTune import tPSO


def Ros_ND(x) :
    "gerneralised Rossenbrock function"
    return sum([100*(x[ii+1]-x[ii]**2)**2 + (1-x[ii])**2 for ii in range(len(x)-1)])

def run_simulated_annealing(CPVs, OFE_budget, randomSeed):
    R = optimize.anneal(Ros_ND, 
                    x0 = -2.048 + 2*2.048*numpy.random.rand(5),
                    dwell=int(CPVs[0]), 
                    m = CPVs[1],
                    T0 = 500.0,
                    lower= -2.048,
                    upper=  2.048,
                    maxeval = OFE_budget, #termination criteria
                    feps = 0.0, 
                    Tf = 0.0)
    return  Ros_ND(R[0]) # where xMin = R[0]

def CPV_valid(CPVs, OFE_budget):
    if CPVs[0] > OFE_budget:
        return False, 'dwell,CPVs[0] > OFE budget'
    if CPVs[0] < 5:
        return False,'dwell,CPVs[0] < 5'
    if CPVs[1] < 0.0001:
        return False,'CPVs[1] < 0.0001'
    return True,''

tuningOpt = tPSO( 
    optAlg = run_simulated_annealing, 
    CPV_lb = numpy.array([10, 0.0]), 
    CPV_ub = numpy.array([50, 5.0]),
    CPV_validity_checks = CPV_valid,
    OFE_budget= 500,
    sampleSizes = [2,8,20], #resampling size of 30
    resampling_interruption_confidence = 0.6,
    gammaBudget = 500*1000,
    N = 10,
    )
print(tuningOpt)
print('''Best CPVs founds for Rossenbrock 5D, given an OFE budget of %i, 
  - dwell               %f
  - cool down rate (m)  %f
''' % (tuningOpt.OFE_budget, tuningOpt.x_gb[0], tuningOpt.x_gb[1]))

Table Of Contents

Previous topic

tMOPSO

Next topic

FBM

This Page