def test_generate(): FIVE_MB = 5 * 1024 * 1024 eq(len(''.join(utils.generate_random(0))), 0) eq(len(''.join(utils.generate_random(1))), 1) eq(len(''.join(utils.generate_random(FIVE_MB - 1))), FIVE_MB - 1) eq(len(''.join(utils.generate_random(FIVE_MB))), FIVE_MB) eq(len(''.join(utils.generate_random(FIVE_MB + 1))), FIVE_MB + 1)
def setup(self, input_n, output, hidden_size): self.input_n = input_n self.input_cells = [1.0] * input_n self.output_m = output self.output_cells = [0.0] * output self.hidden_set = hidden_size self.hidden_result = [0.0] * hidden_size self.input_w = utils.generate_random(input_n, hidden_size) self.output_w = utils.generate_random(hidden_size, output) self.input_b = numpy.random.random(hidden_size) self.output_b = numpy.random.random(output) self.input_delta = [0.0] * self.input_n self.output_delta = [0.0] * self.hidden_set
def panel_vouchers(): form = get_voucher_form(request.form, ShopData.query.all()) if request.method == 'POST' and form.validate(): for_id = form.data['id'] try: uses = int(form.data['uses']) amount = int(form.data['amount']) except Exception as e: flash('Invalid input (did you provide text instead of numbers?)', 'danger') return redirect(url_for('panel_vouchers')) vouchers = [] for i in range(amount): random = generate_random(8) vouchers.append(random) voucher = Voucher() voucher.key = random voucher.offer = for_id voucher.uses = uses database.session.add(voucher) database.session.commit() return render_template('views/panel.html', tab='vouchers', admins=admins, form=form, vouchers=vouchers) return render_template('views/panel.html', tab='vouchers', admins=admins, form=form)
def __init__(self, name, email): self.name = name self.email = email self.exp_time = get_epoch_time() + (30 * 60 * 1000) # 30 minutes self.secret_key = str(hashlib.sha256(bytes(generate_random(32), 'utf-8')).hexdigest())
def main(_): tf.logging.set_verbosity(_verbosity_levels[tf.flags.FLAGS.verbosity]) params = { 'criterion': tf.flags.FLAGS.criterion, 'max_iter': tf.flags.FLAGS.maxiter, 'kernel': tf.flags.FLAGS.kernel, 'bandwidth': tf.flags.FLAGS.bandwidth, 'n_clusters': tf.flags.FLAGS.nclusters, 'batch_size': tf.flags.FLAGS.batchsize } data = generate_random(100, 500) # assert os.path.exists(tf.flags.FLAGS.data) if tf.flags.FLAGS.method in methods: cl = methods[tf.flags.FLAGS.method](**remove_empty(params)) labels = cl.fit(data) centroids = cl.centroids history = cl.history else: history = load(os.path.join(tf.flags.FLAGS.save, 'history.npy')) centroids = load(os.path.join(tf.flags.FLAGS.save, 'centroids.npy')) labels = load(os.path.join(tf.flags.FLAGS.save, 'labels.npy')) if tf.flags.FLAGS.method == 'visualize': assert len(history) > 1 \ and history[0].shape[0] == labels.shape[0], 'Invalid ' \ 'history' plot(history, data, labels, centroids, draw_lines=False) elif tf.flags.FLAGS.method == 'visualize_animated': assert len(history) > 1 \ and history[0].shape[0] == labels.shape[0], 'Invalid ' \ 'history' animated_plot(history, labels) else: raise ValueError('--mode parameter must either ' 'be < means_shift >' '< mini_batch_mean_shift >,' '< kmeans > or < mini_batch_kmeans >.') return if history is None: tf.logging.warn('Data is too large to visualize.') elif data.shape[1] != 2: tf.logging.warn('Data must be 2 dimensional to visualize.') else: tf.logging.info('Creating plot for history visualization.') plot(history, data, labels, centroids, draw_lines=False) save(os.path.join(tf.flags.FLAGS.save, 'history.npy'), history) save(os.path.join(tf.flags.FLAGS.save, 'centroids.npy'), centroids) save(os.path.join(tf.flags.FLAGS.save, 'labels.npy'), labels)
def get_neighbor(result,start,end,step,typ,p,conf): xi = utils.generate_random(result,start,end,step,typ,p,conf) while not in_neighborhood(result, xi, end, start, r, len(conf), step, typ, conf): xi = utils.generate_random(result,start,end,step,typ,p,conf) return xi
# funcs = (bubble_sort, selection_sort, insertion_sort, quick_sort, # quick_sort_3partition, heap_sort, merge_sort, merge_sort_fastest, # counting_sort, bucket_sort, bucket_sort_array, radix_sort) times = [] # for f in funcs: # n, t = utils.print_func_run_time(length, f, utils.generate_random(int(n))[0]) # # times.append((n, t)) # # times.sort(key = lambda x: x[1]) # # for n, t in times: # # print(n, t) times.append( utils.print_func_run_time(length, bubble_sort, utils.generate_random(n)[0])) times.append( utils.print_func_run_time(length, selection_sort, utils.generate_random(n)[0])) times.append( utils.print_func_run_time(length, insertion_sort, utils.generate_random(n)[0])) times.append( utils.print_func_run_time(length, quick_sort, utils.generate_random(n)[0])) times.append( utils.print_func_run_time(length, quick_sort_3partition, utils.generate_random(n)[0])) times.append( utils.print_func_run_time(length, heap_sort, utils.generate_random(n)[0]))