当前位置: 首页>>代码示例>>Python>>正文


Python NetworkWriter.writeToFile方法代码示例

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


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

示例1: big_training

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:37,代码来源:pybrain_mnist.py

示例2: createNet

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:30,代码来源:glaive.py

示例3: _learn

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:30,代码来源:_buildNetwork-v2.py

示例4: save

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
 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,代码行数:9,代码来源:classification_network.py

示例5: save

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
 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,代码行数:9,代码来源:ai.py

示例6: training

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:30,代码来源:CustomNetwork.py

示例7: _InitNet

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
    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,代码行数:36,代码来源:_buildNetwork-v3-Threading.py

示例8: nntester

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:27,代码来源:hills.py

示例9: train

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
    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,代码行数:36,代码来源:BackPropTrainer.py

示例10: process_symbol

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:28,代码来源:learn.py

示例11: entrenarSomnolencia

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:27,代码来源:entrenar.py

示例12: saveToFile

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
    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,代码行数:11,代码来源:learn.py

示例13: main

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:12,代码来源:testnetagent.py

示例14: trainNetwork

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:12,代码来源:netManagement.py

示例15: nn

# 需要导入模块: from pybrain.tools.xml.networkwriter import NetworkWriter [as 别名]
# 或者: from pybrain.tools.xml.networkwriter.NetworkWriter import writeToFile [as 别名]
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,代码行数:12,代码来源:hills.py


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