def test_statistics(): eg = EpsilonGreedy(n_branches=3, epsilon=0.1, seed=1, best_branch=0) routes = [ eg.route(features=None, feature_names=None) for _ in range(100000) ] counter = Counter(routes) assert np.isclose(counter[0] / 100000, 1 - eg.epsilon, atol=0, rtol=0.01)
from EpsilonGreedy import EpsilonGreedy import sys sys.path.append("..") import Report from os.path import isfile, join seed_size = 50 iscontextual = True cost = 0.1 for graph_file in ["subnethept.txt", "nethept.txt"]: if (graph_file == "subnethept.txt"): epochs = 5000 elif (graph_file == "nethept.txt"): epochs = 5000 experiment_name = "contextual_" + graph_file[:-4] pathway = join("../../Misc/active_results/sigmoid", experiment_name, "epsilongreedy_results.json") # Experiment is already done if (isfile(pathway)): continue print(pathway) epsilongreedy = EpsilonGreedy(seed_size, graph_file, epochs, iscontextual, cost) epsilongreedy() Report.report("epsilongreedy", epsilongreedy, experiment_name)
def test_no_branches(): with pytest.raises(TypeError): eg = EpsilonGreedy()
def test_init(): eg = EpsilonGreedy(n_branches=3, epsilon=0.15, seed=1) assert eg.n_branches == 3 assert eg.epsilon == 0.15 assert np.array_equal(eg.branch_values, np.zeros_like(eg.branch_values))
def test_negative_branches(): with pytest.raises(AssertionError): eg = EpsilonGreedy(n_branches=-1)