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


Python Timer.stop方法代码示例

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


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

示例1: __init__

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import stop [as 别名]
class QueryExecutor:

    index = None
    timer = None

    def __init__(self, index):
        self.index = index


    def executeQueries(self, queryList):
        self.timer = Timer()
        self.timer.start()

        queryMatchingList = []
        executedTokens = 0

        for query in queryList:
            searchTokens = query.getSearchTokens()
            excludedTokens = query.getExcludedTokens()

            searchResult = QueryResult()
            for token in searchTokens:
                executedTokens += 1
                tmpPostingsList = self.index.getDictionary().getPostingsList(token)
                searchResult.addPostingList(token, tmpPostingsList)

            excludedResult = QueryResult()
            for token in excludedTokens:
                tmpPostingsList = self.index.getDictionary().getPostingsList(token)
                excludedResult.addPostingList(token, tmpPostingsList)

            if(len(excludedResult.getItems()) > 0):
                queryMatching = QueryResult.mergeWithExclusions(searchResult, excludedResult)
            else:
                queryMatching = searchResult

            queryMatchingList.append(queryMatching)

        queryMatching = QueryResult.mergeWithIntersection(queryMatchingList)

        rankedResult = RankedResult()
        for doc, queryResultItem in queryMatching.getItems().items():
            rank = RankProvider.provideRank(queryResultItem, executedTokens)
            rankedResultItem = RankedResultItem(doc, rank, queryResultItem)
            rankedResult.addRankedResultItem(rankedResultItem)

        self.timer.stop()

        return rankedResult.getSortedResult()


    def getTimer(self):
        return self.timer
开发者ID:mmalfertheiner,项目名称:inverted-index,代码行数:55,代码来源:queryexecutor.py

示例2: worker

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import stop [as 别名]
def worker(args):
    label, method = args

    # call the requested method
    try:
        logger.info('%s: call to DataBuilder.%s' % (label, method))
        t = Timer()
        data = getattr(databuilder, method)()
        t.stop()
        logger.info('%s: done [%.1fs]' % (label, t.elapsed))
        return label, data, None

    except:
        import StringIO
        import traceback
        buffer = StringIO.StringIO()
        traceback.print_exc(file = buffer)
        return label, None, buffer.getvalue()
开发者ID:cms-sw,项目名称:web-confdb,代码行数:20,代码来源:task.py

示例3: __init__

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import stop [as 别名]
class Index:

    source = None
    timer = None
    dictionary = None
    parserType = None

    def __init__(self, source, parserType):
        self.source = source
        self.parserType = parserType
        self.dictionary = Dictionary()

        self.timer = Timer()
        self.timer.start()

        self.setup()

        self.timer.stop()


    def setup(self):
        if self.source == IndexSource.new:
            self.createNewIndex()
        elif self.source == IndexSource.stored:
            self.loadStoredIndex()
        else:
            raise ValueError("Invalid index source")


    def createNewIndex(self):
        docCoordinator = DocumentCoordinator("books")
        documents = docCoordinator.loadDocuments()

        parser = Parser(self.parserType)

        for document in documents:
            text = docCoordinator.getDocumentText(document)
            tokens = parser.parseTokensFromText(text)

            for position, token in enumerate(tokens):
                postingList = self.dictionary.getPostingsList(token)
                postingList.addPosting(document, position)



    def loadStoredIndex(self):
        storage = Storage()
        self.dictionary = storage.loadIndex()


    def storeIndex(self):
        self.timer = Timer()
        self.timer.start()

        storage = Storage()
        storage.saveIndex(self.dictionary)

        self.timer.stop()


    def getDictionary(self):
        return self.dictionary


    def getTimer(self):
        return self.timer


    def getParserType(self):
        return self.parserType
开发者ID:mmalfertheiner,项目名称:inverted-index,代码行数:72,代码来源:index.py

示例4: Parser

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import stop [as 别名]

parser = Parser('data')
parser.readSessionFile('yoochoose-clicks-aa.dat')
#parser.readSessionFile('yoochoose-clicks-ab.dat')
#parser.readSessionFile('yoochoose-clicks-ac.dat')
#parser.readSessionFile('yoochoose-clicks-ad.dat')
#parser.readSessionFile('yoochoose-clicks-ae.dat')
#parser.readSessionFile('yoochoose-clicks-af.dat')

sessionRepository = parser.readBuyFile('yoochoose-buys.dat')

sessionRepository = parser.getSessionRepository()
itemRepository = parser.getItemRepository()

timer.stop()
print("Time for loading files: " + timer.getElapsedSecondsString())

#sessions = sessionRepository.getAllSessions()
#session = sessionRepository.getById(327676)
#print(session.getVector(items))

#for session in sessions:
#    print(str(session.id) + ', ' + str(session.duration) + " sec, " + str(session.numberOfClicks) + " clicks, BUY: " + str(session.buy))


###############################################################
# Training
###############################################################
timer.start()
开发者ID:alexlanz,项目名称:information-retrieval,代码行数:31,代码来源:main.py

示例5: train

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import stop [as 别名]
def train(network, num_epochs, train_fn, train_batches, test_fn=None,
          validation_batches=None, threads=None, early_stop=np.inf,
          early_stop_acc=False, save_epoch_params=False, callbacks=None,
          acc_func=onehot_acc, train_acc=False):
    """
    Train a neural network by updating its parameters.

    Parameters
    ----------
    network : lasagne neural network handle
        Network to be trained.
    num_epochs: int
        Maximum number of epochs to train
    train_fn : theano function
        Function that computes the loss and updates the network parameters.
        Takes parameters from the batch iterators
    train_batches : batch iterator
        Iterator that yields mini batches from the training set. Must be able
        to re-iterate multiple times.
    test_fn : theano function
        Function that computes loss and predictions of the network.
        Takes parameters from the batch iterators.
    validation_batches : batch iterator
        Iterator that yields mini batches from the validation set. Must be able
        to re-iterate multiple times.
    threads : int
        Number of threads to use to prepare mini batches. If None, use
        a single thread.
    early_stop : int
        Number of iterations without loss improvement on validation set that
        stops training.
    early_stop_acc : boolean
        Use validation accuracy instead of loss for early stopping.
    save_epoch_params : str or False
        Save neural network parameters after each epoch. If False, do not save.
        If you want to save the parameters, provide a filename with an
        int formatter so the epoch number can be inserted.
    callbacks : list of callables
        List of callables to call after each training epoch. Can be used to k
        update learn rates or plot data. Functions have to accept the
        following parameters: current epoch number, lists of per-epoch train
        losses, train accuracies, validation losses, validation accuracies.
        The last three lists may be empty, depending on other parameters.
    acc_func : callable
        Function to use to compute accuracies.
    train_acc : boolean
        Also compute accuracy for training set. In this case, the training
        loss will be also re-computed after an epoch, which leads to lower
        train losses than when not using this parameter.

    Returns
    -------
    tuple of four lists
        Train losses, trian accuracies, validation losses,
        validation accuracies for each epoch
    """

    if (test_fn is not None) != (validation_batches is not None):
        raise ValueError('If test function is given, validation set is '
                         'necessary (and vice-versa)!')

    best_val = np.inf if not early_stop_acc else 0.0
    epochs_since_best_val_loss = 0

    if callbacks is None:
        callbacks = []

    if callbacks is None:
        callbacks = []

    best_params = get_params(network)
    train_losses = []
    val_losses = []
    val_accs = []
    train_accs = []

    if threads is not None:
        def threaded(it):
            return dmgr.iterators.threaded(it, threads)
    else:
        def threaded(it):
            return it

    for epoch in range(num_epochs):
        timer = Timer()
        timer.start('epoch')
        timer.start('train')

        try:
            train_losses.append(
                avg_batch_loss(threaded(train_batches), train_fn, timer))
        except RuntimeError as e:
            print(Colors.red('Error during training:'), file=sys.stderr)
            print(Colors.red(str(e)), file=sys.stderr)
            return best_params

        timer.stop('train')

        if save_epoch_params:
            save_params(network, save_epoch_params.format(epoch))
#.........这里部分代码省略.........
开发者ID:fdlm,项目名称:nn,代码行数:103,代码来源:nn.py


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