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

Python networkwriter.NetworkWriter类代码示例

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

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



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

示例1: big_training

def big_training(np_data, num_nets=1, num_epoch=20, net_builder=net_full, train_size=.1, testing=False):
    sss = cross_validation.StratifiedShuffleSplit(np_data[:,:1].ravel(), n_iter=num_nets , test_size=1-train_size, random_state=3476)
    nets=[None for net_ind in range(num_nets)]
    trainaccu=[[0 for i in range(num_epoch)] for net_ind in range(num_nets)]
    testaccu=[[0 for i in range(num_epoch)] for net_ind in range(num_nets)]
    net_ind=0
    for train_index, test_index in sss:
        print ('%s Building %d. network.' %(time.ctime(), net_ind+1))
        #print("TRAIN:", len(train_index), "TEST:", len(test_index))
        trainset = ClassificationDataSet(np_data.shape[1] - 1, 1)
        trainset.setField('input', np_data[train_index,1:]/100-.6)
        trainset.setField('target', np_data[train_index,:1])
        trainset._convertToOneOfMany( )
        trainlabels = trainset['class'].ravel().tolist()
        if testing:
            testset = ClassificationDataSet(np_data.shape[1] - 1, 1)
            testset.setField('input', np_data[test_index,1:]/100-.6)
            testset.setField('target', np_data[test_index,:1])
            testset._convertToOneOfMany( )
            testlabels = testset['class'].ravel().tolist()
        nets[net_ind] = net_builder()
        trainer = BackpropTrainer(nets[net_ind], trainset)
        for i in range(num_epoch):
            for ii in range(3):
                err = trainer.train()
            print ('%s Epoch %d: Network trained with error %f.' %(time.ctime(), i+1, err))
            trainaccu[net_ind][i]=accuracy_score(trainlabels,trainer.testOnClassData())
            print ('%s Epoch %d: Train accuracy is %f' %(time.ctime(), i+1, trainaccu[net_ind][i]))
            print ([sum([trainaccu[y][i]>tres for y in range(net_ind+1)]) for tres in [0,.1,.2,.3,.4,.5,.6]])
            if testing:
                testaccu[net_ind][i]=accuracy_score(testlabels,trainer.testOnClassData(testset))
                print ('%s Epoch %d: Test accuracy is %f' %(time.ctime(), i+1, testaccu[net_ind][i]))
        NetworkWriter.writeToFile(nets[net_ind], 'nets/'+net_builder.__name__+str(net_ind)+'.xml')
        net_ind +=1
    return [nets, trainaccu, testaccu]
开发者ID:1va,项目名称:pybrain_digits,代码行数:35,代码来源:pybrain_mnist.py


示例2: 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


示例3: _learn

def _learn():

    global _TRAIN_RATE;

    _LEARNINGS_GRADE = 0.00012; # 0.00012 == correct
    #_LEARNINGS_GRADE = 0.0012; 
    #_LEARNINGS_GRADE = 0.012; 
    #_LEARNINGS_GRADE = 0.12; 
    #_LEARNINGS_GRADE = 0.80; 
    #_LEARNINGS_GRADE = 1.4;
    #_LEARNINGS_GRADE = 6.2;
    #_LEARNINGS_GRADE = 10.2;
    _LEARNINGS_GRADE = 20.2;

    #_TRAIN_RATE = float(str(_TRAINER.train())); 
    _SECS = int( str(time.time()).split('.')[0] );

    while _TRAIN_RATE > _LEARNINGS_GRADE:

        _TRAIN_RATE = float(str(_TRAINER.train()));
        #NetworkWriter.writeToFile(_NET, str(str(_TRAIN_RATE).split(":")[1])+"_"+_NET_NAME+".AUTO_SAVE.xml")
        NetworkWriter.writeToFile(_NET, "_"+str(_TRAIN_RATE)+"_"+_NET_NAME+".xml")

        print("Learn-Duration: "+str(time.strftime("%H:%M:%S", time.localtime(int( str(time.time()).split('.')[0] )-_SECS))));
        _SECS = int( str(time.time()).split('.')[0] );

    if _TRAIN_RATE < _LEARNINGS_GRADE:
        print('Network ready.');
开发者ID:ch3ll0v3k,项目名称:AI-Alphabet,代码行数:28,代码来源:_buildNetwork-v2.py


