%run scripts/compile-func.py -g 8,3,2+6,3,3.4+8,3,4.6+1,3,10+16,3,11.5+1,3,13 -o func.txt
Для начала посмотрим самый простой случай: по всем имеющимся гармоникам Фурье без всякого шума воссоздали исходную функцию. Неинтересно...
%run scripts/func2fourier.py -i func.txt -o full.txt
%run scripts/fourier2func.py -f func.txt -i full.txt -o full_2func.txt
Создадим функцию, которая бы создавала гармоники с шумом, отбирала только некоторые из них и преобразовывалаих в экспериментальную функию. А также зададим функцию подсчёта разрешения.
from itertools import chain
def count_resolution(select, min_cover=0.9, T=30):
groups = select.split(',')
ranges = []
for group in groups:
if '-' not in group:
group = group+'-'+group
a, b = list(map(int, group.split('-')))
b += 1
ranges.append(range(a, b))
horms = sorted(list(chain(*ranges)))
full_horms = list(range(0, horms[-1]+1))
resolutions = list()
coverages = list()
for i, horm in enumerate(horms):
count = i+1
full_count = full_horms.index(horm) + 1
coverage = count/full_count
coverages.append(coverage)
if horm != 0:
resolution = T / horm
else:
resolution = T
resolutions.append(resolution)
resolutions = resolutions[::-1]
coverages = coverages[::-1]
for i, coverage in enumerate(coverages):
if coverage >= min_cover:
return resolutions[i], coverage
return resolutions[0], coverages[0]
def experiment(func_file, select=None, amp_noise=0, phase_noise=0):
amp_noise = str(amp_noise)
phase_noise = str(phase_noise)
full_file_name = "full_" + amp_noise + "_" + phase_noise + ".txt"
args = "".join(["-i ", func_file, ' -o ', full_file_name,
' -F ', amp_noise, ' -P ', phase_noise])
%run scripts/func2fourier.py $args
if select != None:
sel_file_name = "sel_" + \
select.replace(',', '_') + "_" + amp_noise + \
"_" + phase_noise + ".txt"
args = "".join(["-i ", full_file_name, " -r ",
select, " -o ", sel_file_name])
%run scripts/fourier-filter.py $args
else:
sel_file_name = full_file_name
res_file_name = sel_file_name[:-4] + "_2func.txt"
args = "".join(["-f ", func_file, " -i ",
sel_file_name, " -o ", res_file_name])
%run scripts/fourier2func.py $args
print(select.replace(',', ', ') if select != None else "All", count_resolution(select),
amp_noise + '%', phase_noise + '%', sep="\t")
return (select.replace(',', ', ') if select != None else "All", count_resolution(select)[0],
str(round(count_resolution(select)[1]*100, 2))+"%", amp_noise + '%', phase_noise + '%')
def summarise(results):
print("Summary")
print("Harmonics\tResolution\tCoverage\tAmp Noise\tPhi Noise")
for res in results:
print(*res, sep="\t")
count_resolution("10-30")
selects = []
for i in [0,1,3,4,10,20,25,30,40,50]:
selects.append("0-"+str(i))
results = []
for select in selects:
results.append(experiment("func.txt", select, 0, 0))
summarise(results)
Для гармоник 0-25
select = "0-25"
amp_noises = [5,10,20,30]
results = []
for noise in amp_noises:
results.append(experiment("func.txt", select, noise, 0))
summarise(results)
select = "0-25"
phi_noises = [5,10,20,30]
results = []
for noise in phi_noises:
results.append(experiment("func.txt", select, 0, noise))
summarise(results)
select = "0-25"
comb_noise = [5,10,20,30]
results = []
for noise in comb_noise:
results.append(experiment("func.txt", select, noise, noise))
summarise(results)
Для гармоник 0-30
select = "0-30"
amp_noises = [5,10,20,30]
results = []
for noise in amp_noises:
results.append(experiment("func.txt", select, noise, 0))
summarise(results)
select = "0-30"
phi_noises = [5,10,20,30]
results = []
for noise in phi_noises:
results.append(experiment("func.txt", select, 0, noise))
summarise(results)
select = "0-30"
comb_noise = [5,10,20,30]
results = []
for noise in comb_noise:
results.append(experiment("func.txt", select, noise, noise))
summarise(results)
selects = ["1-30","2-30","5-30","0-3,5-30","0-14,16-30","0-27,29-30", "0-10,20-30", "0-8,10-19,21-25,27-30"]
results = []
for select in selects:
results.append(experiment("func.txt", select, 0, 0))
summarise(results)
Добавим шум к некоторым неполным наборам гармоник
selects = ["0-8,10-19,21-25,27-30"]
noises = [5,20]
results = []
for select in selects:
for noise in noises:
results.append(experiment("func.txt", select, noise, noise))
summarise(results)