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


Python Timer.start方法代码示例

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


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

示例1: __init__

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import start [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: __init__

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import start [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

示例3: Timer

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import start [as 别名]
from parser import Parser
from session import Session
from sessionRepository import SessionRepository
from utils import Timer
from sklearn.neighbors import KNeighborsClassifier
from itemRepository import ItemRepository

timer = Timer()

###############################################################
# Loading files
###############################################################
timer.start()


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())
开发者ID:alexlanz,项目名称:information-retrieval,代码行数:32,代码来源:main.py

示例4: World

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import start [as 别名]
class World(object):
    worlds = []

    @staticmethod
    def clear_all():
        for world in World.worlds:
            world.stop()
        World.worlds = []

    def __init__(self, cols, rows):
        self.cols = cols
        self.rows = rows
        self._objects = []
        self._field = []
        self._timer = None
        self.queue = []
        self.reproductions = 0
        self.plants = 0
        self.herbivores = 0
        self.predators = 0
        self.turns = 0
        self.deaths = 0
        for x in xrange(cols):
            self._field.append([ None for y in xrange(rows)])

        World.worlds.append(self)

    def check_queue(self):
        newqueue = []
        for turns, obj in self.queue:
            if turns == 0:
                self.add_creature(obj)
            else:
                newqueue.append((turns - 1, obj))
        return newqueue

    def loop(self):
        try:
            self.queue = self.check_queue()

            for obj in self._objects:
                obj.turn(self)
            deleted = filter(lambda obj: obj.is_nothing, self._objects)
            #todo: need lock
            for obj in deleted:
                logging.debug("Dead: %r, turns: %s, history: %s" % (obj, obj.turns, repr(obj.history.read())))
                self._field[obj.x][obj.y] = None
                self._objects.remove(obj)
                self.info_update_del(obj)
                self.deaths += 1
            self.stabilize()

            self.turns += 1
        except:
            import traceback
            logging.debug(traceback.format_exc())
            self._timer.cancel()

    def start(self, speed):
        if self._timer:
            raise Exception()
        self.init_count_objects = len(self._objects) + len(self.queue)
        self._timer = Timer(speed, self.loop)
        self._timer.start()

    def stop(self):
        self._timer.cancel()

    def begin_force(self):
        self._timer.is_force = True

    def end_force(self):
        self._timer.is_force = False

    def check_position(self, x, y):
        return 0 <= x < self.cols and 0 <= y < self.rows

    def add_creature(self, creature):
        if not self.check_position(creature.x, creature.y):
            return False
        if self._field[creature.x][creature.y] is not None:
            return False
        self._objects.append(creature)
        self._field[creature.x][creature.y] = creature
        self.info_update_add(creature)
        return True

    def info_update_add(self, creature):
        name = creature.__class__.__name__
        if name == 'Predator':
            self.predators += 1
        elif name == 'Herbivore':
            self.herbivores += 1
        elif name == 'Plant':
            self.plants += 1

    def info_update_del(self, creature):
        name = creature.__class__.__name__
        if name == 'Predator':
            self.predators -= 1
#.........这里部分代码省略.........
开发者ID:NElias,项目名称:swottc,代码行数:103,代码来源:world.py

示例5: train

# 需要导入模块: from utils import Timer [as 别名]
# 或者: from utils.Timer import start [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.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。