コード例 #1
0
ファイル: smapSolverTest.py プロジェクト: tedinburgh/pyEDM
def main():
    '''Test sklearn.linear_model solvers'''

    circle = pyEDM.sampleData['circle']

    lmSolvers = {
        'SVD': None,
        'Ridge': Ridge(alpha=0.05),
        'Lasso': Lasso(alpha=0.005),
        'ElasticNet': ElasticNet(alpha=0.001, l1_ratio=0.001),
        'RidgeCV': RidgeCV(),
        'LassoCV': LassoCV(cv=5),
        'ElasticNetCV': ElasticNetCV(l1_ratio=[.05, .1, .5, .7, .9, .95, 1],
                                     cv=5)
    }

    smapResults = {}

    for solverName in lmSolvers.keys():
        print(solverName)
        result = pyEDM.SMap(dataFrame=circle,
                            lib="1 100",
                            pred="101 198",
                            embedded=True,
                            E=2,
                            theta=3.14,
                            columns="x y",
                            target="x",
                            showPlot=True,
                            solver=lmSolvers[solverName])
        smapResults[solverName] = result
コード例 #2
0
ファイル: examples.py プロジェクト: yuanqingmei/pyEDM
def main():
    '''EDM package examples.
       df denotes a Pandas DataFrame.
       S and M denote dictionaries of Pandas DataFrames'''

    dataFiles = [ "TentMap_rEDM.csv",
                  "TentMapNoise_rEDM.csv",
                  "circle.csv",
                  "block_3sp.csv",
                  "sardine_anchovy_sst.csv" ]
    
    # Create map of module dataFiles pathnames in Files
    Files = {}

    for file in dataFiles:
        filename = "data/" + file
        if pkg_resources.resource_exists( EDM.__name__, filename ):
            Files[ file ] = \
            pkg_resources.resource_filename( EDM.__name__, filename )
        else :
            raise Exception( "examples.py: Failed to find data file " + \
                             file + " in EDM package" )

    # Note the path argument is empty "", file path is in Files{}
    df = EDM.EmbedDimension( "", Files[ "TentMap_rEDM.csv" ], None, "./", "",
                             "1 100", "201 500", 10, 1, 1,
                             "TentMap", "", False, False, 4 )
    
    df = EDM.PredictInterval( "", Files[ "TentMap_rEDM.csv" ], None, "./", "",
                              "1 100", "201 500", 10, 2, 1,
                              "TentMap", "", False, False, 4 );

    df = EDM.PredictNonlinear( "", Files[ "TentMapNoise_rEDM.csv" ], None,
                               "./", "", "1 100", "201 500", "", 2, 1, 0, 1,
                               "TentMap", "", False, False, 4 )
    
    # Tent map simplex : specify multivariable columns embedded = True
    df = EDM.Simplex( "", Files[ "block_3sp.csv" ], None, "./", "", 
                      "1 99", "100 198", 3, 1, 0, 1, 0,
                      "x_t y_t z_t", "x_t", True, False, True, True )

    # Tent map simplex : Embed column x_t to E=3, embedded = False
    df = EDM.Simplex( "", Files[ "block_3sp.csv" ], None, "./", "", 
                      "1 99", "100 195", 3, 1, 0, 1, 0,
                      "x_t", "x_t", False, False, True, True )

    M = EDM.Multiview( "", Files[ "block_3sp.csv" ], None, "./", "", 
                       "1 100", "101 198", 3, 1, 0, 1,
                       "x_t y_t z_t", "x_t", 0, 0, False, 4, True )

    # S-map circle : specify multivariable columns embedded = True
    S = EDM.SMap( "", Files[ "circle.csv" ], None, "./", "", 
                  "1 100", "101 198", 2, 1, 0, 1, 4, 0,
                  "x y", "x", "", "", True, False, True, True )
    
    df = EDM.CCM( "", Files[ "sardine_anchovy_sst.csv" ], None, "./", "", 
                  3, 0, 0, 1, "anchovy", "np_sst",
                  "10 70 10", 100, True, False, 0, True, True )
コード例 #3
0
    def test_smap2(self):
        #--------------------------------------------------------
        # block_3sp embedded = True
        #--------------------------------------------------------
        print("--- S-map block_3sp embedded = True ---")
        SM = EDM.SMap("", self.Files["block_3sp.csv"], None, "./", "", "1 99",
                      "100 198", 3, 1, 0, 1, 2, 0, "x_t y_t z_t", "x_t", "",
                      "", True, False, True, False)

        df = SM['predictions']

        dfv = EDM.ReadDataFrame("",
                                self.Files["Smap_embd_block_3sp_pyEDM.csv"])

        S1 = dfv.get('Prediction_t(+1)')
        S2 = round(df.get('Predictions'), 4)
        self.assertTrue(S1.equals(S2))
コード例 #4
0
    def test_smap(self):
        #--------------------------------------------------------
        # circle test embedded = True
        #--------------------------------------------------------
        print("--- S-map circle embedded = True ---")
        dfc = EDM.ReadDataFrame("", self.Files["circle.csv"])

        # Passing Pandas DataFrame input to Smap rather than path/file
        SM = EDM.SMap("", "", dfc, "", "", "1 100", "101 198", 2, 1, 0, 1, 4,
                      0, "x y", "x", "", "", True, False, True, False)

        df = SM['predictions']

        dfv = EDM.ReadDataFrame("", self.Files["Smap_circle_pyEDM.csv"])

        S1 = dfv.get('Prediction_t(+1)')
        S2 = round(df.get('Predictions'), 4)
        self.assertTrue(S1.equals(S2))
コード例 #5
0
ファイル: test.py プロジェクト: cameronosmith/pyEDM
import pandas as pd
import pyEDM
import numpy as np

df = pd.read_csv("twospike_data.csv")

# showt that prediction is good (contains non-1 values)

exclusion_matrix = np.zeros((df.shape[0],df.shape[0]))

for idx in range(70,83):
    exclusion_matrix[idx-1, -1+np.array(list(range(20,30)))] = 1

'''simplex_out = pyEDM.Simplex(dataFrame=df, E=3, tau=1, knn=20,
                        exclusionMatrix=pd.DataFrame( exclusion_matrix ),
                        lib="1 50", pred="71 81", columns="wave")
print(simplex_out)
'''

simplex_out = pyEDM.SMap(dataFrame=df, E=3, tau=1, knn=20,
                        exclusionMatrix=pd.DataFrame( exclusion_matrix ),
                        lib="1 50", pred="71 81", columns="wave")
print(simplex_out)



# construct exlcusion matrix( exclude all non-1 values)
コード例 #6
0
def main():
    '''EDM package examples.
       df denotes a Pandas DataFrame.
       S and M denote dictionaries of Pandas DataFrames'''

    dataFiles = [ "TentMap_rEDM.csv",
                  "TentMapNoise_rEDM.csv",
                  "circle.csv",
                  "block_3sp.csv",
                  "sardine_anchovy_sst.csv" ]
    
    # Create map of module dataFiles pathnames in Files
    Files = {}

    for file in dataFiles:
        filename = "data/" + file
        if pkg_resources.resource_exists( EDM.__name__, filename ):
            Files[ file ] = \
            pkg_resources.resource_filename( EDM.__name__, filename )
        else :
            raise Exception( "examples.py: Failed to find data file " + \
                             file + " in EDM package" )

    # Note the path argument is empty "", file path is in Files{}
    df = EDM.EmbedDimension( pathIn = "", dataFile = Files["TentMap_rEDM.csv"],
                             lib = "1 100", pred = "201 500", maxE = 10,
                             Tp = 1, tau = -1, exclusionRadius = 0,
                             columns = "TentMap", target = "TentMap",
                             validLib = [], numThreads = 4 )
    
    df = EDM.PredictInterval( pathIn = "", dataFile = Files["TentMap_rEDM.csv"],
                              lib = "1 100", pred = "201 500", maxTp = 10,
                              E = 2, tau = -1, exclusionRadius = 0,
                              columns = "TentMap", target = "TentMap",
                              validLib = [], numThreads = 4 );

    df = EDM.PredictNonlinear( pathIn = "",
                               dataFile = Files[ "TentMapNoise_rEDM.csv" ],
                               lib = "1 100", pred = "201 500", E = 2,
                               Tp = 1, knn = 0, tau = -1,
                               columns = "TentMap", target = "TentMap",
                               validLib = [], numThreads = 4 )
    
    # Tent map simplex : specify multivariable columns embedded = True
    S = EDM.Simplex( pathIn = "", dataFile = Files[ "block_3sp.csv" ],
                     lib = "1 99", pred = "100 198", E = 3, Tp = 1,
                     knn = 0, tau = -1, exclusionRadius = 0,
                     columns = "x_t y_t z_t", target = "x_t",
                     embedded = True, showPlot = True,
                     validLib = [], generateSteps = 0, parameterList = False )

    # Tent map simplex : Embed column x_t to E=3, embedded = False
    S = EDM.Simplex( pathIn = "", dataFile = Files[ "block_3sp.csv" ],
                     lib = "1 99", pred = "100 198", E = 3, Tp = 1,
                     knn = 0, tau = -1, exclusionRadius = 0,
                     columns = "x_t y_t z_t", target = "x_t",
                     embedded = False, showPlot = True,
                     validLib = [], generateSteps = 0, parameterList = False )

    M = EDM.Multiview( pathIn = "", dataFile = Files[ "block_3sp.csv" ],
                       lib = "1 100", pred = "101 198",
                       D = 0, E = 3, Tp = 1, knn = 0, tau = -1,
                       multiview = 0, exclusionRadius = 0,
                       columns = "x_t y_t z_t", target = "x_t",
                       trainLib = True, excludeTarget = False,
                       numThreads = 4, showPlot = True )

    # S-map circle : specify multivariable columns embedded = True
    S = EDM.SMap( pathIn = "", dataFile = Files[ "circle.csv" ], 
                  lib = "1 100", pred = "101 198",
                  E = 2, Tp = 1, knn = 0, tau = -1,
                  theta = 4, exclusionRadius = 0,
                  columns = "x y", target = "x",
                  solver = None, embedded = True,
                  validLib = [], generateSteps = 0, parameterList = False )
    
    CM = EDM.CCM( pathIn = "", dataFile = Files[ "sardine_anchovy_sst.csv" ],
                  E = 3, Tp = 0, knn = 0, tau = -1, exclusionRadius = 0,
                  columns = "anchovy", target = "np_sst",
                  libSizes = "10 70 10", sample = 100, random = True,
                  replacement = False, seed = 0, includeData = False,
                  parameterList = False, verbose = False, showPlot = True )