def main(): # for kernel_size=1, mean kron factoring works for any image size main_vals = AttrDict(n=2, kernel_size=1, image_size=625, num_channels=5, num_layers=4, loss='CrossEntropy', nonlin=False) hess_list1 = compute_hess(method='exact', **main_vals) hess_list2 = compute_hess(method='kron', **main_vals) value_error = max( [u.symsqrt_dist(h1, h2) for h1, h2 in zip(hess_list1, hess_list2)]) magnitude_error = max([ u.l2_norm(h2) / u.l2_norm(h1) for h1, h2 in zip(hess_list1, hess_list2) ]) print(value_error) print(magnitude_error) dimension_vals = dict(image_size=[2, 3, 4, 5, 6], num_channels=range(2, 12), kernel_size=[1, 2, 3, 4, 5]) for method in ['mean_kron', 'kron']: # , 'experimental_kfac']: print() print('=' * 10, method, '=' * 40) for dimension in ['image_size', 'num_channels', 'kernel_size']: value_errors = [] magnitude_errors = [] for val in dimension_vals[dimension]: vals = AttrDict(main_vals.copy()) vals.method = method vals[dimension] = val vals.image_size = max(vals.image_size, vals.kernel_size**vals.num_layers) # print(vals) vals_exact = AttrDict(vals.copy()) vals_exact.method = 'exact' hess_list1 = compute_hess(**vals_exact) hess_list2 = compute_hess(**vals) magnitude_error = max([ u.l2_norm(h2) / u.l2_norm(h1) for h1, h2 in zip(hess_list1, hess_list2) ]) hess_list1 = [h / u.l2_norm(h) for h in hess_list1] hess_list2 = [h / u.l2_norm(h) for h in hess_list2] value_error = max([ u.symsqrt_dist(h1, h2) for h1, h2 in zip(hess_list1, hess_list2) ]) value_errors.append(value_error) magnitude_errors.append(magnitude_error.item()) print(dimension) print(' value: :', value_errors) print(' magnitude :', u.format_list(magnitude_errors))
def format(self, options={}): if (options.get('use_function_group', False)): repr = self.function_group else: repr = self.function if (options.get('one_liner', False)): return repr else: return "%s: %s" % (repr, util.format_list(self.locations, '; '))
def format(self, options={}): if (options.get('one_liner', False)): return util.format_list(self.functions(), ' ', options=options) else: return util.format_list(self.functions(), '\n', options=options)
def format(self,options={}): return util.format_list([getattr(self, name, '?') for name in options.get('display_tokens',['lemma','pos'])],glue='/',options=options)
def format(self,options={'display_tokens':['lemma','pos']}): return util.format_list(self.tokens,glue=' ',options=options)
def format(self,options={'display_tokens':['lemma','pos']}): return "Document %s text:\n%s\nDocument Sentences:\n%s" % (self.get_long_id(),self.get_text(),util.format_list(self.sentences,glue='\n',options=options))