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


Python trainers.RPropMinusTrainer类代码示例

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


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

示例1: train

def train(
    train,
    label,
    custom_net=None,
    training_mse_threshold=0.40,
    testing_mse_threshold=0.60,
    epoch_threshold=10,
    epochs=100,
    hidden_size=20,
):
    # Test Set.
    x_train = train[0:split_at, :]
    y_train_slice = label.__getslice__(0, split_at)
    y_train = y_train_slice.reshape(-1, 1)
    x_test = train[split_at:, :]
    y_test_slice = label.__getslice__(split_at, label.shape[0])
    y_test = y_test_slice.reshape(-1, 1)

    # Shape.
    input_size = x_train.shape[1]
    target_size = y_train.shape[1]

    # prepare dataset
    ds = SDS(input_size, target_size)
    ds.setField("input", x_train)
    ds.setField("target", y_train)

    # prepare dataset
    ds_test = SDS(input_size, target_size)
    ds_test.setField("input", x_test)
    ds_test.setField("target", y_test)

    min_mse = 1000000

    # init and train
    if custom_net == None:
        net = buildNetwork(input_size, hidden_size, target_size, bias=True)
    else:
        print "Picking up the custom network"
        net = custom_net

    trainer = RPropMinusTrainer(net, dataset=ds, verbose=False, weightdecay=0.01, batchlearning=True)
    print "training for {} epochs...".format(epochs)

    for i in range(epochs):
        mse = trainer.train()
        print "training mse, epoch {}: {}".format(i + 1, math.sqrt(mse))

        p = net.activateOnDataset(ds_test)
        mse = math.sqrt(MSE(y_test, p))
        print "-- testing mse, epoch {}: {}".format(i + 1, mse)
        pickle.dump(net, open("current_run", "wb"))

        if min_mse > mse:
            print "Current minimum found at ", i
            pickle.dump(net, open("current_min_epoch_" + model_file, "wb"))
            min_mse = mse

    pickle.dump(net, open(model_file, "wb"))
    return net
开发者ID:korkam,项目名称:beta_learning-matlab-through-case-studies,代码行数:60,代码来源:PyBrainWithCV.py

示例2: exam

    def exam(self, dc, train_com, train_path):
        """
        Here you can train your networks.

        Parameters
        ----------
        :param dc: dict
            Dict of commands with values.
        :param train_com:
            Command what you want teach by ann to recognize.
        :param train_path:
            Path to folder with train examples.

        Returns
        -------
        :return:
            File with network.

        """
        num_hid = 1
        put, out = [], []

        ds = SupervisedDataSet(420, 1)
        nt = buildNetwork(420, 3, 1, bias=True, hiddenclass=SigmoidLayer, outclass=SigmoidLayer)

        for way in train_path:
            for i in os.listdir(way):
                lk = self.link(i)
                if lk:
                    self.logger.debug(u'File was added to training list %s' % i)
                    result = self.ext_t(way+i)
                    ds.addSample(result, (dc[lk],))
                    put.append(result)
                    out.append([dc[lk]])

        net = nl.net.newff([[np.min(put), np.max(put)]]*420, [num_hid, 1], [nl.trans.LogSig(), nl.trans.SatLinPrm()])
        net.trainf = nl.train.train_rprop
        trainer = RPropMinusTrainer(nt, dataset=ds, verbose=False)
        self.logger.info(u'Training brain...')
        trainer.trainUntilConvergence(maxEpochs=100, verbose=False, continueEpochs=100, validationProportion=1e-7)
        self.logger.info(u'Training neural...')
        error = net.train(put, out, epochs=500, show=500, goal=1e-4, lr=1e-10)

        while error[-1] > 1e-3:
            self.logger.info(u'Try to one more training, because MSE are little not enough!')
            net = nl.net.newff([[np.min(put), np.max(put)]]*420, [num_hid, 1], [nl.trans.LogSig(), nl.trans.SatLinPrm()])
            net.trainf = nl.train.train_rprop
            self.logger.info(u'Training neural...')
            error = net.train(put, out, epochs=500, show=500, goal=1e-4, lr=1e-10)
            num_hid += 1

        try:
            net.save(u'networks/%s_neurolab' % train_com)
            fl = open(u'networks/%s_brain' % train_com, 'w')
            pickle.dump(nt, fl)
            fl.close()

        except IOError:
            os.mkdir(u'networks')
            net.save(u'networks/%s_neurolab' % train_com)
开发者ID:noob-saibot,项目名称:Recognition-with-ANN,代码行数:60,代码来源:genann.py

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

示例4: createAndTrainNetworkFromList

def createAndTrainNetworkFromList(train_list, count_input_samples, net_filename, count_layers=33,
                          count_outputs=1, max_epochs=15000, min_epochs=300):
    net = buildNetwork(count_input_samples, count_layers, count_outputs)
    ds = SupervisedDataSet(count_input_samples, count_outputs)
    count_samples = len(train_list)
    for i in range(0, count_samples):
        ds.addSample(train_list[i][:-count_outputs], train_list[i][-count_outputs])
    trainer = RPropMinusTrainer(net, verbose=True)
    trainer.setData(ds)
    a = trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs, validationProportion=0.15)
    net_filename = net_filename[:-4]+str(a[0][-1])+'.xml'
    NetworkWriter.writeToFile(net, net_filename)
    result_list = [a, net_filename]
    return result_list
开发者ID:ivalykhin,项目名称:neirohome,代码行数:14,代码来源:netManagement.py

示例5: train

 def train(self, training_files, learningrate=0.01, scaling=True, noise=False, verbose=True):
     print "building dataset..."
     ds = SupervisedDataSet(SensorModel.array_length(self.sensor_ids), 1)
     # read training file line, create sensormodel object, do backprop
     a = None
     s = None
     for logfile in training_files:
         print "loading file", logfile
         with open(logfile) as f:
             for line in f:
                 if line.startswith("Received:"):
                     s = SensorModel(string=line.split(' ', 1)[1])
                 elif line.startswith("Sending:"):
                     a = Actions.from_string(string=line.split(' ', 1)[1])
                 if s is not None and a is not None:
                     ds.addSample(inp=s.get_array(self.sensor_ids), target=a[self.action_ids[0]])
                     if noise:
                         # add the same training sample again but with noise in the sensors
                         s.add_noise()
                         ds.addSample(inp=s.get_array(self.sensor_ids), target=a[self.action_ids[0]])
                     s = None
                     a = None
     print "dataset size:", len(ds)
     if scaling:
         print "scaling dataset"
         self.scaler_input = StandardScaler(with_mean=True, with_std=False).fit(ds.data['input'])
         ds.data['input'] = self.scaler_input.transform(ds.data['input'])
         ds.data['target'] = ds.data['target']
     #self.trainer = BackpropTrainer(self.net, learningrate=learningrate, verbose=verbose)
     self.trainer = RPropMinusTrainer(self.net, verbose=verbose, batchlearning=True)
     print "training network..."
     self.trainer.trainUntilConvergence(dataset=ds, validationProportion=0.25, maxEpochs=10, continueEpochs=2)
开发者ID:lqrz,项目名称:computational_intelligence,代码行数:32,代码来源:network.py