示例4: save

 def save(self, filename, desc=None):
     NetworkWriter.writeToFile(self.net, filename + '.xml')
     params = {'labels': self.labels,
               'mean': self.mean.tolist(),
               'std': self.std.tolist()}
     with open(filename + '.yaml', 'w') as f:
         f.write(yaml.dump(params, default_flow_style=False))
开发者ID:fsfrk,项目名称:hbrs-youbot-hackathon,代码行数:7,代码来源:classification_network.py


示例5: save

 def save(self, path):
     """
     This function saves the neural network.
     Args:
     :param path (String): the path where the neural network is going to be saved.
     """
     NetworkWriter.writeToFile(self.network, path)
开发者ID:dtu-02819-projects-fall2014,项目名称:Introduction-to-Data-Mining-DTU,代码行数:7,代码来源:ai.py


示例6: training

def training(d):
    # net = buildNetwork(d.indim, 55, d.outdim, bias=True,recurrent=False, hiddenclass =SigmoidLayer , outclass = SoftmaxLayer)
    net = FeedForwardNetwork()
    inLayer = SigmoidLayer(d.indim)
    hiddenLayer1 = SigmoidLayer(d.outdim)
    hiddenLayer2 = SigmoidLayer(d.outdim)
    outLayer = SigmoidLayer(d.outdim)

    net.addInputModule(inLayer)
    net.addModule(hiddenLayer1)
    net.addModule(hiddenLayer2)
    net.addOutputModule(outLayer)

    in_to_hidden = FullConnection(inLayer, hiddenLayer1)
    hidden_to_hidden = FullConnection(hiddenLayer1, hiddenLayer2)
    hidden_to_out = FullConnection(hiddenLayer2, outLayer)

    net.addConnection(in_to_hidden)
    net.addConnection(hidden_to_hidden)
    net.addConnection(hidden_to_out)

    net.sortModules()
    print net

    t = BackpropTrainer(net, d, learningrate = 0.9,momentum=0.9, weightdecay=0.01, verbose = True)
    t.trainUntilConvergence(continueEpochs=1200, maxEpochs=1000)
    NetworkWriter.writeToFile(net, 'myNetwork'+str(time.time())+'.xml')
    return t
开发者ID:ssteku,项目名称:SoftComputing,代码行数:28,代码来源:CustomNetwork.py


示例7: _InitNet

    def _InitNet(self):

        # -----------------------------------------------------------------------
        self._pr_line();
        print("| _InitNet(self): \n");
        start_time = time.time();
        # -----------------------------------------------------------------------
        if self._NET_NAME:
            
            # -----------------------------------------------------------------------
            self._SDS = SupervisedDataSet(900, 52); 

            if self._NET_NEW:

                print('| Bulding new NET: '+self._NET_NAME)
                self._NET = buildNetwork(self._SDS.indim, self._NET_HIDDEN, self._SDS.outdim, bias=True); #,hiddenclass=TanhLayer)
                self._SaveNET();
            else:

                print('| Reading NET from: '+self._NET_NAME)
                self._NET = NetworkReader.readFrom(self._NET_NAME)
            # -----------------------------------------------------------------------
            print('| Making AutoBAK: '+str(self._MK_AUTO_BAK))
            
            if self._MK_AUTO_BAK:
                NetworkWriter.writeToFile(self._NET, self._NET_NAME+".AUTO_BAK.xml");
            # -----------------------------------------------------------------------
            print("| Done in: "+str(time.time()-start_time)+'sec');
            # -----------------------------------------------------------------------

        else:
            
            print('| Unknown NET name: >|'+self._NET_NAME+'|<')
            exit();
开发者ID:ch3ll0v3k,项目名称:AI-Alphabet,代码行数:34,代码来源:_buildNetwork-v3-Threading.py


示例8: nntester

def nntester(tx, ty, rx, ry, iterations):
    """
    builds, tests, and graphs a neural network over a series of trials as it is
    constructed
    """
    resultst = []
    resultsr = []
    positions = range(iterations)
    network = buildNetwork(100, 50, 1, bias=True)
    ds = ClassificationDataSet(100,1, class_labels=["valley", "hill"])
    for i in xrange(len(tx)):
        ds.addSample(tx[i], [ty[i]])
    trainer = BackpropTrainer(network, ds, learningrate=0.01)
    for i in positions:
        print trainer.train()
        resultst.append(sum((np.array([round(network.activate(test)) for test in tx]) - ty)**2)/float(len(ty)))
        resultsr.append(sum((np.array([round(network.activate(test)) for test in rx]) - ry)**2)/float(len(ry)))
        print i, resultst[i], resultsr[i]
    NetworkWriter.writeToFile(network, "network.xml")
    plt.plot(positions, resultst, 'ro', positions, resultsr, 'bo')
    plt.axis([0, iterations, 0, 1])
    plt.ylabel("Percent Error")
    plt.xlabel("Network Epoch")
    plt.title("Neural Network Error")
    plt.savefig('3Lnn.png', dpi=300)
开发者ID:iRapha,项目名称:Machine-Learning,代码行数:25,代码来源:hills.py


示例9: train

    def train(self, network, valid_bp, path):
        """
        Train until convergence, stopping the training when the training
        doesn't reduce the validation error after 1000 continuous epochs

        :param network: model
        :type network: NeuralNetwork.NeuralNetwork
        :param valid_bp: Validation set
        :type valid_bp: SupervisedDataSet
        :param path: Path where to save the trained model
        :type path: str
        :return: None
        :rtype: None
        """
        epochs = 0
        continue_epochs = 0
        # best_epoch = 0
        NetworkWriter.writeToFile(network.network, path)
        min_error = network.valid(valid_bp)
        while True:
            train_error = self.trainer.train()
            valid_error = network.valid(valid_bp)
            if valid_error < min_error:
                min_error = valid_error
                # best_epoch = epochs
                NetworkWriter.writeToFile(network.network, path)
                continue_epochs = 0
            self.training_errors.append(train_error)
            self.validation_errors.append(valid_error)
            epochs += 1
            continue_epochs += 1
            # print str(epochs) + " " + str(continue_epochs) + " " + str(best_epoch)
            if continue_epochs > 1000:
                break
开发者ID:LoreDema,项目名称:ValidPy,代码行数:34,代码来源:BackPropTrainer.py


示例10: process_symbol

def process_symbol(net, symbol):
 print "processing ", symbol
 #zuerst train_data prüfen, wenn keine Trainingsdaten da sind, dann brauchen wir nicht weitermachen
 train_data = load(symbol+'.train')
 if (len(train_data) == 0):
  print "--no training data, skip", symbol
  return
 print "-traing data loaded"
 data = load_stockdata(symbol)
 if (len(data) == 0):
  print "--no data, skip", symbol
  return
 print "-stock data loaded"
 settings = load_settings(symbol,data)
 if(len(settings) == 0):
  print "--no settings, skip", symbol
  return
 print "-settings loaded"
 #jetzt sind alle Daten vorhanden
 ds = build_dataset(data, train_data, settings)
 print "-train"
 trainer = BackpropTrainer(net, ds)
 trainer.trainEpochs(epochs)
 print "-saving network"
 NetworkWriter.writeToFile(net, 'network.xml') 
 return net
开发者ID:ZwenAusZwota,项目名称:aktien,代码行数:26,代码来源:learn.py


示例11: 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


示例12: saveToFile

    def saveToFile(self):
        if self.net is not None:
            if self.major:
                NetworkWriter.writeToFile(self.net, TRAINED_DATA_FILEPATH_MAJOR)
            else:
                NetworkWriter.writeToFile(self.net, TRAINED_DATA_FILEPATH_MINOR)

        else:
            print "Cannot save nothing"
开发者ID:davepagurek,项目名称:Chordi.co,代码行数:9,代码来源:learn.py


示例13: main

def main():
    #agent1 = SimpleMLPMarioAgent(2)
    #agent1 = MLPMarioAgent(4)
    #agent1 = MdrnnAgent()
    
    agent1 = SimpleMdrnnAgent()
    print agent1.name
    NetworkWriter.writeToFile(agent1.module, "../temp/MarioNetwork-"+agent1.name+".xml")
    f = combinedScore(agent1)
    print "\nTotal:", f
开发者ID:DioMuller,项目名称:ai-exercices,代码行数:10,代码来源:testnetagent.py


示例14: trainNetwork

