• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python datasets.SupervisedDataSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pybrain.datasets.SupervisedDataSet的典型用法代码示例。如果您正苦于以下问题:Python SupervisedDataSet类的具体用法?Python SupervisedDataSet怎么用?Python SupervisedDataSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SupervisedDataSet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: entrenarSomnolencia

def entrenarSomnolencia(red):
    #Se inicializa el dataset
    ds = SupervisedDataSet(4096,1)

    """Se crea el dataset, para ello procesamos cada una de las imagenes obteniendo los rostros,
       luego se le asignan los valores deseados del resultado la red neuronal."""

    print "Somnolencia - cara"
    for i,c in enumerate(os.listdir(os.path.dirname('/home/taberu/Imágenes/img_tesis/somnoliento/'))):
        try:
            im = cv2.imread('/home/taberu/Imágenes/img_tesis/somnoliento/'+c)
            pim = pi.procesarImagen(im)
            cara = d.deteccionFacial(pim)
            if cara == None:
                print "No hay cara"
            else:
                print i
                ds.appendLinked(cara.flatten(),10)
        except:
            pass

    trainer = BackpropTrainer(red, ds)
    print "Entrenando hasta converger"
    trainer.trainUntilConvergence()
    NetworkWriter.writeToFile(red, 'rna_somnolencia.xml')
开发者ID:Taberu,项目名称:despierta,代码行数:25,代码来源:entrenar.py


示例2: getErrorPercent

def getErrorPercent(training_dataset, eval_dataset_list, num_hidden, num_epochs):
  num_datapoints = len(training_dataset)
  num_inputs = len(training_dataset[0][0])
  num_outputs = len(training_dataset[0][1])

  # print "Num Inputs:", num_inputs
  # print "Num Outputs:", num_outputs
  # print "Num Hidden Nodes:", num_hidden

  NN = buildNetwork(num_inputs, num_hidden, num_outputs, bias=True, hiddenclass=SigmoidLayer, outclass=SigmoidLayer)

  dataset = SupervisedDataSet(num_inputs, num_outputs)
  for datapoint in training_dataset:
    dataset.addSample(datapoint[0], datapoint[1])


  trainer = BackpropTrainer(NN, dataset=dataset, momentum=0.0, verbose=False, weightdecay=0.0)

  for epoch in range(0, num_epochs):
    #print epoch 
    trainer.train()

  errors = []
  for eval_set in eval_dataset_list:
    total_percent_errors = [0]*num_outputs
    for jj in range(0, len(eval_set)):
      nn_out = NN.activate(eval_set[jj][0])
      percent_error = computeError(eval_set[jj][1], nn_out)
      #print percent_error
      total_percent_errors = map(operator.add, percent_error, total_percent_errors)
    #print total_percent_errors
    errors.append(map(operator.div, total_percent_errors, [len(dataset)]*num_outputs))
  #print errors
  return errors
开发者ID:sethmccammon,项目名称:rob537,代码行数:34,代码来源:evaluation.py


示例3: main

def main():
	inputs = ReadCSV('./data/input.csv')
	outputs = ReadCSV('./data/output.csv')
	
	test_set = test.keys()
	train_set = []
	for k in inputs.keys():
		if k not in test_set:
			train_set.append(k)
	print "Number of training samples", len(train_set)
	print "Number of testing samples", len(test_set)
			
	net = buildNetwork(178, 6, 5)
	ds=SupervisedDataSet(178,5)
	for id in train_set:
		ds.addSample(inputs[id],outputs[id])

	trainer = BackpropTrainer(net, ds, learningrate=0.001, momentum = 0.001)

	trainer.trainUntilConvergence(maxEpochs=1000, validationProportion = 0.5)
	
	
	for id in test_set:
		predicted = net.activate(inputs[id])
		actual = outputs[id]
		print '-----------------------------'
		print test[id]
		print '-----------------------------'
		print 'Trait\t\tPredicted\tActual\tError'
		for i in range(0,5):
			error = abs(predicted[i] - actual[i])*100/4.0
			print traits[i], '\t', predicted[i], '\t', actual[i], '\t', error,"%" 
