Esempio n. 1
0
    def reset(self):
        super(ModeaEnv, self).reset_()
        self.dim = self.instance[0]
        self.function_id = self.instance[1]
        self.instance_id = self.instance[2]
        self.representation = self.ensureFullLengthRepresentation(self.instance[3])

        opts = getOpts(self.representation[: len(options)])
        self.lambda_ = self.representation[len(options)]
        self.mu = self.representation[len(options) + 1]
        values = getVals(self.representation[len(options) + 2 :])

        self.function, self.target = bn.instantiate(int(self.function_id))
        self.es = CustomizedES(
            self.dim, self.function, self.budget, self.mu, self.lambda_, opts, values
        )
        parameter_opts = self.es.parameters.getParameterOpts()
        # print("Local restart on")
        if parameter_opts["lambda_"]:
            self.lambda_init = parameter_opts["lambda_"]
        elif parameter_opts["local_restart"] in ["IPOP", "BIPOP"]:
            self.lambda_init = int(4 + np.floor(3 * np.log(parameter_opts["n"])))
        else:
            self.lambda_init = None
        parameter_opts["lambda_"] = self.lambda_init

        # BIPOP Specific parameters
        self.lambda_ = {"small": None, "large": self.lambda_init}
        self.budgets = {"small": None, "large": None}
        self.regime = "first"
        self.update_parameters()
        return self.get_state(self)
Esempio n. 2
0
    def initializedESAlgorithm(self):
        representation = self.ensureFullLengthRepresentation(self.esconfig)
        opts = getOpts(representation[:len(options)])
        values = getVals(representation[len(options)+2:])
        values = getVals(self.esconfig)

        customES = Algorithms.CustomizedES(self.dimension, self.problemInstance, budget=self.totalBudget, opts=opts, values=values)

        customES.mutateParameters = customES.parameters.adaptCovarianceMatrix

        self.optimizer = customES
Esempio n. 3
0
def printResults():

    os.chdir(ga_location)
    x = np.load('final_GA_results.npz')
    results = x['results'].item()
    for dim in dimensions:
        print("{}-dimensional:".format(dim))
        for func in functions:
            print("  F{}:\t{} {}".format(
                func, results[dim][func]['best_result'],
                getPrintName(getOpts(results[dim][func]['best_result']))))
Esempio n. 4
0
def _problemCases():
    fid = 1
    ndim = 10
    iids = range(Config.ES_num_runs)

    # Known problems
    print("Combinations known to cause problems:")

    rep = ensureFullLengthRepresentation(getBitString({'sequential': True}))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(getBitString({'tpa': True}))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        getBitString({'selection': 'pairwise'}))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        getBitString({
            'tpa': True,
            'selection': 'pairwise'
        }))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    # these are the actual failures
    rep = ensureFullLengthRepresentation(
        getBitString({
            'sequential': True,
            'selection': 'pairwise'
        }))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        getBitString({
            'sequential': True,
            'tpa': True,
            'selection': 'pairwise'
        }))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)

    rep = ensureFullLengthRepresentation(
        [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 113, 0.18770573922911427])
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 107, 0.37768142336353183])
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        [0, 1, 1, 0, 1, 0, 1, 1, 0, 2, 2, None, None])
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
    rep = ensureFullLengthRepresentation(
        [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 27, 0.9383818903266666])
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)

    rep = ensureFullLengthRepresentation(
        [0, 0, 1, 1, 0, 0, 1, 0, 1, 2, 2, 3, 0.923162952008686])
    print(getPrintName(getOpts(rep[:-2])))
    evaluateCustomizedESs(rep, iids=iids, fid=fid, ndim=ndim)
Esempio n. 5
0
def runCustomizedES(representation, iid, rep, ndim, fid, budget):
    """
        Runs a customized ES on a particular instance of a BBOB function in some dimensionality with given budget.
        This function takes care of the BBOB setup and the translation of the representation to input arguments for
        the customizedES.

        :param representation:  Representation of a customized ES (structure and parameter initialization)
        :param iid:             Instance ID for the BBOB function
        :param rep:             Repetition number (for output storage purposes only)
        :param ndim:            Dimensionality to run the ES in
        :param fid:             BBOB function ID
        :param budget:          Evaluation budget for the ES
        :return:                Tuple(target optimum value of the evaluated function, list of fitness-values over time)
    """

    print(reprToString(representation), iid, rep)

    # Setup BBOB function + logging
    bbob_opts['algid'] = representation
    datapath_ext = '{repr}/{ndim}d-f{fid}/i{iid}-r{rep}/'.format(
        ndim=ndim,
        fid=fid,
        repr=reprToString(representation),
        iid=iid,
        rep=rep)
    guaranteeFolderExists(datapath + datapath_ext)

    f = fgeneric.LoggingFunction(datapath + datapath_ext, **bbob_opts)
    f_target = f.setfun(*bbobbenchmarks.instantiate(fid, iinstance=iid),
                        dftarget=Config.default_target).ftarget

    # Interpret the representation into parameters for the ES
    opts = getOpts(representation[:len(options)])
    lambda_ = representation[len(options)]
    mu = representation[len(options) + 1]
    values = getVals(representation[len(options) + 2:])

    # Run the ES defined by opts once with the given budget
    results = _customizedES(ndim,
                            f.evalfun,
                            budget,
                            lambda_=lambda_,
                            mu=mu,
                            opts=opts,
                            values=values)
    f.finalizerun()
    return f_target, results
Esempio n. 6
0
    def step(self, action):
        done = super(ModeaEnv, self).step_()
        # Todo: currently this doesn't support targets
        if (
            self.budget <= self.es.used_budget
            or self.es.parameters.checkLocalRestartConditions(self.es.used_budget)
        ):
            done = True

        self.representation = self.ensureFullLengthRepresentation(action)
        opts = getOpts(self.representation[: len(options)])
        self.adapt_es_opts(opts)

        # TODO: add ipop run (restarts)
        self.es.runOneGeneration()
        self.es.recordStatistics()

        return self.get_state(), self.get_reward(), done, {}
Esempio n. 7
0
    def reset(self):
        super(ModeaEnv, self).reset_()
        self.dim = self.instance[0]
        self.function_id = self.instance[1]
        self.instance_id = self.instance[2]
        self.representation = self.ensureFullLengthRepresentation(self.instance[3])

        opts = getOpts(self.representation[: len(options)])
        self.lambda_ = self.representation[len(options)]
        self.mu = self.representation[len(options) + 1]
        values = getVals(self.representation[len(options) + 2 :])

        self.function = bn.instantiate(int(self.function_id))[0]
        self.es = CustomizedES(
            self.dim, self.function, self.budget, self.mu, self.lambda_, opts, values
        )
        self.es.mutateParameters = self.es.parameters.adaptCovarianceMatrix
        self.adapt_es_opts(opts)
        return self.get_state()
Esempio n. 8
0
    def step(self, action):
        done = super(ModeaEnv, self).step_()
        self.representation = self.ensureFullLengthRepresentation(action)
        opts = getOpts(self.representation[: len(options)])
        self.switchConfiguration(opts)

        self.es.runOneGeneration()
        self.es.recordStatistics()

        if (
            self.es.budget <= self.es.used_budget
            or self.es.parameters.checkLocalRestartConditions(self.es.used_budget)
        ):
            done = done or self.restart()
            if self.es.total_used_budget < self.es.total_budget:
                self.update_parameters()
            else:
                done = True

        return self.get_state(self), self.get_reward(self), done, {}
Esempio n. 9
0
 def test_input_too_long(self):
     expected_output = dict(((opt[0], opt[1][0]) for opt in options))
     self.assertDictEqual(getOpts([0] * (self.length + 1)), expected_output)
Esempio n. 10
0
 def test_incorrect_values(self):
     with self.assertRaises(IndexError):
         getOpts([3] * self.length)
Esempio n. 11
0
 def test_input_too_short(self):
     with self.assertRaises(IndexError):
         getOpts([0] * (self.length - 1))