Method Decoration for Auto-Logging

This notebook is for playing around with different approaches to automatically add decorators to the libraries that are commonly used for scientific computing and data science.


In [ ]:
import acorn
from acorn.msg import set_verbosity
set_verbosity(2)

In [ ]:
def iswhat(o):
    import inspect
    isfs = {n: f for n, f in inspect.getmembers(inspect) if n[0:2] == "is"}
    #Added a comment
    return {n: f(o) for n, f in isfs.items()}

def another(a,b):
    c = a+b
    return c

class SomeClass(object):
    def __init__(self, arg):
        self.a = arg

In [ ]:
import numpy as np
iswhat(np.random.RandomState.uniform)

In [ ]:
from acorn.logging.database import uuids
[u.describe() for u in uuids.values()]

In [ ]:
import inspect
inspect.getmembers(np.random.RandomState)

In [ ]:
from acorn.logging.decoration import _fqdn
from acorn.msg import set_verbosity
set_verbosity(4)
import numpy as np
print(_fqdn(np.random.RandomState, False))

In [ ]:
inspect.isclass(rs.uniform.__class__)

In [ ]:
from acorn.logging.decoration import _get_members
import inspect
inspect.getmodule(np.random.mtrand.RandomState) is None

In [ ]:
from acorn.logging.decoration import _fqdn
_fqdn(np.random.mtrand.RandomState)

In [ ]:
import numpy as np
iswhat(np.random.mtrand.RandomState)

In [ ]:
import numpy as np

In [ ]:
from acorn.msg import set_verbosity
set_verbosity(2)
from acorn.logging.database import set_writeable
set_writeable(False)

import acorn.sklearn as skl
#import acorn.scipy as sp
import acorn.matplotlib as mpl
import acorn.pandas as pd
import acorn.numpy as np
from acorn import set_task
set_task("acorn", "x")

In [ ]:
import matplotlib.pyplot as plt
plt.plot(range(1000), range(1000))

In [ ]:
from acorn.logging.database import tracker
from acorn.logging.decoration import _get_members
_get_members(np.sqrt)
tracker(np.sqrt.__acornext__)

In [ ]:
a=np.array(range(10))

In [ ]:
a[0:4]

In [ ]:
from acorn.logging.database import tracker
tracker(slice(0,2,4))

In [ ]:
import pandas as pd

In [ ]:
import scipy.optimize as opt

In [ ]:
ti.uuid

In [ ]:
ti.describe()

In [ ]:
a[3]

In [ ]:
from acorn.msg import set_verbosity
set_verbosity(3)

In [ ]:
a[0:3]

In [ ]:
sp.array(range(10))

In [ ]:
from acorn.logging.database import uuids
uuids["cc9908e9-6812-4b00-8f24-60597f6ca7ac"].describe()

In [ ]:
np.array(range(10)).flatten()

In [ ]:
from sklearn.datasets import make_classification
kwds = {'n_clusters_per_class': 1, 'n_informative': 2,
        'random_state': 1, 'n_features': 2, 'n_redundant': 0}
X, y = make_classification(**kwds)
rng = np.random.RandomState(2)
X += 2 * rng.uniform(size=X.shape)

from sklearn.preprocessing import StandardScaler
X = StandardScaler().fit_transform(X)

In [ ]:
def localfun(a, b):
    return a + b

In [ ]:
class localclass():
    def __init__(self, dog):
        self.dog = dog

In [ ]:
cli = localclass("husky")

In [ ]:
localfun(1,3)

In [ ]:
np.array((0,0,600,400), dtype=np.float_).flatten()

In [ ]:
a = np.array(range(10))
a += 2

In [ ]:
from sklearn.datasets import make_moons, make_circles, make_classification
X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,
                           random_state=1, n_clusters_per_class=1)

import acorn.numpy as np
rng = np.random.RandomState(2)
X += 2 * rng.uniform(size=X.shape)

In [ ]:
X += 2

In [ ]:
import acorn.pywt as pywt

In [ ]:
wl = pywt.Wavelet("db4")

In [ ]:
np.squeeze(np.array([0.]), 0)

In [ ]:
np.percentile(range(10), 0.25)

In [ ]:
khnp.sq

In [ ]:
import pandas as pd

In [ ]:
from acorn.logging.decoration import _get_members
_get_members(pd.core.frame.DataFrame)

In [ ]:
pd.core.frame.DataFrame.__old__(pd.core.frame.DataFrame)

In [ ]:
pdf=pd.DataFrame(range(10))
pdf.describe()

In [ ]:
csdf=pd.read_csv("../../tests/darwin.csv")
csdf.describe()

In [ ]:
ind = pd.Index([1./i for i in range(1, 11)], dtype=float)
ser=pd.Series(range(2, 12), index=ind)

In [ ]:
ser

In [ ]:
import matplotlib.pyplot as plt
plt.plot(range(10), range(10))

In [ ]:
a = np.array(range(10))

In [ ]:
c = a[0:4]

In [ ]:
d = a[2:6]/3

In [ ]:
np.multiply(a, 2)

In [ ]:
a *= 2

In [ ]:
d = a.copy()

In [ ]:
a*2

In [ ]:
2*a

In [ ]:
isinstance(np.asarray(a), np.ndarray)

In [ ]:
a.reshape((5,2))

In [ ]:
b = a.flatten()

In [ ]:
np.delete(b, 2, 0)

In [ ]:
np.ndarray.reshape(a.flatten(), (5,2))

In [ ]:
np.empty(10)

In [ ]:
np.linspace(0,1,2500)

In [ ]:
set_verbosity(3)

In [ ]:
from acorn.logging.decoration import _get_members
_get_members(np.random.RandomState)

In [ ]:
from sklearn.datasets import make_moons, make_circles, make_classification
X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,
                           random_state=1, n_clusters_per_class=1)

import acorn.numpy as np
rng = np.random.RandomState(2)
X += 2 * rng.uniform(size=X.shape)

In [ ]:
from sklearn.preprocessing import StandardScaler
from sklearn.cross_validation import train_test_split
X = StandardScaler().fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.4)

In [ ]:
from sklearn.svm import SVC
svc = SVC()
svc.fit(X_train, y_train)

In [ ]:
from acorn.logging.database import uuids
{u: v.describe() for u, v in uuids.items()}

In [ ]:
yL=svc.predict(X_test)

In [ ]:
yL-y_test

In [ ]:
from scipy.interpolate import splev, splrep
tck = splrep(a, sp.fftpack.hilbert(a))
y = splev(a, tck)

In [ ]:
lambfun = lambda x: x**2
pdf = pd.DataFrame(range(15,25))
pdf.apply(lambfun)

In [ ]:
import numpy as np
pdf.apply(np.sqrt)

In [ ]:
pdf.describe()

In [ ]:
e = np.empty(1, complex)

In [ ]:
zz = np.zeros((10,2), int)

In [ ]:
np.linspace(0, 1, 25)

In [ ]:
ser

In [ ]: