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


Python Timer.total方法代码示例

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


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

示例1: graft

# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import total [as 别名]
    def graft(self, dump_every = 0, \
              dump_file = None, \
              nActiveSet = None, \
              tester = None, \
              test_every = 10, \
              samplePerRun = 1, \
              fromDumpFile = None \
             ):
        '''
        the main grafting algorithm
        ==Parameters==
        dump_every: the frequency to dump the current result. 0 if you do not want to dump
        dump_file: dump file name.
        nActiveSet: when retraining, the number of features in the active set.
            pass None for full retraining (may be slow!)
            pass a positive number to select the last features
            pass a negative number to select features via their gradient values
                (recommended, much better than other approaches)
            pass 0 for boosting
        tester: the grafterMPI class that hosts the test data
        test_every: the frequency to compute test accuracy
        samplePerRun: in each feature selection run, how many features (in proportions)
            we should sample to select feature from. Pass 1 to enumerate all features.
        fromDumpFile: restore from dump file (not implemented for the mb version yet)
        '''
        self.comm.barrier()
        mpi.rootprint('*'*38)
        mpi.rootprint('*'*15+'grafting'+'*'*15)
        mpi.rootprint('*'*38)

        if True:
            mpi.rootprint('Number of data: {}'.format(self.nData))
            mpi.rootprint('Number of labels: {}'.format(self.nLabel))
            mpi.rootprint('Number of codes: {}'.format(self.nCodes))
            mpi.rootprint('Bins: {0}x{0}'.format(self.nBinsPerEdge))
            mpi.rootprint('Total pooling areas: {}'.format(self.nMetabins))
            mpi.rootprint('Total features: {}'.format(self.nMetabins*self.nCodes))
            mpi.rootprint('Number of features to select: {}'.format(self.maxGraftDim))
        mpi.rootprint('Graft Settings:')
        mpi.rootprint('dump_every = {}\nnActiveSet={}\ntest_every={}\nsamplePerRun={}'.format(\
                            dump_every, nActiveSet, test_every, samplePerRun))
        self.comm.barrier()

        if tester is not None:
            # normalize the test data with the stats of the training data
            tester.normalize_data(self.mLocal, self.stdLocal)
        if fromDumpFile is not None:
            self.restore_from_dump_file(fromDumpFile, tester)

        old_loss = 1e10
        timer = Timer()
        itertimer = Timer()
        for T in range(self.nSelFeats, self.maxGraftDim):
            itertimer.reset()
            mpi.rootprint('*'*15+'Round {}'.format(T)+'*'*15)
            score, codeid, metabinid = self.select_new_feature_by_grad(samplePerRun)
            mpi.rootprint('Selected Feature [code: {}, metabin: {}], score {}'.format(codeid, metabinid, score))
            # add this feature to the selected features
            self.append_feature(codeid, metabinid)
            mpi.rootprint('Number of Features: {}'.format(self.nSelFeats))
            mpi.rootprint('Feature selection took {} secs'.format(itertimer.lap()))
            mpi.rootprint('Retraining the model...')
            loss = self.retrain_model(nActiveSet, samplePerRun)
            mpi.rootprint('Total loss reduction {}/{}={}'.format(loss, old_loss, loss/old_loss))
            mpi.rootprint('Current training accuracy: {}'.format(self.compute_current_accuracy()))
            mpi.rootprint('Model retraining took {} secs'.format(itertimer.lap()))
            old_loss = loss

            if tester is not None:
                tester.append_feature(codeid, metabinid)
                if (T+1) % test_every == 0:
                    # print test accuracy
                    test_accuracy = tester.compute_test_accuracy(self.weights, self.b)
                    mpi.rootprint('Current Testing accuracy: {}'.format(test_accuracy))

            self.safebarrier()
            mpi.rootprint('This round took {} secs, total {} secs'.format(timer.lap(), timer.total()))
            mpi.rootprint('ETA {} secs.'.format(timer.total() * (self.maxGraftDim-T)/(T+1.0e-5)))

            if dump_every > 0 and (T+1) % dump_every == 0 and dump_file is not None:
                mpi.rootprint('*'*15 + 'Dumping' + '*'*15)
                self.dump_current_state(dump_file + str(T)+'.mat')

        mpi.rootprint('*'*15+'Finalizing'.format(T)+'*'*15)
        if dump_file is not None:
            self.dump_current_state(dump_file + 'final.mat')
开发者ID:cc13ny,项目名称:galatea,代码行数:88,代码来源:grafting_mb.py


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