def plot():
    plt.figure(figsize=(20, 10))
    width = 0.5
    index = np.arange(26)

    print 'SUM PLOT 1', sum(row[0] for row in data)
    print 'SUM PLOT 2', sum(row[1] for row in data)
    print 'SUM PLOT 3', sum(row[2] for row in data)

    print data[0]
    
    p0 = plt.bar(index, data[0], width, color='y')  # people
    p1 = plt.bar(index, data[1], width, color='g')  # nature
    p2 = plt.bar(index, data[2], width, color='r')  # activity
    p3 = plt.bar(index, data[3], width, color='b')  # food
    p4 = plt.bar(index, data[4], width, color='c')  # symbols
    p5 = plt.bar(index, data[5], width, color='m')  # objects
    p6 = plt.bar(index, data[6], width, color='k')  # flags
    p7 = plt.bar(index, data[7], width, color='w')  # uncategorized


    plt.ylabel('Usage')
    plt.title('Emoji category usage per city')
    plt.xticks(index + width/2.0, cities)
    plt.yticks(np.arange(0, 1, 0.1))
    plt.legend((p0[0], p1[0], p2[0], p3[0], p4[0], p5[0], p6[0], p7[0]), categories_names)

    plt.show()
예제 #2
0
def plot_single(df_metrics):
    """
    APFD plot for single Embedding Neural Network model
    :param df_metrics:
    :return:
    """
    apfd = df_metrics['apfd']

    miu = np.round(np.mean(apfd), 2)
    sigma = np.round(np.std(apfd), 2)
    label = 'regression' + '\n $\mu$ - ' + str(miu) + ' $\sigma$ - ' + str(
        sigma)

    sns.distplot(apfd,
                 kde=True,
                 bins=int(180 / 5),
                 color=sns.color_palette()[0],
                 hist_kws={'edgecolor': 'black'},
                 kde_kws={
                     'linewidth': 4,
                     'clip': (0.0, 1.0)
                 },
                 label=label)

    plt.legend(frameon=True, loc='upper left', prop={'size': 20})
    plt.xlabel('APFD')

    #plt.title('APFD Distribution - 100 revisions ')
    plt.show()
예제 #3
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """

        # plot data
        plt.subplot(121)
        plt.plot(self.tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne,yne = self._smooth( self.tn_it, self.tn_err, w )
        xte,yte = self._smooth( self.tt_it, self.tt_err, w )
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration'), plt.ylabel('cost energy')

        plt.subplot(122)
        plt.plot(self.tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth( self.tn_it, self.tn_cls, w )
        xtc, ytc = self._smooth( self.tt_it, self.tt_cls, w )
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration'), plt.ylabel( 'classification error' )
        plt.legend()
        plt.show()
        return
예제 #4
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """

        # plot data
        plt.subplot(121)
        plt.plot(self.tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne, yne = self._smooth(self.tn_it, self.tn_err, w)
        xte, yte = self._smooth(self.tt_it, self.tt_err, w)
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration'), plt.ylabel('cost energy')

        plt.subplot(122)
        plt.plot(self.tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth(self.tn_it, self.tn_cls, w)
        xtc, ytc = self._smooth(self.tt_it, self.tt_cls, w)
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration'), plt.ylabel('classification error')
        plt.legend()
        plt.show()
        return
예제 #5
0
def AddRegressor():
    rng = np.random.RandomState(1)  # 和random_state的用法一致   在这可以固定生成的随机数
    x = np.sort(5 * rng.rand(80, 1),
                axis=0)  # rng.rand(80,1)  生成80行1列的随机数 乘以5就是生成0-5的随机数
    y = np.sin(x).ravel()  # ravel()降维
    y[::5] += 0.3 * (0.5 - rng.rand(16))

    # plt.show()
    reg1 = tree.DecisionTreeRegressor(max_depth=2)
    reg2 = tree.DecisionTreeRegressor(max_depth=5)
    reg1.fit(x, y)
    reg2.fit(x, y)

    test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis]
    y1 = reg1.predict(test)
    y2 = reg2.predict(test)
    #plt.figure()
    plt.figure()
    plt.scatter(x, y, label='dian')
    plt.plot(test, y1, color='red', label='max_depth=2')
    plt.plot(test, y2, color='yellow', label="max_depth=5")
    plt.xlabel('data')
    plt.ylabel('target')
    plt.legend(loc='upper right')
    plt.show()
예제 #6
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()
예제 #7
0
def plotting(sim_context1,sim_context2,diff,data_df,total_samples):

    plt.plot(sim_context1,label="Context 1")
    plt.plot(sim_context2,label="Context 2")


    x_labels_word1 = data_df["word1"]
    x_labels_word2 = data_df["word2"]

    xlabels = [0] * total_samples
    xticks_x = [0] * total_samples


    for wp in range (total_samples):
        xlabels[wp] = x_labels_word1[wp]+ "\n"+x_labels_word2[wp]
        xticks_x[wp] = wp+1

    plt.plot(diff,label="Difference")

    plt.legend(loc='center right')

    # Add title and x, y labels
    plt.title("Elmo Embedding Model Results", fontsize=16, fontweight='bold')

    plt.xlabel("Word")
    plt.ylabel("Similarity")

    plt.xticks(xticks_x, xlabels)
    plt.show()
def plot_first_factors(X_data, y_data, analysis_type="lda"):
    """Generate scatterplot of two principal components (pca or lda) of data set."""
    le = preprocessing.LabelEncoder()
    le.fit(y_data)
    colours = [
        'blue', 'green', 'red', 'cyan', 'magenta', 'yellow', 'darkgreen',
        'darkorange', 'yellow', 'black'
    ]
    if analysis_type == "pca":
        transform = PCA(n_components=2)
        XX_data = transform.fit(X_data).transform(X_data)
    elif analysis_type == "lda":
        transform = LinearDiscriminantAnalysis(n_components=2)
        XX_data = transform.fit(X_data, y_data).transform(X_data)
    else:
        print("Type", analysis_type,
              "not recognised, use either 'pca' or 'lda'.")
        return
    plt.figure()
    for i, j in enumerate(le.classes_):
        plt.scatter(XX_data[y_data == j, 0],
                    XX_data[y_data == j, 1],
                    alpha=0.8,
                    color=colours[i],
                    label=str(j))
    plt.legend(loc='best', shadow=False, scatterpoints=1)
    plt.title(analysis_type)
def graph(train_df, test_df, p_forecast, f_forecast, metric, key):
	fig = plt.figure(figsize=(40,10))
	forecast_ds = np.array(f_forecast["ds"])
	print(len(forecast_ds))
	print(len(train_df))
	forecast_ds = forecast_ds[int(train_df["values"].count()):]


	plt.plot(np.array(train_df["ds"]), np.array(train_df["y"]),'b', label="train", linewidth=3)
	plt.plot(np.array(test_df["ds"]), np.array(test_df["y"]), 'k', label="test", linewidth=3)

	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_raw_" + metric + ".png", transparent=True)
	prophet = np.array(p_forecast["yhat"])
	prophet_upper = np.array(p_forecast["yhat_upper"])
	prophet_lower = np.array(p_forecast["yhat_lower"])

	fourier = f_forecast["yhat"]
	fourier = fourier[len(train_df["values"]):]
	print(len(forecast_ds))
	print(len(fourier))
	plt.plot(forecast_ds, fourier, 'g', label="fourier_yhat", linewidth=3)
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_fourier_" + metric + ".png", transparent=True)

	prophet = prophet[len(train_df["values"]):]
	prophet_upper = prophet_upper[len(train_df["values"]):]
	prophet_lower = prophet_lower[len(train_df["values"]):]
	plt.plot(forecast_ds, prophet, '*y', label="prophet_yhat", linewidth=3)
	plt.plot(forecast_ds, prophet_upper, 'y', label="yhat_upper", linewidth=3)
	plt.plot(forecast_ds, prophet_lower, 'y', label="yhat_lower", linewidth=3)
	
	
	plt.plot()
	plt.xlabel("Timestamp")
	plt.ylabel("Value")
	plt.legend(loc=1)
	plt.title("Prophet Model Forecast")
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_compare_" + metric + ".png", transparent=True)
	plt.close()


	fig = plt.figure(figsize=(40,10))
	forecast_ds = np.array(f_forecast["ds"])
	forecast_ds = forecast_ds[len(train_df["values"]):]


	plt.plot(np.array(train_df["ds"]), np.array(train_df["y"]),'b', label="train", linewidth=3)
	plt.plot(np.array(test_df["ds"]), np.array(test_df["y"]), 'k', label="test", linewidth=3)

	prophet = np.array(p_forecast["yhat"])
	prophet_upper = np.array(p_forecast["yhat_upper"])
	prophet_lower = np.array(p_forecast["yhat_lower"])
	prophet = prophet[len(train_df["values"]):]
	prophet_upper = prophet_upper[len(train_df["values"]):]
	prophet_lower = prophet_lower[len(train_df["values"]):]
	plt.plot(forecast_ds, prophet, '*y', label="prophet_yhat", linewidth=3)
	plt.plot(forecast_ds, prophet_upper, 'y', label="yhat_upper", linewidth=3)
	plt.plot(forecast_ds, prophet_lower, 'y', label="yhat_lower", linewidth=3)
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_prophet_" + metric + ".png", transparent=True)
	plt.close()
예제 #10
0
 def plot_error(self, train_errors):
     n = len(train_errors)
     training, = plt.plot(range(n), train_errors, label="Training Error")
     plt.legend(handles=[training])
     plt.title("Error Plot")
     plt.ylabel('Error')
     plt.xlabel('Iterations')
     plt.show()
예제 #11
0
 def plot_accuracy(self, train_acc, test_acc):
     n = len(train_acc)
     plt.plot(range(n), train_acc, label="train")
     plt.plot(range(n), test_acc, label="test")
     plt.legend(loc='lower right')
     plt.title("Overfit")
     plt.ylabel('accuracy')
     plt.xlabel('epoch')
     plt.show()
예제 #12
0
def pretty_plot_metrics(name, data):
    plt.plot(data['labeled_acc'], '-', color='b', label='Labeled Accuracy')
    plt.plot(data['labeled_loss'], ':', color='b', label='Labeled Loss')
    plt.plot(data['unlabeled_acc'],
             '-',
             color='r',
             label='Unsupervised Accuracy')
    plt.plot(data['unlabeled_loss'], ':', color='r', label='Unsupervised Loss')
    plt.legend()
    plt.savefig(name + '.png')
def multiplot_gen_property_type():
    #
    # font = {'family': 'Liberation Serif',
    #         'weight': 'normal',
    #         'size': 15
    #         }
    #
    # # play around with the font size if it is too big or small
    # matplotlib.rcParams['axes.titlesize'] = 12
    # matplotlib.rcParams['axes.labelsize'] = 12
    # matplotlib.rc('font', **font)
    # # matplotlib.rcParams['text.usetex'] = True
    # matplotlib.rcParams['pdf.fonttype'] = 42
    # matplotlib.rcParams['pdf.use14corefonts'] = True

    x = list(data.keys())

    y1=[]
    y2=[]
    y3=[]
    y4=[]
    y5=[]
    y6=[]
    
    for year in data.keys():
        for option_name, count in data[year].items():
            if option_name == 'domain':
                y1.append(count)
            if option_name == 'sitekey':
                y2.append(count)
            if option_name == 'third-party':
                y3.append(count)
            if option_name == 'websocket':
                y4.append(count)
            if option_name == 'webrtc':
                y5.append(count)
            if option_name == 'csp':
                y6.append(count)
    
                   
    plt.plot(x, y1,'-o',label='domain')
    plt.plot(x, y2,'-v',label='sitekey')
    plt.plot(x, y3,'-^',label='third-party')
    plt.plot(x, y4,'-<',label='websocket')
    plt.plot(x, y5,'->',label='webrtc')
    plt.plot(x, y6,'-1',label='csp')

    plt.xticks(rotation='vertical')
    plt.xlabel('Year')
    plt.ylabel('Count')

    plt.legend(ncol=2)

    plt.tight_layout()
    plt.savefig('easylist-property-type.pdf ', format='pdf', dpi=1200)
    def convergence_plots(self):
        obj_value_plot = []
        obj_value_DIFT_plot = []
        obj_value_APT_plot = []
        iteration_number = []

        t_sim_avg_reward = 1000
        avergae_value_DIFT = []
        avergae_value_APT = []
        average_reward_DIFT = []
        average_reward_APT = []

        for tt in range(0, self.t_sim, 500):
            Eval_Func_Obj = Eval_and_Plots(
                self.Policy_Data, tt, self.N_ss, self.stage_ID,
                self.ss_entry_dest, self.CD, self.APT_win, self.APT_drop,
                self.DIFT_win, self.DIFT_lose, self.trap_set,
                self.state_transition_matrix, self.FN, self.s0, self.V_Data)
            Output_Data_average_reward = Eval_Func_Obj.find_average_reward(
                t_sim_avg_reward)
            rho_Data = []

            rho_Data.append(Output_Data_average_reward[0][t_sim_avg_reward -
                                                          1])
            rho_Data.append(Output_Data_average_reward[1][t_sim_avg_reward -
                                                          1])

            average_reward_DIFT.append(
                Output_Data_average_reward[0][t_sim_avg_reward - 1])
            average_reward_APT.append(
                Output_Data_average_reward[1][t_sim_avg_reward - 1])
            #Caculating the avrage value
            avergae_value_DIFT.append(mean(self.V_Data[tt][0]))
            avergae_value_APT.append(mean(self.V_Data[tt][1]))

            Output_Data_obj_evaluate = Eval_Func_Obj.obj_evaluate(rho_Data)
            obj_value_plot.append(Output_Data_obj_evaluate[0])
            obj_value_DIFT_plot.append(Output_Data_obj_evaluate[1])
            obj_value_APT_plot.append(Output_Data_obj_evaluate[2])
            iteration_number.append(tt)

        plt.plot(avergae_value_DIFT)
        plt.plot(avergae_value_APT)
        plt.show()

        plt.plot(average_reward_DIFT)
        plt.plot(average_reward_APT)
        plt.show()

        plt.plot(obj_value_plot, label="Obj")
        plt.plot(obj_value_DIFT_plot, label="DIFT Obj")
        plt.plot(obj_value_APT_plot, label="APT Obj")
        plt.legend(loc='lower left')
        plt.show()
예제 #15
0
    def _build_plot_static(self, metric_group):
        metrics = self.get_metrics_history()
        if metric_group not in metrics:
            raise ValueError("can't find metric group")
        for name, values in metrics[metric_group].items():
            plt.plot(values, label=name)
        plt.legend(loc='best')
        plt.title(metric_group, fontsize=16, fontweight='bold')
        plt.xlabel("Generations")
        plt.show()

        return None
예제 #16
0
 def plot_graph(self, auroc_results, y_label: str):
     for ad_key, ad_label in AD_NAMES.items():
         plt.plot(self.x_axis,
                  numpy.asarray(auroc_results[ad_key], ),
                  label=ad_label)
     plt.legend(loc='lower left')
     plt.xlabel(self.x_axis_label)
     plt.ylabel(ylabel=y_label)
     to_print = plt.gcf()
     plt.show()
     file_name_with_metric = y_label + "-" + self.file_name
     to_print.savefig(file_name_with_metric, bbox_inches='tight')
예제 #17
0
def plot(ranks):
    plt.figure(figsize=(20, 10))
    plt.title("A2.3 PageRank (s-Sensibility)")
    plt.xlabel("Node ID")
    plt.ylabel("Pagerank")
    for row in ranks:
        plt.plot(row)

    plt.legend(['s = %.2f' % s for s in numpy.arange(0.0, 1.0, 0.05)],
               loc='upper right',
               prop={'size': 7})
    plt.savefig("submission/pagerank.png")
예제 #18
0
def update_data(args, show_seconds=20, subsampling=10):

    # load previous
    metadata1 = np.load(os.path.join(args.session1, 'metadata.npy'), allow_pickle=True).item()
    data1 = np.load(os.path.join(args.session1, 'NIdaq.npy'), allow_pickle=True).item()
    t1 = np.arange(len(data1['analog'][0,:]))/metadata1['NIdaq-acquisition-frequency']
    
    metadata2 = np.load(os.path.join(args.session2, 'metadata.npy'), allow_pickle=True).item()
    data2 = np.load(os.path.join(args.session2, 'NIdaq.npy'), allow_pickle=True).item()
    t2 = np.arange(len(data2['analog'][0,:]))/metadata1['NIdaq-acquisition-frequency']


    metadata = np.load(os.path.join(args.session1, 'metadata.npy'), allow_pickle=True).item()
    data = np.load(os.path.join(args.session, 'NIdaq.npy'), allow_pickle=True).item()
    t = np.arange(len(data['analog'][0,:]))/metadata1['NIdaq-acquisition-frequency']

    tstart = np.min([t.max(), t1.max(), t2.max()])-show_seconds # showing the last 5 seconds


    # checking that the two realisations are the same:
    plt.figure(figsize=(7,5))

    plt.plot(t1[t1>tstart][::subsampling],
             data1[args.type][args.channel,t1>tstart][::subsampling], label='session #1')
    
    plt.plot(t2[t2>tstart][::subsampling],
             data2[args.type][args.channel,t2>tstart][::subsampling], label='session #2')

    plt.plot(t[t>tstart][::subsampling],
             data[args.type][args.channel,t>tstart][::subsampling], label='session')
    
    plt.legend()
    plt.show()


    y = input('  /!\ ----------------------- /!\ \n  Confirm that you want to replace\n the "%s" data of channel "%s" in session:\n "%s"\n by the data of session #1 ? [yes/No]' % (args.type, args.channel, args.session))
    if y in ['y', 'Y', 'yes', 'Yes']:
        
        temp = str(tempfile.NamedTemporaryFile().name)+'.npy'
        print("""
        ---> moving the old data to the temporary file directory as: "%s" [...]
        """ % temp)
        shutil.move(os.path.join(args.session, 'NIdaq.npy'), temp)
        print('applying changes [...]')
        data[args.type][args.channel,:] = data1[args.type][args.channel,:len(data[args.type][args.channel,:])]
        np.save(os.path.join(args.session, 'NIdaq.npy'), data)
        print('done !')

    else:
        print('--> data update aborted !! ')
예제 #19
0
def f3():
    xs = [0, 1, 2, 5]
    ys = [0, 0, 1, 1]
    fig, ax = plt.subplots()
    ax.set_yticklabels([])
    ax.set_xticklabels([])
    plt.plot(xs, ys, label="$f_n(x)$")

    plt.xticks(xs, ['', r'$n-1$', r'$n$', ''])
    plt.yticks([1], ['$1$'])

    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')
    ax.axis('equal')
    plt.show()
예제 #20
0
def plt_score(history):
    plt.figure()
    plt.plot()
    plt.plot(history.history['acc'])
    plt.plot(history.history['val_acc'])
    plt.title('model accuracy')
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.savefig('acc.png')
    # loss
    plt.figure()
    plt.plot(history.history['loss'])
    plt.plot(history.history['val_loss'])
    plt.title('model loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.savefig('loss.png')
def update_NIdaq_data(args,
                      window=20,
                      subsampling=100):

    metadata = np.load(os.path.join(args.datafolder, 'metadata.npy'),
                       allow_pickle=True).item()
    
    if os.path.isfile(os.path.join(args.datafolder, 'NIdaq.start.npy')):
        NIdaq_Tstart = np.load(os.path.join(args.datafolder, 'NIdaq.start.npy'))[0]

        NIdaq_Tstart = np.load(os.path.join(args.datafolder, 'NIdaq.start.npy'))[0]
        

    data = np.load(os.path.join(args.datafolder, 'NIdaq.npy'), allow_pickle=True).item()
    t = np.arange(len(data['analog'][0,:]))/float(metadata['NIdaq-acquisition-frequency'])
    
    # checking that the two realisations are the same:
    fig, ax = plt.subplots(1, figsize=(7,5))
    cond = (t>(args.time-window)) & (t<(args.time+window))
    ax.plot(t[cond][::subsampling], data['analog'][0,cond][::subsampling], label='data')
    ax.plot(args.time*np.ones(2), ax.get_ylim(), 'r-', label='reset point')
    plt.legend()
    plt.show()


    y = input('  /!\ ----------------------- /!\ \n  Confirm that you want to remove episodes after the reset point ? [yes/No]\n')
    
    if y in ['y', 'Y', 'yes', 'Yes']:
        
        temp = str(tempfile.NamedTemporaryFile().name)+'.npy'
        print("""
        ---> moving the old data to the temporary file directory as: "%s" [...]
        """ % temp)
        shutil.move(os.path.join(args.datafolder, 'NIdaq.npy'), temp)
        print('applying changes [...]')
        cond = (t>args.time)
        data['analog'][0,cond] = data['analog'][0,cond][0]
        np.save(os.path.join(args.datafolder, 'NIdaq.npy'), data)
        print('done !')

    else:
        print('--> data update aborted !! ')
예제 #22
0
def f4():
    capped_xs = np.linspace(-0.94, 0.8, 1000)
    xs = np.linspace(-1, 1, 1000)
    ys = [1 / (1 - x) for x in capped_xs]

    def getN(N):
        def fN(x):
            total = 0.0
            for i in range(N + 1):
                total += x**i
            return total

        return fN

    yss = []
    for N in range(1, 4):
        fN = getN(N)
        yss.append([fN(x) for x in xs])
    fig, ax = plt.subplots()
    ax.set_yticklabels([])
    ax.set_xticklabels([])
    plt.plot(capped_xs, ys, label=r"$\frac{1}{1-x}$")

    for i, ys in enumerate(yss):
        plt.plot(xs, ys, label="$N={}$".format(i + 1), alpha=0.3)
    plt.plot([1, 1], [0, 5], "k--", alpha=0.3)
    plt.plot(-1,
             0.5,
             'o',
             markerfacecolor='None',
             markeredgecolor='C0',
             markersize=5)
    plt.xticks([-1, 1], ['-1', '1'])

    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')
    ax.axis('equal')
    plt.show()
예제 #23
0
def print_all_results(collected_results, versions, args):
    test_type = args.test_type
    model_name = args.model

    for test_name in collected_results:
        test_results = collected_results[test_name]
        x, y = [], []
        for version in versions:
            if (version in test_results):
                x.append(version)
                y.append(test_results[version]['mean'])
        plt.plot(x, y, label=test_name)

    plt.xticks(np.arange(len(x)), x)
    plt.xlabel(XLABELS[test_type])
    plt.ylabel('average absolute effect size')
    plt.legend(loc='best')
    plt.title("SEAT effect sizes on {} with {}".format(model_name,
                                                       TITLES[test_type]))
    plot_path = os.path.join(args.eval_results_dir, "plots",
                             "{}-{}.png".format(model_name, test_type))
    plt.savefig(plot_path)
예제 #24
0

def exact():
    W = Lea.fastMax(W0 + U, 0)
    for k in range(1, 21):
        if k % 5 == 0:
            plt.plot(W.support(), W.pmf(), label="k={}".format(k))
        W = Lea.fastMax(W + U, 0)
    return W.support(), W.pmf()


plt.figure()
plt.axis([0, 20, 0, 0.3])
plt.title("Exact")
xex, yex = exact()
plt.legend()
tikz_save('waiting_time_1.tex', figureheight='5cm', figurewidth='5cm')
plt.close()

plt.figure()
plt.axis([0, 20, 0, 0.3])
plt.title("Simulation")
xsim, ysim = simulate()
plt.legend()
tikz_save('waiting_time_2.tex', figureheight='5cm', figurewidth='5cm')
plt.close()

plt.figure()
plt.axis([0, 20, 0, 0.3])
plt.title("Sim/Exact")
plt.plot(xsim, ysim, label="sim")
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")
plt.close("all")


# plot the model vs the predictions

for what_plot in [0,1,2,3]:
    fig=plt.figure(figsize=(16,8))
    #
    ax1 = fig.add_subplot(1,2,1); ax2 = fig.add_subplot(1,2,2)
    ax1.tick_params(labelsize=20); ax2.tick_params(labelsize=20)
    #
    if(what_plot==3):
        # actual data
예제 #26
0
import pandas as pd
import numpy as np
from matplotlib.pylab import plt #load plot library


df = pd.read_csv("../data/well_monthly_2017.csv", header=0)

months = range(1, 13)
for well_i in range(1, 18):
    data_i = df[df["well"] == well_i]
    data_i.drop(columns=["month", "well"], inplace=True)

    data = data_i.values.flatten()
    plt.plot(months, data, label="Well " + str(well_i))
    print("well ", well_i)
plt.legend(loc='top left')
plt.xlabel("Month")
plt.ylabel("Pumped Amount 2017")

plt.show()
예제 #27
0
ax[0][2].set_xlabel(r'$v [km s^{-1}]$')
ax[0][2].set_ylabel('(g - i)')
ax[0][2].set_xticks(np.arange(-500, 2600,500))

# - - - - - - - - - - - - - - - - - - - - - - - 
# - - - - - - - - - - - - - - - - - - - - - - - 

x = GCs['R'].copy().sort_values()
y = np.arange(1,len(GCs)+1)
plt.plot(x,y,label='GCs')

x = stars['R'].copy().sort_values()
y = np.arange(1,len(stars)+1)
plt.plot(x,y,label='Stars')

plt.legend()

# - - - - - - - - - - - - - - - - - - - - - - - 
# - - - - - - - - - - - - - - - - - - - - - - - 


mask = (((result['g_auto'] - result['r_auto']) < (0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['r_auto']) > (-0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['i_auto']) > 0.5) & 
        ((result['g_auto'] - result['i_auto']) < 1.3) &
        ((result['i_auto']) < 24))

subset = result[mask]
subset = subset.sample(n=1000)

plt.figure()
예제 #28
0
BergondGCs = Bergond[Bergond['Type'] =='gc']
BergondGCs[['RAJ2000', 'DEJ2000']].to_csv('/Volumes/VINCE/OAC/imaging/BergondGCs_RADEC.reg', index = False, sep =' ', header = None)

cat1 = coords.SkyCoord(GCs['RA_g'], GCs['DEC_g'], unit=(u.degree, u.degree))
cat2 = coords.SkyCoord(BergondGCs['RAJ2000'], BergondGCs['DEJ2000'], unit=(u.degree, u.degree))

index,dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop = True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop = True)
print len(BergondMatch)

x = VIMOS['VREL_helio'] 
xerr = VIMOS['VERR'] 
y = BergondMatch['HRV'] 
yerr = BergondMatch['e_HRV'] 

plt.errorbar(x, y, yerr= yerr, xerr = xerr, fmt = 'o', c ='red',label = 'Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')    
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc = 'upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x-y)
예제 #29
0
index, dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop=True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop=True)
print len(BergondMatch)

x = VIMOS['VREL_helio']
xerr = VIMOS['VERR']
y = BergondMatch['HRV']
yerr = BergondMatch['e_HRV']

plt.errorbar(x,
             y,
             yerr=yerr,
             xerr=xerr,
             fmt='o',
             c='red',
             label='Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x - y)
예제 #30
0
    xdot = [[], []]
    xdot[0] = dy
    xdot[1] = my_func(K, y, dy)
    return xdot


time = np.linspace(a, b, 11)
z2 = odeint(model, [y0, y1], time)
print('Вбудована функція')
print('     y', ' ' * 13, 'z')
print(z2)
# plt.plot(z1['time'],z1['y'],'r-')
# plt.plot(z1['time'],z1['dy'],'b--')
plt.plot(time, z2[:, 0], 'g:')
plt.plot(time, z2[:, 1], 'k-.')
plt.legend(['y (Python)', 'dy/dt (Python)'])
# plt.show()


def getXY(x0, y1, a, b, h):

    # numbers = [int, float]
    #
    # if type(x0) not in numbers or type(y1) not in numbers or type(a) not in numbers or type(b) not in numbers or type(h) not in numbers:
    #     raise TypeError('All input data must be numbers')
    #
    # if x0 < a or x0 > b:
    #     raise ValueError('x0 must be in bounds')
    #
    # if h > b - a:
    #     raise ValueError('step can`t be more than segment')
예제 #31
0
for layername in fclaynms + laynms:
    SV_all[layername] = SgVals[layername]
#%%
#%%
fig, ax = plt.subplots()
colormap = plt.get_cmap('jet')
ax.set_prop_cycle(cycler(color=[colormap(k) for k in np.linspace(0, 1, 12)]))
for layername, SV in SV_all.items():
    print(layername, SV.shape)
    SVnum = np.prod(SV.shape)
    plt.plot(np.arange(SVnum) / SVnum,
             np.sort(SV, axis=None)[::-1])  # np.sort(SV.reshape(-1)))
plt.ylabel("SV")
plt.xlabel("Singular Value Id (Ratio of All SV that layer)")
plt.title("Singular Value per Layer in FC6 GAN")
plt.legend(fclaynms + laynms)
plt.savefig(join(figdir, "SV_per_layer_ratio.png"))
plt.savefig(join(figdir, "SV_per_layer_ratio.pdf"))
plt.show()
#%%
fig, ax = plt.subplots()
colormap = plt.get_cmap('jet')
ax.set_prop_cycle(cycler(color=[colormap(k) for k in np.linspace(0, 1, 12)]))
for layername, SV in SV_all.items():
    print(layername, SV.shape)
    plt.plot(np.sort(SV, axis=None)[::-1])
plt.ylabel("SV")
plt.xlabel("Singular Value Id")
plt.title("Singular Value per Layer in FC6 GAN")
plt.legend(fclaynms + laynms)
plt.savefig(join(figdir, "SV_per_layer.png"))
예제 #32
0
plt.scatter(x2,
            y2,
            color=secondcloudcolor,
            alpha=1,
            marker='+',
            s=60,
            label='second distribution')
plt.scatter(xL, yL, color='k', marker='P', s=135, label='release location')

plt.xlabel('$^{\circ}$E', fontsize=18)
ax.tick_params(labelbottom=False, labelleft=False)
plt.title('(c)', fontsize=18)
plt.xlim(-40, 40)
plt.ylim(-40, 40)

plt.legend(bbox_to_anchor=(1.92, 1.05))

step = 8
xs, ys = np.mgrid[-44:48:step, -44:48:step]
vs = np.ones(xs.shape, dtype=bool)

xss = xs[:, 0]
yss = ys[0]

boxes = []
for i in range(len(x1)):
    nex = find_nearest_index(xss, x1[i])
    ney = find_nearest_index(yss, y1[i])
    if (xss[nex] < x1[i]):
        lbx = xss[nex]
        hbx = xss[nex + 1]
예제 #33
0
    # sample code: remove before submitting  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # process one frame #10
    image_number = 10

    image_file = rf'elephant/image{image_number:03d}.png'
    green_file = rf'green/image{image_number:03d}.png'
    process_file = rf'processed/image{image_number:03d}.png'

    start_time = timeit.default_timer()
    create_new_frame(image_file, green_file, process_file)
    print(
        f'\nTime To Process all images = {timeit.default_timer() - start_time}'
    )
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    log.write(
        f'Total Time for ALL processing: {timeit.default_timer() - all_process_time}'
    )

    # create plot of results and also save it to a PNG file
    plt.plot(xaxis_cpus, yaxis_times, label=f'{FRAME_COUNT}')

    plt.title('CPU Core yaxis_times VS CPUs')
    plt.xlabel('CPU Cores')
    plt.ylabel('Seconds')
    plt.legend(loc='best')

    plt.tight_layout()
    plt.savefig(f'Plot for {FRAME_COUNT} frames.png')
    plt.show()
예제 #34
0
    dfs = {}
    for csv_tuple in csv_paths:
        csv_path, produce_item = csv_tuple
        df = pd.read_csv(csv_path, sep=',', quotechar='"', skiprows=8, header=0, index_col=0)
        df1 = df.loc[2010:]
        dfs[produce_item] = df1
    stacked_dfs = []
    for key in dfs:
        produce_df = dfs[key]
        produce_df_stacked = produce_df.stack()
        stacked_dfs.append(produce_df_stacked)
        produce_df_stacked.plot(kind='bar', color='c')
        title = '{0} CPI'.format(key)
        y_label = '{0} Average Price/lb'.format(key)
        x_label = 'Month'
        plt.title(title)
        plt.ylabel(y_label)
        plt.xlabel(x_label)
        plt.legend(loc='best')
        fig = gcf()
        fig.set_size_inches(18.5, 14.5)
        figure_name = 'plots\\{0}.png'.format(key)
        fig.savefig(figure_name)
    s_df_0 = stacked_dfs[0]
    s_df_0.index.names = ['year', 'month']
    
    # print(s_df_0)
    # s_df_0_2011 = s_df_0.loc[(2011, 'Feb'):(2014, 'Mar')]
    # print(s_df_0_2011)
    
예제 #35
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """
        if len(self.tn_mc) > 0:
            # malis training, increase number of subplots
            nsp = 5
        else:
            nsp = 3

        # print the maximum iteration
        self.print_max_update()

        # using K as iteration unit
        tn_it = self.tn_it
        for i in xrange(len(tn_it)):
            tn_it[i] = tn_it[i] / float(1000)
        tt_it = self.tt_it
        for i in xrange(len(tt_it)):
            tt_it[i] = tt_it[i] / float(1000)

        # plot data
        plt.subplot(1,nsp, 1)
        plt.plot(tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne,yne = self._smooth( tn_it, self.tn_err, w )
        xte,yte = self._smooth( tt_it, self.tt_err, w )
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration (K)'), plt.ylabel('cost energy')

        plt.subplot(1,nsp,2)
        plt.plot(tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth( tn_it, self.tn_cls, w )
        xtc, ytc = self._smooth( tt_it, self.tt_cls, w )
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration (K)'), plt.ylabel( 'classification error' )

        if len(tn_it) == len( self.tn_re ):
            plt.subplot(1, nsp, 3)
            plt.plot(tn_it, self.tn_re, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_re, 'r.', alpha=0.2)
            # plot smoothed line
            xnr, ynr = self._smooth( tn_it, self.tn_re, w )
            xtr, ytr = self._smooth( tt_it, self.tt_re, w )
            plt.plot(xnr, ynr, 'b', label='train')
            plt.plot(xtr, ytr, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'rand error' )


        if len(tn_it) == len( self.tn_mc ):
            plt.subplot(1, nsp, 4)
            plt.plot(tn_it, self.tn_mc, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_mc, 'r.', alpha=0.2)
            # plot smoothed line
            xnm, ynm = self._smooth( tn_it, self.tn_mc, w )
            xtm, ytm = self._smooth( tt_it, self.tt_mc, w )
            plt.plot(xnm, ynm, 'b', label='train')
            plt.plot(xtm, ytm, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'malis weighted cost energy' )

        if len(tn_it) == len( self.tn_me ):
            plt.subplot(1, nsp, 5)
            plt.plot(tn_it, self.tn_me, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_me, 'r.', alpha=0.2)
            # plot smoothed line
            xng, yng = self._smooth( tn_it, self.tn_me, w )
            xtg, ytg = self._smooth( tt_it, self.tt_me, w )
            plt.plot(xng, yng, 'b', label='train')
            plt.plot(xtg, ytg, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'malis weighted pixel error' )

        plt.legend()
        plt.show()
        return
예제 #36
0
def surface_plot(name: str = 'start_date_analysis1.pkl'):
    """
    3D plot of data cleaning steps
    :param name:
    :return:
    """
    df = pd.read_pickle(name)

    # set up a figure twice as wide as it is tall
    fig = plt.figure(figsize=plt.figaspect(0.5))
    # ===============
    #  First subplot
    # ===============
    # set up the axes for the first plot
    ax = fig.add_subplot(1, 2, 1, projection='3d')
    ax.set_title('Modifications per File')
    ax.set_xlabel('Date (Months)')
    ax.set_ylabel('Threshold Individual')
    for idx, row in enumerate(sorted(df['threshold_pairs'].unique())):
        data = df[df['threshold_pairs'] == row]
        label = 'Threshold pairs ' + str(row)
        # Plot the surface.
        surf = ax.plot_trisurf(data['date'],
                               data['threshold'],
                               data['mpf'],
                               alpha=0.7,
                               linewidth=0,
                               antialiased=False,
                               label=label)
        surf._facecolors2d = surf._facecolors3d
        surf._edgecolors2d = surf._edgecolors3d
    # ===============
    # Second subplot
    # ===============
    # set up the axes for the second plot
    ax = fig.add_subplot(1, 2, 2, projection='3d')
    ax.set_title('Transitions per Test')
    ax.set_xlabel('Date (Months)')
    ax.set_ylabel('Threshold Individual')
    for idx, row in enumerate(sorted(df['threshold_pairs'].unique())):
        data = df[df['threshold_pairs'] == row]
        label = 'Threshold pairs ' + str(row)
        # Plot the surface.

        surf = ax.plot_trisurf(data['date'],
                               data['threshold'],
                               data['tpt'],
                               alpha=0.7,
                               linewidth=0,
                               antialiased=False,
                               label=label)

        surf._facecolors2d = surf._facecolors3d
        surf._edgecolors2d = surf._edgecolors3d

    # cbar = fig.colorbar(surf)
    # cbar.locator = LinearLocator(numticks=10)
    # cbar.update_ticks()

    plt.suptitle('Threshold Start Date Analysis 3D', fontsize=14)
    plt.legend()
    plt.show()
def multiplot_gen_content_type():
    font = {'family': 'Liberation Serif',
            'weight': 'normal',
            'size': 15
            }

    # play around with the font size if it is too big or small
    matplotlib.rcParams['axes.titlesize'] = 12
    matplotlib.rcParams['axes.labelsize'] = 12
    matplotlib.rc('font', **font)
    # matplotlib.rcParams['text.usetex'] = True
    matplotlib.rcParams['pdf.fonttype'] = 42
    matplotlib.rcParams['pdf.use14corefonts'] = True

    x = list(data.keys())
    y1 =[]
    y2 =[]
    y3 =[]
    y4 =[]
    y5 =[]
    y6 =[]
    y7 =[]
    y8 =[]
    y9 =[]
    y10 =[]
    y11 =[]
    y12 =[]
    y13 =[]
    y14 =[]
    y15 =[]
    
    print("---",y1)
    
    for year in data.keys():
        for option_name, count in data[year].items():
            if option_name == 'script':
                y1.append(count)
            if option_name == 'xmlhttprequest':
                y2.append(count)
            if option_name == 'document':
                y3.append(count)
            if option_name == 'elemhide':
                y4.append(count)
            if option_name == 'subdocument':
                y5.append(count)
            if option_name == 'image':
                y6.append(count)
            if option_name == 'popup':
                y7.append(count)
            if option_name == 'ping':
                y8.append(count)
            if option_name == 'stylesheet':
                y9.append(count)
            if option_name == 'object':
                y10.append(count)
            if option_name == 'generichide':
                y11.append(count)
            if option_name == 'font':
                y12.append(count)
            if option_name == 'media':
                y13.append(count)
            if option_name == 'genericblock':
                y14.append(count)
            if option_name == 'other':
                y15.append(count)
    
    print("x-->",x)
    print("y-->",y1)
    print("y-->",y2)

    plt.xticks(rotation='vertical')
    
    plt.xlabel('Year')
    plt.ylabel('Count')

    
    plt.legend(ncol=2)

    plt.tight_layout()
    plt.savefig('easylist-content-type.pdf ', format='pdf', dpi=1200)