Esempio n. 1
0
def run():
    net = NeuralNet(2,1)
    plotInput(net)
    for i in range(5):
        print net.getTheta()
        plotOutputMap(net,i*2)
        net.train()
        net.train()
    plotOutputMap(net,10)
Esempio n. 2
0
def initNNController(rs, thetaFile):
    '''
	Initializes the controller allowing to compute the output from the input and the vector of parameters theta
	
	Input:		-rs: ReadSetupFile, parameters
	'''
    #Initializes the function approximator
    fa = NeuralNet(rs.inputDim, rs.outputDim)
    fa.loadTheta(thetaFile + ".theta")
    return fa
Esempio n. 3
0
def initNNController(rs,thetaFile):
    '''
	Initializes the controller allowing to compute the output from the input and the vector of parameters theta
	
	Input:		-rs: ReadSetupFile, parameters
	'''
    #Initializes the function approximator
    fa = NeuralNet(rs.inputDim,rs.outputDim)
    fa.loadTheta(thetaFile+".theta")
    return fa
Esempio n. 4
0
def runNN(name):
    ''' 
    Takes the Brent trajectories as input, shuffles them, and then runs the NN 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 = NeuralNet(rs.inputDim, rs.outputDim)
    fa.getTrainingData(stateAll, commandAll)
    fa.train()
    fa.saveTheta(rs.NNpath + name + ".theta")
Esempio n. 5
0
def runNN(name):
    ''' 
    Takes the Brent trajectories as input, shuffles them, and then runs the NN 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 = NeuralNet(rs.inputDim,rs.outputDim)
    fa.getTrainingData(stateAll, commandAll)
    fa.train()
    fa.saveTheta(rs.NNpath + name+".theta")
Esempio n. 6
0
def UnitTestNN():
    fa = NeuralNet(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.train()
    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])
Esempio n. 7
0
def run():
    net = NeuralNet(2, 1)
    plotInput(net)
    for i in range(5):
        print net.getTheta()
        plotOutputMap(net, i * 2)
        net.train()
        net.train()
    plotOutputMap(net, 10)
Esempio n. 8
0
def UnitTestNN():
    fa = NeuralNet(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.train()
    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])
Esempio n. 9
0
def saveRandomNN():
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim, rs.outputDim)
    fa.saveTheta(rs.NNpath + "Random.theta")
Esempio n. 10
0
def createNN(name):
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim,rs.outputDim)
    fa.saveTheta(rs.NNpath + name+".theta")
Esempio n. 11
0
def saveRandomNN():
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim,rs.outputDim)
    fa.saveTheta(rs.NNpath+"Random.theta")
Esempio n. 12
0
def createNN(name):
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim, rs.outputDim)
    fa.saveTheta(rs.NNpath + name + ".theta")