Example #1
0
def main():
    months = [
        'January', 'February', 'March', 'April', 'May', 'June', 'July',
        'August', 'September', 'October', 'November', 'December'
    ]
    while True:
        year_of_birth = input('Enter year of birth, or press enter to exit: ')
        if not year_of_birth:
            break

        try:
            year_of_birth = int(year_of_birth)
        except ValueError:
            print('Invalid input.')
            continue

        if year_of_birth >= 1900 and year_of_birth <= 2020:
            while True:
                try:
                    month_of_birth = int(input('Enter month of birth: '))
                    if month_of_birth not in range(1, 13):
                        raise ValueError
                    break
                except ValueError:
                    print('Invalid input.')

            ssa = SSA(year_of_birth, month_of_birth)
            retirement_age, retirement_age_months = ssa.calculate_retirement_age(
            )
            retirement_year, retirement_month = ssa.calculate_retirement_date()
            print(
                f'Your full retirement age is {retirement_age} and {retirement_age_months} months\nThis will be in {months[retirement_month-1]} of {retirement_year}'
            )
        else:
            print(
                'Year of birth must be 1900 or greater, up to the current year.'
            )
            continue
Example #2
0
from ssa import SSA
# Loading the monthly runoff of Huaxian station
huaxian = pd.read_excel(root_path +
                        '/time_series/HuaxianRunoff1951-2018(1953-2018).xlsx')
huaxian = huaxian['MonthlyRunoff'][24:
                                   576]  #from 1953/01 to 1998/12, 552 samples
# plotting the data
plt.figure()
huaxian.plot()
plt.xlabel("Time(1953/01-1998/12)")
plt.ylabel(r"Runoff($m^3/s$)")

#%%
# Decomposing the monthly Runoff of huaxian With SSA
window = 12
huaxian_ssa = SSA(huaxian, window)
plt.figure()
huaxian_ssa.plot_wcorr()
plt.title("W-Correlation for monthly Runoff of Huaxian")
plt.tight_layout()

#%%
# Of course, with a larger windown length (and therefore a large number
# of elementary components), such a view of the w-correlation matrix is
# not the most helpful. Zoom into the w-correlation matrix for the first
# 50 components
print("corr:\n{}".format(huaxian_ssa.calc_wcorr()))
plt.figure(figsize=(5.51, 5))
huaxian_ssa.plot_wcorr(max=11)
plt.title("W-Correlation for the monthly Runoff of Huaxian", fontsize=10)
plt.subplots_adjust(left=0.12,
Example #3
0
def calculator(birthyear, birthmonth):
    return SSA(birthyear, birthmonth)
Example #4
0
    'Periodic1',  #F1
    'Periodic2',  #F2
    'Periodic3',  #F3
    'Periodic4',  #F4
    'Periodic5',  #F5
    'Periodic6',  #F6
    'Periodic7',  #F7
    'Periodic8',  #F8
    'Periodic9',  #F9
    'Periodic10',  #F10
    'Noise',  #F11
]

#%%
# Decompose the entire monthly runoff of HuaXian
HuaXian_ssa = SSA(full, window)
F0 = HuaXian_ssa.reconstruct(0)
F1 = HuaXian_ssa.reconstruct(1)
F2 = HuaXian_ssa.reconstruct(2)
F3 = HuaXian_ssa.reconstruct(3)
F4 = HuaXian_ssa.reconstruct(4)
F5 = HuaXian_ssa.reconstruct(5)
F6 = HuaXian_ssa.reconstruct(6)
F7 = HuaXian_ssa.reconstruct(7)
F8 = HuaXian_ssa.reconstruct(8)
F9 = HuaXian_ssa.reconstruct(9)
F10 = HuaXian_ssa.reconstruct(10)
F11 = HuaXian_ssa.reconstruct(11)
orig_TS = HuaXian_ssa.orig_TS
df = pd.concat([orig_TS, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11],
               axis=1)
Example #5
0
plt.xlim(-0.5, 6.5)
plt.ylim(6.5, -0.5)
plt.clim(0, 1)
plt.title("The W-Correlation Matrix for Components 0-6")

#%%
import os
root_path = os.path.dirname(os.path.abspath('__file__'))
parent_path = os.path.abspath(os.path.join(root_path, os.path.pardir))
grandpa_path = os.path.abspath(os.path.join(parent_path, os.path.pardir))
data_path = parent_path + '\\data\\'

import sys
sys.path.append(grandpa_path + '/tools/')
from ssa import SSA
F_ssa_L2 = SSA(F, 2)
F_ssa_L2.components_to_df().plot()
F_ssa_L2.orig_TS.plot(alpha=0.4)
plt.xlabel("$t$")
plt.ylabel(r"$\tilde{F}_i(t)$")
plt.title(r"$L=2$ for the Toy Time Series")

#%%
F_ssa_L5 = SSA(F, 5)
F_ssa_L5.components_to_df().plot()
F_ssa_L5.orig_TS.plot(alpha=0.4)
plt.xlabel("$t$")
plt.ylabel(r"$\tilde{F}_i(t)$")
plt.title(r"$L=5$ for the Toy Time Series")

#%%
    'Periodic1',  #F1
    'Periodic2',  #F2
    'Periodic3',  #F3
    'Periodic4',  #F4
    'Periodic5',  #F5
    'Periodic6',  #F6
    'Periodic7',  #F7
    'Periodic8',  #F8
    'Periodic9',  #F9
    'Periodic10',  #F10
    'Noise',  #F11
]

#%%
# Decompose the entire monthly runoff of huaxian
huaxian_ssa = SSA(full, window)
F0 = huaxian_ssa.reconstruct(0)
F1 = huaxian_ssa.reconstruct(1)
F2 = huaxian_ssa.reconstruct(2)
F3 = huaxian_ssa.reconstruct(3)
F4 = huaxian_ssa.reconstruct(4)
F5 = huaxian_ssa.reconstruct(5)
F6 = huaxian_ssa.reconstruct(6)
F7 = huaxian_ssa.reconstruct(7)
F8 = huaxian_ssa.reconstruct(8)
F9 = huaxian_ssa.reconstruct(9)
F10 = huaxian_ssa.reconstruct(10)
F11 = huaxian_ssa.reconstruct(11)
orig_TS = huaxian_ssa.orig_TS
df = pd.concat([orig_TS, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11],
               axis=1)
Example #7
0
from ssa import SSA

from pystan import stan

# Test 1 : Generate long path with SSA
# and then recover the parameters with
# STAN. This should fail.

# x holds the path
# t holds the time steps

N = 1000
alpha = 1.0
mu = 10

x, t = SSA(100, N, a=alpha, mu=mu)

x = x.astype(int)  # path data supposed to be integers.

path_data = {'N': N, 't': t, 'x': x}

# Setup STAN :
model_description = """
data{
  int<lower=0> N; ## number of time steps
  vector[N] t; ## time value at each time step
  int<lower=0> x[N]; ## population value at each time step
}

transformed data{
  int<lower=0> x0; ## starting population value
Example #8
0
T1, T2 = 1.0, 5.0
f1, f2 = 2. * pi / T1, 2. * pi / T2
p1, p2 = 0.1, 0.05
periodic1 = p1 * np.sin(f1 * (X + Y))
periodic2 = p2 * np.sin(f2 * (X + Y))

np.random.seed(123)
noise = 0.01 * np.random.rand(x.size, y.size)

F = trend + periodic1 + periodic2 + noise

lx = 20
ly = 20

f_ssa = SSA(F, (lx, ly))

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X,
                       Y,
                       F,
                       cmap=cm.coolwarm,
                       linewidth=0,
                       antialiased=False)
# customize the z axis
from matplotlib.ticker import LinearLocator, FormatStrFormatter