How to use test_projection method in Airtest

Best Python code snippet using Airtest

hill_climbing.py

Source:hill_climbing.py Github

copy

Full Screen

...48 return best_theta, best_ratio, best_w, best_h, best_l49@jit(nopython=True)50def hill_climb(p2, p2_inv, box_2d, x2d, y2d, z2d, w3d, h3d, l3d, ry3d, step_r_init, r_lim=0.0,min_ol_dif=0.0):51 step_r = step_r_init52 ol_best = test_projection(p2, p2_inv, box_2d, x2d, y2d, z2d, w3d, h3d, l3d, ry3d)53 # attempt to fit z/rot more properly54 while (step_r > r_lim):55 if step_r > r_lim:56 ol_neg = test_projection(p2, p2_inv, box_2d, x2d, y2d, z2d, w3d, h3d, l3d, ry3d - step_r)57 ol_pos = test_projection(p2, p2_inv, box_2d, x2d, y2d, z2d, w3d, h3d, l3d, ry3d + step_r)58 59 invalid = ((ol_pos - ol_best) <= min_ol_dif) and ((ol_neg - ol_best) <= min_ol_dif)60 if invalid:61 step_r = step_r * 0.562 elif (ol_pos - ol_best) > min_ol_dif and ol_pos > ol_neg:63 ry3d += step_r64 ol_best = ol_pos65 elif (ol_neg - ol_best) > min_ol_dif:66 ry3d -= step_r67 ol_best = ol_neg68 else:69 step_r = step_r * 0.570 while ry3d > 3.14: ry3d -= 3.14 * 271 while ry3d < (-3.14): ry3d += np.pi * 272 return ry3d, ol_best73@jit(nopython=True)74def test_projection(p2, p2_inv, box_2d, cx, cy, z, w3d, h3d, l3d, rotY):75 x = box_2d[0]76 y = box_2d[1]77 x2 = box_2d[2]78 y2 = box_2d[3]79 coord3d = p2_inv.dot(np.array([cx * z, cy * z, z, 1]))80 cx3d = coord3d[0]81 cy3d = coord3d[1]82 cz3d = coord3d[2]83 #top_3d = p2_inv.dot(np.array([cx * z, (cy-h3d/2) * z, z, 1]))84 # put back on ground first85 #cy3d += h3d/286 fy = p2[1, 1]87 # re-compute the 2D box using 3D (finally, avoids clipped boxes)88 verts3d, corners_3d = project_3d(p2, cx3d, cy3d, cz3d, w3d, h3d, l3d, rotY)...

Full Screen

Full Screen

test_projection.py

Source:test_projection.py Github

copy

Full Screen

1"""2.. module:: test_projection3 :synopsis: Test Projection strategy4.. moduleauthor:: David Eriksson <dme65@cornell.edu>5"""6from pySOT import check_opt_prob, SyncStrategyProjection, \7 LatinHypercube, RBFInterpolant, CubicKernel, LinearTail, \8 CandidateDYCORS9from poap.controller import ThreadController, BasicWorkerThread10import numpy as np11import os.path12import logging13class AckleyUnit:14 def __init__(self, dim=10):15 self.xlow = -1 * np.ones(dim)16 self.xup = 1 * np.ones(dim)17 self.dim = dim18 self.info = str(dim)+"-dimensional Ackley function on the unit sphere \n" +\19 "Global optimum: f(1,0,...,0) = ... = f(0,0,...,1) = " +\20 str(np.round(20*(1-np.exp(-0.2/np.sqrt(dim))), 3))21 self.min = 20*(1 - np.exp(-0.2/np.sqrt(dim)))22 self.integer = []23 self.continuous = np.arange(0, dim)24 check_opt_prob(self)25 def objfunction(self, x):26 n = float(len(x))27 return -20.0 * np.exp(-0.2*np.sqrt(np.sum(x**2)/n)) - \28 np.exp(np.sum(np.cos(2.0*np.pi*x))/n) + 20 + np.exp(1)29 def eval_eq_constraints(self, x):30 return np.linalg.norm(x) - 131def main():32 if not os.path.exists("./logfiles"):33 os.makedirs("logfiles")34 if os.path.exists("./logfiles/test_projection.log"):35 os.remove("./logfiles/test_projection.log")36 logging.basicConfig(filename="./logfiles/test_projection.log",37 level=logging.INFO)38 print("\nNumber of threads: 4")39 print("Maximum number of evaluations: 1000")40 print("Sampling method: CandidateDYCORS")41 print("Experimental design: Latin Hypercube")42 print("Surrogate: Cubic RBF")43 nthreads = 444 maxeval = 100045 nsamples = nthreads46 data = AckleyUnit(dim=10)47 print(data.info)48 def projection(x):49 return x / np.linalg.norm(x)50 # Create a strategy and a controller51 controller = ThreadController()52 controller.strategy = \53 SyncStrategyProjection(54 worker_id=0, data=data,55 maxeval=maxeval, nsamples=nsamples,56 exp_design=LatinHypercube(dim=data.dim, npts=2*(data.dim+1)),57 response_surface=RBFInterpolant(kernel=CubicKernel, tail=LinearTail, maxp=maxeval),58 sampling_method=CandidateDYCORS(data=data, numcand=100*data.dim),59 proj_fun=projection60 )61 # Launch the threads and give them access to the objective function62 for _ in range(nthreads):63 worker = BasicWorkerThread(controller, data.objfunction)64 controller.launch_worker(worker)65 # Run the optimization strategy66 result = controller.run()67 print('Best value found: {0}'.format(result.value))68 print('Best solution found: {0}'.format(69 np.array_str(result.params[0], max_line_width=np.inf,70 precision=5, suppress_small=True)))71 print('||x||_2 = {0}\n'.format(np.linalg.norm(result.params[0])))72if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful