def draw_line(self, pos): if self.viewer._ocr and self.x_clicked or self.y_clicked: img_line = cv.line(self.image.copy(), (self.x_clicked, self.y_clicked), (pos.x(), pos.y()), (0, 0, 0), 2) image_height, image_width, image_depth = img_line.shape QIm = cv.cvtColor(img_line, cv.COLOR_BGR2RGB) QIm = QImage(QIm.data, image_width, image_height, image_width * image_depth, QImage.Format_RGB888) self.viewer.setPhoto(QPixmap.fromImage(QIm)) # 终止画线 if self.x_released or self.y_released: self.choosePoints = [] # 初始化存储点组 inf = float("inf") if self.x_released or self.y_released: if (self.x_released - self.x_clicked) == 0: slope = inf else: slope = (self.y_released - self.y_clicked) / ( self.x_released - self.x_clicked) siteLenth = 0.5 * math.sqrt( square(self.y_released - self.y_clicked) + square(self.x_released - self.x_clicked)) mySiteLenth = 2 * siteLenth self.siteLenth = ("%.2f" % mySiteLenth) self.editSiteLenth.setText(self.siteLenth) radian = math.atan(slope) self.siteSlope = ("%.2f" % radian) self.editSiteSlope.setText(self.siteSlope) x_bas = math.ceil(math.fabs(0.5 * siteLenth * math.sin(radian))) y_bas = math.ceil(math.fabs(0.5 * siteLenth * math.cos(radian))) if slope <= 0: self.choosePoints.append([(self.x_clicked - x_bas), (self.y_clicked - y_bas)]) self.choosePoints.append([(self.x_clicked + x_bas), (self.y_clicked + y_bas)]) self.choosePoints.append([(self.x_released + x_bas), (self.y_released + y_bas)]) self.choosePoints.append([(self.x_released - x_bas), (self.y_released - y_bas)]) elif slope > 0: self.choosePoints.append([(self.x_clicked + x_bas), (self.y_clicked - y_bas)]) self.choosePoints.append([(self.x_clicked - x_bas), (self.y_clicked + y_bas)]) self.choosePoints.append([(self.x_released - x_bas), (self.y_released + y_bas)]) self.choosePoints.append([(self.x_released + x_bas), (self.y_released - y_bas)]) self.viewer._ocr = False
def _function(self, individual, function): functions = [] set_ = {} self._InOrder(individual["key"], functions) '''para cada objeto, calcula a funcao correspondente a ele baseado no individuo que chegou''' if self._doing_train == True: set_ = self._train_set else: set_ = self._test_set for key, value in set_.iteritems(): function_ = 0 count = 0 operations = "" for node in functions: if node == "+" or node == "-" or node == "/" or node == "*": operations = node continue if type(node) is float: if count == 0: function_ = node count = 1 else: if operations == "+": function_ += node elif operations == "-": function_ -= node elif operations == "*": function_ *= node elif operations == "/": if math.fabs(node) <= 0.001: function_ = function else: function_ /= node else: if count == 0: function_ = float(value[int(float(node))]) count = 1 else: if operations == "+": function_ += float(value[int(node)]) elif operations == "-": function_ -= float(value[int(node)]) elif operations == "*": function_ *= float(value[int(node)]) elif operations == "/": if math.fabs(float(value[int(node)])) <= 0.001: function_ = function_ else: function_ /= float(value[int(node)]) function[key] = function_
def BL2XYZ(lat, lon): R = 6371000.0 #6371km eps = 1.0E-10 xyz = zeros(3) if math.fabs(lat - 90) < eps: xyz[0] = 0 xyz[1] = 0 xyz[2] = R elif math.fabs(lat + 90) < eps: xyz[0] = 0 xyz[1] = 0 xyz[2] = -R else: xyz[0] = math.cos(lat * math.pi / 180.0) * math.cos( lon * math.pi / 180.0) * R xyz[1] = math.cos(lat * math.pi / 180.0) * math.sin( lon * math.pi / 180.0) * R xyz[2] = math.sin(lat * math.pi / 180.0) * R return xyz
def update_metrics(self, value_label, model_value_prediction): self.mae.append(math.fabs(model_value_prediction - value_label)) class_label = get_class(value_label, self.mode) model_class_prediction = get_class(model_value_prediction, self.mode) if model_value_prediction < 0: return self.conf['num_rel'] += 1 self.update_confusion(actual_class=class_label, prediction_class=model_class_prediction) self.update_prediction_err(actual_val=value_label, prediction_val=model_value_prediction, actual_class=class_label, prediction_class=model_class_prediction)
def XYZ2BL(x, y, z): blh = zeros(2) t = math.sqrt(x * x + y * y) eps = 1.0E-10 if math.fabs(t) < eps: if z > 0: blh[0] = 90.0 blh[1] = 0.0 elif z < 0: blh[0] = -90 blh[1] = 0.0 else: blh[0] = math.atan(z / t) * 180.0 / math.pi # -90 to 90 # 0-360 blh[1] = math.atan2(y, x) * 180.0 / math.pi if blh[1] < 0.0: blh[1] = blh[1] + 360.0 return blh
def update_err(actual, prediction, false_pes, false_opt): err = actual - prediction if err > 0: false_pes.append(err) elif err < 0: false_opt.append(math.fabs(err))
run = 0 canvas = {} for line in dataset: arr_LEt = {} ls_LEt = [] run += 1 ls_L2Etcells = [] ls_line = line.split(",") acc = float(ls_line[-1]) # acc = net-true/true ls_acc.append(acc) ls_run.append(run) hist.Fill(acc) sum_single += acc sum_square += ((acc)**2) if math.fabs( float(ls_line[-1]) ) < 0.001: # optional; only print epoch with net-true/true < 0.001 ls_LEtcells = [] for i in range(12): ls_LEtcells.append(float(ls_line[i])) extent = [0, 11, 3, 0] fig, ax = pyplot.subplots() pyplot.title("Pre-processed LEt 12 Weights: Adam Rate = 1, Epoch = " + str(run)) pyplot.axis('off') for j in range(0, 4): arr_LEt[j] = np.asarray([0] * 33).reshape(11, 3).transpose() ls_LEt.append(arr_LEt[j])
''' sinsum.py v. 1 8/27/18 calculate the sine of an angle from the series expansion ''' # Import factorial from numpy from numpy import math # Initialization of variables # Get the angle from the user x = input("Enter the angle in degrees: ") # convert angle to radians x = x * math.pi / 180 # get the number of terms to compute from user N = input("Enter number of terms to compute: ") sum = 0 #create the loop for our calculation for j in range (0, N+1): sum = sum + (-1)**j*x**(2*j+1)/math.factorial(2*j+1) #print out result print "sin(x) = ", sum print "Percent error = ", math.fabs((math.sin(x)) - sum) / (math.sin(x)) * 100