开发者ID:niyasc,项目名称:Personality-Prediction-using-facebook-profile,代码行数:32,代码来源:sample.py


示例4: __init__

class Brain:
	def __init__(self, hiddenNodes = 30):
		# construct neural network 
		self.myClassifierNet = buildNetwork(12, hiddenNodes, 1, bias=True, hiddenclass=TanhLayer) #parameters to buildNetwork are inputs, hidden, output
		# set up dataset
		self.myDataset = SupervisedDataSet(12, 1)
		self.myClassifierTrainer = BackpropTrainer(self.myClassifierNet, self.myDataset)

	def addSampleImageFromFile(self, imageFile, groupId):
		"adds a data sample from an image file, including needed processing"
		myImage = Image.open(imageFile)
		self.myDataset.addSample(twelveToneParallel(myImage), (groupId,))

	def train(self):
		#myClassifierTrainer.trainUntilConvergence() #this will take forever (possibly literally in the pathological case)
		for i in range(0, 15):
			self.myClassifierTrainer.train() #this may result in an inferior network, but in practice seems to work fine

	def save(self, saveFileName="recognizernet.brain"):
		saveFile = open(saveFileName, 'w')
		pickle.dump(self.myClassifierNet, saveFile)
		saveFile.close()

	def load(self, saveFileName="recognizernet.brain"):
		saveFile = open(saveFileName, 'r')
		myClassifierNet = pickle.load(saveFile)
		saveFile.close()

	def classify(self, fileName):
		myImage = Image.open(fileName)
		if self.myClassifierNet.activate(twelveToneParallel(myImage)) < 0.5:
			return 0
		else:
			return 1
开发者ID:anurive,项目名称:pybrain-picture-sort,代码行数:34,代码来源:recognizer.py


示例5: loadDataSet

def loadDataSet(ds_file):
  global X, Y
  BB = set()
  aaa = {}
  ds = SupervisedDataSet(400, 10)
  #ds = SupervisedDataSet(1024, 5)
  with open(ds_file,"rb") as f:
    lines = f.readlines()
    for line in lines:
      l = [float(a) for a in line.strip().split(',')]
      #A = [float(1.0)] + l[:-1]
      A = l[:-1]
      X.append(A)
      B = int(l[-1])
      #BB.update([B])
      #for aa,bb in enumerate(BB):
      #  aaa[bb] = aa
      #print aaa
      #Y.append(aaa[bb])
      Y.append(B)
      C = []
      for i in range(10):
        C.append(int(1) if i==B or (i==0 and B==10) else int(0))
      ds.addSample(tuple(A), tuple(C))
  return ds
开发者ID:onidzelskyi,项目名称:VSN,代码行数:25,代码来源:trainNN.py


示例6: run_data

def run_data():
    with open('new_data2.txt') as data_file:
        data = json.load(data_file)
    ds = SupervisedDataSet(1316, 1316)
    for i in xrange(0, 51):
        print "Adding {}th data sample".format(i),
        input = tuple(data[str(i)]['input'])
        output = tuple(data[str(i)]['output'])        
        # print len(input), len(output)
        ds.addSample( input, output)
        print ":: Done"

    print "Train"
    net = buildNetwork( 1316, 100, 1316, bias=True, )
    trainer = BackpropTrainer(net, ds)

    terrors = trainer.trainUntilConvergence(verbose = True, validationProportion = 0.33, maxEpochs = 20, continueEpochs = 10 )
    # print terrors[0][-1],terrors[1][-1]
    fo = open("results2.txt", "w")
    for input, expectedOutput in ds:
        output = net.activate(input)
        count = 0
        for q in xrange(0, 1316):
            print output[q], expectedOutput[q]
            if math.floor(output[q]) == math.floor(expectedOutput[q]):
                count+=1    
        m = float(count)/1316.00
        print "{0} ::  {1}".format(count, m)
        fo.write("{0} ::  {1}\n".format(count, m))
