def test_spiral_even(self): self.assertListEqual([ [1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7] ], spiral(4))
def test_spiral(): gen = spiral() assert next(gen) == (0, 0) assert next(gen) == (1, 0) assert next(gen) == (1, -1) assert next(gen) == (0, -1) assert next(gen) == (-1, -1) assert next(gen) == (-1, 0)
def generate_spiral(gridsize, aperture, r_max, r_min, splits, settings): split_odd = splits[0] split_even = splits[1] first = settings[0] second = settings[1] third = settings[2] fourth = settings[3] sampling = aperture / (gridsize // 2) wfarr = np.zeros([gridsize, gridsize], dtype=np.complex128) c = gridsize // 2 for i in range(gridsize): for j in range(gridsize): x = i - c y = j - c phi = math.atan2(y, x) r = sampling * math.hypot(x, y) wfarr[i][j] = spiral(r, phi, aperture, r_max, r_min, split_odd, split_even, first, second, third, fourth) return wfarr
group2.add_argument('-s', '--solvable', action='store_true', help='Generate only solvable puzzle') group2.add_argument('-u', '--unsolvable', action='store_false', help='Generate only unsolvable puzzle') parser.add_argument('-a', '--anim', action='store_true' , help='Launch an animation of the resolution of the puzzle') return parser.parse_args(arg) if __name__ == '__main__': arg = parse_argument(sys.argv[1:]) if (arg.file): try: fd = open(arg.file, "r") parsing = Parsing(fd) except: sys.exit("Error - Openning error") start = parsing.puzzle goal = printspiral(spiral(int(sqrt(len(start))))) if (my_resolvable(parsing, start, goal) == 1): exit else: if arg.length < 71 and arg.length > 2: goal = printspiral(spiral(arg.length)) solvable = None if (arg.solvable == True): solvable = True elif (arg.unsolvable == False): solvable = False start = get_puzzle(arg.length, goal, solvable) else: sys.exit('Wrong size')
def create_dataset(N, data_type, noise, sm=0.1, d=1, angle=3*np.pi, ndist=1, means=np.array([[-0.25, 0.0],[0.25, 0.0]]), sigmas=np.array([0.1, 0.1]), ml=1, b=0.2, sl=0.05, ssin=0.02, sspi=1, wrappings = 4, mspi=0.5): #Sample a dataset from different distributions # X, Y = create_dataset(N, type, noise) # # INPUT # N Number of samples # data_type Type of distribution used. It must be one from # 'Moons' 'Gaussian' 'Linear' 'Sinusoidal' 'Spiral' # noise probability to have a wrong label in the dataset. # # 'Moons' parameters: # 1- sm: standard deviation of the gaussian noise. Default is 0.1 # 2- d: 1X2 translation vector between the two classes. With d = 0 # the classes are placed on a circle. Default is 1. # 3- angle: rotation angle of the moons in (radians). Default is 3*np.pi. # # 'Gaussian' parameters: # 1- ndist: number of gaussians for each class. Default is 1. # 2- means: vector of size(2*ndist X 2) with the means of each gaussian. # Default is np.array([[-0.25, 0.0],[0.25, 0.0]]). # 3- sigmas: A sequence of covariance matrices of size (2*ndist, 2). # Default is np.array([0.1, 0.1]). # # 'Linear' parameters: # 1- ml: slope of the separating line. Default is 1. # 2- b: bias of the line. Default is 0.2. # 3- sl: standard deviation of the gaussian noise. Default is 0.05. # # 'Sinusoidal' parameters: # 1- ssin: standard deviation of the gaussian noise. Default is 0.02. # # 'Spiral' parameters: # 1- sspi: standard deviation of the gaussian noise. Default is 1. # 2- wrappings: wrappings number of wrappings of each spiral. Default is 4. # 3- mspi: multiplier m of x * sin(m * x) for the second spiral. Default is 0.5. # # OUTPUT # X data matrix with a sample for each row # Y vector with the labels # # EXAMPLE: # X, Y = create_dataset(100, 'SPIRAL', 0.01) # X, Y = create_dataset(100, 'SPIRAL', 0, sspi=0.1, wrappings=2, m=2); NN = [int(math.floor(float(N) / 2.0)), int(math.ceil(float(N) / 2.0))] if data_type=='Moons': X, Y = moons(NN, sm, angle, d) elif data_type=='Gaussian': X, Y = gaussian(NN, ndist, means, sigmas) elif data_type=='Linear': X, Y = linear_data(NN, ml, b, sl) elif data_type=='Sinusoidal': X, Y = sinusoidal(NN, ssin) elif data_type=='Spiral': X, Y = spiral(NN, sspi, wrappings, mspi) else: print 'Specified dataset type is not correct. It must be one of "Moons", "Gaussian", "Linear", "Sinusoidal", "Spiral"' swap=np.random.random((np.size(Y, axis=0), np.size(Y, axis=1)))<=noise Y[swap]=Y[swap]*-1 return X, Y
from spiral import spiral import numpy as np import matplotlib.pyplot as plt s = spiral(0, 1) x1, y1 = s.out() z1 = np.zeros(*x1.shape) d1 = np.vstack((x1, y1, z1)) np.save('s1.npy', d1) x2, y2 = -x1, -y1 z2 = np.ones(*x2.shape) d2 = np.vstack((x2, y2, z2)) np.save('s2.npy', d2) plt.plot(x1, y1, 'bo') plt.plot(x2, y2, 'ro') plt.show()
+ str(objectPrint.position) + '}') def changePosition(positionBox, positionChange): positionBox.position = positionChange fin = open('base.pov') sdl = fin.read() fin.close() #regular expression for camera findStr = r"camera\s*{\s*location\s*<\s*\-*\d+,\-*\d+,\-*\d+\s*>" listForCam = range(0, 10) #lists for x, y, and z cordinates listOfX, listOfY = spiral.spiral() listOfZ = range(0, 50) num = 1 #in this for loop we change the camera a bit for i in range(0, 10): #finding and changing in sdl the camera line if i % 2 == 0: sdl = re.sub( findStr, "camera{location < " + str(0) + ' , ' + str(listForCam[num]) + ' , ' + str(-7) + " >", sdl) num = num + 1 outfile = 'temp.pov' fout = open(outfile, 'w') fout.write(sdl) fout.close()
def test_spiral_stop(): assert len(list(spiral(10))) == 10
def test_spiral_odd(self): self.assertListEqual([ [1, 2, 3], [8, 9, 4], [7, 6, 5] ], spiral(3))
def test_spiral_one(self): self.assertListEqual([[1]], spiral(1))
def test_spiral_5(self): result = spiral.diagonalSum(spiral.spiral(5)) self.assertEqual(result, 101)
def test_spiral_1001(self): result = spiral.diagonalSum(spiral.spiral(1001)) self.assertEqual(result, 669171001) print("Result: {0}".format(result))