Beispiel #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)
Beispiel #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
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
Beispiel #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")
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")
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])
Beispiel #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)
Beispiel #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])
Beispiel #9
0
def saveRandomNN():
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim, rs.outputDim)
    fa.saveTheta(rs.NNpath + "Random.theta")
def createNN(name):
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim,rs.outputDim)
    fa.saveTheta(rs.NNpath + name+".theta")
def saveRandomNN():
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim,rs.outputDim)
    fa.saveTheta(rs.NNpath+"Random.theta")
def createNN(name):
    rs = ReadSetupFile()
    fa = NeuralNet(rs.inputDim, rs.outputDim)
    fa.saveTheta(rs.NNpath + name + ".theta")