Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def format_meter(self, n, total, elapsed, ncols=None, prefix='',
ascii=False, unit='it', unit_scale=False, rate=None,
bar_format=None):
# Add new point and fit
# But only if new iteration (else can be called by __repr__() and refresh())
if n > self.model.last_it:
# Add point (n, elapsed)
self.model.add_sample([n], elapsed, n)
# Fit (learn/train)
# We do in a loop because to avoid the need to manually adjust learning rate
for _ in _range(self.repeat):
self.model.fit(**self.fit_params)
# Plot if required
if self.plot:
self.model.plot(n)
# Compute rate and ending time
if n > 0 and total:
# Predict ending time
predicted_endtime = float(self.model.predict([total]))
# Predicted endtime must be greater than current time else fitting failed!
if predicted_endtime > 0 and predicted_endtime >= elapsed:
# Pessimistic: predict rate against remaining time, not total time
rate = (total - n) / (predicted_endtime - elapsed)
# Do the rest as usual, with the provided rate computed by polynomial regression
return super(tqdm_regress, self).format_meter(n, total, elapsed, ncols, prefix,
def trange(*args, **kwargs):
"""
A shortcut for tqdm(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm(_range(*args), **kwargs)
def tcrange(*args, **kwargs):
"""
A shortcut for tqdm_custom(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm_custom(_range(*args), **kwargs)
"""Compute polynomials from a single value
If order = z.5 (z + 1/2) then sqrt, log and exp will be added.
Note: should polynomize always before feature scaling."""
if not isinstance(x, list):
x = [x]
x_poly = deepcopy(x) # copy the list
if order > 1.0:
# special funcs: sqrt, log and exp
if order - int(order) > 0.0:
for xi in x:
try:
x_poly.extend([xi**0.5, log(xi), exp(xi)])
except ValueError: # log(0.0) is undefined
x_poly.extend([0.0, 0.0, 0.0])
# Higher order polynomials (starting from x^2)
for o in _range(2, int(order)+1): # start from x^2
x_poly.extend([xi**o for xi in x])
return x_poly
filler_lines = c_symb[-1][0].splitlines() if isinstance(c_symb[-1], list) else c_symb[-1].splitlines()
filler_width = len(filler_lines[0])
bar_length, frac_bar_length = divmod(
int(frac * int(N_BARS/filler_width) * nb_symb), nb_symb)
# If animated, get what animation we will show
if isinstance(c_symb[-1], list):
# If random, pick frame randomly
if bar_format['symbols'].get('random', False):
# Need filler symbol
if bar_length:
# Randomly select the frame for each filler
filler_rand = [random.choice(c_symb[-1]).splitlines() for _ in _range(bar_length)]
# Generate filler (stack lines horizontally)
filler_lines = []
for i in _range(len(filler_rand[0])):
filler_lines.append(''.join(frame[i] for frame in filler_rand))
# Just started, no filler, only frac,
# generate empty lines
else:
filler_lines = ['' for line in filler_lines]
# Generate frac randomly
frac_lines = random.choice(c_symb[frac_bar_length]).splitlines()
# Else advance one frame per display
else:
# Get current bar animation frame
filler_symb = c_symb[-1][divmod(self.n_anim, len(c_symb[-1]))[1]]
frac_symb = c_symb[frac_bar_length][divmod(self.n_anim, len(c_symb[frac_bar_length]))[1]]
# Repeat as required
filler_lines = [line * bar_length for line in filler_symb.splitlines()]
frac_lines = frac_symb.splitlines()
# Not animated, don't need to select a frame
def tcmrange(*args, **kwargs):
"""
A shortcut for tqdm_custommulti(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm_custommulti(_range(*args), **kwargs)
# Calculate bar length given progress
# last symbol is always the filler
nb_symb = len(c_symb)
filler_lines = c_symb[-1][0].splitlines() if isinstance(c_symb[-1], list) else c_symb[-1].splitlines()
filler_width = len(filler_lines[0])
bar_length, frac_bar_length = divmod(
int(frac * int(N_BARS/filler_width) * nb_symb), nb_symb)
# If animated, get what animation we will show
if isinstance(c_symb[-1], list):
# If random, pick frame randomly
if bar_format['symbols'].get('random', False):
# Need filler symbol
if bar_length:
# Randomly select the frame for each filler
filler_rand = [random.choice(c_symb[-1]).splitlines() for _ in _range(bar_length)]
# Generate filler (stack lines horizontally)
filler_lines = []
for i in _range(len(filler_rand[0])):
filler_lines.append(''.join(frame[i] for frame in filler_rand))
# Just started, no filler, only frac,
# generate empty lines
else:
filler_lines = ['' for line in filler_lines]
# Generate frac randomly
frac_lines = random.choice(c_symb[frac_bar_length]).splitlines()
# Else advance one frame per display
else:
# Get current bar animation frame
filler_symb = c_symb[-1][divmod(self.n_anim, len(c_symb[-1]))[1]]
frac_symb = c_symb[frac_bar_length][divmod(self.n_anim, len(c_symb[frac_bar_length]))[1]]
# Repeat as required
def tsrange(*args, **kwargs):
"""
A shortcut for tqdm_regress(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm_regress(_range(*args), **kwargs)