コード例 #1
0
    def sanity_expCorrRN_Example1(self):
        """
        Sanity of example 1 for expCorrRN
        """
        import matplotlib.pylab as plt
        from PyAstronomy import pyasl

        # Generate 200 exponentially correlated Gaussian
        # random numbers with a decay time of 5
        c1 = pyasl.expCorrRN(200, 5)

        # Generate 200 exponentially correlated Gaussian
        # random numbers with decay time 10, mean 4, and
        # standard deviation of 2.3.
        #
        # The results are: The correlated random numbers,
        # the uncorrelated numbers used as input, and the
        # correlated coefficient (exp(-1/tau)).
        c2, g, f = pyasl.expCorrRN(200, 10, mean=4.0, std=2.3, fullOut=True)

        plt.subplot(2, 1, 1)
        plt.plot(range(200), c1, 'bp-')
        plt.subplot(2, 1, 2)
        plt.plot(range(200), c2, 'bp-')
        plt.plot(range(200), g, 'g.')
コード例 #2
0
 def sanity_expCorrRN_Example1(self):
   """
     Sanity of example 1 for expCorrRN
   """
   import matplotlib.pylab as plt
   from PyAstronomy import pyasl
   
   # Generate 200 exponentially correlated Gaussian
   # random numbers with a decay time of 5
   c1 = pyasl.expCorrRN(200, 5)
   
   # Generate 200 exponentially correlated Gaussian
   # random numbers with decay time 10, mean 4, and
   # standard deviation of 2.3.
   #
   # The results are: The correlated random numbers,
   # the uncorrelated numbers used as input, and the
   # correlated coefficient (exp(-1/tau)).
   c2, g, f = pyasl.expCorrRN(200, 10, mean=4.0, std=2.3, fullOut=True)
   
   plt.subplot(2,1,1)
   plt.plot(range(200), c1, 'bp-')
   plt.subplot(2,1,2)
   plt.plot(range(200), c2, 'bp-')
   plt.plot(range(200), g, 'g.')
コード例 #3
0
    def sanity_expCorrRN_Example2(self):
        """
        Sanity of example 2 for expCorrRN
        """
        import numpy as np
        import matplotlib.pylab as plt
        from PyAstronomy import pyasl

        # Generate n exponentially correlated Gaussian
        # random numbers with a decay time, tau
        n = 500
        tau = 5.
        c1 = pyasl.expCorrRN(n, tau)

        # Obtain autocorrelation function
        ac = np.correlate(c1, c1, mode="full")[n - 1:]

        # Plot correlated random numbers and autocorrelation
        # function along with exponential model.
        x = np.arange(float(n))
        plt.subplot(2, 1, 1)
        plt.plot(x, c1, 'bp-')
        plt.subplot(2, 1, 2)
        plt.plot(x, ac, 'b.')
        plt.plot(x, np.exp(-x / tau) * ac.max(), 'r--')
コード例 #4
0
 def sanity_expCorrRN_Example2(self):
   """
     Sanity of example 2 for expCorrRN
   """
   import numpy as np
   import matplotlib.pylab as plt
   from PyAstronomy import pyasl
   
   # Generate n exponentially correlated Gaussian
   # random numbers with a decay time, tau
   n = 500
   tau = 5.
   c1 = pyasl.expCorrRN(n, tau)
   
   # Obtain autocorrelation function
   ac = np.correlate(c1, c1, mode="full")[n-1:]
   
   # Plot correlated random numbers and autocorrelation
   # function along with exponential model.
   x = np.arange(float(n))
   plt.subplot(2,1,1)
   plt.plot(x, c1, 'bp-')
   plt.subplot(2,1,2)
   plt.plot(x, ac, 'b.')
   plt.plot(x, np.exp(-x/tau)*ac.max(), 'r--')
コード例 #5
0
ファイル: Generate_Data.py プロジェクト: hsmurali/ML-Project
def Simulate_ARIMA_Like_Timeseries(arparams, maparams, num_samples, A1=6, A2=0.5):
    TS = Generate_ARMA_Timeseries_Data(arparams, maparams, num_samples, frac = 0)
    TS_LRD = Generate_ARMA_Timeseries_Data(arparams, maparams, num_samples, frac = 1)
    TS_non_stationary = np.cumsum(TS)
    TS_LRD_non_stationary = np.cumsum(TS_LRD)
    W_Noise = np.random.normal(0,1, len(TS))
    TS_Periodic_F1 = Generate_Periodic_Signal(288, len(TS))
    TS_Periodic_F2 = Generate_Periodic_Signal(356/12.0*288, len(TS))
    corr, uncorr, f = pyasl.expCorrRN(len(TS), 25, mean=4.0, std=2.3, fullOut=True)
    brownian_ser = np.empty((1,len(TS)+1))
    brownian_ser[:, 0] = 50
    brownian(brownian_ser[:,0], len(TS), dt=2e-5, delta=10, out=brownian_ser[:,1:])
    brownian_ser = brownian_ser[0][:-1]
    
    df = pd.DataFrame()
    df.loc[:,'TS_ARIMA'] = TS
    df.loc[:,'TS_ARIMA_LRD'] = TS_LRD
    df.loc[:,'TS_Non_Stationary'] = TS_non_stationary
    df.loc[:,'TS_LRD_Non_Stationary'] = TS_LRD_non_stationary
    df.loc[:,'Periodic'] = A1*TS_Periodic_F1 + W_Noise
    df.loc[:,'Periodic_Multiple_Seasonality'] = (A1*TS_Periodic_F1)*(A2*TS_Periodic_F2) + W_Noise
    df.loc[:,'SARIMA'] = (A2*TS_Periodic_F1)*(A1*TS)
    df.loc[:,'SARFIMA'] = (A1*TS_Periodic_F1)*(TS_LRD)
    df.loc[:,'Periodic_Non_Stationary'] = ((A1*TS_Periodic_F1)*TS_non_stationary
                                           + W_Noise)
    df.loc[:,'Periodic_Non_Stationary_LRD'] = ((A1*TS_Periodic_F1)*TS_LRD_non_stationary 
                                               + W_Noise)
    df.loc[:,'Exp_Corr_RN'] = corr
    df.loc[:,'Brownian'] = brownian_ser
    
    color = ['red','blue','green','orange',
             'black', 'magenta','indigo','violet',
             'brown','gold','olive','gray']
    columns = df.columns.tolist()
    fig_TS, ax_TS = plt.subplots(6,2,figsize = (16,12))
    fig_ACF, ax_ACF = plt.subplots(6,2,figsize = (16,12))
    fig_FFT, ax_FFT = plt.subplots(6,2,figsize = (16,12))
    
    counter = 0
    for i in range(0, 6):
        for j in range(0, 2):
            print columns[counter]
            df[[columns[counter]]].plot(ax = ax_TS[i][j], color = color[counter], legend = False)
            ax_TS[i][j].grid()
            #ax_TS[i][j].legend(loc = 1)
            ax_TS[i][j].set_title(columns[counter])
                        
            if 'Periodic' in columns[counter]:
                lags = 5000
                lim = [0, 0.00005]
                v_lines = False
            else:
                lags = 100
                lim = [0,0.00175]
                v_lines = True
            tsaplots.plot_acf(df[columns[counter]], ax = ax_ACF[i][j], lags = lags,
                              title = 'ACF of '+columns[counter], color = color[counter],
                              marker = 'x', use_vlines = v_lines)
            ax_ACF[i][j].axhline(0)
            ax_ACF[i][j].grid()
            
            f, Pxx_den = signal.periodogram(df[columns[counter]], 1/(5*60.0))
            ax_FFT[i][j].plot(f, np.sqrt(Pxx_den), color = color[counter])
            ax_FFT[i][j].set_title('FFt of '+columns[counter])
            ax_FFT[i][j].grid()
            ax_FFT[i][j].set_xlim(lim)
            counter += 1
            
    fig_TS.tight_layout()
    fig_ACF.tight_layout()
    fig_FFT.tight_layout()
    fig_TS.savefig('TS.pdf')
    fig_ACF.savefig('ACF.pdf')
    fig_FFT.savefig('FFT.pdf')
    return df