Progressbar for xgboost using tqdm library.

    Examples
    --------

    >>> model = xgb.train(params, X_train, 1000, callbacks=[xgb_progress(1000), ])
7551
def xgb_progressbar(rounds=1000):
    
    pbar = tqdm(total=rounds)

    def callback(_, ):
        pbar.update(1)

    return callback
277468
def get_xgb_params(self):
        """"""
        xgb_params = self.get_params()
        random_state = xgb_params.pop('random_state')
        if 'seed' in xgb_params and xgb_params['seed'] is not None:
            warnings.warn('The seed parameter is deprecated as of version .6.'
                          'Please use random_state instead.'
                          'seed is deprecated.', DeprecationWarning)
        else:
            xgb_params['seed'] = random_state
        n_jobs = xgb_params.pop('n_jobs')
        if 'nthread' in xgb_params and xgb_params['nthread'] is not None:
            warnings.warn('The nthread parameter is deprecated as of version .6.'
                          'Please use n_jobs instead.'
                          'nthread is deprecated.', DeprecationWarning)
        else:
            xgb_params['nthread'] = n_jobs

        if 'silent' in xgb_params and xgb_params['silent'] is not None:
            warnings.warn('The silent parameter is deprecated.'
                          'Please use verbosity instead.'
                          'silent is depreated', DeprecationWarning)
            # TODO(canonizer): set verbosity explicitly if silent is removed from xgboost,
            # but remains in this API
        else:
            # silent=None shouldn't be passed to xgboost
            xgb_params.pop('silent', None)

        if xgb_params['nthread'] <= 0:
            xgb_params.pop('nthread', None)
        return xgb_params
1046630
def create_examples(candidate_dialog_paths, examples_num, creator_function):
    
    i = 0
    examples = []
    unique_dialogs_num = len(candidate_dialog_paths)

    while i < examples_num:
        context_dialog = candidate_dialog_paths[i % unique_dialogs_num]
        # counter for tracking progress
        if i % 1000 == 0:
            print str(i)
        i += 1

        examples.append(creator_function(context_dialog, candidate_dialog_paths))

    return examples
450985
def print_warning(cls):
        
        if not cls.warning:
            cls.warning = True
            print('Can\'t create progress bar:', str(TQDM_IMPORT_ERROR),
                  file=sys.stderr)
567515
def progress(self, *msg):
        
        label = colors.purple("Progress")
        self._msg(label, *msg)
674846
def train_model(model, train_data_loader, val_data_loader, embedding, ctx, args):
    
    logger.info(vars(args))

    # Initialization
    model.hybridize()
    model.collect_params().initialize(mx.init.Normal(0.01), ctx=ctx)
    model.word_emb.weight.set_data(embedding.idx_to_vec)
    # Fix word embedding
    model.word_emb.weight.grad_req = 'null'

    loss_func = gluon.loss.SoftmaxCrossEntropyLoss()
    trainer = gluon.Trainer(model.collect_params(), 'adagrad',
                            {'learning_rate': args.lr,
                             'wd': args.weight_decay,
                             'clip_gradient': 5})

    checkpoints_dir = os.path.join(args.output_dir, 'checkpoints')
    if not os.path.exists(checkpoints_dir):
        os.makedirs(checkpoints_dir)

    best_val_acc = 0.
    for epoch_id in range(args.epochs):
        avg_loss = 0.
        avg_acc = 0.
        for batch_id, example in enumerate(train_data_loader):
            s1, s2, label = example
            s1 = s1.as_in_context(ctx)
            s2 = s2.as_in_context(ctx)
            label = label.as_in_context(ctx)

            with autograd.record():
                output = model(s1, s2)
                loss = loss_func(output, label).mean()
            loss.backward()
            trainer.step(1)
            avg_loss += loss.sum().asscalar()

            pred = output.argmax(axis=1)
            acc = (pred == label.astype(np.float32)).mean()
            avg_acc += acc.asscalar()

            if (batch_id + 1) % args.print_interval == 0:
                avg_loss /= args.print_interval
                avg_acc /= args.print_interval
                logger.info('[Epoch {} Batch {}/{}] loss={:.4f}, acc={:.4f}'
                            .format(epoch_id, batch_id + 1, len(train_data_loader),
                                    avg_loss, avg_acc))
                avg_loss = 0.
                avg_acc = 0.

        # Validation
        val_loss, val_acc = test_model(model, val_data_loader, loss_func, ctx)
        if val_acc > best_val_acc:
            best_val_acc = val_acc
            checkpoint_path = os.path.join(args.output_dir, 'checkpoints', 'valid_best.params')
            model.save_parameters(checkpoint_path)
        logger.info('[Epoch {}] valid loss={:.4f}, valid acc={:.4f}, best valid acc={:.4f}'
                    .format(epoch_id, val_loss, val_acc, best_val_acc))

        # Save checkpoint of last epoch
        checkpoint_path = os.path.join(args.output_dir, 'checkpoints', 'last.params')
        model.save_parameters(checkpoint_path)