开发者ID:kevcal69,项目名称:thesis,代码行数:29,代码来源:rep.py


示例7: learn

    def learn(self):
        # convert reinforcement dataset to NFQ supervised dataset
        supervised = SupervisedDataSet(self.module.network.indim, 1)

        for seq in self.dataset:
            lastexperience = None
            for state, action, reward in seq:
                if not lastexperience:
                    # delay each experience in sequence by one
                    lastexperience = (state, action, reward)
                    continue

                # use experience from last timestep to do Q update
                (state_, action_, reward_) = lastexperience

                Q = self.module.getValue(state_, action_[0])

                inp = r_[state_, one_to_n(action_[0], self.module.numActions)]
                tgt = Q + 0.5*(reward_ + self.gamma * max(self.module.getActionValues(state)) - Q)
                supervised.addSample(inp, tgt)

                # update last experience with current one
                lastexperience = (state, action, reward)

        # train module with backprop/rprop on dataset
        trainer = RPropMinusTrainer(self.module.network, dataset=supervised, batchlearning=True, verbose=False)
        trainer.trainUntilConvergence(maxEpochs=self.maxEpochs)
开发者ID:myeaton1,项目名称:euphoriaAI,代码行数:27,代码来源:eunfq.py


示例8: NeuralKinect

class NeuralKinect():
    def __init__(self):
        # Softmax layer -> great for classification networks
        #self.neuralNet = buildNetwork(60, 60, 5, outclass=SoftmaxLayer)
        #self.neuralNet = buildNetwork(60, 60, 5, hiddenclass=TanhLayer)
        #self.neuralNet = buildNetwork(60, 60, 5, bias=True)
        self.neuralNet = buildNetwork(60, 60, 5)
        self.dataSet = SupervisedDataSet(60, 5)

    def trainBackProp(self):
        trainer = BackpropTrainer(self.neuralNet, self.dataSet)
        start = time.time()
        trainer.trainEpochs(EPOCHS)
        end = time.time()
        print("Training time -> " + repr(end-start))
        print(repr(trainer.train()))

    def loadDataSet(self):
        points = []
        for csvFile in glob.iglob("TrainData/*.csv"):
            with open(csvFile, 'rt') as letterSet:
                reader = csv.reader(letterSet)
                header = str(reader.next())
                letter = header[2:3]
                targetStr = header[4:9]
                print("Processing Dataset for letter -> " + letter)
                target = []
                for digit in targetStr:
                    target.append(digit)
                rows = 1
                for row in reader:              
                    for col in row:
                        points.append(col)
                    if rows % 20 == 0:
                        self.dataSet.addSample(points, target)
                        points = []
                    rows += 1
                    
    def processResults(self, output):
        result = ""
        for digit in output:
            if digit > 0.5:
                result += "1"
            else:
                result += "0"
        print("Network result -> " + chr(64+int(result,2)))
                    
    def testNetwork(self):
        points = []
        for csvFile in glob.iglob("TestData/*.csv"):
            with open(csvFile, 'rt') as testPose:
                reader = csv.reader(testPose)
                rows = 1
                for row in reader:
                    for col in row:
                        points.append(col)
                    if rows % 20 == 0:
                        self.processResults(self.neuralNet.activate(points))
                        points = []
                    rows += 1
开发者ID:kepplemr,项目名称:neuralKinect,代码行数:60,代码来源:neuralkinect.py


示例9: neural_network

def neural_network(data, target, network):
    DS = SupervisedDataSet(len(data[0]), 1)
    nn = buildNetwork(len(data[0]), 7, 1, bias = True)
    kf = KFold(len(target), 10, shuffle = True);
    RMSE_NN = []
    for train_index, test_index in kf:
        data_train, data_test = data[train_index], data[test_index]
        target_train, target_test = target[train_index], target[test_index]
        for d,t in zip(data_train, target_train):
            DS.addSample(d, t)
        bpTrain = BackpropTrainer(nn,DS, verbose = True)
        #bpTrain.train()
        bpTrain.trainUntilConvergence(maxEpochs = 10)
        p = []
        for d_test in data_test:
            p.append(nn.activate(d_test))
        
        rmse_nn = sqrt(np.mean((p - target_test)**2))
        RMSE_NN.append(rmse_nn)
        DS.clear()
    time = range(1,11)
    plt.figure()
    plt.plot(time, RMSE_NN)
    plt.xlabel('cross-validation time')
    plt.ylabel('RMSE')
    plt.show()
    print(np.mean(RMSE_NN))
开发者ID:eprym,项目名称:EE-239AS,代码行数:27,代码来源:problem3_predict.py


示例10: get_dataset_for_pybrain_regression

def get_dataset_for_pybrain_regression(X,y):
	ds = SupervisedDataSet(250,1)
	tuples_X = [tuple(map(float,tuple(x))) for x in X.values]
	tuples_y = [tuple(map(float,(y,))) for y in y.values]
	for X,y in zip(tuples_X,tuples_y):
		ds.addSample(X,y)
	return ds
开发者ID:SaarthakKhanna2104,项目名称:Home-Depot-Product-Search-Relevance,代码行数:7,代码来源:NeuralNetsReg.py


示例11: learn

    def learn(self,dataset):
        """
            This function trains network

            Input:
            dataset     - Dataset to train network

            Returns:
            Nothing
        """
        from pybrain.supervised.trainers import BackpropTrainer
        from pybrain.datasets import SupervisedDataSet
        from neuraltrainer import NeuralTrainer

        if self._net == None: raise NeuralBrainException("Brain is not configured!")
        if dataset == {}: raise NeuralBrainException("Dataset for learning is empty.")

        data = SupervisedDataSet(self._input,self._output)
        for input,output in dataset.items():
            input = self._normalize(input,self._input)
            output = self._normalize(output,self._output)
            data.addSample(input,output)
            data.addSample(input,output)# For better learning 2x

        trainer = NeuralTrainer(self._net, data)
        trainer.simpleTrain()
开发者ID:0x1001,项目名称:jarvis,代码行数:26,代码来源:neuralbrain.py


示例12: get_train_samples

def get_train_samples(input_num,output_num):
    '''
    从new_samples文件夹中读图,根据输入数和输出数制作样本,每一原始样本加入随机噪音生成100个样本
    '''
    print 'getsample start.'
    sam_path='./new_samples'
    samples = SupervisedDataSet(input_num,output_num)
    nlist = os.listdir(sam_path)
    t=int(np.sqrt(input_num))
    for n in nlist:
        file = os.path.join(sam_path,n)
        im = Image.open(file)
        im = im.convert('L')
        im = im.resize((t,t),Image.BILINEAR)
        buf = np.array(im).reshape(input_num,1)
        buf = buf<200
        buf = tuple(buf)
        buf1=int(n.split('.')[0])
        buf2=range(output_num)
        for i in range(len(buf2)):
            buf2[i] = 0
        buf2[buf1]=1
        buf2 = tuple(buf2)
        samples.addSample(buf,buf2)
        for i in range(100):
            buf3 = list(buf)
            for j in range(len(buf)/20):
                buf3[np.random.randint(len(buf))] = bool(np.random.randint(2))
            samples.addSample(tuple(buf3),buf2)
    return samples 
开发者ID:Bayoscar,项目名称:ChineseNumberIdentify,代码行数:30,代码来源:ChineseNumberIdentify.py


示例13: convertDataNeuralNetwork

def convertDataNeuralNetwork(x, y):
	data = SupervisedDataSet(x.shape[1], 1)
	for xIns, yIns in zip(x, y):
    	data.addSample(xIns, yIns)    
	return data

def NN(xTrain, yTrain, xTest, yTest):
	trainData = convertDataNeuralNetwork(xTrain, yTrain)
	testData = convertDataNeuralNetwork(xTest, yTest)
	fnn = FeedForwardNetwork()
	inLayer = SigmoidLayer(trainData.indim)
	hiddenLayer = SigmoidLayer(5)
	outLayer = LinearLayer(trainData.outdim)
	fnn.addInputModule(inLayer)
	fnn.addModule(hiddenLayer)
	fnn.addOutputModule(outLayer)
	in_to_hidden = FullConnection(inLayer, hiddenLayer)
	hidden_to_out = FullConnection(hiddenLayer, outLayer)
	fnn.addConnection(in_to_hidden)
	fnn.addConnection(hidden_to_out)
	fnn.sortModules()
	trainer = BackpropTrainer(fnn, dataset = trainData, momentum = 0.1, verbose = True, weightdecay = 0.01)

	for i in xrange(10):
	    trainer.trainEpochs(500)
	    
	rmse = percentError(trainer.testOnClassData(dataset = testData), yTest)
	return rmse/100

def main():
	rmse = NN(xTrain, yTrain, xTest, yTest)
	print rmse

if __name__=="__main__":
	main()
开发者ID:amish-goyal,项目名称:yelp-ratings,代码行数:35,代码来源:NeuralNets.py


示例14: run_try

    def run_try(self, rand_chance=0, rand_count=0, rand_count_ref=0, render=False):
        ds = SupervisedDataSet(env_size, 1)
        observation = env.reset()

        random_indexes = []

        while len(random_indexes) < rand_count:
            random_index = math.floor(random() * rand_count_ref)
            if random_index not in random_indexes:
                random_indexes.append(random_index)

        for t in range(max_frames):
            if render:
                env.render()
            # print(observation)

            action = 0 if net.activate(observation)[0] < 0 else 1

            if t in random_indexes or random() < rand_chance:
                action = (action + 1) % 1

            ds.addSample(observation, (action,))
            observation, reward, done, info = env.step(action)

            if done:
                print("Episode finished after {} timesteps".format(t + 1))
                break

        if t == max_frames - 1:
            print("Passed!!")
            self.run_try(render=True)

        return t, ds
开发者ID:jpodeszwik,项目名称:openai,代码行数:33,代码来源:gnn_pybrain.py


示例15: __init__

class dataset:
    # Initialize the dataset with input and label size
    def __init__(self, inputsize, labelsize):
        self.inputsize = inputsize
        self.labelsize = labelsize
        self.DS = SupervisedDataSet(self.inputsize, self.labelsize)
    
    # Adds data to existing training dataset
    def addTrainingData(self,inputdata, labeldata):
        try:
            if inputdata.size == self.inputsize and labeldata.size == self.labelsize:
                self.DS.appendLinked(inputdata, labeldata)
                return 1
        except AttributeError:
            print "Input error."
            return 0
    
    def getTrainingDataset(self):
        return self.DS
    
    def generateDataSet(self):
        for line in fileinput.input(['data/inputdata3.txt']):
            x = line.split(':')
#            print ft.feature.getImageFeatureVector(x[0]),np.array([int(x[1])])
            self.addTrainingData(ft.feature.getImageFeatureVector(x[0]),np.array([int(x[1])]))
        return 1
开发者ID:bryanmoore4,项目名称:ANN_project,代码行数:26,代码来源:dataset.py


示例16: initializeNetwork

    def initializeNetwork(self):
        can1 = NNTrainData.NNTrainData(cv2.imread('NNTrain/can1.png'), self.encodingDict["can"])
        can2 = NNTrainData.NNTrainData(cv2.imread('NNTrain/can2.png'), self.encodingDict["can"])
        can3 = NNTrainData.NNTrainData(cv2.imread('NNTrain/can3.png'), self.encodingDict["can"])
        stain1 = NNTrainData.NNTrainData(cv2.imread('NNTrain/stain1.png'), self.encodingDict["stain"])
        stain2 = NNTrainData.NNTrainData(cv2.imread('NNTrain/stain2.png'), self.encodingDict["stain"])
        stain3 = NNTrainData.NNTrainData(cv2.imread('NNTrain/stain3.png'), self.encodingDict["stain"])
        dirt1 = NNTrainData.NNTrainData(cv2.imread('NNTrain/dirt1.png'), self.encodingDict["dirt"])
        dirt2 = NNTrainData.NNTrainData(cv2.imread('NNTrain/dirt2.png'), self.encodingDict["dirt"])
        dirt3 = NNTrainData.NNTrainData(cv2.imread('NNTrain/dirt3.png'), self.encodingDict["dirt"])

        self.trainData.append(can1)
        self.trainData.append(can2)
        self.trainData.append(can3)
        self.trainData.append(stain1)
        self.trainData.append(stain2)
        self.trainData.append(stain3)
        self.trainData.append(dirt1)
        self.trainData.append(dirt2)
        self.trainData.append(dirt3)

        for x in self.trainData:
            x.prepareTrainData()

        self.net = buildNetwork(4, 3, 3, hiddenclass=TanhLayer, outclass=SoftmaxLayer)
        ds = SupervisedDataSet(4, 3)

        for x in self.trainData:
            ds.addSample((x.contours/100.0, x.color[0]/1000.0, x.color[1]/1000.0, x.color[2]/1000.0), x.output)

        trainer = BackpropTrainer(self.net, momentum=0.1, verbose=True, weightdecay=0.01)
        trainer.trainOnDataset(ds, 1000)
        trainer.testOnData(verbose=True)
        print "\nSiec nauczona\n"
开发者ID:maciejbiesek,项目名称:InteligentnyOdkurzacz,代码行数:34,代码来源:NeuralNetwork.py


示例17: trainDataSet

def trainDataSet():
    cases = Case.objects.exclude(geocode__isnull=True, geocode__grid=-1)

    print "Data Representation"
    ds = SupervisedDataSet(5245, 5245)
    for w in xrange(0,52):
        print "Start week w",
        dataset_input = [0 for i in xrange(0,5245)]
        dataset_output = [0 for i in xrange(0,5245)]
        for i in xrange(0,5245):
            dataset_input[i] = cases.filter(geocode__grid=i, morbidity__week=w).count()
            dataset_output[i] = 1 if (cases.filter(geocode__grid=i, morbidity__week=w+1).count() > 0 or cases.filter(geocode__grid=i, morbidity__week=w+2).count() > 0) else 0
        ds.addSample( (dataset_input), (dataset_output))
        print " - done week w"
    # tstdata, trndata = ds.splitWithProportion(0.25)
    print "Train"
    net = buildNetwork( 5245, 1000, 5245, bias=True)
    trainer = BackpropTrainer(net, ds, learningrate=0.1, momentum=0.99)

    terrors = trainer.trainUntilConvergence(verbose = None, validationProportion = 0.33, maxEpochs = 1000, continueEpochs = 10 )
    # print terrors[0][-1],terrors[1][-1]
    fo = open("data.txt", "w")
    for input, expectedOutput in ds:
        output = net.activate(input)
        count = 0
        for q in xrange(0, 5245):
            print math.floor(output[q]), math.floor(expectedOutput[q])
            if math.floor(output[q]) == math.floor(expectedOutput[q]):
                count+=1    
        m = count/5245
        fo.write("{0} ::  {1}".format(count, m));
开发者ID:kevcal69,项目名称:thesis,代码行数:31,代码来源:rep.py


