Esempio n. 1
0
def main():

    if db in [
            'lorenz', 'chua', 'duffing', 'nose_hoover', 'rikitake', 'rossler',
            'wang'
    ]:
        x, y, z = tsg.chaoticSystem(samples=samples, systemType=db)
        ux = np.array([x[i - L:i] for i in range(L, len(x))])
        uy = np.array([y[i - L:i] for i in range(L, len(y))])
        u = np.concatenate((ux, uy), axis=1)  # INPUT
        d = np.array([z[i] for i in range(L, len(z))]).reshape(-1, 1)
        dmin = d.min() - (d.max() - d.min()) * 0.1
        dmax = d.max() + (d.max() - d.min()) * 0.1
        print('Input', u.shape, 'Output', d.shape)

    else:
        print('Unknown dataset')
        return

    if kaf == 'KRLS_ALD':
        from KAF import KRLS_ALD
        f = KRLS_ALD(sigma=sigma, epsilon=eps)
    elif kaf == 'QKLMS_AKB':
        from KAF import QKLMS_AKB
        f = QKLMS_AKB(sigma_init=sigma, epsilon=eps, K=5)
    elif kaf == 'ALDKRLS_AKB_2':
        from KAF import ALDKRLS_AKB_2
        f = ALDKRLS_AKB_2(sigma=sigma, epsilon=eps, K_akb=10)
    elif kaf == 'QKLMS_AMK':
        from KAF import QKLMS_AMK
        f = QKLMS_AMK(sigma=sigma, epsilon=eps)
    else:
        print('Unknown KAF')
        return

    fig = plt.figure()
    ax = fig.add_subplot(111)

    y = np.zeros(d.shape)
    CB_ant = 0
    for n in range(len(u)):
        y[n] = f.evaluate(u[n].reshape(1, -1), d[n].reshape(1, -1))[0]
        if n > 3:
            ax.plot(np.array([n - 1, n]),
                    d[n - 2:n],
                    color='blue',
                    label='Target')
            ax.plot(np.array([n - 1, n]),
                    y[n - 2:n],
                    color='red',
                    label='Predicted')
            plt.ylim([dmin, dmax])
            plt.pause(1e-3)
        if CB_ant != len(f.CB):
            ax.scatter(n, y[n], color='black', label='CB update', marker='+')
            CB_ant = len(f.CB)
    plt.show()
    return
def db(samples=5040,system='lorenz',L=40):
    import numpy as np
    import TimeSeriesGenerator as tsg
    x, y, z = tsg.chaoticSystem(samples=samples,systemType=system)
    ux = np.array([x[i-L:i] for i in range(L,len(x))])
    uy = np.array([y[i-L:i] for i in range(L,len(y))])
    u = np.concatenate((ux,uy), axis=1) # INPUT
    d = np.array([z[i] for i in range(L,len(z))]).reshape(-1,1)
    return u,d
Esempio n. 3
0
def _get_ts_df():
    tsg = TSG.TimeSeriesGenerator()
    list_ts = tsg.generate_month_data()

    ts = TS.TimeSeries()
    ts.set_ts_list(list_ts, ["TIME", "VALUE"])

    df = ts.get_ts_df()

    return df
Esempio n. 4
0
def _get_ts_array(time_type):
    tsg = TSG.TimeSeriesGenerator()
    ts = TS.TimeSeries()

    if time_type == "d":
        ts.set_ts_list(tsg.generate_day_data(), ["TIME", "VALUE"])
    elif time_type == "w":
        ts.set_ts_list(tsg.generate_week_data(), ["TIME", "VALUE"])
    elif time_type == "m" or time_type == "y":
        ts.set_ts_list(tsg.generate_month_data(), ["TIME", "VALUE"])

    ts_d = ts.get_ts_df()

    return ts_d["TIME"].array
Esempio n. 5
0
def _get_ts_df(time_type):
    tsg = TSG.TimeSeriesGenerator()
    ts = TS.TimeSeries()

    if time_type == "d":
        ts.set_ts_list(tsg.generate_day_data(), ["TIME", "VALUE"])
    elif time_type == "w":
        ts.set_ts_list(tsg.generate_week_data(), ["TIME", "VALUE"])
    elif time_type == "m" or time_type == "y":
        ts.set_ts_list(tsg.generate_month_data(), ["TIME", "VALUE"])

    ts_df = ts.get_ts_df()
    ts_df["VALUE"] = [1] * ts_df.shape[0]

    return ts_df
Esempio n. 6
0
def kafSearch_MC(filterName,systemName,n_samples,trainSplit,MC_runs):
    import KAF
    from tqdm import tqdm
    from sklearn.metrics import r2_score
    from sklearn.metrics import mean_squared_error
    import pandas as pd  
    import numpy as np
    
    n_paramters = 0
    
    # 1. Generate data for grid search
    n_train = int(n_samples*trainSplit)
    n_test = n_samples - n_train
    
    folder = 'GridSearchWang2/'
    
    attractors = ['lorenz','wang', 'rossler', 'rikitake']
    
    if systemName in attractors:
        signalEmbedding = 5
        import TimeSeriesGenerator
        inputSignal, y, z = TimeSeriesGenerator.chaoticSystem(samples=(n_samples+signalEmbedding)*MC_runs,systemType=systemName)
        inputSignal -= inputSignal.mean()
        inputSignal /= inputSignal.std()
        y -= y.mean()
        y /= y.std()
        z -= z.mean()
        z /= z.std()
               
    elif systemName == "4.1":
        signalEmbedding = 5
        import testSystems as ts
        inputSignal, targetSignal = ts.testSystems(samples = (n_samples+signalEmbedding)*MC_runs, systemType = "4.1_AKB")
        # inputSignal -= inputSignal.mean()
        # inputSignal /= inputSignal.std()
        
    elif systemName == "4.2":
        signalEmbedding = 2
        import testSystems as ts
        inputSignal = ts.testSystems(samples = (n_samples+signalEmbedding)*MC_runs, systemType = "4.2_AKB")
        inputSignal -= inputSignal.mean()
        inputSignal /= inputSignal.std()
        
    else:
        raise ValueError("Database does not exist")
      
    # 2. Pick filter    
    if filterName == "QKLMS":
        # 2.1. Generate parameters for QKLMS grid search
        if systemName in attractors:
            eta = [0.05, 0.1, 0.3, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 1, 2, 4, 8]
            epsilon = [1e-1, 0.5, 1, 2]
            
        elif systemName == "chua":
            eta = [0.05, 0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 0, 2, 4]
            epsilon = [1e-2, 1e-1, 1,2]
            
        elif systemName == "4.1":
            eta = [0.05, 0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 0, 2, 4]
            epsilon = [1e-2, 1e-1, 1,2]
            
        elif systemName == "4.2":
            eta = [0.05, 0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 0, 2, 4]
            epsilon = [1e-2, 1e-1, 1,2]
            
        params = [{'eta':et,'epsilon':ep, 'sigma':s } for et in eta for ep in epsilon for s in sigma]
                       
        # 2.2. Search over QKLMS with Montecarlo Simulation
        results = []
        testing_mse_xRun = []
        CB_size_xRun = []
        tradeOff_dist_xRun = []
        
        signalPower = inputSignal.var()
        
        singleRunDataSize = n_samples
        trainLength = n_train
        
        for run in range(MC_runs):
            print("\n\nRunning Monte Carlo simulation #{}...\n".format(run))           
            try:
                u_train, u_test, d_train, d_test = trainAndTestSplitWithEmbedding(inputSignal, targetSignal,signalEmbedding, run, singleRunDataSize, trainLength)
            except:
                u_train, u_test, d_train, d_test = customEmbeddingForKAFs(inputSignal, signalEmbedding, run, singleRunDataSize, trainLength)
                # u_train, u_test, d_train, d_test = customExogenousEmbeddingForKAFs(inputSignal, y, z, signalEmbedding, run, singleRunDataSize, trainLength)
                
            for p in tqdm(params):
                try:
                    f = KAF.QKLMS(eta=p['eta'],epsilon=p['epsilon'],sigma=p['sigma'])
                    y = f.evaluate(u_train,d_train)
                    y_pred = f.predict(u_test)
                    err = d_test-y_pred.reshape(-1,1)
                    t_mse = np.mean(err**2)
                    testing_mse_xRun.append(t_mse/signalPower)
                    CB_size_xRun.append(len(f.CB))                  
                except:
                    testing_mse_xRun.append(np.nan)
                    CB_size_xRun.append(np.nan)
            
        allTestingMSEs = np.array(testing_mse_xRun).reshape(MC_runs,-1)
        allCB_sizes = np.array(CB_size_xRun).reshape(MC_runs,-1)
        
        testing_mse_average = np.nanmean(allTestingMSEs, axis=0)
        CB_size_average = np.nanmean(allCB_sizes, axis=0)
        
        tradeOff_distance = [tradeOffDistance(testing_mse_average[j],CB_size_average[j]/n_train) for j in range(len(params))]
        
        
        results = [p for p in params]
        results_df = pd.DataFrame(data=results)
        results_df['testing_mse'] = testing_mse_average
        results_df['CB_size'] = CB_size_average
        results_df['CB_size'] = results_df['CB_size'].astype(int)
        results_df['tradeOff_dist'] = tradeOff_distance
        
        results_df.to_csv(folder + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')
        
        
        
    elif filterName == "QKLMS_AKB": 
        # 2.1. Generate parameters for QKLMS_AKB grid search
        import numpy as np
        if systemName in attractors:
            eta = [0.05, 0.1, 0.3, 0.9]
            sigma = [ 1e-1, 1, 2]
            epsilon = [1e-1, 0.5, 1, 2]
            mu = [1e-3, 1e-1, 0.1, 1]
            K = [2,5,10,20]

        elif systemName == "chua":
            eta = [0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 2, 4]
            epsilon = [1e-2, 1e-1, 1]
            mu = [1e-3, 1e-1, 0.1, 1]
            K = [2,5,10,20]
            
        elif systemName == "4.1":
            eta = [0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 2, 4]
            epsilon = [1e-2, 1e-1, 1]
            mu = [1e-3, 1e-1, 0.1, 1]
            K = [2,5,10,20]

        elif systemName == "4.2":
            eta = [0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 2, 4]
            epsilon = [1e-2, 1e-1, 1]
            mu = [1e-3, 1e-1, 0.1, 1]
            K = [2,5,10,20]
            

        params = [{'eta':et,'epsilon':ep, 'sigma_init':s, 'mu':m, 'K':int(k) } for et in eta for ep in epsilon for s in sigma for m in mu for k in K]
                      
            
        # 2.2. Search over QKLMS AKB with Montecarlo Simulation
        results = []
        testing_mse_xRun = []
        CB_size_xRun = []
        tradeOff_dist_xRun = []
        
        signalPower = inputSignal.var()
        
        singleRunDataSize = n_samples
        trainLength = n_train
        
        for run in range(MC_runs):
            print("\n\nRunning Monte Carlo simulation #{}...\n".format(run))
            
            try:
                u_train, u_test, d_train, d_test = trainAndTestSplitWithEmbedding(inputSignal, targetSignal,signalEmbedding, run, singleRunDataSize, trainLength)
            except:
                # u_train, u_test, d_train, d_test = customEmbeddingForKAFs(inputSignal, signalEmbedding, run, singleRunDataSize, trainLength)
                u_train, u_test, d_train, d_test = customExogenousEmbeddingForKAFs(inputSignal, y, z, signalEmbedding, run, singleRunDataSize, trainLength)
                
            for p in tqdm(params):
                try:
                    f = KAF.QKLMS_AKB(eta=p['eta'],epsilon=p['epsilon'],sigma_init=p['sigma_init'], mu=p['mu'], K=p['K'])
                    y = f.evaluate(u_train,d_train)
                    y_pred = f.predict(u_test)
                    err = d_test-y_pred.reshape(-1,1)
                    t_mse = np.mean(err**2)
                    testing_mse_xRun.append(t_mse/signalPower)
                    CB_size_xRun.append(len(f.CB))                  
                except:
                    testing_mse_xRun.append(np.nan)
                    CB_size_xRun.append(np.nan)
            
        allTestingMSEs = np.array(testing_mse_xRun).reshape(MC_runs,-1)
        allCB_sizes = np.array(CB_size_xRun).reshape(MC_runs,-1)
        
        testing_mse_average = np.nanmean(allTestingMSEs, axis=0)
        CB_size_average = np.nanmean(allCB_sizes, axis=0)
        
        tradeOff_distance = [tradeOffDistance(testing_mse_average[j],CB_size_average[j]/n_train) for j in range(len(params))]
        
        
        results = [p for p in params]
        results_df = pd.DataFrame(data=results)
        results_df['testing_mse'] = testing_mse_average
        results_df['CB_size'] = CB_size_average
        results_df['CB_size'] = results_df['CB_size'].astype(int)
        results_df['tradeOff_dist'] = tradeOff_distance
        
        results_df.to_csv(folder + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')
        
    elif filterName == "QKLMS_AMK": 
        # 2.1. Generate parameters for QKLMS_AKB grid search
        import numpy as np
        if systemName in attractors:
            mu = [0.1, 0.5,1,1.5]
            eta = [0.05, 0.1, 0.3, 0.5, 0.9]
            epsilon = [1e-1, 0.5, 1, 2]
            K = [5,10,15,20]
            
        elif systemName == "chua":
            eta = np.linspace(0.02,1,n_paramters)
            epsilon = np.linspace(1e-3,100,n_paramters)
            mu = np.linspace(1e-4,1,n_paramters)
            K = np.linspace(2,20,n_paramters)
            
        elif systemName == "4.1":
            mu = [1e-3,1e-1, 0.1,1]
            eta = [0.05, 0.1,0.5,0.9]
            epsilon = [1e-2, 1e-1, 1, 1.5, 2]
            K = [2,5,10,15,20]
            
        elif systemName == "4.2":
            mu = [1e-3,1e-1, 0.1,1]
            eta = [0.05, 0.1,0.5,0.9]
            epsilon = [1e-2, 1e-1, 1, 1.5, 2]
            K = [2,5,10,15,20]
        
    
        params = [{'eta':et,'epsilon':ep, 'mu':m, 'K':int(k)} for et in eta for ep in epsilon for m in mu for k in K]
                      
        # 2.2. Search over QKLMS_AMK with Montecarlo Simulation
        results = []
        testing_mse_xRun = []
        CB_size_xRun = []
        tradeOff_dist_xRun = []
        
        signalPower = inputSignal.var()
        
        singleRunDataSize = n_samples
        trainLength = n_train
              
        for run in range(MC_runs):
            print("\n\n Running Monte Carlo simulation #{}...\n".format(run))
            try:
                u_train, u_test, d_train, d_test = trainAndTestSplitWithEmbedding(inputSignal, targetSignal,signalEmbedding, run, singleRunDataSize, trainLength)
            except:
                u_train, u_test, d_train, d_test = customEmbeddingForKAFs(inputSignal, signalEmbedding, run, singleRunDataSize, trainLength)
                # u_train, u_test, d_train, d_test = customExogenousEmbeddingForKAFs(inputSignal, y, z, signalEmbedding, run, singleRunDataSize, trainLength)
                        
            for p in tqdm(params):
                try:
                    f = KAF.QKLMS_AMK(eta=p['eta'],epsilon=p['epsilon'], mu=p['mu'], Ka=p['K'], A_init="pca")
                    y = f.evaluate(u_train,d_train)
                    y_pred = f.predict(u_test)
                    err = d_test-y_pred.reshape(-1,1)
                    t_mse = np.mean(err**2)
                    testing_mse_xRun.append(t_mse/signalPower)
                    CB_size_xRun.append(len(f.CB))                  
                except:
                    testing_mse_xRun.append(np.nan)
                    CB_size_xRun.append(np.nan)
            
        allTestingMSEs = np.array(testing_mse_xRun).reshape(MC_runs,-1)
        allCB_sizes = np.array(CB_size_xRun).reshape(MC_runs,-1)
        
        testing_mse_average = np.nanmean(allTestingMSEs, axis=0)
        CB_size_average = np.nanmean(allCB_sizes, axis=0)
        
        tradeOff_distance = [tradeOffDistance(testing_mse_average[j],CB_size_average[j]/n_train) for j in range(len(params))]
        
        
        results = [p for p in params]
        results_df = pd.DataFrame(data=results)
        results_df['testing_mse'] = testing_mse_average
        results_df['CB_size'] = CB_size_average
        results_df['CB_size'] = results_df['CB_size'].astype(int)
        results_df['tradeOff_dist'] = tradeOff_distance
        
        results_df.to_csv(folder + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')   
    else:
        raise ValueError("Filter does not exist")   
    return       
Esempio n. 7
0
def kafSearch(filterName,systemName,n_samples,trainSplit):
    import KAF
    from tqdm import tqdm
    from sklearn.metrics import r2_score
    from sklearn.metrics import mean_squared_error
    import pandas as pd  
    import numpy as np
    
    n_paramters = 0
    
    # 1. Generate data for grid search
    n_train = int(n_samples*trainSplit)
    n_test = n_samples - n_train
    
    if systemName == "lorenz" or systemName == "chua":
        embedding = 5
        import TimeSeriesGenerator
        x, y, z = TimeSeriesGenerator.chaoticSystem(samples=200000,systemType='lorenz')
        x -= x.mean()
        x /= x.std()
        
        u_train = np.array([x[i-embedding:i] for i in range(embedding,n_train)])
        d_train = np.array([x[i] for i in range(embedding,n_train)]).reshape(-1,1)
        
        u_test = np.array([x[i-embedding:i] for i in range(n_train,n_samples)])
        d_test = np.array([x[i] for i in range(n_train,n_samples)]).reshape(-1,1)
        
    elif systemName == "4.2":
        embedding = 2
        import testSystems as ts
        x = ts.testSystems(samples = n_samples+embedding, systemType = "4.2_AKB")
        x -= x.mean()
        x /= x.std()
        
        u_train = np.array([x[i-embedding:i] for i in range(embedding,n_train)])
        d_train = np.array([x[i] for i in range(embedding,n_train)]).reshape(-1,1)
        
        u_test = np.array([x[i-embedding:i] for i in range(n_train,n_samples)])
        d_test = np.array([x[i] for i in range(n_train,n_samples)]).reshape(-1,1)
    else:
        raise ValueError("Database does not exist")
      
    # 2. Pick filter    
    if filterName == "QKLMS":
        # 2.1. Generate parameters for QKLMS grid search
        import numpy as np
        if systemName == "lorenz":
            eta = [0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 0, 2, 4]
            epsilon = [1e-2, 1e-1, 1]
            
        elif systemName == "chua":
            # eta = np.linspace(0.1,0.9,n_paramters)
            # sigma = np.linspace(100,500,n_paramters)
            # epsilon = np.linspace(0.01,20,n_paramters)
            a = 0
            
        elif systemName == "4.2":
            eta = [0.1, 0.5, 0.9]
            sigma = [1e-2, 1e-1, 0, 2, 4]
            epsilon = [1e-2, 1e-1, 1]
            
        params = [{'eta':et,'epsilon':ep, 'sigma':s } for et in eta for ep in epsilon for s in sigma]
                       
        # 2.2. Search over QKLMS
        results = []
        for p in tqdm(params):
            try:
                f = KAF.QKLMS(eta=p['eta'],epsilon=p['epsilon'],sigma=p['sigma'])
                y = f.evaluate(u_train,d_train)
                y_pred = f.predict(u_test)
                err = d_test-y_pred.reshape(-1,1)
                t_mse = np.mean(err**2)
                signalPower = x.var()
                p['testing_mse'] = t_mse/signalPower
                p['CB_size'] = len(f.CB)
                p['tradeOff_dist'] = tradeOffDistance(p['testing_mse'],p['CB_size']/n_train)
            except:
                p['testing_mse'] = np.nan
                p['CB_size'] = np.nan
                p['tradeOff_dist'] = np.nan
            results.append(p)
            pd.DataFrame(data=results).to_csv('GridSearchResults2ndRun/' + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')
            
    elif filterName == "QKLMS_AKB": 
        # 2.1. Generate parameters for QKLMS_AKB grid search
        import numpy as np
        if systemName == "lorenz":
            eta = [0.1, 0.9]
            sigma = [1e-2, 1e-1, 2]
            epsilon = [1e-2, 1e-1, 1]
            mu = [1e-3, 1e-1, 0.1,1]
            K = [2,5,10,20]

        elif systemName == "chua":
            eta = np.linspace(0.1,0.9,n_paramters)
            sigma = np.linspace(0.01,200,n_paramters)
            epsilon = np.linspace(1e-3,100,n_paramters)
            mu = np.linspace(1e-4,1,n_paramters)
            K = np.linspace(2,20,n_paramters)

        elif systemName == "4.2":
            eta = np.linspace(0.1,0.9,n_paramters)
            sigma = np.linspace(0.01,200,n_paramters)
            epsilon = np.linspace(1e-3,100,n_paramters)
            mu = np.linspace(1e-4,1,n_paramters)
            K = np.linspace(2,20,n_paramters)

        params = [{'eta':et,'epsilon':ep, 'sigma_init':s, 'mu':m, 'K':int(k) } for et in eta for ep in epsilon for s in sigma for m in mu for k in K]
                      
        # 2.2. Search over QKLMS
        results = []
        for p in tqdm(params):
            try:
                f = KAF.QKLMS_AKB(eta=p['eta'],epsilon=p['epsilon'],sigma_init=p['sigma_init'], mu=p['mu'], K=p['K'])
                y = f.evaluate(u_train,d_train)
                y_pred = f.predict(u_test)
                err = d_test-y_pred.reshape(-1,1)
                t_mse = np.mean(err**2)
                signalPower = x.var()
                p['testing_mse'] = t_mse/signalPower
                p['CB_size'] = len(f.CB)
                p['tradeOff_dist'] = tradeOffDistance(p['testing_mse'],p['CB_size']/n_train)
            except:
                p['testing_mse'] = np.nan
                p['CB_size'] = np.nan
                p['tradeOff_dist'] = np.nan
            results.append(p)
            pd.DataFrame(data=results).to_csv('GridSearchResults2ndRun/' + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')
            
    elif filterName == "QKLMS_AMK": 
        # 2.1. Generate parameters for QKLMS_AKB grid search
        import numpy as np
        if systemName == "lorenz":
            mu = [1e-3,1e-1, 0.1,1,1.5,2]
            eta = [0.05, 0.1,0.5,0.9]
            epsilon = [1e-2, 1e-1, 1, 1.5, 2]
            K = [2,5,10,15,20]
        elif systemName == "chua":
            eta = np.linspace(0.02,1,n_paramters)
            epsilon = np.linspace(1e-3,100,n_paramters)
            mu = np.linspace(1e-4,1,n_paramters)
            K = np.linspace(2,20,n_paramters)
        elif systemName == "4.2":
            mu = [1e-3,1e-1, 0.1,1]
            eta = [0.05, 0.1,0.5,0.9]
            epsilon = [1e-2, 1e-1, 1, 1.5, 2]
            K = [2,5,10,15,20]
        
    
        params = [{'eta':et,'epsilon':ep, 'mu':m, 'K':int(k)} for et in eta for ep in epsilon for m in mu for k in K]
                      
        # 2.2. Search over QKLMS_AMK
        results = []
        for p in tqdm(params):
            try:
                f = KAF.QKLMS_AMK(eta=p['eta'],epsilon=p['epsilon'], mu=p['mu'], Ka=p['K'], A_init="pca")
                y = f.evaluate(u_train,d_train)
                y_pred = f.predict(u_test)
                err = d_test-y_pred.reshape(-1,1)
                t_mse = np.mean(err**2)
                signalPower = x.var()
                p['testing_mse'] = t_mse/signalPower
                p['CB_size'] = len(f.CB)
                p['tradeOff_dist'] = tradeOffDistance(p['testing_mse'],p['CB_size']/n_train)
            except:
                p['testing_mse'] = np.nan
                p['CB_size'] = np.nan
                p['tradeOff_dist'] = np.nan
            results.append(p)
            pd.DataFrame(data=results).to_csv('GridSearchResults2ndRun/' + filterName + '_' + systemName + '_' + str(n_samples) + '.csv')
            
    else:
        raise ValueError("Filter does not exist")   
    return       
Esempio n. 8
0
Created on Mon Dec 21 23:17:34 2020

@author: USUARIO
"""

import TimeSeriesGenerator as tsg
import numpy as np
import search
import pandas as pd

samples = 500
batchSize = 10
# epList = np.logspace(0, 2, 20)
# sgmList = np.logspace(0,2,20)
"""ATRACTOR DE LORENZ"""
x, y, z = tsg.chaoticSystem(samples=samples + 10, systemType="lorenz")
ua = x[-samples - 2:-2].reshape(-1, 1)
ub = y[-samples - 3:-3].reshape(-1, 1)
u = np.concatenate((ua, ub), axis=1)  # INPUT
d = z[-samples - 1:-1].reshape(-1, 1)  #TARGET

epList = np.linspace(1e-1, 300, 300)
sR_QKLMS = search.searchQKLMS(u, d, epList, "lorenz")

sgmList = np.linspace(0.1, np.max(u), 20)
epList = np.linspace(1e-6, 1e-1, 20)
sR_KRLS = search.searchKRLS_ALD(u, d, sgmList, epList, "lorenz")

sgmList = np.linspace(0.1, np.max(u), 20)
epList = np.linspace(1e-1, 300, 300)
sR_QKLMS_base = search.searchQKLMS_base(u, d, sgmList, epList, "lorenz")
Esempio n. 9
0
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 21 00:28:14 2021

@author: USUARIO
"""

import numpy as np
import testSystems as ts
N = 5000
u,d = ts.testSystems(N,'4.1_AKB')

import TimeSeriesGenerator
x, y, z = TimeSeriesGenerator.chaoticSystem(samples=6000,systemType='wang')

def std(x):
    x = x - x.mean()
    return x/x.std()

# signalEmbedding = 5
# X = np.array([u[i-signalEmbedding:i] for i in range(signalEmbedding,len(u))])
# y = np.array([d[i] for i in range(signalEmbedding,len(u))]).reshape(-1,1)

u = d = std(x)

 
import KAF
f = KAF.QKLMS_AMK(eta=0.01,epsilon=0.5,embedding=10, Ka=10, mu=0.05)
f.evaluate(u[:100],d[:100])

f.fit(u[:4000],d[:4000])
Esempio n. 10
0
from sklearn.mixture import BayesianGaussianMixture as bgm
from sklearn.linear_model import LinearRegression
from scipy.spatial.distance import cdist
from sklearn.metrics import r2_score
import TimeSeriesGenerator as tsg
import numpy as np

samples = 10000
batch_size = 50  #Batch size

attr_list = [
    "chua", "duffing", "nose_hoover", "rikitake", "rossler", "wang", "lorenz"
]

for att_type in attr_list:
    x, y, z = tsg.chaoticSystem(samples=samples + 10, systemType=att_type)
    u = np.concatenate(
        (x[-samples - 2:-2].reshape(-1, 1), y[-samples - 3:-3].reshape(-1, 1)),
        axis=1)  # INPUT
    d = z[-samples - 1:-1].reshape(-1, 1)  #TARGET

    # Training data dimensions
    Nu, Du = u.shape
    Nd, Dd = d.shape

    #inicializacion
    scr = []  #Score
    """PRETRAIN STAGE"""
    #split data in batches
    u_train = u.reshape(-1, batch_size, Du)
    d_train = d.reshape(-1, batch_size, Dd)
Esempio n. 11
0
db = 'lorenz'

R = 10  #MC repetions
tsLength = 1000

trainLength = int(tsLength * 0.7)
testLength = tsLength - trainLength

samples = R * tsLength

sigma = 1
eps = 1e-4

scale = 5  #For plotting purposes

x, y, z = tsg.chaoticSystem(samples=samples + L, systemType=db)

x -= x.mean()
x /= x.std()

mse = []

for r in range(R):
    #print(L+r*tsLength,L+r*tsLength+trainLength,L+r*tsLength+trainLength,L+(r+1)*tsLength)
    u_train = np.array([
        x[i - L:i]
        for i in range(L + r * tsLength, L + r * tsLength + trainLength)
    ])
    d_train = np.array([
        x[i] for i in range(L + r * tsLength, L + r * tsLength + trainLength)
    ]).reshape(-1, 1)