922423
def iterprogress( sized_iterable ):
    
    pb = ProgressBar( 0, len( sized_iterable ) )
    for i, value in enumerate( sized_iterable ):
        yield value
        pb.update_and_print( i, sys.stderr )
957401
def tqdm(self):
    """"""
    async_tqdm = utils.async_tqdm
    with async_tqdm(total=0, desc='Dl Completed...', unit=' url') as pbar_url:
      with async_tqdm(total=0, desc='Dl Size...', unit=' MiB') as pbar_dl_size:
        self._pbar_url = pbar_url
        self._pbar_dl_size = pbar_dl_size
        yield
1337256
def progress_all(self):
        
        return self.progress_idxs(range(np.shape(self.get_data_x())[0] - self.progress_win_size, 
                                        np.shape(self.get_data_x())[0]))
604694
private void defineProgressBars(UIDefaults d) {
        // Copied from nimbus

      //Initialize ProgressBar
        d.put("ProgressBar.contentMargins", new InsetsUIResource(0, 0, 0, 0));
        d.put("ProgressBar.States", "Enabled,Disabled,Indeterminate,Finished");
        d.put("ProgressBar.tileWhenIndeterminate", Boolean.TRUE);
        d.put("ProgressBar.paintOutsideClip", Boolean.TRUE);
        d.put("ProgressBar.rotateText", Boolean.TRUE);
        d.put("ProgressBar.vertictalSize", new DimensionUIResource(19, 150));
        d.put("ProgressBar.horizontalSize", new DimensionUIResource(150, 19));
        addColor(d, "ProgressBar[Disabled].textForeground", "seaGlassDisabledText", 0.0f, 0.0f, 0.0f, 0);
        d.put("ProgressBar[Disabled+Indeterminate].progressPadding", new Integer(3));
        
        // Seaglass starts below.
        
        d.put("progressBarTrackInterior", Color.WHITE);
        d.put("progressBarTrackBase", new Color(0x4076bf));

        d.put("ProgressBar.Indeterminate", new ProgressBarIndeterminateState());
        d.put("ProgressBar.Finished", new ProgressBarFinishedState());

        String p = "ProgressBar";
        String c = PAINTER_PREFIX + "ProgressBarPainter";

        d.put(p + ".cycleTime", 500);
        d.put(p + ".progressPadding", new Integer(3));
        d.put(p + ".trackThickness", new Integer(19));
        d.put(p + ".tileWidth", new Integer(24));
        d.put(p + ".backgroundFillColor", Color.WHITE);
        d.put(p + ".font", new DerivedFont("defaultFont", 0.769f, null, null));
        d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, ProgressBarPainter.Which.BACKGROUND_ENABLED));
        d.put(p + "[Disabled].backgroundPainter", new LazyPainter(c, ProgressBarPainter.Which.BACKGROUND_DISABLED));
        d.put(p + "[Enabled].foregroundPainter", new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_ENABLED));
        d.put(p + "[Enabled+Finished].foregroundPainter",
              new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_ENABLED_FINISHED));
        d.put(p + "[Enabled+Indeterminate].foregroundPainter",
              new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_ENABLED_INDETERMINATE));
        d.put(p + "[Disabled].foregroundPainter", new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_DISABLED));
        d.put(p + "[Disabled+Finished].foregroundPainter",
              new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_DISABLED_FINISHED));
        d.put(p + "[Disabled+Indeterminate].foregroundPainter",
              new LazyPainter(c, ProgressBarPainter.Which.FOREGROUND_DISABLED_INDETERMINATE));
    }
804200
def bar(self, progress):
        """"""
        if not hasattr(self, "_limit") or not self._limit:
            self._limit = self.terminal_size()
        graph_progress = int(progress * self._limit)
        self.stdout.write('\r', ending='')
        progress_format = "[%-{}s] %d%%".format(self._limit)
        self.stdout.write(
            self.style.SUCCESS(progress_format % (self.progress_symbol * graph_progress, int(progress * 100))),
            ending=''
        )
        self.stdout.flush()
