コード例 #1
0
def CCM(pathIn="./",
        dataFile="",
        dataFrame=None,
        pathOut="./",
        predictFile="",
        E=0,
        Tp=0,
        knn=0,
        tau=1,
        columns="",
        target="",
        libSizes="",
        sample=0,
        random=True,
        replacement=False,
        seed=0,
        verbose=False,
        showPlot=False):
    '''Convergent Cross Mapping on path/file.'''

    # Establish DF as empty list or Pandas DataFrame for CCM()
    if dataFile:
        DF = pyBindEDM.DF()
    elif isinstance(dataFrame, DataFrame):
        if dataFrame.empty:
            raise Exception("CCM(): dataFrame is empty.")
        DF = pyEDM.AuxFunc.PandasDataFrametoDF(dataFrame)
    else:
        raise Exception("CCM(): Invalid data input.")

    # D is a Python dict from pybind11 < cppEDM CCM
    D = pyBindEDM.CCM(pathIn, dataFile, DF, pathOut, predictFile, E, Tp, knn,
                      tau, columns, target, libSizes, sample, random,
                      replacement, seed, verbose)

    df = DataFrame(D)  # Convert to pandas DataFrame

    if showPlot:
        title = dataFile + "\nE=" + str(E)

        ax = df.plot('LibSize', [df.columns[1], df.columns[2]],
                     title=title,
                     linewidth=3)
        ax.set(xlabel="Library Size", ylabel="Correlation ρ")
        axhline(y=0, linewidth=1)
        show()

    return df
コード例 #2
0
def CCM( pathIn           = "./",
         dataFile         = "",
         dataFrame        = None,
         pathOut          = "./",
         predictFile      = "",
         E                = 0, 
         Tp               = 0,
         knn              = 0,
         tau              = -1,
         exclusionRadius  = 0,
         columns          = "",
         target           = "",
         libSizes         = "",
         sample           = 0,
         random           = True,
         replacement      = False,
         seed             = 0,
         embedded         = False,
         includeData      = False,
         parameterList    = False,
         verbose          = False,
         showPlot         = False ) :
    '''Convergent Cross Mapping on path/file.'''

    # Establish DF as empty list or Pandas DataFrame for CCM()
    if dataFile :
        DF = pyBindEDM.DF()
    elif isinstance( dataFrame, DataFrame ) :
        if dataFrame.empty :
            raise Exception( "CCM(): dataFrame is empty." )
        DF = pyEDM.AuxFunc.PandasDataFrametoDF( dataFrame )
    else :
        raise Exception( "CCM(): Invalid data input." )

    # If columns, libSizes, target are not string, but iterable, convert to string
    if pyEDM.AuxFunc.NotStringIterable( columns ) :
        columns = ' '.join( map( str, columns ) )
    if pyEDM.AuxFunc.NotStringIterable( libSizes ) :
        libSizes = ' '.join( map( str, libSizes ) )
    if pyEDM.AuxFunc.NotStringIterable( target ) :
        target = ' '.join( map( str, target ) )

    # D is a Python dict from pybind11 < cppEDM CCM
    D = pyBindEDM.CCM( pathIn,
                       dataFile,
                       DF,
                       pathOut,
                       predictFile,
                       E, 
                       Tp,
                       knn,
                       tau,
                       exclusionRadius,
                       columns,
                       target,
                       libSizes,
                       sample,
                       random,
                       replacement,
                       seed,
                       embedded,
                       includeData,
                       parameterList,
                       verbose )

    # D has { "LibMeans" : DF }
    # and if includeData has : { PredictStats1 : DF, PredictStats2 : DF }
    libMeans = DataFrame( D[ "LibMeans" ] ) # Convert to pandas DataFrame

    # If includeData, create dict with means and individual prediction stats
    if includeData :
        CM = { 'LibMeans'      : libMeans,
               'PredictStats1' : DataFrame( D[ "PredictStats1" ] ),
               'PredictStats2' : DataFrame( D[ "PredictStats2" ] ) }

    if parameterList and includeData :
        CM[ 'parameters' ] = D[ 'parameters' ]

    if showPlot :
        title = dataFile + "\nE=" + str(E)

        ax = libMeans.plot( 'LibSize',
                            [ libMeans.columns[1], libMeans.columns[2] ],
                            title = title, linewidth = 3 )
        ax.set( xlabel = "Library Size", ylabel = "Correlation ρ" )
        axhline( y = 0, linewidth = 1 )
        show()

    if includeData :
        return CM
    else :
        return libMeans