Ejemplo n.º 1
0
    def __init__(self,
                 dir_name='/home/steve/Data/FusingLocationData/0010/'):
        if not dir_name[-1] is '/':
            dir_name = dir_name + '/'

        imu_left = np.loadtxt(dir_name + 'LEFT_FOOT.data', delimiter=',')
        imu_right = np.loadtxt(dir_name + 'RIGHT_FOOT.data', delimiter=',')
        imu_head = np.loadtxt(dir_name + 'HEAD.data', delimiter=',')

        uwb_head = np.loadtxt(dir_name + 'uwb_result.csv', delimiter=',')
        beacon_set = np.loadtxt(dir_name + 'beaconSet.csv', delimiter=',')

        print('average time interval of left:',
              float(imu_left[-1, 1] - imu_left[0, 1]) / float(imu_left.shape[0]))
        print('average time interval of right:',
              float(imu_right[-1, 1] - imu_right[0, 1]) / float(imu_right.shape[0]))

        print('average time interval of head:',
              float(imu_head[-1, 1] - imu_head[0, 1]) / float(imu_head.shape[0]))

        plt.figure()
        plt.plot(imu_left[1:, 1] - imu_left[:-1, 1], label='time left')
        plt.plot(imu_right[1:, 1] - imu_right[:-1, 1], label='time right')
        # time_diff = imu_left[1:,1] - imu_left[:-1,1]
        # plt.plot(time_diff-time_diff.mean(),label='time diff')
        plt.plot(imu_head[1:, 1] - imu_head[:-1, 1], label=' time head')

        plt.grid()
        plt.legend()
        plt.show()
def plot_histogram(entries):
    n, bins, patches = plt.hist(entries.values(), 50, normed=1, facecolor='green', alpha=0.75)

    plt.xlabel('Time (h)')
    plt.ylabel('Probability')
    plt.grid(True)
    plt.show()
Ejemplo n.º 3
0
def plot_events(real, pred, real_, pred_, label=None):
    from matplotlib.pylab import plt
    import random
    fig, ax = plt.subplots(figsize=(10, 2))
    ax.set_title(label)
    plt.xlim(0, max(real[-1][1], 10))
    ax.set_xticks(np.arange(0, max(real[-1][1], 10), .1), minor=True)
    maxsize = 20
    for i in range(min(maxsize, len(pred_))):
        d = pred_[i]
        plt.axvspan(d[0],
                    d[1],
                    0,
                    0.4,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='m',
                    alpha=.6)

    for i in range(min(maxsize, len(pred))):
        d = pred[i]
        plt.axvspan(d[0],
                    d[1],
                    0.1,
                    0.5,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='r',
                    alpha=.6)


#     maxsize=len(real)
    for i in range(min(maxsize, len(real_))):
        gt = real_[i]
        plt.axvspan(gt[0],
                    gt[1],
                    0.6,
                    1,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='y',
                    alpha=.6)

    for i in range(min(maxsize, len(real))):
        gt = real[i]
        plt.axvspan(gt[0],
                    gt[1],
                    0.5,
                    .9,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='g',
                    alpha=.6)
    plt.grid(True)
    plt.minorticks_on()
    plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2)
Ejemplo n.º 4
0
def plot_histogram(entries):
    n, bins, patches = plt.hist(entries.values(),
                                50,
                                normed=1,
                                facecolor='green',
                                alpha=0.75)

    plt.xlabel('Time (h)')
    plt.ylabel('Probability')
    plt.grid(True)
    plt.show()
Ejemplo n.º 5
0
def plot_score_dist(spacing, std_along, prob_miss, max_distance):
    from matplotlib.pylab import plt
    plt.close("Score Dist")
    plt.figure("Score Dist")
    d = np.linspace(0, max_distance, 500)
    plt.plot(d, [score_dist(di, spacing, std_along, prob_miss) for di in d])
    plt.vlines(spacing, 0, 1)
    plt.vlines(spacing * 2, 0, 1, ls='--')
    plt.annotate("Miss-detect the next mine", (spacing * 2, 0.5), (12, 0),
                 textcoords='offset points')
    plt.ylabel('$p(d)$')
    plt.xlabel('$d$')
    plt.grid()
    plt.xticks(np.arange(max_distance))
    plt.xlim(0, max_distance)
    plt.savefig('score_dist.pdf')
Ejemplo n.º 6
0
 def saveMagPhasePlot(self, t, x, filename):
     mag = absolute(x).astype('float')
     phase = angle(x).astype('float')
     
     plt.subplot(211)
     plt.plot(t, mag)
     plt.ylabel('Magitude')
     plt.title('SSPF Sequence')
     plt.grid(True)
     
     plt.subplot(212)
     plt.plot(t, phase)
     plt.xlabel('Off-Resonance (Hz)')
     plt.ylabel('Phase')
     plt.grid(True)
     plt.savefig(filename)
Ejemplo n.º 7
0
    def showMagPhasePlot(self, t, x):
        mag = absolute(x)
        phase = angle(x)
    
        plt.subplot(211)
        plt.plot(t, mag)
        plt.ylabel('Magitude')
        plt.title('SSPF Sequence')
        plt.grid(True)

        plt.subplot(212)
        plt.plot(t, phase)
        plt.xlabel('Off-Resonance (Hz)')
        plt.ylabel('Phase')
        plt.grid(True)
        plt.show()
    the_best_models.append(the_best_model[0])
    final_scores.append(best_model.score(X_test[models_features[i]],X_test[models_response[i]]))
    best_mse.append(the_mse[0])

for i in range(len(models_features)):
    print("Log10_"+models_response[i] + " ~ " + "Log10_"+" + Log10_".join(models_features[i]),"\t",final_scores[i],best_mse[i])

from sklearn.learning_curve import learning_curve

train_sizes, train_scores, test_scores = learning_curve(model,X,y,train_sizes=np.logspace(-3,0,100))

train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()

plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                 train_scores_mean + train_scores_std, alpha=0.1,
                 color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                 test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, '-', color="r",
         label="Training score")
plt.plot(train_sizes, test_scores_mean, '-', color="g",
         label="Cross-validation score")
plt.ylim(0,1.2)
plt.xlim(0,200)
plt.legend(loc="best")
plt.xlabel("Train test size")
plt.savefig("learning_curves.png")
Ejemplo n.º 9
0
def textual_update_analysis(
    df: pd.DataFrame, extra_columns: List
) -> Tuple[Dict[str, str], List[Dict[str, Union[str, float]]]]:
    template_vars: Dict[str, Any] = {}
    summary = []
    df = df.rename(columns={'date': 'ds', 'search_downloads': 'y'})
    if 'asa' in df.columns:
        df['y'] = df['y'] - df['asa']
    df.index = df['ds']

    df = handle_outliers(df)

    if options.weekly:
        df = df.resample('W').apply(safe_mean)

    time_regressors = []
    for _, row in df.iterrows():
        if row['update'] == 'textual' or row['update'] == 'all':
            additional_regressor = '{} (text)'.format(
                str(row['ds']).split(" ")[0])
            df[additional_regressor] = [
                other_row['y'] if other_row['ds'] >= row['ds'] else 0
                for _, other_row in df.iterrows()
            ]
            time_regressors.append(additional_regressor)

    seasonality_scale = df['y'].std(
    ) if options.seasonality_scale == 0 else options.seasonality_scale
    model = create_model('sherlock_textual', df, seasonality_scale, True,
                         time_regressors + extra_columns)

    model.fit(10000 if options.sampler == 'metropolis' else 2000,
              method=Sampler.METROPOLIS
              if options.sampler == 'metropolis' else Sampler.NUTS,
              step_kwargs={'compute_convergence_checks': False}
              if options.sampler == 'metropolis' else {})

    fig = plot_nowcast(model, [
        row['ds'] for _, row in df.iterrows()
        if row['update'] == 'textual' or row['update'] == 'all'
    ])
    plt.title('Downloads & Textual Updates')
    template_vars['textual_model'] = figure_to_base64(fig)

    summary.extend(
        summary_from_model_regressors(model, time_regressors + extra_columns))

    extra_regressors_plots: List[Dict[str, str]] = []
    for i in range(len(time_regressors),
                   len(time_regressors) + len(extra_columns)):
        fig = plt.figure()
        plt.grid()
        plt.hist(model.trace['regressors_{}'.format(model.name)][:, i] * 100,
                 bins=30,
                 alpha=0.8,
                 histtype='stepfilled',
                 density=True)
        plt.axvline(
            np.median(model.trace['regressors_{}'.format(model.name)][:, i]) *
            100,
            color="C3",
            lw=1,
            ls="dotted")
        plt.title("{} (in %)".format(extra_columns[i - len(time_regressors)]))
        extra_regressors_plots.append({
            'name':
            extra_columns[i - len(time_regressors)],
            'img_data':
            figure_to_base64(fig)
        })

    template_vars['extra_regressors_plots'] = extra_regressors_plots

    seasonality = {}
    for period, fig in plot_seasonality(model,
                                        alpha=options.alpha,
                                        plot_kwargs={}).items():
        seasonality[int(period)] = figure_to_base64(fig)
    template_vars['textual_seasonality'] = seasonality

    return template_vars, summary
Ejemplo n.º 10
0
import numpy as np
from matplotlib.pylab import plt


fig, ax = plt.subplots()
plt.legend()
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
plt.grid()
plt.ylim(-4.5,4.5)
plt.xlim(-5.5,5.5)
ax.xaxis.set_ticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
plt.show()