def angleSet_Finite(p, quadrants=1, finiteList=False): ''' Generate the minimal L1 angle set for the MT that has finite coverage. If quadrants is more than 1, two quadrants will be used. ''' fareyVectors = farey.Farey() octants = 2 if quadrants > 1: octants = 4 if quadrants > 2: octants = 8 fareyVectors.compactOn() fareyVectors.generate(p / 2, octants) vectors = fareyVectors.vectors sortedVectors = sorted( vectors, key=lambda x: x.real**2 + x.imag**2) #sort by L2 magnitude #compute corresponding m values finiteAngles = [] for vector in sortedVectors: if vector.real == 0: m = 0 elif vector.imag == 0: m = p else: m, inv = toFinite(vector, p) finiteAngles.append(m) # print("m:", m, "vector:", vector) # print("sortedVectors:", sortedVectors) #print(finiteAngles) #ensure coverage count = 0 filled = [0] * (p + 1) #list of zeros finalVectors = [] finalFiniteAngles = [] for vector, m in zip(sortedVectors, finiteAngles): if filled[m] == 0: count += 1 filled[m] = 1 finalVectors.append(vector) finalFiniteAngles.append(m) if count == p + 1: break if finiteList: return finalVectors, finalFiniteAngles return finalVectors
def angleSubSets_Symmetric(s, mode, P, Q, octant=0, binLengths=False, K=1): ''' Generate the minimal L1 angle set for the MT for s subsets. Parameter K controls the redundancy, K = 1 is minimal. If octant is non-zero, full quadrant will be used. Octant schemes are as follows: If octant = -1, the opposing octant is also used. If octant = 0,1 (default), only use one octant. If octant = 2, octant will be mirrored from diagonal to form a quadrant. If octant = 4, 2 quadrants. If octant = 8, all quadrants. Function can also return bin lengths for each bin. ''' angles = [] subsetAngles = [] for i in range(s): subsetAngles.append([]) fareyVectors = farey.Farey() maxPQ = max(P, Q) fareyVectors.compactOff() fareyVectors.generate(maxPQ - 1, 1) vectors = fareyVectors.vectors sortedVectors = sorted( vectors, key=lambda x: x.real**2 + x.imag**2) #sort by L2 magnitude index = 0 subsetIndex = 0 binLengthList = [] angles.append(sortedVectors[index]) subsetAngles[subsetIndex].append(sortedVectors[index]) binLengthList.append(projectionLength(sortedVectors[index], P, Q)) while not isKatzCriterion(P, Q, angles, K) and index < len(sortedVectors): # check Katz index += 1 angles.append(sortedVectors[index]) subsetAngles[subsetIndex].append(sortedVectors[index]) p, q = farey.get_pq(sortedVectors[index]) # p = imag, q = real binLengthList.append(projectionLength(sortedVectors[index], P, Q)) # if isKatzCriterion(P, Q, angles): # break if octant == 0: continue #add octants if octant == -1: nextOctantAngle = farey.farey(p, -q) #mirror from axis angles.append(nextOctantAngle) subsetAngles[subsetIndex].append(nextOctantAngle) binLengthList.append(projectionLength(nextOctantAngle, P, Q)) if mode == 1: subsetIndex += 1 subsetIndex %= s if octant > 0 and p != q: nextOctantAngle = farey.farey(q, p) #swap to mirror from diagonal angles.append(nextOctantAngle) subsetAngles[subsetIndex].append(nextOctantAngle) binLengthList.append(projectionLength(nextOctantAngle, P, Q)) if mode == 1: subsetIndex += 1 subsetIndex %= s if octant > 1: nextOctantAngle = farey.farey(p, -q) #mirror from axis angles.append(nextOctantAngle) subsetAngles[subsetIndex].append(nextOctantAngle) binLengthList.append(projectionLength(nextOctantAngle, P, Q)) if mode == 1: subsetIndex += 1 subsetIndex %= s if p != q: #dont replicate nextOctantAngle = farey.farey( q, -p) #mirror from axis and swap to mirror from diagonal angles.append(nextOctantAngle) subsetAngles[subsetIndex].append(nextOctantAngle) binLengthList.append(projectionLength(nextOctantAngle, P, Q)) if mode == 1: subsetIndex += 1 subsetIndex %= s if mode == 0: subsetIndex += 1 subsetIndex %= s if octant > 1: #add the diagonal and column projections when symmetric (all quadrant are wanted) nextOctantAngle = farey.farey(1, 0) #mirror from axis angles.append(nextOctantAngle) subsetAngles[0].append(nextOctantAngle) binLengthList.append(projectionLength(nextOctantAngle, P, Q)) if binLengths: return angles, subsetAngles, binLengthList return angles, subsetAngles
# -*- coding: utf-8 -*- """ Created on Fri Dec 18 14:30:21 2015 @author: shakes """ import _libpath #add custom libs import numpy as np import finitetransform.farey as farey n = 32 #Farey vectors fareyVectors = farey.Farey() #~ fareyVectors.compactOn() fareyVectors.generate(n - 1, 8) #fareyVectors.generate2(n, 8) vectors = fareyVectors.vectors print vectors countX = 0 countY = 0 vectorImage = np.zeros((2 * n + 1, 2 * n + 1)) vectorImage[n, n] += 1 for vector in vectors: x = abs(vector.real) y = abs(vector.imag) vectorImage[int(vector.real + n), int(vector.imag + n)] += 1 countX += x countY += y