def __init__(self, vector, iterations = 200): self.vector = vector if not isinstance(vector, Polynomial) else vector.coefficents assert np.linalg.norm(self.vector) > 0 self.hyper_sphere = hyperSphere(len(self.vector)) self.sub_space_hyper_sphere = hyperSphere(len(self.vector) - 1) self.iterations = iterations self.o = self.optimize()
def __init__(self, poly, iterations=200): self.poly = poly self.vector = self.poly.coefficents self.normalization = lambda x: x / np.linalg.norm(x) self.normal_vector = self.normalization(self.vector) self.mult = Multiply(self.poly.order + 1) self.sub_space_hyper_sphere = hyperSphere(self.poly.order) self.iterations = iterations self.o, self.measure___ = self.optimize()
def __init__(self, domain_in, control_points=controlPointsUniformRandomEnclosingPrism, samples=200, offset=None): self.domain_in = domain_in self.domain_out = self.domain_in + np.pi * 2 self.dims = len(self.domain_in) + 1 self.control_points = control_points(self.domain_in, self.domain_out)(5) self.bezier = bezierCurve(self.domain_in, self.domain_out, self.control_points).sample(samples) self.hyper_sphere = hyperSphere(len(domain_in) + 1) self.offset = np.zeros(self.bezier.shape[1] + 1) if not offset else offset
A = np.apply_along_axis(hypS, 1, sample) B = np.apply_along_axis(np.linalg.norm, 1, A) return B def test_angle(hypS, sample_size): pass def plot_Loop(*loop): fig = plt.figure() ax = plt.axes(projection='3d') A = np.concatenate([_() for _ in loop], 0) ax.scatter3D(*[A[:, i] for i in range(A.shape[1])]) plt.show() if __name__ == "__main__": hS = hyperSphere(2) hS1 = hyperSphere(3) n = 2 m = Multiply(hS, *[hS1 for i in range(n)]) m_ = Multiply(hS, hS) m__ = Multiply(7) a = Add(hS, *[hS1 for i in range(n)]) sample = np.ones(3) loops = [Loop(sample) for _ in range(4)] hyper_spheres = [hyperSphere(2), hyperSphere(3), hyperSphere(3)]
domain_ball = self.domain_ball(sub_domain, i + 1) domain_, range_ = self.make_domain_range(domain_, domain_ball) measure__index, domain_ = self.measure_(domain_, range_) return domain_ % np.pi*2 def sample_domain_sub_domain(self, domain = None, samples = 100): if isinstance(domain, type(None)): domain = 2*np.pi*np.random.random_sample(size=(samples, self.hyper_sphere.dims-1)) sub_domain = 2*np.pi*np.random.random_sample(size=(samples, self.hyper_sphere.dims-2)) return domain, sub_domain def domain_ball(self, sub_domain, radius = .5): domain_ball = self.sub_space_hyper_sphere(sub_domain) domain_ball = np.apply_along_axis(lambda x: (.5/radius)*np.random.random_sample()*x, 1, domain_ball) return domain_ball def make_domain_range(self, domain, domain_ball): domain_ = np.concatenate([q + domain_ball for q in domain], axis=0) range_ = self.hyper_sphere(domain_) return domain_, range_ def measure_(self, domain_, range_, n=20): measure__ = np.apply_along_axis(np.linalg.norm, 1, range_ - self.vector) measure__index = np.argpartition(measure__, n) return measure__index, domain_[measure__index[:n]] if __name__ == "__main__": vector = hyperSphere(7)([np.pi/3, 0, 0, 0, 0, 0]) poly = Polynomial(vector) rD = resolveDirection(poly)
def make_derivitive(self): dictionary = self.make_derivitive_dictionary() shift_ = self.shift() container_ = self.container(shift_) # there's currently a bug in the code with respect to the replace statements. # The problem is that on the first loop, cos is turned to sin and on the second # loop, we need to have the recently changed sin functions immutable. They're # being changed back to cos in this current iteration. # # Bizzare fix at line 32 # Consider if this will work for multiply object. for index in range(len(container_[0])): for key in dictionary: print(key, dictionary[key]) container_[0][index] = container_[0][index].replace(key, dictionary[key]) container_[0][index] = container_[0][index].replace("oo", "o").replace("ii", "i") return container_[0] if __name__ == "__main__": hS = hyperSphere(5) m = Multiply(hS,hS) d = Derivitive(0,m) l = d.container(d.shift())[0] q = d.make_derivitive()
import numpy as np from functools import reduce from hyperSphere import hyperSphere class Polynomial: def __init__(self, coefficents): self.coefficents = coefficents self.order = len(self.coefficents) - 1 def __call__(self, x): f = lambda q: [ self.coefficents[element] * (q**element) for element in range(self.order + 1) ] terms = f(x) return reduce(lambda x, y: x + y, terms) if __name__ == "__main__": hS = hyperSphere(3) poly = Polynomial(np.array([1, 2, 3]))
def mhSfi(self, int_): int_ -= 1 linear_form = [] if int_ % 2 != 1 else [hyperSphere(2)] quadradic_forms = [hyperSphere(3) for _ in range(int_ // 2)] return linear_form + quadradic_forms
else: hyper_rectangle[index] += f"*{vector[sub_index]}" return hyper_rectangle def container_vector(self, container_hyper_rectangle_): vector_shape = reduce(lambda x, y: x + y, self.DomainDims) + 1 container_vector = np.empty(shape=(vector_shape), dtype="O") cartesian_product = product(*self.basis_bounds) for index in cartesian_product: A = reduce(lambda x, y: x + y, index) print(A, index) if container_vector[A] == None: container_vector[A] = f"{container_hyper_rectangle_[index]}" else: container_vector[A] += f"+{container_hyper_rectangle_[index]}" return container_vector def mhSfi(self, int_): int_ -= 1 linear_form = [] if int_ % 2 != 1 else [hyperSphere(2)] quadradic_forms = [hyperSphere(3) for _ in range(int_ // 2)] return linear_form + quadradic_forms if __name__ == "__main__": n = 2 linear = hyperSphere(2) quadratic = [hyperSphere(3) for _ in range(n)] m = Multiply(linear, *quadratic)
___________ self() : evaluate loop over generated domain. """ def __init__(self, domain_in, control_points=controlPointsUniformRandomEnclosingPrism, samples=200, offset=None): self.domain_in = domain_in self.domain_out = self.domain_in + np.pi * 2 self.dims = len(self.domain_in) + 1 self.control_points = control_points(self.domain_in, self.domain_out)(5) self.bezier = bezierCurve(self.domain_in, self.domain_out, self.control_points).sample(samples) self.hyper_sphere = hyperSphere(len(domain_in) + 1) self.offset = np.zeros(self.bezier.shape[1] + 1) if not offset else offset def __call__(self): return np.apply_along_axis(self.hyper_sphere, 1, self.bezier) + self.offset if __name__ == "__main__": sample = np.ones(4) adjust = np.ones_like(sample) * np.pi * 2 loops = [Loop(sample) for _ in range(9)] hyper_spheres = [hyperSphere(2), hyperSphere(3), hyperSphere(3)]