示例18: _set_dataset

    def _set_dataset(self, trn_index, tst_index):
        '''
        set the dataset according to the index of the training data and the test data
        Then do feature normalization
        '''
        this_trn = self.tot_descs[trn_index]
        this_tst = self.tot_descs[tst_index]
        this_trn_target = self.tot_target[trn_index]
        this_tst_target = self.tot_target[tst_index]
        
        # get the normalizer
        trn_normalizer = self._getNormalizer(this_trn)
        
        # feature normal and target log for traning data
        trn_normed = self._featureNorm(this_trn, trn_normalizer)
        trn_log_tar = np.log(this_trn_target)
        
        # feature normalization for the test data, with the normalizer of the training data
        tst_normed = self._featureNorm(this_tst, trn_normalizer)
        tst_log_tar = np.log(this_tst_target)
        
        trn_ds_ann = SupervisedDataSet(self.indim, self.outdim)
        trn_ds_ann.setField('input', trn_normed)
        trn_log_tar = trn_log_tar.reshape((trn_log_tar.shape[0],1))
        trn_ds_ann.setField('target', trn_log_tar)
        
        tst_ds_ann = SupervisedDataSet(self.indim, self.outdim)
        tst_ds_ann.setField('input', tst_normed)
        tst_log_tar = tst_log_tar.reshape((tst_log_tar.shape[0],1))
        tst_ds_ann.setField('target', tst_log_tar)

        return trn_ds_ann, tst_ds_ann
开发者ID:RunshengSong,项目名称:CLiCC_Packages,代码行数:32,代码来源:cross_validator.py


示例19: createNet

def createNet():
	"""Create and seed the intial neural network"""
	#CONSTANTS
	nn_input_dim = 6 #[x_enemy1, y_enemy1, x_enemy2, y_enemy2, x_enemy3, y_enemy3]
	nn_output_dim = 6 #[x_ally1, y_ally1, x_ally2, y_ally2, x_ally3, y_ally3]

	allyTrainingPos, enemyTrainingPos = runExperiments.makeTrainingDataset()

	ds = SupervisedDataSet(nn_input_dim, nn_output_dim)

	#normalizes and adds it to the dataset
	for i in range(0, len(allyTrainingPos)):
		x = normalize(enemyTrainingPos[i])
		y = normalize(allyTrainingPos[i])
		x = [val for pair in x for val in pair]
		y = [val for pair in y for val in pair]
		ds.addSample(x, y)

	for inpt, target in ds:
		print inpt, target

	net = buildNetwork(nn_input_dim, 30, nn_output_dim, bias=True, hiddenclass=TanhLayer)
	trainer = BackpropTrainer(net, ds)
	trainer.trainUntilConvergence()
	NetworkWriter.writeToFile(net, "net.xml")
	enemyTestPos = runExperiments.makeTestDataset()
	print(net.activate([val for pair in normalize(enemyTestPos) for val in pair]))
	return ds
开发者ID:peixian,项目名称:Ultralisk,代码行数:28,代码来源:glaive.py


示例20: createBetterSupervisedDataSet

def createBetterSupervisedDataSet(input_file):
	print "Creating a BETTER supervised dataset from", input_file

	ds = SupervisedDataSet(nFeatures, 1)
	answers_by_question = {}

	try:
		with open(training_data_pickle_name, 'rb') as p:
			print "Loading from pickle"
			answers_by_question = pickle.load(p)
			print "Load successful"
			print "Size of answers_by_question:", len(answers_by_question.keys())

	except IOError:
		answers_by_question = loadAnswersByQuestion(input_file)

		print "Saving to a pickle..."
		with open(training_data_pickle_name, 'wb') as p:
			pickle.dump(answers_by_question, p)
		print "Saved to", training_data_pickle_name

	# loop to load stuff into ds
	for qid in answers_by_question:
		for aid in answers_by_question[qid]:
			if aid != 'info':
				ds.addSample( tuple(answers_by_question[qid][aid]['data']), (answers_by_question[qid][aid]['target'], ) )
				# ds.addSample(tuple(ans[1]), (ans[0],))

	return ds, answers_by_question
开发者ID:petitJAM,项目名称:TGMC-Watson-Edition,代码行数:29,代码来源:train_data.py



注:本文中的pybrain.datasets.SupervisedDataSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python supervised.SupervisedDataSet类代码示例发布时间:2022-05-25
下一篇:
Python datasets.SequentialDataSet类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap