Esempio n. 1
0
def get_new_g(ws, params):
    np.random.seed(42)
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    return g, shocks
Esempio n. 2
0
    def plot_prio_samples(self, save_fig):
        for f in self.available_prio_samples_files:
            print(f"sample file: {f.name}")
            prio = str(f.name).split("_")[1]
            translated_prio = 0
            if prio == "6":
                scatter_plot_name = f"Priority 0 Samples"
                translated_prio = 0
            if prio == "2":
                scatter_plot_name = f"Priority 2 Samples"
                translated_prio = 2
            if prio == "0":
                scatter_plot_name = f"Priority 1 Samples"
                translated_prio = 1

            fig, (ax1, ax2, ax3) = plt.subplots(3, 1)
            y = []
            x = []
            point_cnt = 0
            with open(f, "r") as input_file:
                line = input_file.readline()
                line = line.strip("\n")
                while len(line)!= 0:
                    line = line.split(",")
                    duration = float(line[0])
                    time_stamp = float(line[1])
                    y.append(duration)
                    x.append(time_stamp)
                    point_cnt +=1
                    line = input_file.readline()
                    line = line.strip("\n")
            
            # scatter plot
            ax1.scatter(x, y,s=0.8, marker='o')
            ax1.set_xlabel(f"Simulation Time(ms)")
            ax1.set_ylabel("Network Transfer time(ms)")
            ax1.set_title(f"{scatter_plot_name}")
            
            # histogram show network transfer time distribution
            ax2.hist(y, bins=40)
            ax2.set_title(f"Priority {translated_prio} Histogram")        
            
            # ecdf 
            e_x, e_y = ecdf(y)
            ax3.scatter(e_x, e_y, s=2**2)
            ax3.set_title(f"Priority {translated_prio} CDF")
            ax3.set_xlabel("Network Transfer time(ms)")

            fig.set_size_inches(12.5, 20.5)
            plt.subplots_adjust(hspace = 0.3)

            if save_fig == False:
                plt.show(block=True)
            else:

                plot_name = pathlib.Path(f).stem
                # curr_date = datetime.now().strftime('%H_%M_%Y_%m_%d')
                fig.savefig(self.log_dir/f"{plot_name}")
Esempio n. 3
0
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out,
                                kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict
Esempio n. 4
0
def get_g(pi, lambda_, period=28):
    """
    Helper function to get to a wage distribution.

    Warning: Will not touch the params in your global state.
    If you go on the to more things make sure to adjust those params.
    """
    import analyze_run as ar
    params = load_params()
    params['pi'] = pi, 'a'
    params['lambda_'] = lambda_, 'b'

    all_files = ar.get_all_files(params)
    wses = ar.read_output(all_files, kind='ws')
    ws = wses[(pi, lambda_)]
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30, seed=42)

    pth, shocks = pths[28], shks[28]
    shocks = np.sort(shocks)
    g = ecdf(np.sort(pth))
    return g, shocks
def get_g(pi, lambda_, period=28):
    """
    Helper function to get to a wage distribution.

    Warning: Will not touch the params in your global state.
    If you go on the to more things make sure to adjust those params.
    """
    import analyze_run as ar
    params = load_params()
    params['pi'] = pi, 'a'
    params['lambda_'] = lambda_, 'b'

    all_files = ar.get_all_files(params)
    wses = ar.read_output(all_files, kind='ws')
    ws = wses[(pi, lambda_)]
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30, seed=42)

    pth, shocks = pths[28], shks[28]
    shocks = np.sort(shocks)
    g = ecdf(np.sort(pth))
    return g, shocks
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out, kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict
Esempio n. 7
0
_ = plt.hist(sol['Velocity'], bins=n_bins)
plt.show()

# ML estimation of distribution parameters

mean = np.mean(sol['Velocity'])
std = np.std(sol['Velocity'])
'''
    Compare w/ true normal
'''
n_samples = 1E4
samples = np.random.normal(mean, std, size=n_samples)
n_bins_samples = int(np.sqrt(n_samples))

x_sol_ecdf, y_sol_ecdf = ecdf.ecdf(sol['Velocity'])
x_samples_ecdf, y_samples_ecdf = ecdf.ecdf(samples)

_ = plt.plot(x_sol_ecdf, y_sol_ecdf, marker='.', linestyle='none')
_ = plt.plot(x_samples_ecdf, y_samples_ecdf, marker='.', linestyle='none')

# Make nice margins
_ = plt.margins(0.02)

# Annotate the plot
plt.legend(("Michelson's data", 'Normal'), loc='lower right')
_ = plt.xlabel('Velocity')
_ = plt.ylabel('ECDF')

# Display the plot
plt.show()
Esempio n. 8
0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from random import randint
from random import random
import math
import seaborn as sns
import itertools as it
import ecdf as ecdf

testData = [
    3, 4, 6, 7, 8, 9, 2, 3, 6, 5, 3, 2, 4, 6, 7, 8, 9, 6, 4, 2, 1, 3, 4, 5, 7,
    8, 6, 7, 8, 9, 9, 8, 7, 6, 6, 7, 8, 9
]

means = [np.mean(testData)]
trials = 1000
for i in range(trials):

    resample = np.random.choice(testData, len(testData))
    resampleMean = np.mean(resample)
    means.append(resampleMean)
print(means)
x, y = ecdf.ecdf(means)
plt.plot(x, y, marker='.', linestyle='none')
plt.show()
Esempio n. 9
0
        1. ,  1.7,  1.9,  1.6,  1.6,  1.5,  1.4,  1.6,  1.6,  1.5,  1.5,
        1.4,  1.5,  1.2,  1.3,  1.5,  1.3,  1.5,  1.3,  1.3,  1.3,  1.6,
        1.9,  1.4,  1.6,  1.4,  1.5,  1.4] 
versicolor_petal_length = [ 4.7,  4.5,  4.9,  4. ,  4.6,  4.5,  4.7,  3.3,  4.6,  3.9,  3.5,
        4.2,  4. ,  4.7,  3.6,  4.4,  4.5,  4.1,  4.5,  3.9,  4.8,  4. ,
        4.9,  4.7,  4.3,  4.4,  4.8,  5. ,  4.5,  3.5,  3.8,  3.7,  3.9,
        5.1,  4.5,  4.5,  4.7,  4.4,  4.1,  4. ,  4.4,  4.6,  4. ,  3.3,
        4.2,  4.2,  4.2,  4.3,  3. ,  4.1]
virginica_petal_length = [ 6. ,  5.1,  5.9,  5.6,  5.8,  6.6,  4.5,  6.3,  5.8,  6.1,  5.1,
        5.3,  5.5,  5. ,  5.1,  5.3,  5.5,  6.7,  6.9,  5. ,  5.7,  4.9,
        6.7,  4.9,  5.7,  6. ,  4.8,  4.9,  5.6,  5.8,  6.1,  6.4,  5.6,
        5.1,  5.6,  6.1,  5.6,  5.5,  4.8,  5.4,  5.6,  5.1,  5.1,  5.9,
        5.7,  5.2,  5. ,  5.2,  5.4,  5.1]

# Compute ECDFs
x_set, y_set = ecdf.ecdf(setosa_petal_length)
x_vers, y_vers = ecdf.ecdf(versicolor_petal_length)
x_virg, y_virg = ecdf.ecdf(virginica_petal_length)

# Plot all ECDFs on the same plot
_ = plt.plot(x_set, y_set, marker='.', linestyle='none')
_ = plt.plot(x_vers, y_vers, marker='.', linestyle='none')
_ = plt.plot(x_virg, y_virg, marker='.', linestyle='none')

# Make nice margins
_ = plt.margins(0.02)

# Annotate the plot
plt.legend(('setosa', 'versicolor', 'virginica'), loc='lower right')
_ = plt.xlabel('petal length (cm)')
_ = plt.ylabel('ECDF')
Esempio n. 10
0
import matplotlib.pyplot as plt
import ecdf
'''
    Show the creation of ECDF plots
'''

versicolor_petal_length = [
    4.7, 4.5, 4.9, 4., 4.6, 4.5, 4.7, 3.3, 4.6, 3.9, 3.5, 4.2, 4., 4.7, 3.6,
    4.4, 4.5, 4.1, 4.5, 3.9, 4.8, 4., 4.9, 4.7, 4.3, 4.4, 4.8, 5., 4.5, 3.5,
    3.8, 3.7, 3.9, 5.1, 4.5, 4.5, 4.7, 4.4, 4.1, 4., 4.4, 4.6, 4., 3.3, 4.2,
    4.2, 4.2, 4.3, 3., 4.1
]

# Compute ECDF for versicolor data: x_vers, y_vers
x_vers, y_vers = ecdf.ecdf(versicolor_petal_length)
print(x_vers)
print(y_vers)

# Generate plot
_ = plt.plot(x_vers, y_vers, marker='.', linestyle='none')

# Make the margins nice
_ = plt.margins(0.02)

# Label the axes
_ = plt.ylabel('ECDF')
_ = plt.xlabel('Iris Versicolor Petal Length [cm]')

# Display the plot
plt.show()
Esempio n. 11
0
tau = np.mean(nohitter_times)

# Draw out of an exponential distribution with parameter tau: inter_nohitter_time
inter_nohitter_time = np.random.exponential(tau, 100000)

# Plot the PDF and label axes
_ = plt.hist(nohitter_times, bins=50, normed=True, histtype='step')
_ = plt.hist(inter_nohitter_time, bins=50, normed=True, histtype='step')
plt.legend(("No hitter times", 'Exponential'), loc='lower right')
_ = plt.xlabel('Games between no-hitters')
_ = plt.ylabel('PDF')

# Show the plot
plt.show()

x_nohitter_times, y_nohitter_times = ecdf.ecdf(nohitter_times)
x_inter_nohitter_time, y_inter_nohitter_time = ecdf.ecdf(inter_nohitter_time)
_ = plt.plot(x_nohitter_times, y_nohitter_times, marker='.', linestyle='none')
_ = plt.plot(x_inter_nohitter_time,
             y_inter_nohitter_time,
             marker='.',
             linestyle='none')
plt.legend(("No hitter times", 'Exponential'), loc='lower right')
_ = plt.xlabel('Games between no-hitters')
_ = plt.ylabel('ECDF')

# Make nice margins
_ = plt.margins(0.02)

plt.show()
'''