Esempio n. 1
0
 def extr(self, name='testing'):
     self.error = self.y_test - self.yqcnn
     fraction = 0.5
     width = 512
     fig, ax = plt.subplots(figsize=set_size(width, fraction),
                            sharex='all',
                            sharey='all',
                            gridspec_kw={'hspace': 0.5})
     #ax.scatter(range(0,len(self.y_test)),self.y_test, s=50, marker='*', c='blue', alpha=0.7, label='test data')
     plt.scatter(np.where(
         np.logical_or(self.y_test > self.yqcnnu,
                       self.y_test < self.yqcnnl)),
                 self.uncertainty[self.id_anomaly],
                 c='red',
                 s=50,
                 marker='*',
                 alpha=0.7)
     fig.text(-0.005,
              0.5,
              'eXtreme scores',
              va='center',
              rotation='vertical',
              fontsize=plt.rcParams['axes.labelsize'])
     plt.xlabel(r'time')
     plt.tight_layout()
Esempio n. 2
0
    def _save(self, name='wiki1'):
        '''

        Parameters
        ----------
        name : TYPE, optional
            DESCRIPTION. The default is 'wiki1'.

        Returns
        -------
        None.

        '''
        fraction = 1
        width = 212
        fig, ax = plt.subplots(figsize=set_size(width, fraction),
                               sharex='all',
                               gridspec_kw={'hspace': 0.5})
        #plt.plot(self.y10, color='green', alpha=0.9)
        plt.plot(self.y50, color='red', alpha=0.8, label='OFAT')
        plt.plot(self.y_test, color='olive', alpha=0.8, label='ground truth')
        ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax.xaxis.set_major_locator(plt.LinearLocator(6))
        ax.yaxis.set_major_locator(plt.LinearLocator(6))
        plt.legend(loc='upper right', bbox_to_anchor=(1.0, 1.05), ncol=2)
        plt.xlabel('Time (days)')
        #print('{} smae: {} std: {}'.format(name, self.smae, self.std_s))
        plt.ylabel('Weekly prices')
        plt.tight_layout()
        plt.savefig('../../ofat/figures/' + name + '.pdf',
                    format='pdf',
                    bbox_inches='tight')
Esempio n. 3
0
 def plot(self, name='wikipgs'):
     fraction = 1
     width = 512
     fig, ax = plt.subplots(figsize=set_size(width, fraction),
                            sharex='all',
                            gridspec_kw={'hspace': 0.5})
     #plt.plot(self.uncertainty, color='green', alpha=0.9)
     #plt.plot(self.y50,alpha=0.8, label='ofat')
     plt.plot(self.y_test, alpha=0.8, label='gt')
     plt.plot(self.yqcnn, alpha=0.8, label='qcnn')
     plt.plot(self.ycnn, alpha=0.8, label='cnn')
     plt.plot(self.yqclnn, alpha=0.8, label='qconvl')
     plt.plot(self.yqlstm[1], alpha=0.8, label='qlstm')
     plt.plot(self.ylstm, alpha=0.6, label='lstm')
     ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_locator(plt.LinearLocator(6))
     ax.yaxis.set_major_locator(plt.LinearLocator(6))
     plt.legend(loc='upper right',
                bbox_to_anchor=(1.01, 1.05),
                ncol=3,
                columnspacing=0.5)
     plt.xlabel('Time (days)')
     #print('{} smae: {} std: {}'.format(name, self.smae, self.std_s))
     plt.ylabel('Daily page visits')
     plt.tight_layout()
Esempio n. 4
0
 def plotuncertanty(self, name='preduncer'):
     fraction = 0.5
     width = 510
     timex = 2000
     y = np.concatenate((self.y_train[-timex:], self.yqcnn), axis=0)
     #self.y_test[91]=9.06
     fig, ax = plt.subplots(figsize=set_size(width, fraction), sharey='all')
     #plt.plot(self.y_train[-timex:],'grey', label='fitted model')
     plt.plot(y + 0.1, 'red', label='ground truth', alpha=0.9)
     ax.fill_between(range(timex,
                           len(self.y_test) + timex),
                     self.yqcnnl,
                     self.yqcnnu - 0.5,
                     color='royalblue',
                     alpha=0.5,
                     label='predictive uncertainty')
     plt.plot(range(timex,
                    len(self.y_test) + timex),
              self.y_test + 0.1,
              'orange',
              label='fitted model',
              alpha=0.8)
     ax.axvline(x=timex,
                ymin=0,
                ymax=5,
                color='grey',
                ls='--',
                lw=2,
                alpha=0.7)
     #plt.scatter(timex+91, self.y_test[91], marker='*', s=70, color='red', label='predicted extreme event')#extreme event
     #ax.grid(True, zorder=5)
     #plt.plot(self.y_test, color='olive', alpha=0.8, label ='ground truth')
     #plt.plot(range(timex,len(self.y_test)+timex), self.yqlstm[0],color='grey',alpha=0.3)
     #plt.plot(range(timex,len(self.y_test)+timex), self.yqlstm[2],color='grey',alpha=0.3)
     plt.ylim([8.8, 10.2])
     ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_locator(plt.LinearLocator(6))
     ax.yaxis.set_major_locator(plt.LinearLocator(6))
     plt.legend(loc='upper right',
                bbox_to_anchor=(0.75, 1.03),
                ncol=1,
                columnspacing=0.05)
     ax.set_xlabel('Time ')
     ax.set_ylabel(r'EDF stock price (\pounds)')
     plt.tight_layout()
     plt.savefig('../_8th/myphd/thesis_1/figures/' + name + '.pdf',
                 format='pdf',
                 bbox_inches='tight')
Esempio n. 5
0
    def plot(self, name='testing'):
        '''

        Parameters
        ----------
        name : TYPE, optional
            DESCRIPTION. The default is 'testing'.

        Returns
        -------
        None.

        '''
        fraction = 0.5
        width = 510
        fig, ax = plt.subplots(figsize=set_size(width, fraction), sharex='all')
        plt.plot(self.y50, 'red')
        plt.plot(self.y_test, 'orange')
        ax.fill_between(range(0, len(self.y50)),
                        self.y10,
                        self.y90,
                        color='grey',
                        alpha=0.5)
        #ax.grid(True, zorder=5)
        plt.plot(self.y50, color='red', alpha=0.8, label='OFAT')
        plt.plot(self.y_test, color='olive', alpha=0.8, label='ground truth')
        ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax.xaxis.set_major_locator(plt.LinearLocator(6))
        ax.yaxis.set_major_locator(plt.LinearLocator(6))
        #plt.legend(loc='upper right', bbox_to_anchor=(1.0, 1.05), ncol=2)
        ax.set_xlabel('Time (weeks)')
        ax.set_ylabel('Average price')
        plt.tight_layout()
        plt.savefig('../../ofat/figures/' + name + '.pdf',
                    format='pdf',
                    bbox_inches='tight')
Esempio n. 6
0
    def _predict(self, name='stock'):
        fraction = 0.5
        width = 510
        fig, ax = plt.subplots(3,
                               figsize=set_size(width, fraction),
                               sharex='all',
                               gridspec_kw={'hspace': 0.5})
        ax[0].plot(self.y10[28:], color='green', alpha=0.9)
        ax[0].plot(self.y50[28:], color='blue', alpha=0.6)
        ax[0].plot(self.y90[28:], color='purple', alpha=0.8)
        ax[0].yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax[0].yaxis.set_major_locator(plt.LinearLocator(3))
        ax[0].set_title('fitted model (blue) and thresholds')
        #ax[0].setylabel(r'thresholds')
        ax[1].plot(self.y_test[28:], alpha=0.9, lw=2, c='orange')
        ax[1].yaxis.set_major_locator(plt.LinearLocator(3))
        ax[1].yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax[1].set_title('test data')
        ax[2].plot(self.anom_scores[28:],
                   c='navy',
                   label='scores',
                   alpha=0.9,
                   lw=2)
        ax[2].yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax[2].yaxis.set_major_locator(plt.LinearLocator(3))
        #ax[2].plot(self.id_anomaly)
        ax[2].scatter(np.where(
            np.logical_or(self.y_test[28:] > self.y90[28:],
                          self.y_test[28:] < self.y10[28:]))[0],
                      self.anom_scores[28:][np.logical_or(
                          self.y_test[28:] > self.y90[28:],
                          self.y_test[28:] < self.y10[28:])],
                      c='red',
                      s=50,
                      marker='*',
                      alpha=0.7)
        # ax[2].scatter(np.where(np.logical_or(self.y_test[28:]>self.y90[28:], self.y_test[28:]<self.y10[28:]))[0],
        #             self.anom_scores[28:][self.id_anomaly], c='red', s=50, marker='*',  alpha=0.7) #best simplified version for marking anomalies
        plt.ylim([-0.27, 0.1])
        ax[2].xaxis.set_major_locator(plt.LinearLocator(6))
        fig.text(-0.06,
                 0.5,
                 'OFA scores',
                 va='center',
                 rotation='vertical',
                 fontsize=plt.rcParams['axes.labelsize'])
        plt.xlabel(r'time', fontsize=plt.rcParams['axes.labelsize'])
        plt.tight_layout()

        #plot anomalies

        #ax.xaxis.set_major_locator(plt.LinearLocator(6))
        #ax.yaxis.set_major_locator(plt.LinearLocator(4))
        #ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        #ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        #ax.yaxis.set_major_formatter(ScalarFormatter())
        #ax.yaxis.major.formatter._useMathText = True
        #ax.yaxis.major.formatter._useMathText = True
        #ax.yaxis.set_minor_locator(AutoMinorLocator(1))
        #plt.ylim([self.y10.min()-1, self.y90.max()+1])
        #plt.legend(loc='lower right')
        #plt.tight_layout()

        #fig, ax = plt.subplots(figsize=set_size(width, fraction))
        #ax[1].plot(self.error, c='green', label='scores', alpha=0.9, lw=2)
        plt.savefig('/latex/figures/' + name + '.pdf',
                    format='pdf',
                    bbox_inches='tight')
Esempio n. 7
0
    def plot(self, name='testing'):
        #plt.figure(figsize=(16,8))
        #plt.xlabel(r'$\bf {running time(s)} x10$', fontsize=45, fontweight ='bold')
        #plt.ylabel(r'$\bf {window size~}x100$', fontsize=45, fontweight ='bold')
        #plt.xlabel(r'\textbf{execution time(s)} $x10$', fontsize=10, fontweight ='bold')
        #plt.ylabel(r'$\psi~x10^2$', fontsize=10, fontweight ='bold')
        fraction = 0.5
        width = 512
        fig, ax = plt.subplots(3,
                               figsize=set_size(width, fraction),
                               sharex='all',
                               sharey='all',
                               gridspec_kw={'hspace': 0.5})
        ax[0].scatter(range(0, len(self.y_test)),
                      self.y_test,
                      s=50,
                      marker='*',
                      c='blue',
                      alpha=0.7,
                      label='test data')
        ax[1].plot(self.error, c='green', label='scores', alpha=0.9, lw=2)
        for i in range(2):
            #ax[i].xaxis.set_major_locator(plt.LinearLocator(6))
            #ax[i].yaxis.set_major_locator(plt.LinearLocator(3))
            #ax[i].xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
            #ax[i].yaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
            ax[i].yaxis.set_minor_locator(AutoMinorLocator(2))
            #ax[i].xaxis.set_minor_locator(AutoMinorLocator(2))
        #plot anomalies
        plt.scatter(np.where(
            np.logical_or(self.y_test > self.y90, self.y_test < self.y10))[0],
                    self.anom_scores,
                    c='red',
                    s=50,
                    marker='*',
                    alpha=0.7)
        plt.plot(self.error, c='green', alpha=0.9, lw=2)
        fig.text(-0.005,
                 0.5,
                 'OFA scores',
                 va='center',
                 rotation='vertical',
                 fontsize=plt.rcParams['axes.labelsize'])
        plt.xlabel(r'time')
        #plt.ylabel(r'OFA score')
        plt.tight_layout()
        # plt.savefig('/media/c1ph3r/colls/Dropbox/_China/_Xidian/_6th/vldb/vldb_style_sample/latex/figures/'+name+'.pdf',
        #             format='pdf', bbox_inches='tight')

        fraction = 0.5
        width = 510
        fig, ax = plt.subplots(3,
                               figsize=set_size(width, fraction),
                               sharex='all',
                               gridspec_kw={'hspace': 0.5})
        ax[0].plot(self.y90, c='orange', alpha=0.9, lw=2)
        ax[1].plot(self.y50, c='cyan', alpha=0.9, lw=2)
        ax[2].plot(self.y10, c='purple', alpha=0.9, lw=2)
        for i in range(3):
            #ax[i].xaxis.set_major_locator(plt.LinearLocator(6))
            ax[i].yaxis.set_major_locator(plt.LinearLocator(3))
            # ax[i].xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
            ax[i].yaxis.set_major_formatter(plt.FormatStrFormatter('%.5f'))
            #ax[i].yaxis.set_minor_locator(AutoMinorLocator(1))
            #ax[i].xaxis.set_minor_locator(AutoMinorLocator(2))
        plt.xlabel(r'time')
        #plt.ylim([-0.001, 0.001])
        plt.tight_layout()
Esempio n. 8
0
    def evt(self, tx=[], name='', mode=3):
        fraction = 0.5
        width = 512
        if mode == 0:
            tx = tx.strftime('%H:%M')
            fig, ax = plt.subplots(figsize=set_size(width, fraction),
                                   sharex='all')
            #plt.scatter(range(len(self.uncertainty[3900:9500])), self.uncertainty[3900:9500], color='gray', alpha=0.7, label='uncertainty')
            # plt.plot(self.y_test[3900:9500],color='red', alpha=0.3, label='ground truth')
            #plt.ylabel(r'SYN packets/ms')
            plt.plot(self.yqcnnu[:400],
                     ls='--',
                     alpha=0.5,
                     color='orange',
                     label='UB')
            plt.plot(self.yqcnnl[:400],
                     ls='--',
                     alpha=0.6,
                     color='purple',
                     label='LB')
            plt.plot(self.y_test[:400], label='Gt', color='grey', alpha=0.8)
            plt.scatter([self.id_anomaly[:4]],
                        self.anomaly[:4],
                        s=30,
                        marker='*',
                        alpha=0.8,
                        color='red',
                        label='Ext')
            plt.xlabel(r'time (hour)')
            plt.ylabel('EDF Stock price')
            #fig.text(0.005, 0.5, 'EDF Stock price', va='center', rotation='vertical', fontsize=plt.rcParams['axes.labelsize'])
            #ax.fill_between(range(len(self.y_test)), self.yqcnnl, self.yqcnnu,color='royalblue',alpha=0.5, label='PU')
            ax.xaxis.set_major_locator(plt.LinearLocator(6))
            ax.yaxis.set_major_locator(plt.LinearLocator(5))
            #plt.scatter(range(len(self.y_test)),self.uncertainty)
            #plt.ylim([9,9.7])
            plt.xticks([x for x in range(0, len(tx[:400]), 9 * 5)],
                       [tx[x] for x in range(0, len(tx[:400]), 9 * 5)],
                       rotation=40)
            ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
            #ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
            plt.legend(loc='upper right',
                       bbox_to_anchor=(1, 1.05),
                       ncol=5,
                       labelspacing=0.1,
                       columnspacing=1)
            plt.tight_layout()
            # plt.savefig('../_8th/papers/vldb/pvldbstyle-master/figures/'+
            #       name+'.pdf',format='pdf', bbox_inches='tight')

        elif mode == 1:
            name = ''
            fraction = 0.5
            width = 512
            fig, ax = plt.subplots(figsize=set_size(width, fraction),
                                   sharex='all')
            plt.scatter(range(len(self.uncertainty[3900:9500])),
                        self.uncertainty[3900:9500],
                        color='gray',
                        alpha=0.7,
                        label='Uncertainty ')
            plt.plot(self.y_test[3900:9500],
                     color='red',
                     alpha=0.3,
                     label='ground truth')
            plt.ylabel(r'SYN packets/ms')
            plt.xlabel(r'time (s)')
            ax.xaxis.set_major_locator(plt.LinearLocator(8))
            ax.yaxis.set_major_locator(plt.LinearLocator(8))
            ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
            ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
            plt.legend(loc='upper right',
                       bbox_to_anchor=(0.9, 1.05),
                       ncol=2,
                       labelspacing=0.1,
                       columnspacing=1)
            plt.tight_layout()
            # plt.savefig('../_8th/papers/vldb/pvldbstyle-master/figures/'+
            #       name+'.pdf',format='pdf', bbox_inches='tight')
        else:
            name = 'field'
            fraction = 0.5
            width = 512
            fig, ax = plt.subplots(figsize=set_size(width, fraction),
                                   sharex='all')
            # plt.scatter(range(len(self.uncertainty)), self.uncertainty, color='gray', alpha=0.7, label='Uncertainty ')
            # plt.plot(self.y_test,color='red', alpha=0.3, label='ground truth')
            plt.plot(self.yqcnnu,
                     ls='--',
                     alpha=0.5,
                     color='orange',
                     label='UB')
            plt.plot(self.yqcnnl,
                     ls='--',
                     alpha=0.6,
                     color='purple',
                     label='LB')
            plt.plot(self.y_test, label='Gt', color='grey', alpha=0.8)
            plt.scatter([self.id_anomaly],
                        self.anomaly,
                        s=30,
                        marker='*',
                        alpha=0.8,
                        color='red',
                        label='Ext')
            plt.ylabel(r'Magnetic field (nT)')
            plt.xlabel(r'time (s)')
            ax.xaxis.set_major_locator(plt.LinearLocator(8))
            ax.yaxis.set_major_locator(plt.LinearLocator(8))
            ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
            ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
            plt.legend(loc='upper right',
                       bbox_to_anchor=(0.9, 1.05),
                       ncol=4,
                       labelspacing=0.1,
                       columnspacing=1)
            plt.tight_layout()