def compareAllAngles(elements,dims,reduceddims, q, e): beforeAngles = [] afterAngles = [] maxAfterAngles = [] minAfterAngles = [] randomCube = np.random.rand(elements,dims) broken = 0 a = randomCube res = fjlt(a.transpose(),reduceddims, q).transpose() for i in range(0, elements - 2): for j in range(i + 1, elements - 1): for k in range(j + 1, elements): beforeAngle = getAngle(a[i],a[j],a[k]) afterAngle = getAngle(res[i],res[j],res[k]) distA = np.linalg.norm(a[j]-a[k]) distB = np.linalg.norm(a[i]-a[j]) distC = np.linalg.norm(a[i]-a[k]) distAL = sqrt((distA**2)*(1+e)) distBL = sqrt((distB**2)*(1+e)) distCL = sqrt((distC**2)*(1+e)) distAS = sqrt((distA**2)*(1-e)) distBS = sqrt((distB**2)*(1-e)) distCS = sqrt((distC**2)*(1-e)) beforeAngles.append(beforeAngle) afterAngles.append(afterAngle) maxAfter = getAngle2(distAL,distBS,distCS) minAfter = getAngle2(distAS,distBL,distCL) maxAfterAngles.append(maxAfter) minAfterAngles.append(minAfter) if(afterAngle > maxAfter or afterAngle < minAfter): broken = broken + 1 afterAngles = [x for _,x in sorted(zip(beforeAngles,afterAngles))] maxAfterAngles = [x for _,x in sorted(zip(beforeAngles,maxAfterAngles))] minAfterAngles = [x for _,x in sorted(zip(beforeAngles,minAfterAngles))] beforeAngles = sorted(beforeAngles) print(broken) plt.plot(afterAngles,"bo", alpha=0.25, markerSize=2,color="blue") plt.plot(afterAngles, alpha=0.25, label= "after angle",color="purple") plt.plot(maxAfterAngles, alpha=0.7, label= "max after",color="red") plt.plot(minAfterAngles, alpha=0.7, label= "min after",color="red") plt.plot(beforeAngles, alpha=0.7, label="before",color="black") plt.ylim(ymin = 0) _,ymax = plt.ylim() plt.ylim(ymax = ymax + 10) plt.legend(loc='upper left') plt.show()
def createDimReducedFiles(input, output): allPoints = parse(input) npPoints = arrayToNumpy(allPoints) q = 0.5 for i in range(1, 11): dims = 2**i res = fjlt(npPoints.transpose(), dims, q).transpose() np.savetxt((output) + str(dims) + ".txt", res, fmt="%e")
def printE(elements,dims,reduceddims, q, e): beforeAngles = [] afterAngles = [] maxAfterAngles = [] minAfterAngles = [] outlier = np.full((1, dims),5) print(outlier.shape) randomSphere = np.random.rand(elements,dims) print(randomSphere.shape) a = np.append(outlier, randomSphere,axis=0) res = fjlt(a.transpose(),reduceddims, q).transpose() for i in range(1, elements -1 ): j = i k = i + 1 beforeAngle = getAngle(a[0],a[j],a[k]) afterAngle = getAngle(res[0],res[j],res[k]) distA = np.linalg.norm(a[j]-a[k]) distB = np.linalg.norm(a[0]-a[j]) distC = np.linalg.norm(a[0]-a[k]) distAL = sqrt((distA**2)*(1+e)) distBL = sqrt((distB**2)*(1+e)) distCL = sqrt((distC**2)*(1+e)) distAS = sqrt((distA**2)*(1-e)) distBS = sqrt((distB**2)*(1-e)) distCS = sqrt((distC**2)*(1-e)) beforeAngles.append(beforeAngle) afterAngles.append(afterAngle) maxAfterAngles.append(getAngle2(distAL,distBS,distCS)) minAfterAngles.append(getAngle2(distAS,distBL,distCL)) afterAngles = [x for _,x in sorted(zip(beforeAngles,afterAngles))] maxAfterAngles = [x for _,x in sorted(zip(beforeAngles,maxAfterAngles))] minAfterAngles = [x for _,x in sorted(zip(beforeAngles,minAfterAngles))] beforeAngles = sorted(beforeAngles) plt.plot(afterAngles,"bo", alpha=0.25, markerSize=2, label= "afterPoints") plt.plot(afterAngles, alpha=0.25, label= "afterLines") plt.plot(maxAfterAngles, alpha=0.7, label= "maxafter") plt.plot(minAfterAngles, alpha=0.7, label= "minafter") plt.plot(beforeAngles, alpha=0.7, label="before") ymin,ymax = plt.ylim() #plt.ylim(ymax = ymax + ) #plt.yticks(np.arange(ymin, ymax, 15)) plt.ylabel("angle") plt.xticks(np.arange(0, individuals, individuals +1)) plt.legend(loc='upper left') plt.show()
def compareAllAngles(elements, dims, reduceddims, q, e): beforeAnglesInlier = [] beforeAnglesFringe = [] beforeAnglesOutlier = [] afterAnglesInlier = [] afterAnglesFringe = [] afterAnglesOutlier = [] randomCube = np.random.rand(elements, dims) inlier = np.full((1, dims), 0.5) fringe = np.full((1, dims), 1) outlier = np.full((1, dims), 2) broken = 0 a = np.append(randomCube, inlier, axis=0) a = np.append(a, fringe, axis=0) a = np.append(a, outlier, axis=0) res = fjlt(a.transpose(), reduceddims, q).transpose() for i in range(0, elements - 2): for j in range(i + 1, elements - 1): beforeAnglesInlier.append(getAngle(a[elements], a[i], a[j])) beforeAnglesFringe.append(getAngle(a[elements + 1], a[i], a[j])) beforeAnglesOutlier.append(getAngle(a[elements + 2], a[i], a[j])) afterAnglesInlier.append(getAngle(res[elements], res[i], res[j])) afterAnglesFringe.append( getAngle(res[elements + 1], res[i], res[j])) afterAnglesOutlier.append( getAngle(res[elements + 2], res[i], res[j])) plt.plot(afterAnglesInlier, alpha=0.5, label="Inlier", color="purple") plt.plot(beforeAnglesInlier, alpha=0.5, color="black") plt.plot(afterAnglesFringe, alpha=0.5, label="Fringe", color="blue") plt.plot(beforeAnglesFringe, alpha=0.5, color="black") plt.plot(afterAnglesOutlier, alpha=0.5, label="Outlier", color="green") plt.plot(beforeAnglesOutlier, alpha=0.5, color="black") plt.ylim(ymin=0) _, ymax = plt.ylim() plt.ylim(ymax=ymax + 10) plt.legend(loc='upper left') plt.show()
def printE(elements, dims, reduceddims, q, e): maxE = 0 minE = 1 sumE = 0 vals = [] beforeDists = [] afterDists = [] maxAfterDists = [] minAfterDists = [] mu = 584 sigma = 14.2 a = np.random.normal(mu, sigma, (elements, dims)) res = fjlt(a.transpose(), reduceddims, q).transpose() #res = fjlt_usp(a.transpose(),reduceddims).transpose() for i in range(0, elements - 1): j = i + 1 beforeDistance = np.linalg.norm(a[i] - a[j]) beforeDists.append(beforeDistance) maxAfterDists.append(sqrt((beforeDistance**2) * (1 + e))) minAfterDists.append(sqrt((beforeDistance**2) * (1 - e))) afterDistance = np.linalg.norm(res[i] - res[j]) afterDists.append(afterDistance) val = (beforeDistance - afterDistance) / beforeDistance vals.append(val) sumE += val if (val < minE): minE = val if (val > maxE): maxE = val afterDists = [x for _, x in sorted(zip(beforeDists, afterDists))] maxAfterDists = [x for _, x in sorted(zip(beforeDists, maxAfterDists))] minAfterDists = [x for _, x in sorted(zip(beforeDists, minAfterDists))] beforeDists = sorted(beforeDists) plt.plot(afterDists, "bo", alpha=0.25, markerSize=2, label="afterPoints") plt.plot(afterDists, alpha=0.25, label="afterLines") plt.plot(maxAfterDists, alpha=0.7, label="maxafter") plt.plot(minAfterDists, alpha=0.7, label="minafter") plt.plot(beforeDists, alpha=0.7, label="before") plt.legend(loc='upper right') plt.show()
def compareAllAngles(elements,dims,reduceddims, q, e): beforeAngles = [] afterAngles = [] randomCube = np.random.rand(elements,dims) broken = 0 a = randomCube res = fjlt(a.transpose(),reduceddims, q).transpose() varianceMatrixBefore = np.empty([elements]) varianceMatrixAfter = np.empty([elements]) for i in range(0, elements): for j in range(0, elements): for k in range(0, elements): if(i != j and i != k and j != k): beforeAngle = getAngle(a[i],a[j],a[k]) afterAngle = getAngle(res[i],res[j],res[k]) beforeAngles.append(beforeAngle) afterAngles.append(afterAngle) varianceMatrixAfter[i] = np.array(afterAngles).var() varianceMatrixBefore[i] = np.array(beforeAngles).var() afterAngles = [] beforeAngles = [] plt.plot(varianceMatrixAfter.tolist(),"bo", alpha=0.25, markerSize=2,color="blue" , label="after") plt.plot(varianceMatrixBefore.tolist(),"bo", alpha=0.25, markerSize=2,color="red", label="before") plt.ylim(ymin = 0) _,ymax = plt.ylim() plt.ylim(ymax = ymax + 10) plt.legend(loc='upper left') plt.show()