Exemplo n.º 1
0
            if pos == smaller:
                new_data.append(data[smaller])
            else:
                # smaller == pos 인 경우 smaller == larger 이니까 이렇게 else를 larger = smaller + 1 으로
                larger = smaller + 1
                slope = data[larger] - data[smaller]
                new_data.append(data[smaller] + slope * (pos - smaller))

    new_data.append(data[peaks[-1]])
    return new_data


if __name__ == '__main__':
    inflation, unemployment = load_data()
    # why not use mark real peaks, remove ambiguous peaks?
    mod_inf, peak_inf = PeakAnalysis.find_peak(inflation, 0.6)
    mod_une, peak_une = PeakAnalysis.find_peak(unemployment, 0.7)

    matched = match_peaks(mod_inf, peak_inf, mod_une, peak_une)

    interpolated_inf = interpolate_peaks(mod_inf,
                                         list(map(lambda t: t[0], matched)))
    interpolated_une = interpolate_peaks(mod_une,
                                         list(map(lambda t: t[1], matched)))

    assert (len(interpolated_inf) == len(interpolated_une))

    # with EXPRESSION as NAME:
    with open('interpolated_data.csv', 'w') as f:
        for idx in range(len(interpolated_inf)):
            f.write(