|
1 | 1 | import sys
|
2 |
| -import numpy as np |
3 |
| -from scipy.special import erf |
| 2 | +sys.path.append('../..') |
| 3 | +from error_utils import * |
4 | 4 |
|
5 | 5 | names_and_norms = [('l2', 2), ('froebenius', 'fro')]
|
6 | 6 | variances = [1, 10, 100]
|
7 | 7 | names_and_args = [('%s_%d' % (name, variance), norm, variance)
|
8 | 8 | for name, norm in names_and_norms for variance in variances]
|
9 | 9 | error_names = [name for name, _, _ in names_and_args]
|
10 | 10 |
|
11 |
| -def string_to_matrix(s): |
12 |
| - return np.asarray([[float(e) for e in l.split()] for l in s.strip().split('\n')]) |
13 |
| - |
14 |
| -def error_function(perforated, variance): |
15 |
| - return erf(abs(perforated)/variance) |
16 |
| - |
17 | 11 | def error(standard_fn, perforated_fn):
|
18 |
| - standard = get_contents(standard_fn) |
19 |
| - perforated = get_contents(perforated_fn) |
20 |
| - standard = string_to_matrix(standard) |
21 |
| - perforated = string_to_matrix(perforated) |
| 12 | + standard = string_to_matrix(get_contents(standard_fn)) |
| 13 | + perforated = string_to_matrix(get_contents(perforated_fn)) |
22 | 14 |
|
23 | 15 | # max error if sizes differ
|
24 | 16 | if standard.shape != perforated.shape:
|
25 | 17 | return {name: 1.0 for name in error_names}
|
26 | 18 |
|
27 | 19 | return {name:
|
28 |
| - error_function(np.linalg.norm(standard - perforated, ord=norm), variance) |
| 20 | + norm_and_error_function(standard, perforated, norm, variance) |
29 | 21 | for name, norm, variance in names_and_args}
|
30 | 22 |
|
31 |
| -def get_contents(fn): |
32 |
| - with open(fn, 'r') as f: |
33 |
| - return f.read() |
34 |
| - |
35 | 23 | def main():
|
36 | 24 | standard_fn = sys.argv[1] if len(sys.argv) > 2 else 'standard.txt'
|
37 | 25 | perforated_fn = sys.argv[2] if len(sys.argv) > 2 else 'perforated.txt'
|
|
0 commit comments