def bootstrap():
  parser = ArgumentParser(description='Compiler arguments.')
  parser.add_argument('file_names', metavar='File Names', type=str, nargs='+',
                      help='name of the input files.')
  parser.add_argument('-d', '--debug', action='store_true',
                      help='Enable debug logging to the console.')
  parser.add_argument('-t', '--trace', metavar="Trace Mode", type=str,
                      nargs='?', const=True,
                      help='Enable trace mode for optimizations.')
  parser.add_argument('-o', '--optimized', metavar="Optimized", type=str,
                      nargs='?', const=True,
                      help='Generates the optimized output.')
  parser.add_argument('-g', '--vcg', metavar="VCG", type=str,
                      nargs='?', const=True,
                      help='Generate the Visualization Compiler Graph output.')
  args = parser.parse_args()

  if args.debug:
    LOGGER.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    LOGGER.addHandler(ch)

  try:
    p = Parser(args.file_names[0])
    ir = IntermediateRepresentation(p)

    ir.generate()
    cfg = ir.build_cfg()
    cfg.compute_dominance_frontiers()

    ssa = SSA(ir, cfg)
    ssa.construct()

    optimize = Optimize(ssa)
    optimize.optimize()

    if args.optimized:
      external_file = isinstance(args.optimized, str)
      optimized_file = open(args.optimized, 'w') if external_file \
          else sys.stdout
      optimized_file.write('\n'.join([str(s) for s in ssa.optimized()]))
      if external_file:
        optimized_file.close()

    if args.vcg:
      vcg_file = open(args.vcg, 'w') if isinstance(args.vcg, str) else \
          sys.stdout
      vcg_file.write(ssa.ssa_cfg.generate_vcg())
      vcg_file.close()

    return ssa

  except LanguageSyntaxError, e:
    print e
    sys.exit(1)
def cell_cycle_sim(time):
    exp_time = 0
    sim = SSA(gnxp_reactions,init_state)
    while exp_time < time:
        exp_time += replication_time
        sim.run(exp_time) # run until exp_time
        new_state = [rbinom(n,division_prob) if n > 0 else 0
                     for n in sim.state]
        sim.state = new_state
        print exp_time
    return sim
Beispiel #3
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
Beispiel #4
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,
Beispiel #5
0
from ssa import SSA

kr = 1/100.0
gr = 10**4
kp = 500 * gr
gp = 6.79 #approx H_500 (harmonic number)
k3 = 10**6
gnxp_reactions = [((1,0,0),kr), #mRNA production
                  ((-1,0,0),gr), #mRNA degradation
                  ((-1,0,1),kp), #protein complex formation
                  ((1,1,-1),k3), #protein formation we do things this way
                  #to pack everything into mass action kinetics
                  ((0,-1,0),gp), #protein degradation
                  ]
init_state = (0,0,0)
gnxp_sim = SSA(gnxp_reactions,init_state)
gnxp_sim.verbose = True
gnxp_sim.run(1000)

print "loaded"
Beispiel #6
0
def calculator(birthyear, birthmonth):
    return SSA(birthyear, birthmonth)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #10
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
Beispiel #11
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