def test_visual(): """ Test 2-D basis func visualization. """ kernel = gaussian_kernel normalization=False domain = InfiniteTrackCartPole.InfTrackCartPole() #2 continuous dims discretization = 20 # not used num = 1 # number of basis functions to use resolution_min=1 resolution_max=5 rep = RandomLocalBases(domain, kernel, num, resolution_min, resolution_max, seed=1, normalization=normalization, discretization=discretization) rep.plot_2d_feature_centers()
def test_parametric_rep(): """ For fixed representations: test successful kernel function use, using varying number of features. Ensure get expected result. Test normalization, ensure expected result. """ for normalization in [False, True]: # verify everything with/out norm kernel = gaussian_kernel domain = InfiniteTrackCartPole.InfTrackCartPole() #2 continuous dims discretization = 20 # not used num = 1 # number of basis functions to use IN EACH DIMENSION resolution_min = 1 resolution_max = 5 rep = RandomLocalBases(domain, kernel, num, resolution_min, resolution_max, seed=1, normalization=normalization, discretization=discretization) assert rep.features_num == num # in reality, theres one in each dim. # Center lies within statespace limits assert np.all(domain.statespace_limits[:, 0] <= rep.centers[0]) assert np.all(rep.centers[0] <= domain.statespace_limits[:, 1]) # width lies within resolution bounds statespace_range = domain.statespace_limits[:, 1] - domain.statespace_limits[:, 0] assert np.all(statespace_range / resolution_max <= rep.widths[0]) # widths[0] has `state_space_dims` cols assert np.all(rep.widths[0] <= statespace_range / resolution_min) phiVecOrigin = rep.phi(np.array([0, 0], dtype=np.float), terminal=False) assert np.all(phiVecOrigin >= 0) # nonnegative feat func values # feature func only dependent on own dimension phiVec2 = rep.phi(np.array([0, 1], dtype=np.float), terminal=False) if normalization: assert sum(phiVecOrigin) == 1 assert sum(phiVec2) == 1
def make_experiment(exp_id=1, path="./Results/Temp", initial_learn_rate=.40, lambda_=0., resolution=25, num_rbfs=300): """ Each file specifying an experimental setup should contain a make_experiment function which returns an instance of the Experiment class with everything set up. @param id: number used to seed the random number generators @param path: output directory where logs and results are stored """ # import sys # import os # cur_dir = os.path.expanduser("~/work/clipper/models/rl/") # sys.path.append(cur_dir) # from Domains import RCCarModified # from Policies import RCCarGreedy # Experiment variables opt = {} opt["path"] = path opt["exp_id"] = exp_id opt["max_steps"] = 200000 opt["num_policy_checks"] = 15 opt["checks_per_policy"] = 2 # Logging domain = RCCarLeftTurn(noise=0.) opt["domain"] = domain # Representation kernel = gaussian_kernel representation = RandomLocalBases(domain, gaussian_kernel, num=int(num_rbfs), normalization=True, resolution_max=resolution, seed=exp_id) policy = eGreedy(representation, epsilon=0.15) # if biasedaction > -1: # print "No Random starts with biasing {}".format(i % 4) # policy = BiasedGreedy(representation, epsilon=0.5, biasedaction=biasedaction) # Agent opt["agent"] = Q_Learning(policy, representation, domain.discount_factor, initial_learn_rate=initial_learn_rate, lambda_=lambda_, learn_rate_decay_mode="const") experiment = Experiment(**opt) return experiment
def test_parametric_rep(): """ For fixed representations: test successful kernel function use, using varying number of features. Ensure get expected result. Test normalization, ensure expected result. """ for normalization in [False, True]: # verify everything with/out norm kernel = gaussian_kernel domain = InfiniteTrackCartPole.InfTrackCartPole() #2 continuous dims discretization = 20 # not used num = 1 # number of basis functions to use IN EACH DIMENSION resolution_min=1 resolution_max=5 rep = RandomLocalBases(domain, kernel, num, resolution_min, resolution_max, seed=1, normalization=normalization, discretization=discretization) assert rep.features_num == num # in reality, theres one in each dim. # Center lies within statespace limits assert np.all(domain.statespace_limits[:,0] <= rep.centers[0]) assert np.all(rep.centers[0] <= domain.statespace_limits[:,1]) # width lies within resolution bounds statespace_range = domain.statespace_limits[:, 1] - domain.statespace_limits[:, 0] assert np.all(statespace_range / resolution_max <= rep.widths[0]) # widths[0] has `state_space_dims` cols assert np.all(rep.widths[0] <= statespace_range / resolution_min) phiVecOrigin = rep.phi(np.array([0,0], dtype=np.float), terminal=False) assert np.all(phiVecOrigin >= 0) # nonnegative feat func values # feature func only dependent on own dimension phiVec2 = rep.phi(np.array([0,1], dtype=np.float), terminal=False) if normalization: assert sum(phiVecOrigin) == 1 assert sum(phiVec2) == 1