示例6: __init__

  def __init__(self, ds): 

    num_inputs = ds.num_features * sequence_classifier.num_time_steps
    self.alldata = SequenceClassificationDataSet(num_inputs, 
                                                 target = 1,
                                                 nb_classes   = ds.get_num_classes(),
                                                 class_labels = ds.get_classes() )

    for Idx in range(len(ds.all_moves)):
      if not (Idx + sequence_classifier.num_time_steps < len(ds.all_moves)):
        continue
   
      class_first = ds.all_moves[Idx].class_ 
      features  = []
      for i in range(sequence_classifier.num_time_steps):
        features = features + ds.all_moves[Idx + i].get_features()

      class_last = ds.all_moves[Idx + sequence_classifier.num_time_steps].class_
  
      if class_first == class_last:
        self.alldata.appendLinked(features, [ds.get_classes().index(ds.all_moves[Idx].class_)])
        self.alldata.newSequence()
      

    self.tstdata, self.trndata = self.alldata.splitWithProportion(0.25)
    self.trndata._convertToOneOfMany()
    self.tstdata._convertToOneOfMany()

    self.seq_rnn      = None #buildNetwork(num_inputs, 2, self.trndata.outdim, hiddenclass=LSTMLayer,recurrent=True ,outclass=SoftmaxLayer)
    self.create_network(num_inputs)

    self.trainer  = RPropMinusTrainer(module=self.seq_rnn, dataset=self.trndata)
开发者ID:SameerAsal,项目名称:accelerometer_training,代码行数:32,代码来源:sequence_classifier.py

示例7: __init__

 def __init__(self): 
     self.inputs = 3
     self.outputs = 1
     self.n = buildNetwork(self.inputs, 200,200,200,200,self.outputs, bias=True,hiddenclass=TanhLayer)
     self.n.sortModules()
     self.ds = SupervisedDataSet(self.inputs, self.outputs)
     self.trainer = RPropMinusTrainer(self.n)
     self.trainer.setData(self.ds)
开发者ID:akeenan22,项目名称:NeuroSoccer,代码行数:8,代码来源:Brain.py

示例8: train

    def train(self, trndata, valdata, hidden_neurons=5, hidden_class=SigmoidLayer, iterations=3):
        print "Hidden neurons: " + str(hidden_neurons)
        print "Hidden class: " + str(hidden_class)
        print "Iterations: " + str(iterations)

        fnn = buildNetwork(trndata.indim, hidden_neurons, trndata.outdim, outclass=SoftmaxLayer,
                           hiddenclass=hidden_class)
        trainer = RPropMinusTrainer(fnn, dataset=trndata, verbose=False)
        #trainer = BackpropTrainer(fnn, dataset=trndata, momentum=0.5, verbose=True, learningrate=0.05)

        for i in range(iterations):
            trainer.train()
            out, tar = trainer.testOnClassData(dataset=valdata, return_targets=True, verbose=False)
            #used to return final score, not used yet :D
            print str(i) + " " + str(accuracy(out, tar))

        self.model = trainer
开发者ID:sacherus,项目名称:pca-image,代码行数:17,代码来源:forest_main.py

示例9: train_net

def train_net():
    fnn = buildNetwork(len(input_args), 3, 2)
    ds = ClassificationDataSet(len(input_args),2,nb_classes=2)

    ds = generate_data(ds , hour_to_use_app = 10)
    
    trainer = RPropMinusTrainer( fnn, dataset= ds, verbose=True)

    trainer.train()
    trainer.trainEpochs(15)
    
    test = ClassificationDataSet(4,2)
    test.addSample((12,6,10,6),[1,0])
    test.addSample((12,1,7,2),[0,1])
    test.addSample((12,3,11,1),[0,1])
    
    fnn.activateOnDataset(test)
    
    return fnn,trainer,ds,test
开发者ID:tweksteen,项目名称:neuralsession,代码行数:19,代码来源:svmlearning.py

示例10: createAndTrainNetworkFromFile

