before remove of assertions for counter

This commit is contained in:
Maria Marchwicka 2020-10-05 18:08:35 +02:00
parent c51064abf0
commit 4c8df7468e

View File

@ -1,8 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
import collections
import numpy as np import numpy as np
import itertools as it import itertools as it
from typing import Iterable from typing import Iterable
from collections import Counter
SIGNATURE = 0 SIGNATURE = 0
SIGMA = 1 SIGMA = 1
@ -16,7 +16,7 @@ class SignatureFunction(object):
def __init__(self, values=None, counter=None): def __init__(self, values=None, counter=None):
# builed counter based on values of signature jumps # builed counter based on values of signature jumps
if counter is None: if counter is None:
counter = collections.Counter() counter = Counter()
if values is None: if values is None:
values = [] values = []
@ -36,8 +36,8 @@ class SignatureFunction(object):
def double_cover(self): def double_cover(self):
# to read values for t^2 # to read values for t^2
items = self.cnt_signature_jumps.items() items = self.cnt_signature_jumps.items()
counter = collections.Counter({ (1 + k) / 2 : v for k, v in items}) counter = Counter({ (1 + k) / 2 : v for k, v in items})
counter.update(collections.Counter({ k / 2 : v for k, v in items})) counter.update(Counter({ k / 2 : v for k, v in items}))
new_data = [] new_data = []
for jump_arg, jump in self.cnt_signature_jumps.items(): for jump_arg, jump in self.cnt_signature_jumps.items():
new_data.append((jump_arg/2, jump)) new_data.append((jump_arg/2, jump))
@ -52,7 +52,7 @@ class SignatureFunction(object):
if jump_arg < 1/2: if jump_arg < 1/2:
new_data.append((2 * jump_arg, jump)) new_data.append((2 * jump_arg, jump))
counter = collections.Counter() counter = Counter()
for jump_arg, jump in self.cnt_signature_jumps.items(): for jump_arg, jump in self.cnt_signature_jumps.items():
if jump_arg < 1/2: if jump_arg < 1/2:
counter[2 * jump_arg] = jump counter[2 * jump_arg] = jump
@ -64,11 +64,11 @@ class SignatureFunction(object):
# to read values for t^(1/2) # to read values for t^(1/2)
items = self.cnt_signature_jumps.items() items = self.cnt_signature_jumps.items()
counter = collections.Counter() counter = Counter()
for jump_arg, jump in self.cnt_signature_jumps.items(): for jump_arg, jump in self.cnt_signature_jumps.items():
if jump_arg >= 1/2: if jump_arg >= 1/2:
counter[mod_one(2 * jump_arg)] = jump counter[mod_one(2 * jump_arg)] = jump
counter2 = collections.Counter({ mod_one(2 * k) : v for k, v in items if k >= 1/2 }) counter2 = Counter({mod_one(2 * k) : v for k, v in items if k >= 1/2 })
assert counter2 == counter assert counter2 == counter
return SignatureFunction(counter=counter) return SignatureFunction(counter=counter)
@ -93,7 +93,7 @@ class SignatureFunction(object):
new_data.append((mod_one(jump_arg + shift), jump)) new_data.append((mod_one(jump_arg + shift), jump))
sf = SignatureFunction(values=new_data) sf = SignatureFunction(values=new_data)
counter = collections.Counter({mod_one(k + shift) : v \ counter = Counter({mod_one(k + shift) : v \
for k,v in self.cnt_signature_jumps.items()}) for k,v in self.cnt_signature_jumps.items()})
assert SignatureFunction(counter=counter) == \ assert SignatureFunction(counter=counter) == \
SignatureFunction(values=new_data) SignatureFunction(values=new_data)
@ -103,7 +103,7 @@ class SignatureFunction(object):
return self.__rshift__(-shift) return self.__rshift__(-shift)
def __neg__(self): def __neg__(self):
counter = collections.Counter() counter = Counter()
counter.subtract(self.cnt_signature_jumps) counter.subtract(self.cnt_signature_jumps)
return SignatureFunction(counter=counter) return SignatureFunction(counter=counter)
@ -113,6 +113,11 @@ class SignatureFunction(object):
return SignatureFunction(counter=counter) return SignatureFunction(counter=counter)
def __eq__(self, other): def __eq__(self, other):
self_cnt = Counter({ k : v for k, v in self.cnt_signature_jumps.items()
if v != 0})
other_cnt = Counter({ k : v for k, v in other.cnt_signature_jumps.items()
if v != 0})
return self.cnt_signature_jumps == other.cnt_signature_jumps return self.cnt_signature_jumps == other.cnt_signature_jumps
def __sub__(self, other): def __sub__(self, other):
@ -173,28 +178,32 @@ class SignatureFunction(object):
# Draw the graph of the signature and transform it into TiKz. # Draw the graph of the signature and transform it into TiKz.
# header of the LaTeX file # header of the LaTeX file
with open(file_name, "w") as output_file: with open(file_name, "w") as f:
output_file.write("\\documentclass[tikz]{standalone}\n") f.write("\\documentclass[tikz]{standalone}\n")
output_file.write("\\usetikzlibrary{datavisualization,datavisualization.formats.functions}\n") f.write("\\usetikzlibrary{datavisualization, " +
output_file.write("\\begin{document}\n") "datavisualization.formats.functions}\n")
output_file.write("\\begin{tikzpicture}\n") f.write("\\begin{document}\n")
f.write("\\begin{tikzpicture}\n")
data = sorted(self.step_function_data()) data = sorted(self.step_function_data())
print("data") print("data")
print(data) print(data)
output_file.write(" \\datavisualization[scientific axes,visualize as smooth line,\n") f.write(" \\datavisualization[scientific axes, " +
output_file.write(" x axis={ticks={none,major={at={") "visualize as smooth line,\n")
output_file.write(", " + str(N(data[0][0],digits=4)) + " as \\(" + str(data[0][0]) + "\\)") f.write(" x axis={ticks={none,major={at={")
f.write(", " + str(N(data[0][0],digits=4)) + " as \\(" + \
str(data[0][0]) + "\\)")
for jump_arg, jump in data: for jump_arg, jump in data:
output_file.write(", " + str(N(jump_arg,digits=4)) + " as \\(" + str(jump_arg) + "\\)") f.write(", " + str(N(jump_arg,digits=4)) +
output_file.write("}}}}\n") " as \\(" + str(jump_arg) + "\\)")
output_file.write(" ]\n") f.write("}}}}\n")
output_file.write("data [format=function]{\n") f.write(" ]\n")
output_file.write("var x : interval [0:1];\n") f.write("data [format=function]{\n")
output_file.write("func y = \\value x;\n") f.write("var x : interval [0:1];\n")
output_file.write("};\n") f.write("func y = \\value x;\n")
f.write("};\n")
# close LaTeX enviroments # close LaTeX enviroments
output_file.write("\\end{tikzpicture}\n") f.write("\\end{tikzpicture}\n")
output_file.write("\\end{document}\n") f.write("\\end{document}\n")
class TorusCable(object): class TorusCable(object):
@ -333,7 +342,7 @@ class TorusCable(object):
k = abs(k_n) k = abs(k_n)
ksi = 1/(2 * k + 1) ksi = 1/(2 * k + 1)
counter = collections.Counter() counter = Counter()
# print("lambda_odd, i.e. (theta + e) % 2 != 0") # print("lambda_odd, i.e. (theta + e) % 2 != 0")
for e in range(1, k + 1): for e in range(1, k + 1):
if (theta + e) % 2 != 0: if (theta + e) % 2 != 0: