コード例 #1
0
def learn_tran_regression(num_learners, tree_depth):
    #learns a transition function from data using adaboost.
    #------------------------------------------------------
    #Load all data
    examples = loadFile2()
    examples2 = loadFile()
    tot_examples = examples + examples2
    #Folds get generated here
    train_examples = tot_examples
    #test_examples = tot_examples[-2::]
    dimensions = examples[0].states.shape[1]
    #Build X which is the same for all regressors
    estimators = []
    X = np.concatenate([
        np.hstack((example.states[:-1, :], example.actions[:-1, :]))
        for example in train_examples
    ],
                       axis=0)
    y = np.concatenate([example.states[1:, :] for example in train_examples],
                       axis=0)
    estimators = [
        adaboost_reg(X, y[:, i], num_learners, tree_depth)
        for i in range(dimensions)
    ]
    return estimators
コード例 #2
0
def loss_augmentation(amount):
	examples = loadFile()
	disc = DiscModel()
	loss_aug = np.ones([disc.tot_states])*amount
	for example in examples:
		for step in range(len(example.states)):
			state = disc.quantityToState(example.states[step])
			action = disc.actionToIndex(example.actions[step])
			loss_aug[state] = 1
	return loss_aug
コード例 #3
0
def loss_augmentation(amount):
    examples = loadFile()
    disc = DiscModel()
    loss_aug = np.ones([disc.tot_states]) * amount
    for example in examples:
        for step in range(len(example.states)):
            state = disc.quantityToState(example.states[step])
            action = disc.actionToIndex(example.actions[step])
            loss_aug[state] = 1
    return loss_aug
コード例 #4
0
def learn_tran_regression(num_learners,tree_depth):
	#learns a transition function from data using adaboost.
	#------------------------------------------------------
	#Load all data
	examples = loadFile2()
	examples2 = loadFile()
	tot_examples = examples + examples2
	#Folds get generated here
	train_examples = tot_examples
	#test_examples = tot_examples[-2::]
	dimensions = examples[0].states.shape[1]
	#Build X which is the same for all regressors
	estimators = []	
	X =np.concatenate([np.hstack((example.states[:-1,:],example.actions[:-1,:])) for example in train_examples],axis = 0)
	y =np.concatenate([example.states[1:,:] for example in train_examples],axis = 0)
	estimators = [adaboost_reg(X,y[:,i],num_learners,tree_depth) for i in range(dimensions)]
	return estimators