def createAndTrainNetworkFromFile(curs_filename, count_input_samples, count_samples, net_filename, count_layers=33,
                          count_outputs=1, max_epochs=15000, min_epochs=300):
    net = buildNetwork(count_input_samples, count_layers, count_outputs)
    ds = SupervisedDataSet(count_input_samples, count_outputs)
    wb = load_workbook(filename=curs_filename)
    ws = wb.active
    for i in range(0, count_samples):
        loaded_data = []
        for j in range(0, count_input_samples + 1):
            loaded_data.append(round(float(ws.cell(row=i+1, column=j+1).value), 4))
            #ds.addSample(loaded_data[:-1], loaded_data[-1])
        #print loaded_data[:-1], loaded_data[-1]
        ds.addSample(loaded_data[:-1], loaded_data[-1])
    trainer = RPropMinusTrainer(net, verbose=True)
    trainer.setData(ds)
    a = trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs, validationProportion=0.15)
    net_filename = net_filename[:-4]+str(a[0][-1])+'.xml'
    NetworkWriter.writeToFile(net, net_filename)
    result_list = [a, net_filename]
    return result_list
开发者ID:ivalykhin,项目名称:neirohome,代码行数:20,代码来源:netManagement.py

示例11: train

    def train(self,
              cycles,
              percent,
              hidden_layers=3,
              hiddenclass=None,
              num_outputs=1,
              num_inputs=-1):
        num_inputs = self._count_inputs() if num_inputs == -1 else num_inputs
        if num_inputs <= 0 or num_outputs <= 0 or cycles <= 0 or (percent > 100 or percent <= 0):
            return

        network = self._buildNet(hidden_layers, num_outputs, num_inputs, hiddenclass)
        data_set = self.get_data_set(percent, num_inputs, num_outputs)

        trainer = RPropMinusTrainer(network, dataset=data_set)

        for i in range(cycles):
            trainer.train()

        return network
开发者ID:ArsEmchik,项目名称:course_project,代码行数:20,代码来源:resilient_propagation.py

示例12: Brain

class Brain():
    def __init__(self): 
        self.inputs = 3
        self.outputs = 1
        self.n = buildNetwork(self.inputs, 200,200,200,200,self.outputs, bias=True,hiddenclass=TanhLayer)
        self.n.sortModules()
        self.ds = SupervisedDataSet(self.inputs, self.outputs)
        self.trainer = RPropMinusTrainer(self.n)
        self.trainer.setData(self.ds)
    def wipedataset(self):
        self.ds = SupervisedDataSet(self.inputs, self.outputs)
        pass
    def cycle(self,action,state):
        return self.n.activate([action,state[0],state[1]])
    def AddToTrainingSet(self,action,state,output):
        out= "New Set","Action: ",action,"State: ", state,"Output: ", output
        f.write(str(out)+"\n")
        self.ds.addSample((action,state[0],state[1]),output)
    def train(self):
        return "ERROR",self.trainer.train()
    def traintoconverg(self):
        x = 10000
        y=0
        z=100
        print len(self.ds),"DS SIZE"
        while x > 0.0001 and y < z:
            print len(self.ds)
            x = self.trainer.train()
            print x,"ERROR",y
            y+=1
        f = open('brains/brain2000.ann','w')
        pickle.dump(self.n,f)
    def trainfinal(self):
        x = 10000
        y=0
        z=25
        while x > 0.00001 and y < z:
            x = self.trainer.train()
            print x,"ERROR",y
            y+=1
开发者ID:akeenan22,项目名称:NeuroSoccer,代码行数:40,代码来源:Brain.py

示例13: trainNetwork

