def _load(self, obj): try: super(_FailsafeFiniteSliceGaussianController, self)._load(obj) except Exception as e: logger.warning(str(e)) obj.STATS = [] obj.POTENTIAL = fc.empty_array( (2**obj.k, 2**obj.k * (2**obj.k + 1) // 2, 2 * obj.sampling_frequency + 1, obj.sampling_frequency + 1, 2 * obj.sampling_frequency + 1)) obj.A = fc.empty_array((2**obj.k, 2**obj.k * (2**obj.k + 1) // 2))
def _make_interpolator(self, COMPRESSED): sf = self.sampling_frequency POTENTIAL = fc.empty_array((sf + 1, len(self.Y_SAMPLE), sf + 1)) for xz_idx, (x_idx, z_idx) in enumerate(self._xz_idx): P = COMPRESSED[xz_idx, :] POTENTIAL[x_idx, :, z_idx] = P if x_idx < z_idx: POTENTIAL[z_idx, :, x_idx] = P interpolator = RegularGridInterpolator( (self.X_SAMPLE[sf:], self.Y_SAMPLE, self.Z_SAMPLE[sf:]), POTENTIAL, bounds_error=False, fill_value=np.nan) return interpolator
H = np.linspace(0, fem.H, 33) X = np.linspace(0, fem.H, 33) Y = np.linspace(0, fem.H, 33) stats = [] results = { 'SD': SD, 'H': H, 'X': X, 'Y': Y, 'STATS': stats, } for degree in [1, 2, 3]: results['A_{}'.format(degree)] = [] RES = fc.empty_array((len(SD), len(H), len(X), len(Y))) results['Gaussian_{}'.format(degree)] = RES for i_sd, sd in enumerate(SD): for i_h, h in enumerate(H): logger.info('Gaussian (deg={}, sd={}, h={})'.format( degree, sd, h)) potential = fem(degree, y=h, standard_deviation=sd) stats.append((degree, sd, h, potential is not None, fem.iterations, fem.time.total_seconds())) logger.info('Gaussian (deg={}, sd={}, h={}): {}'.format( degree, sd, h, 'SUCCEED' if potential is not None else 'FAILED'))
def _empty_solutions(self): n = 2**self.k self.A = fc.empty_array(n * self.source_resolution) self.STATS = [] self.POTENTIAL = fc.empty_array(self._potential_size(n))
stats.append((degree, potential is not None, fem.iterations, fem.time.total_seconds())) logger.info( 'Gaussian SD={} (deg={}): {}\t({fem.iterations}, {fem.time})' .format( sd, degree, 'SUCCEED' if potential is not None else 'FAILED', fem=fem)) if potential is not None: N_LIMIT = ( N - 1 ) * SAMPLING_FREQUENCY + 1 # TODO: prove correctness POTENTIAL = fc.empty_array(N_LIMIT * (N_LIMIT + 1) * (N_LIMIT + 2) // 6) GT = POTENTIAL.copy() for x in range(N_LIMIT): for y in range(x + 1): for z in range(y + 1): idx = x * (x + 1) * (x + 2) // 6 + y * ( y + 1) // 2 + z xx = x / float(SAMPLING_FREQUENCY) yy = y / float(SAMPLING_FREQUENCY) zz = z / float(SAMPLING_FREQUENCY) r = np.sqrt(xx**2 + yy**2 + zz**2) if r >= fem.RADIUS: v = fem.potential_behind_dome(r, sd) else: try: v = potential(xx, yy, zz)
def _empty_solutions(self): n = len(self.R) self.COMPLETED = np.zeros(n, dtype=bool) self.STATS = [] self.POTENTIAL = fc.empty_array(self._potential_size(n))