diff --git a/GPRL/MCTS/MCTS.py b/GPRL/MCTS/MCTS.py index 04cbedf009aaf4df68523635e6a3d6136fc2646f..e0b784944bfe76f1894075885b89f5a3f3dce5d7 100644 --- a/GPRL/MCTS/MCTS.py +++ b/GPRL/MCTS/MCTS.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from ..genetic_programming.linearGP import Instruction import numpy as np diff --git a/GPRL/UCB.py b/GPRL/UCB.py index 9aaaab13ef362e0681d53628a737212460fbd07a..0d7f520fc5ec154c5593a72b04fc8603312c847b 100644 --- a/GPRL/UCB.py +++ b/GPRL/UCB.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from copy import deepcopy from functools import partial import heapq diff --git a/GPRL/algorithms.py b/GPRL/algorithms.py index 2c7799e0a82c28db5c4bda4f61348d3b04532fbf..020a6521e647dc8be55f135d4957221035e62cf1 100644 --- a/GPRL/algorithms.py +++ b/GPRL/algorithms.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from collections import deque from deap import tools, algorithms import heapq diff --git a/GPRL/containers/grid.py b/GPRL/containers/grid.py index 8f5c13ec26aea68388077de129ef9d33e180f7b4..50d0f4d0da5724b770922887478721923e4533f4 100644 --- a/GPRL/containers/grid.py +++ b/GPRL/containers/grid.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from functools import reduce import operator import numpy as np diff --git a/GPRL/factory.py b/GPRL/factory.py index 4098c6cac465b28bc9d2382005d13035521e1929..cbdaec1a9ad2112bf5a909bb849393cb001b82ba 100644 --- a/GPRL/factory.py +++ b/GPRL/factory.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from abc import ABC, abstractmethod class EvolveFactory(ABC):#Base class to produce toolbox in different script and keep multiprocessing support (evolve.py script) diff --git a/GPRL/genetic_programming/linearGP.py b/GPRL/genetic_programming/linearGP.py index 5c19ea6561e78d8dfc9130555c6b90588cbdef2a..6565d9807d345fe2799e710d8d1f453ead8ed761 100644 --- a/GPRL/genetic_programming/linearGP.py +++ b/GPRL/genetic_programming/linearGP.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import random from functools import partial import copy diff --git a/GPRL/genetic_programming/team.py b/GPRL/genetic_programming/team.py index 273049ff4e21f030851103e41d097fc94700d5a1..a7e85a00eac07a1bbbc26eb8516d3ce381ca6080 100644 --- a/GPRL/genetic_programming/team.py +++ b/GPRL/genetic_programming/team.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import random import numpy as np from sklearn.linear_model import LinearRegression diff --git a/GPRL/utils/FEC.py b/GPRL/utils/FEC.py index d2044e5c9fe53fcc597d6706d8e4910666cfac23..549b670605b27d0c61481d74223fd660b49573c2 100644 --- a/GPRL/utils/FEC.py +++ b/GPRL/utils/FEC.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from collections import OrderedDict from functools import reduce import numpy as np diff --git a/GPRL/utils/gp_utils.py b/GPRL/utils/gp_utils.py index 66f9d2c5227294c6220687c26fa8b1b38a68d702..f61469f3094807981684c10f7d7c1e25a4cdb78f 100644 --- a/GPRL/utils/gp_utils.py +++ b/GPRL/utils/gp_utils.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import numpy as np import random from deap import gp diff --git a/GPRL/utils/optim.py b/GPRL/utils/optim.py index 2c3553585eb1273b4b25c6a43d0f4b7195c11fc9..7b203ecf3138bb22d3b0142292b999271f543b95 100644 --- a/GPRL/utils/optim.py +++ b/GPRL/utils/optim.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import numpy as np from functools import partial diff --git a/GPRL/utils/utils.py b/GPRL/utils/utils.py index 7d7136762dd648520f01ac3d7eba0c830c9ffafc..1ed935cf5b30340fed55de631ac6e1e4e5089a6e 100644 --- a/GPRL/utils/utils.py +++ b/GPRL/utils/utils.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from functools import reduce from operator import add, itemgetter import pickle diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..72cf512d0ab657c3f12e8200a57bc1871f3b4e90 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Mathurin Videau + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/conf/conf_qdgp-BipedalWalker.yml b/conf/conf_qdgp-BipedalWalker.yml index 43d11de6020d2f1ddfe1722f4203c9c309e31622..ef39b9288b4b4ac6f6e81744c502e6082cdfcd73 100644 --- a/conf/conf_qdgp-BipedalWalker.yml +++ b/conf/conf_qdgp-BipedalWalker.yml @@ -1,6 +1,7 @@ algorithm: name: algo.qdLambda args: + save_every: 10 batch_size: 100 lambda_: 500 ngen: 5000 diff --git a/conf/conf_qdgp-Hopper.yml b/conf/conf_qdgp-Hopper.yml index 077c0acb759be2ca702ecccf649764d8a0caeb45..58d632c16dd3f5b630fed18684020d943b92816a 100644 --- a/conf/conf_qdgp-Hopper.yml +++ b/conf/conf_qdgp-Hopper.yml @@ -1,6 +1,7 @@ algorithm: name: algo.qdLambda args: + save_every: 10 batch_size: 100 lambda_: 500 ngen: 5000 diff --git a/conf/conf_qdlingp-BipedalWalker.yml b/conf/conf_qdlingp-BipedalWalker.yml index 9281981a63e4d64785722a113418229565ff563f..2edc0e8ab9322160096fcb993396f19fa46c5c06 100644 --- a/conf/conf_qdlingp-BipedalWalker.yml +++ b/conf/conf_qdlingp-BipedalWalker.yml @@ -1,6 +1,7 @@ algorithm: name: algo.qdLambda args: + save_every: 10 batch_size: 100 lambda_: 500 ngen: 5000 diff --git a/conf/conf_qdlingp-Hopper.yml b/conf/conf_qdlingp-Hopper.yml index b4e8c63a4fa48f4193400edffb68361c29b17345..3936eeb9c28504963e5320ae290443bc0f88f2b6 100644 --- a/conf/conf_qdlingp-Hopper.yml +++ b/conf/conf_qdlingp-Hopper.yml @@ -1,6 +1,7 @@ algorithm: name: algo.qdLambda args: + save_every: 10 batch_size: 100 lambda_: 500 ngen: 5000 diff --git a/experiments/ADF.py b/experiments/ADF.py index fc4f1b130fd079dee2a97b01c3e308f6f60f4c36..2a47d432c807eac5503ea20ae6de5b75846148eb 100644 --- a/experiments/ADF.py +++ b/experiments/ADF.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from deap import gp, creator, base, tools import numpy as np diff --git a/experiments/MCTS.py b/experiments/MCTS.py index 48e282ee4ea6bf183c4d3489868ef7dc51790a8d..40c24a9a5431276fd73ac58ea164dd1a9f3ab7d1 100644 --- a/experiments/MCTS.py +++ b/experiments/MCTS.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from functools import partial import operator import numpy as np @@ -19,14 +24,25 @@ def init(env_name, func_set): exp_function = [ (gp_utils.exp, [float], float), (gp_utils.log, [float], float)] trig_function = [(np.sin, [float], float)] if_function = [ (gp_utils.if_then_else, [bool, float, float], float), (operator.gt, [float, float], bool), (operator.and_, [bool, bool], bool), (operator.or_, [bool, bool], bool) ] - classification_func = [(gp_utils.classification, [float, float, float], int)] #(gp_utils.intervales, [float], int) if func_set == "small": function_set = core_function + if_function elif func_set == "extended": function_set = core_function + exp_function + trig_function + + if bool(ENV.action_space.shape): + ret = float + OUTPUT = ENV.action_space.shape[0] + else: + OUTPUT = 1 + if ENV.action_space.n == 2: + ret = bool + else: + ret = int + classification_func = [(gp_utils.classification, [float]*ENV.action_space.n, int)] #(gp_utils.intervales, [float], int) + function_set += classification_func - pset = gp.PrimitiveSetTyped("MAIN", [float]*INPUT, bool) + pset = gp.PrimitiveSetTyped("MAIN", [float]*INPUT, ret) for primitive in function_set: pset.addPrimitive(*primitive) pset.addTerminal(0.1, float) @@ -37,12 +53,16 @@ def init(env_name, func_set): def fitness(individual, n_steps, gamma): - agent = gp.compile(gp.PrimitiveTree(individual), pset=pset) + if ENV.action_space.shape: + func = gp.compile(gp.PrimitiveTree(individual), pset=pset) + agent = lambda *s: [func(*s)] + else: + func = gp.compile(gp.PrimitiveTree(individual), pset=pset) + agent = lambda *s: int(func(*s)) s = 0 state = ENV.reset() for _ in range(n_steps): - #state, reward, done, _ = env.step(int(agent(*state))) - state, reward, done, _ = ENV.step([agent(*state)]) + state, reward, done, _ = ENV.step(agent(*state)) s+= gamma*reward if done: return s @@ -69,8 +89,8 @@ if __name__ == "__main__": args = parser.parse_args() - init() - pool = Pool(args.n_thread, initializer=init) + init(args.env, args.function_set) + pool = Pool(args.n_thread, initializer=init, initargs=(args.env, args.function_set)) func = partial(fitness, n_steps=args.n_steps, gamma=args.gamma) diff --git a/experiments/bench.py b/experiments/bench.py index e7f2593f7d0d7c3cd307ae14295a3ee17fcb1abc..4cb6622bcd96dae5cbe18d786aac061dc1024864 100644 --- a/experiments/bench.py +++ b/experiments/bench.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from GPRL.UCB import UpdateFitnessHof, selDoubleTournament, UCBFitness from functools import partial import operator diff --git a/experiments/gp.py b/experiments/gp.py index 7f57183767a1d16990b08b0f2e4228659ee7d3dd..17d6d8b4aff2eee89ad87c6d8d6eebc88e234181 100644 --- a/experiments/gp.py +++ b/experiments/gp.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import warnings import gym try: @@ -54,7 +59,6 @@ class Factory(EvolveFactory): exp_function = [ (gp_utils.exp, [float], float), (gp_utils.log, [float], float)] trig_function = [(np.sin, [float], float)] if_function = [ (gp_utils.if_then_else, [bool, float, float], float), (operator.gt, [float, float], bool), (operator.and_, [bool, bool], bool), (operator.or_, [bool, bool], bool) ] - classification_func = [(gp_utils.classification, [float, float, float], int)] #(gp_utils.intervales, [float], int) if self.conf['function_set'] == "small": @@ -72,6 +76,7 @@ class Factory(EvolveFactory): ret = bool else: ret = int + classification_func = [(gp_utils.classification, [float]*ENV.action_space.n, int)] #(gp_utils.intervales, [float], int) function_set += classification_func diff --git a/experiments/imitation_learning/imitation_gp.py b/experiments/imitation_learning/imitation_gp.py index 59fca97512ad590e9f0351a7d42448bc41c6c84d..3ae15d1b786fccf6d5173b7b537d84e603352433 100644 --- a/experiments/imitation_learning/imitation_gp.py +++ b/experiments/imitation_learning/imitation_gp.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from deap import gp, creator, base, tools import numpy as np diff --git a/experiments/imitation_learning/imitation_linGP.py b/experiments/imitation_learning/imitation_linGP.py index 2e361f34ddc2eeca978993c85b4785f749a5744a..07986c137c4c7854d04d5c4d86549a035974254f 100644 --- a/experiments/imitation_learning/imitation_linGP.py +++ b/experiments/imitation_learning/imitation_linGP.py @@ -1,3 +1,7 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. from functools import partial from GPRL.genetic_programming import linearGP as linGP diff --git a/experiments/imitation_learning/imitation_utils.py b/experiments/imitation_learning/imitation_utils.py index 3f4990216b631587fd185f4adb22be669ebfbbf9..03ff1660c24bf86a606d62cb529c2149e0cdd91e 100644 --- a/experiments/imitation_learning/imitation_utils.py +++ b/experiments/imitation_learning/imitation_utils.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import numpy as np class RingReplayBuffer(object): diff --git a/experiments/imitation_learning/time_feature.py b/experiments/imitation_learning/time_feature.py index 3d04c469d935223e6a5f5e76f7850312472dfac2..9129ca8581d90b4c3ed1765c8576dc8e3bf32a9e 100644 --- a/experiments/imitation_learning/time_feature.py +++ b/experiments/imitation_learning/time_feature.py @@ -1,3 +1,8 @@ +#Copyright (c) 2020 Stable-Baselines Team +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of stable-baselines3-contrib. + from typing import Dict, Union import gym diff --git a/experiments/linGP.py b/experiments/linGP.py index fc5ec8475e511147e686f89708d0b96636b792d9..349e83f0bd12c7964daa55b7cd3d19e269d4766e 100644 --- a/experiments/linGP.py +++ b/experiments/linGP.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + from functools import partial import warnings import random diff --git a/experiments/qdgp.py b/experiments/qdgp.py index c106dca354616e32bd1e11a39fcde8a80055f53b..b32cbd238f94a74c15ac01f065ef6aa5c297d39b 100644 --- a/experiments/qdgp.py +++ b/experiments/qdgp.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import operator import numpy as np import pandas as pd diff --git a/experiments/qdlinGP.py b/experiments/qdlinGP.py index 216149ae6815a7c3d76854e4698c734c4ac9e445..d4fcb626f8138440d3e8549ad640beca9e966847 100644 --- a/experiments/qdlinGP.py +++ b/experiments/qdlinGP.py @@ -1,3 +1,8 @@ +# Copyright (c) Mathurin Videau. All Rights Reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + import numpy as np from GPRL.containers.grid import FixGrid as Grid