def trainNetwork(dirname):
    numFeatures = 5000
    ds = SequentialDataSet(numFeatures, 1)
    
    tracks = glob.glob(os.path.join(dirname, 'train??.wav'))
    for t in tracks:
        track = os.path.splitext(t)[0]
        # load training data
        print "Reading %s..." % track
        data = numpy.genfromtxt(track + '_seg.csv', delimiter=",")
        labels = numpy.genfromtxt(track + 'REF.txt', delimiter='\t')[0::10,1]
        numData = data.shape[0]

        # add the input to the dataset
        print "Adding to dataset..."
        ds.newSequence()
        for i in range(numData):
            ds.addSample(data[i], (labels[i],))
    
    # initialize the neural network
    print "Initializing neural network..."
    net = buildNetwork(numFeatures, 50, 1,
                       hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
    
    # train the network on the dataset
    print "Training neural net"
    trainer = RPropMinusTrainer(net, dataset=ds)
##    trainer.trainUntilConvergence(maxEpochs=50, verbose=True, validationProportion=0.1)
    error = -1
    for i in range(100):
        new_error = trainer.train()
        print "error: " + str(new_error)
        if abs(error - new_error) < 0.1: break
        error = new_error

    # save the network
    print "Saving neural network..."
    NetworkWriter.writeToFile(net, os.path.basename(dirname) + 'net')
开发者ID:tediris,项目名称:MusicML,代码行数:38,代码来源:trainer.py

示例14: train

 def train(self, input_row, output_row):
     """
     Training network by r-prop.
     PARTITION_OF_EDUCATION_VERIFICATION_SET - education|validation ratio
     MAX_EPOCHS - count of max steps of education
     OUTCASTING_EPOCHS - if education can't get out of local minimum it given count of steps, it stops
     """
     self._form_set(input_row, output_row)
     trainer = RPropMinusTrainer(module=self.network, dataset=self.data_set)
     self.training_errors, self.validation_errors = trainer.trainUntilConvergence(
         validationProportion=self.settings.training_part_fraction,
         maxEpochs=self.settings.maximum_training_epochs,
         continueEpochs=self.settings.quit_epochs)
     len_validate = int(len(output_row[0]['data']) * (1 - self.settings.training_part_fraction))
     results_of = [list(self.network.activate(x))[0] for x in self.inputs_for_validation[len_validate:]]
     self.mse = sum(map(lambda result, target: fabs(result - target), list(results_of),
                        list(output_row[0]['data'][len_validate:]))) / len(results_of)
     print 'DUMB-dd'
     for it in results_of:
         print it
     print 'DUMB-pp'
     for it in list(output_row[0]['data'][len_validate:]):
         print it
     print '| | |-MSE = ', self.mse
开发者ID:UIR-workigteam,项目名称:UIR,代码行数:24,代码来源:OwnNeuro.py

示例15: fit

    def fit(self, X, y):
        """
        Trains the classifier

        :param pandas.DataFrame X: data shape [n_samples, n_features]
        :param y: labels of events - array-like of shape [n_samples]
        .. note::
            doesn't support sample weights
        """

        dataset = self._prepare_net_and_dataset(X, y, 'classification')

        if self.use_rprop:
            trainer = RPropMinusTrainer(self.net,
                                        etaminus=self.etaminus,
                                        etaplus=self.etaplus,
                                        deltamin=self.deltamin,
                                        deltamax=self.deltamax,
                                        delta0=self.delta0,
                                        dataset=dataset,
                                        learningrate=self.learningrate,
                                        lrdecay=self.lrdecay,
                                        momentum=self.momentum,
                                        verbose=self.verbose,
                                        batchlearning=self.batchlearning,
                                        weightdecay=self.weightdecay)
        else:
            trainer = BackpropTrainer(self.net,
                                      dataset,
                                      learningrate=self.learningrate,
                                      lrdecay=self.lrdecay,
                                      momentum=self.momentum,
                                      verbose=self.verbose,
                                      batchlearning=self.batchlearning,
                                      weightdecay=self.weightdecay)

        if self.epochs < 0:
            trainer.trainUntilConvergence(maxEpochs=self.max_epochs,
                                          continueEpochs=self.continue_epochs,
                                          verbose=self.verbose,
                                          validationProportion=self.validation_proportion)
        else:
            for i in range(self.epochs):
                trainer.train()
        self.__fitted = True

        return self
开发者ID:tyamana,项目名称:rep,代码行数:47,代码来源:pybrain.py


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