def trainNetwork(net, sample_list, validate_list, net_filename, max_epochs=5500, min_epochs=300):
    count_input_samples = len(sample_list)
    count_outputs = len(validate_list)
    ds = SupervisedDataSet(count_input_samples, count_outputs)
    ds.addSample(sample_list, validate_list)
    trainer = RPropMinusTrainer(net, verbose=True)
    trainer.setData(ds)
    trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs)
    NetworkWriter.writeToFile(net, net_filename)
    return net
开发者ID:ivalykhin,项目名称:neirohome,代码行数:10,代码来源:netManagement.py


示例15: nn

def nn(tx, ty, rx, ry, iterations):
    network = buildNetwork(14, 5, 5, 1)
    ds = ClassificationDataSet(14,1, class_labels=["<50K", ">=50K"])
    for i in xrange(len(tx)):
        ds.addSample(tx[i], [ty[i]])
    trainer = BackpropTrainer(network, ds)
    trainer.trainOnDataset(ds, iterations)
    NetworkWriter.writeToFile(network, "network.xml")
    results = sum((np.array([round(network.activate(test)) for test in rx]) - ry)**2)/float(len(ry))
    return results
开发者ID:iRapha,项目名称:Machine-Learning,代码行数:10,代码来源:hills.py


示例16: train

    def train(self):

        self.done = False
        trainer = BackpropTrainer(self.network, learningrate=0.2)

        train_until_convergence(trainer=trainer, dataset=self.ds,
                                max_error=self.max_error,
                                max_epochs=self.epochs)

        self.done = True
        if self.save:
            NetworkWriter.writeToFile(self.network, self.save)
开发者ID:nihn,项目名称:speedometer,代码行数:12,代码来源:neural_network.py


示例17: train

def train(net,ds):
 trainer = BackpropTrainer(net, ds)
 #for i in range(0,epochs):
 # print trainer.train()
 #trainer.trainEpochs(epochs)
 print "-e", trainer.train()
 #trainer.trainUntilConvergence()
 trainer.trainEpochs(epochs)
 print "-e", trainer.train()
 print "-saving network"
 NetworkWriter.writeToFile(net, network_file)
 return net
开发者ID:ZwenAusZwota,项目名称:aktien,代码行数:12,代码来源:learn200.py


示例18: save_network

 def save_network(self,name_of_the_net):
     '''
     Save the network and the index of the test data
     '''
     print "Saving the trained network and test data index"
     if self.network is None:
         print "Network has not been trained!!"
     else:
         NetworkWriter.writeToFile(self.network, name_of_the_net)
         fileName = name_of_the_net.replace('.xml','')
         fileName = fileName+'_testIndex.txt'
         np.savetxt(fileName,self.tstIndex)
         print "Saving Finished"
开发者ID:RunshengSong,项目名称:CLiCC_Packages,代码行数:13,代码来源:classifier.py


示例19: writeAgentNet

def writeAgentNet(score, counter):
    NetworkWriter.writeToFile(
        agent.module,
        "../temp/"
        + str(port)
        + "x/SimpleMdrnnANet-fit:"
        + str(round(score, 2))
        + "-after:"
        + str(counter)
        + "-"
        + str(idd)
        + ".xml",
    )
开发者ID:lcaaroe,项目名称:MCTSMario,代码行数:13,代码来源:evolvemrnnmario.py


示例20: _train

def _train(X, Y, filename, epochs=50):
    global nn
    nn = buildNetwork(INPUT_SIZE, HIDDEN_LAYERS, OUTPUT_LAYER, bias=True, outclass=SoftmaxLayer)
    ds = ClassificationDataSet(INPUT_SIZE, OUTPUT_LAYER)
    for x, y in zip(X, Y):
        ds.addSample(x, y)
    trainer = BackpropTrainer(nn, ds)
    for i in xrange(epochs):
        error = trainer.train()
        print "Epoch: %d, Error: %7.4f" % (i+1, error)
    # trainer.trainUntilConvergence(verbose=True, maxEpochs=epochs, continueEpochs=10)
    if filename:
        NetworkWriter.writeToFile(nn, 'data/' + filename + '.nn')
开发者ID:igorcoding,项目名称:digrecog,代码行数:13,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utilities.abstractMethod函数代码示例发布时间:2022-05-25
下一篇:
Python networkreader.NetworkReader类代码示例发布时间: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