Ejemplo n.º 1
0
def learn_tran():
	#examples = loadFile2()
	#examples2 = loadFile()
	examples3 = loadFile3("data/UPO/Experiments Folder/2014-11-17 11.08.31 AM/")
	examples4 = loadFile3("data/UPO/Experiments Folder/2014-11-28 01.22.03 PM/") 
	tot_examples  = examples3[:12] + examples4[:12]
	#tot_examples = examples + examples2
	disc = DiscModel()
	unorm_transition_f = np.zeros([disc.tot_actions,disc.tot_states,disc.tot_states])
	for example in tot_examples:
		for i in range(len(example.states)-1):
			state = disc.quantityToState(example.states[i])
			action = disc.actionToIndex(example.actions[i+1])
			next = disc.quantityToState(example.states[i+1])
			unorm_transition_f[action,state,next]+=1
	return unorm_transition_f
Ejemplo n.º 2
0
def learn_correction(num_learners, tree_depth):
    def plot_fit():
        f, axarr = plt.subplots(2, sharex=True)
        x = range(diff_test.shape[0])
        axarr[0].plot(x, diff_test[:, 0])
        axarr[0].plot(x, fit[0, :], color='red', alpha=0.6)
        axarr[0].set_xlabel("Data Sample")
        axarr[0].set_ylabel("sin(angle difference)")
        axarr[1].plot(x, diff_test[:, 1])
        axarr[1].plot(x, fit[1, :], color='red', alpha=0.6)
        axarr[1].set_xlabel("Data Sample")
        axarr[1].set_ylabel("Distance Difference")

    #learns a transition function from data using adaboost.
    #------------------------------------------------------
    #Load all data
    examples = loadFile3("data/UPO/Experiments Folder/2014-11-17 11.08.31 AM/")
    examples2 = loadFile3(
        "data/UPO/Experiments Folder/2014-11-28 01.22.03 PM/")
    tot_examples = examples[0:12] + examples2[0:12]

    #Folds get generated here
    train_examples = tot_examples
    test_examples = tot_examples[0:5]
    X_train, diff_train = get_dataset(train_examples)
    X_test, diff_test = get_dataset(test_examples)
    #plt.show()
    #test_examples = tot_examples[-2::]
    dimensions = examples[0].states.shape[1]
    print 'Dimentions', dimensions
    #Build X which is the same for all regressors
    #y =np.concatenate([example.states[1:,:] for example in train_examples],axis = 0)
    estimators = [
        adaboost_reg(X_train, diff_train[:, i], num_learners, tree_depth)
        for i in range(dimensions)
    ]
    fit = []
    #for example in train_examples:
    #	for n, step in enumerate(example.states[:-1]):
    #		fit.append(predict_next(step,exax]mple.actions[n+1],estimators))
    fit = np.array([estimator.predict(X_test) for estimator in estimators])
    print fit.shape
    #fit[:,0] =np.arcsin(fit[:,0])*2

    #plot_fit()

    return estimators
Ejemplo n.º 3
0
def learn_correction(num_learners,tree_depth):
	def plot_fit():
		f,axarr = plt.subplots(2,sharex=True)
		x = range(diff_test.shape[0])
		axarr[0].plot(x,diff_test[:,0]) 
		axarr[0].plot(x,fit[0,:],color='red',alpha = 0.6)
		axarr[0].set_xlabel("Data Sample")
		axarr[0].set_ylabel("sin(angle difference)")
		axarr[1].plot(x,diff_test[:,1]) 
		axarr[1].plot(x,fit[1,:],color='red',alpha = 0.6)
		axarr[1].set_xlabel("Data Sample")
		axarr[1].set_ylabel("Distance Difference")		

	#learns a transition function from data using adaboost.
	#------------------------------------------------------
	#Load all data
	examples = loadFile3("data/UPO/Experiments Folder/2014-11-17 11.08.31 AM/")
	examples2 = loadFile3("data/UPO/Experiments Folder/2014-11-28 01.22.03 PM/") 
	tot_examples = examples[0:12] + examples2[0:12]
	
	#Folds get generated here
	train_examples = tot_examples
	test_examples = tot_examples[0:5]
	X_train,diff_train = get_dataset(train_examples)
	X_test,diff_test = get_dataset(test_examples)
	#plt.show()
	#test_examples = tot_examples[-2::]
	dimensions = examples[0].states.shape[1]
	print 'Dimentions',dimensions
	#Build X which is the same for all regressors
	#y =np.concatenate([example.states[1:,:] for example in train_examples],axis = 0)
	estimators = [adaboost_reg(X_train,diff_train[:,i],num_learners,tree_depth) for i in range(dimensions)]
	fit = []
	#for example in train_examples:
	#	for n, step in enumerate(example.states[:-1]):
	#		fit.append(predict_next(step,exax]mple.actions[n+1],estimators))
	fit = np.array([estimator.predict(X_test) for estimator in estimators])
	print fit.shape
	#fit[:,0] =np.arcsin(fit[:,0])*2

	#plot_fit()

	return estimators
Ejemplo n.º 4
0
def learn_tran():
    #examples = loadFile2()
    #examples2 = loadFile()
    examples3 = loadFile3(
        "data/UPO/Experiments Folder/2014-11-17 11.08.31 AM/")
    examples4 = loadFile3(
        "data/UPO/Experiments Folder/2014-11-28 01.22.03 PM/")
    tot_examples = examples3[:12] + examples4[:12]
    #tot_examples = examples + examples2
    disc = DiscModel()
    unorm_transition_f = np.zeros(
        [disc.tot_actions, disc.tot_states, disc.tot_states])
    for example in tot_examples:
        for i in range(len(example.states) - 1):
            state = disc.quantityToState(example.states[i])
            action = disc.actionToIndex(example.actions[i + 1])
            next = disc.quantityToState(example.states[i + 1])
            unorm_transition_f[action, state, next] += 1
    return unorm_transition_f