def runRBFN(name,fromStruct):
    ''' 
    Takes the Brent trajectories as input, shuffles them, and then runs the RBFN regression algorithm
    '''
    rs = ReadSetupFile()
    #state, command = getStateAndCommandData(BrentTrajectoriesFolder)
    #stateAll, commandAll = dicToArray(state), dicToArray(command)
    #print ("old:", stateAll[0])

    stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(pathDataFolder + "TrajRepository/"))
    #stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(BrentTrajectoriesFolder))
    #print ("len:", len(commandAll[0]))
    stateAll = np.vstack(np.array(stateAll))
    commandAll = np.vstack(np.array(commandAll))
    #print ("len global:", len(commandAll))
    #print ("new:", commandAll[0])

    #this works because both shuffles generate the same order, due to the seed
    np.random.seed(0)
    np.random.shuffle(stateAll)
    np.random.seed(0)
    np.random.shuffle(commandAll)

    print("nombre d'echantillons: ", len(stateAll))
    fa = rbfn(rs.numfeats,rs.inputDim,rs.outputDim)
    fa.getTrainingData(stateAll, commandAll)
    if fromStruct == True:
        initFromExistingStruct(fa,rs.RBFNpath+name+".struct")
    else:
        initFromData(fa,rs.RBFNpath+name+".struct")
    fa.train_reg_rbfn(rs.lamb)
    fa.saveTheta(rs.RBFNpath + name+".theta")
def runRBFN(name, fromStruct):
    """ 
    Takes the Brent trajectories as input, shuffles them, and then runs the RBFN regression algorithm
    """
    rs = ReadSetupFile()
    # state, command = getStateAndCommandData(BrentTrajectoriesFolder)
    # stateAll, commandAll = dicToArray(state), dicToArray(command)
    # print ("old:", stateAll[0])

    stateAll, commandAll = stateAndCommandDataFromTrajs(
        loadStateCommandPairsByStartCoords(pathDataFolder + "TrajRepository/")
    )
    # stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(BrentTrajectoriesFolder))
    # print ("len:", len(commandAll[0]))
    stateAll = np.vstack(np.array(stateAll))
    commandAll = np.vstack(np.array(commandAll))
    # print ("len global:", len(commandAll))
    # print ("new:", commandAll[0])

    # this works because both shuffles generate the same order, due to the seed
    np.random.seed(0)
    np.random.shuffle(stateAll)
    np.random.seed(0)
    np.random.shuffle(commandAll)

    print("nombre d'echantillons: ", len(stateAll))
    fa = rbfn(rs.numfeats, rs.inputDim, rs.outputDim)
    fa.getTrainingData(stateAll, commandAll)
    if fromStruct == True:
        initFromExistingStruct(fa, rs.RBFNpath + name + ".struct")
    else:
        initFromData(fa, rs.RBFNpath + name + ".struct")
    fa.train_reg_rbfn(rs.lamb)
    fa.saveTheta(rs.RBFNpath + name + ".theta")
def initRBFNController(rs,filename):
    '''
	Initializes the controller allowing to compute the output from the input and the vector of parameters theta
	
	Input:		-rs: ReadSetup, class object
			-fr, FileReading, class object
	'''
    #Initializes the function approximator with the number of feature used
    fa = rbfn(rs.numfeats,rs.inputDim,rs.outputDim)
    fa.loadFeatures(filename+".struct")
    return fa
Exemple #4
0
def initRBFNController(rs, filename):
    '''
	Initializes the controller allowing to compute the output from the input and the vector of parameters theta
	
	Input:		-rs: ReadSetup, class object
			-fr, FileReading, class object
	'''
    #Initializes the function approximator with the number of feature used
    fa = rbfn(rs.numfeats, rs.inputDim, rs.outputDim)
    fa.loadFeatures(filename + ".struct")
    return fa
def UnitTest():
    fa = rbfn(3,2,3)
    input, output = [], []
    for i in range(10000):
        x,y = rd.random(), rd.random()
        input.append([x,y])
        output.append([x*y, x-y, x+y])
    fa.getTrainingData(np.vstack(np.array(input)), np.vstack(np.array(output)))
    fa.saveFeatures("test.struct")
    fa.setCentersAndWidths()
    fa.train_rbfn()
    fa.saveTheta("test.theta")

    fa.loadTheta("test.theta")
    for i in range(20):
        x,y = 3*rd.random(), 3*rd.random()
        approx = fa.computeOutput(np.array([x,y]))
        print("in:", [x,y])
        print(" out:", approx)
        print(" real:",  [x*y, x-y, x+y])
def UnitTest():
    fa = rbfn(3, 2, 3)
    input, output = [], []
    for i in range(10000):
        x, y = rd.random(), rd.random()
        input.append([x, y])
        output.append([x * y, x - y, x + y])
    fa.getTrainingData(np.vstack(np.array(input)), np.vstack(np.array(output)))
    fa.saveFeatures("test.struct")
    fa.setCentersAndWidths()
    fa.train_rbfn()
    fa.saveTheta("test.theta")

    fa.loadTheta("test.theta")
    for i in range(20):
        x, y = 3 * rd.random(), 3 * rd.random()
        approx = fa.computeOutput(np.array([x, y]))
        print("in:", [x, y])
        print(" out:", approx)
        print(" real:", [x * y, x - y, x + y])