Exemplo n.º 1
0
 def show_run(self, params):
     model_file = '/Users/Siebe/Dropbox/Thesis/Scratches/model.xml'
     perturbations = []
     render = True
     logging = False
     evaluate(model_file, self.closed_loop, params, perturbations, render,
              logging)
Exemplo n.º 2
0
def verify_experiment(ex, params=None):
	std_dev_percent = get_std_dev_percent(ex)
	print('Verifying ' + str(std_dev_percent) + '% training noise')

	if params is None:
		params = get_best_params(ex)

	test_percentages = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
	# test_percentages = [22, 24, 26, 28, 30]

	results = {}

	for test_percentage in test_percentages:
		print('Testing on ' + str(test_percentage) + '% test noise')
		successful = []
		fails = []

		variation_paths = generate_variations(ex['default_morphology'], test_percentage)

		test_id = 0
		for path in variation_paths:
			printProgressBar(test_id, 100, prefix = 'Progress:', suffix = 'Complete', length = 50)
			succes, st, d, ec, ah, sh = sim.evaluate(path, False, params, [], False, False)
			if succes and d > 0:
				successful.append((d/10, ec/10))
			else:
				fails.append((d/10, ec/10, st))
			test_id += 1
		printProgressBar(test_id, 100, prefix = 'Progress:', suffix = 'Complete', length = 50)
		print()
		results[test_percentage] = {'successful': successful, 'fails': fails}

	return (std_dev_percent, results)
Exemplo n.º 3
0
    def run_simulation(self, render, logging):
        cpg_params = self.simulation['cpg_params']
        self.model_file = None
        if not self.experiment['default_morphology']:
            self.model_file = '/Users/Siebe/Dropbox/Thesis/Scratches/model.xml'
        elif self.experiment['variation_params']:
            model_files, variation_dicts = generate_model_variations(
                self.experiment['default_morphology'],
                self.experiment['variation_params'],
                num=1)
            print(variation_dicts)
            self.model_file = model_files[0]
        elif not self.experiment['delta_dicts']:
            self.model_file = generate_temp_model_file(
                self.experiment['default_morphology'])
        elif not self.model_file:
            model_config = dict_elementwise_operator(
                self.experiment['default_morphology'],
                self.experiment['delta_dicts'][
                    self.simulation['variation_index']])
            self.model_file = generate_temp_model_file(model_config)

        perturbations = self.simulation.get('perturbation', [])
        return evaluate(self.model_file, self.closed_loop, cpg_params,
                        perturbations, render, logging)
Exemplo n.º 4
0
def eval_wrapper(variables):
	model_file = variables['model_file']
	closed_loop = variables['closed_loop']
	params = variables['params']
	perturbations = variables['perturbations']
	render = variables['render']
	logging = variables['logging']
	return sim.evaluate(model_file, closed_loop, params, perturbations, render, logging)
Exemplo n.º 5
0
def eval_wrapper(variables):
    model_files = variables['model_files']
    closed_loop = variables['closed_loop']
    params = variables['params']
    perturbations = variables['perturbations']
    render = variables['render']
    logging = variables['logging']
    # print(model_files)
    results = []
    for model_file in model_files:
        r = sim.evaluate(model_file, closed_loop, params.tolist(),
                         perturbations, render, logging)
        results.append(r)
    # print(results)
    print("I'm done")
    return results
Exemplo n.º 6
0
    def perturbation_test(self):
        perturbation_params = self.experiment.get('perturbation_params', [])
        num_tests = 20

        if perturbation_params:
            test_perturbations = []
            perturb_cov = np.diag(perturbation_params['perturb_variances'])
            for _ in range(num_tests):
                occurences = np.random.geometric(
                    p=1 / perturbation_params['expected_occurences']
                ) - 1  # numpy uses shifted geometric
                perturbations = []
                for i in range(occurences):
                    perturb_time = np.random.random() * 14
                    force_torque = np.random.multivariate_normal(
                        perturbation_params['perturb_means'], perturb_cov)
                    perturbations.append([perturb_time, list(force_torque)])
                test_perturbations.append(perturbations)

            # Test in simulation
            cpg_params = self.experiment['results']['simulations'][
                self.experiment['results']['best_id']]['cpg_params']
            model_file = None
            if not self.experiment['default_morphology']:
                model_file = '/Users/Siebe/Dropbox/Thesis/Scratches/model.xml'
            elif not self.experiment['delta_dicts']:
                model_file = generate_temp_model_file(
                    self.experiment['default_morphology'])
            elif not self.model_file:
                model_config = dict_elementwise_operator(
                    self.experiment['default_morphology'],
                    self.experiment['delta_dicts'][
                        self.simulation['variation_index']])
                model_file = generate_temp_model_file(model_config)

            rewards = []
            for perturbation in test_perturbations:
                succes, simulated_time, distance, energy_consumed, action_history, sensor_history = evaluate(
                    model_file, self.closed_loop, cpg_params, perturbation,
                    False, False)
                reward = 0 if distance < 0 or not succes else (
                    10 - 0.01 *
                    (energy_consumed - self.experiment['E0'])**2) * (distance)
                rewards.append(reward)

            print('Minimum: ' + str(min(rewards)))
            print('Mean: ' + str(sum(rewards) / len(rewards)))
            print('Maximum: ' + str(max(rewards)))
            print('Standard deviation: ' + str(np.std(rewards)))