def get_flip_error(val): while True: pos = random.randint(0, 19) error = bit_flip(val, pos) if not math.isnan(error) and not math.isinf(error): break return error
def preprocess_for_classifier(dataset, N=10): dataset = np.vstack([dataset] * N) # copy the dataset N times has_error = np.zeros(len(dataset)) sign = 1 THREASHOLD = 0.5 for i in range(len(dataset)): if random.randint(0, 1): x = random.randint(0, dataset[i].shape[0] - 1) y = random.randint(0, dataset[i].shape[1] - 1) has_error[i] = 1 ''' d = dataset[i][x,y] error = random.uniform(0.01*d, 0.9*d) sign = 1 if random.randint(0,1) == 1 else -1 dataset[i][x,y] = error ''' bit_pos = random.randint(1, 10) #bit_pos = 8 error = bit_flip(dataset[i][x, y], bit_pos) if math.isnan(error) or math.isinf(error): has_error[i] = 0 continue #if error < 0.0001: # error = 0.0001 #if error > 5*d: # error = 5*d #print 'old:', dataset[i][x,y], ', pos:', bit_pos, ', new:', error dataset[i][x, y] = error return dataset, has_error
def get_flip_error(val): while True: pos = random.randint(0, 20) error = bit_flip(val, pos) if not math.isnan(error) and not math.isinf(error): break error = min(10e+5, error) error = max(-10e+5, error) return error
def get_flip_error(val): tmp = val # flip bits 30 times for i in range(30): while True: pos = random.randint(0, 63) tmp = bit_flip(tmp, pos) if not math.isnan(tmp) and not math.isinf(tmp): break error = tmp return error