642182
def train(self, input, label):
        

        assert self._mode == MpsGraphMode.Train
        assert input.shape == self._ishape
        assert label.shape == self._oshape

        input_array = MpsFloatArray(input)
        label_array = MpsFloatArray(label)
        result_handle = _ctypes.c_void_p()
        status_code = self._LIB.TCMPSTrainGraph(
            self.handle, input_array.handle, label_array.handle,
            _ctypes.byref(result_handle))

        assert status_code == 0, "Error calling TCMPSTrainGraph"
        assert result_handle, "TCMPSTrainGraph unexpectedly returned NULL pointer"

        result = MpsFloatArray(result_handle)

        # Output from training should be a one-dimensional array of loss values,
        # one per example in the batch.
        assert result.shape() == (self._oshape[0],)

        return result
91953
def progressbar(length, label):
    
    return click.progressbar(length=length, label=label, show_pos=True)
1191041
def progress(iterator, enum=False, length=None):
    
    progress = ProgressBar()
    length = len(iterator) if length is None else length
    gen = enumerate(iterator)
    while True:
        i, val = next(gen)
        progress((i+1.0)/length * 100)
        if enum:
            yield i, val
        else:
            yield val
271837
def updateProgressBar(self, *args, **kwargs):
        '''
         
        '''
        value = kwargs.get('progress')
        pb = self.progress_bar
        if value is None:
            return
        if value < 0:
            pb.Pulse()
        else:
            value = min(int(value), pb.GetRange())
            if pb.GetValue() != value:
                # Windows 7 progress bar animation hack
                # http://stackoverflow.com/questions/5332616/disabling-net-progressbar-animation-when-changing-value
                if self.buildSpec['disable_progress_bar_animation'] \
                        and sys.platform.startswith("win"):
                    if pb.GetRange() == value:
                        pb.SetValue(value)
                        pb.SetValue(value - 1)
                    else:
                        pb.SetValue(value + 1)
                pb.SetValue(value)
1360745
def _ProgressMeterUpdate(bar, value, text_elem, *args):
    '''
    
    '''
    global _my_windows
    if bar == None: return False
    if bar.BarExpired: return False
    message, w, h = ConvertArgsToSingleString(*args)
    text_elem.Update(message)
    # bar.TextToDisplay = message
    bar.CurrentValue = value
    rc = bar.UpdateBar(value)
    if value >= bar.MaxValue or not rc:
        bar.BarExpired = True
        bar.ParentForm._Close()
        if rc:  # if update was OK but bar expired, decrement num windows
            _my_windows.Decrement()
    if bar.ParentForm.RootNeedsDestroying:
        try:
            bar.ParentForm.TKroot.destroy()
            # there is a bug with progress meters not decrementing the number of windows
            # correctly when the X is used to close the window
            # uncommenting this line fixes that problem, but causes a double-decrement when
            # the cancel button is used... damned if you do, damned if you don't, so I'm choosing
            # don't, as in don't decrement too many times. It's OK now to have a mismatch in
            # number of windows because of the "hidden" master window. This ensures all windows
            # will be toplevel.  Sorry about the bug, but the user never sees any problems as a result
            # _my_windows.Decrement()
        except:
            pass
        bar.ParentForm.RootNeedsDestroying = False
        bar.ParentForm.__del__()
        return False

    return rc
300229
def log_progress(sequence, every=None, size=None, name='Items'):
    """"""
    from ipywidgets import IntProgress, HTML, VBox
    from IPython.display import display

    is_iterator = False
    if size is None:
        try:
            size = len(sequence)
        except TypeError:
            is_iterator = True
    if size is not None:
        if every is None:
            if size <= 200:
                every = 1
            else:
                every = int(size / 200)     # every 0.5%
    else:
        assert every is not None, 'sequence is iterator, set every'

    if is_iterator:
        progress = IntProgress(min=0, max=1, value=1)
        progress.bar_style = 'info'
    else:
        progress = IntProgress(min=0, max=size, value=0)
    label = HTML()
    box = VBox(children=[label, progress])
    display(box)

    index = 0
    try:
        for index, record in enumerate(sequence, 1):
            if index == 1 or index % every == 0:
                if is_iterator:
                    label.value = '{name}: {index} / ?'.format(
                        name=name,
                        index=index
                    )
                else:
                    progress.value = index
                    label.value = u'{name}: {index} / {size}'.format(
                        name=name,
                        index=index,
                        size=size
                    )
            yield record
    except Exception as e:
        progress.bar_style = 'danger'
        raise
    else:
        progress.bar_style = 'success'
        progress.value = index
        label.value = "{name}: {index}".format(
            name=name,
            index=str(index or '?')
        )