Basic functionality


In [21]:
%matplotlib inline
%load_ext autoreload
%autoreload 2

from __future__ import division

import numpy as np
import matplotlib.pyplot as plt

import logging
# logging.getLogger('pygrfnn').setLevel(logging.INFO)  # use/change this for development/debuging (use logging.DEBUG for debugging)
logging.getLogger('pygrfnn.resonances').setLevel(logging.INFO)

from pygrfnn import Zparam, GrFNN, Model
from pygrfnn.vis import vector_field

sr = 100
dur = 1.0
t = np.linspace(0, dur, sr*dur)
x = np.exp(2j*np.pi*3*t)
x[np.real(x)<0] = 0

plt.plot(t, np.real(x))


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Out[21]:
[<matplotlib.lines.Line2D at 0x11209aad0>]

In [22]:
zp = Zparam(-0.001, 2, -5, epsilon=0.9)
l = GrFNN(zp,
          frequency_range=(0.5, 8),
          num_oscs=128,
          stimulus_conn_type='active',
          name='Layer 1')

vector_field(zp, F=np.arange(0,1,0.1))
plt.ylim(-0.5, 1)


Out[22]:
(-0.5, 1)

In [23]:
from pygrfnn.network import make_connections


model = Model()
model.add_layer(l, input_channel=0)

# C = make_connections(l, l, modes=[1/2, 1, 2])
# model.connect_layers(l, # source
#                      l, # destination
#                      C, # connection matrix
#                      connection_type='allfreq', 
# #                      connection_type='3freq', 
# #                      connection_params={'N': 15, 'tol':1e-6, 'lowest_order_only': True},
#                      weight=0.01,
#                     )

In [24]:
from pygrfnn.vis import tf_detail

model.run(0.01*x, t, sr)
tf_detail(l.Z, t, l.f, t_detail=dur/2, title='TFR')


100/100 done!
/Users/jorgeh/Documents/CCRMA/research/pygrfnn/pygrfnn/oscillator.py:112: RuntimeWarning: invalid value encountered in divide
  nl2 = zp.b2 * f * zp.e * (np.abs(z) ** 4) / (1 - zp.e * np.abs(z) ** 2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-24-5473810b5be4> in <module>()
      2 
      3 model.run(0.01*x, t, sr)
----> 4 tf_detail(l.Z, t, l.f, t_detail=dur/2, title='TFR')

/Users/jorgeh/Documents/CCRMA/research/pygrfnn/pygrfnn/vis.pyc in display_wrapper(*args, **kwargs)
     44             import os
     45             if "DISPLAY" in os.environ:
---> 46                 return fun(*args, **kwargs)
     47             else:
     48                 warnings.warn("Couldn't find a DISPLAY, so visualizations are disabled")

/Users/jorgeh/Documents/CCRMA/research/pygrfnn/pygrfnn/vis.pyc in tf_detail(TF, t, f, title, t_detail, x, display_op, figsize, cmap, vmin, vmax)
    234         t_detail, idx = find_nearest(t, t_detail)
    235         # axF.invert_xaxis()
--> 236         detail = axF.semilogy(opTF[:, idx], f)
    237         axF.set_yticks(nice_freqs)
    238         axF.get_yaxis().set_major_formatter(mpl.ticker.ScalarFormatter())

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in semilogy(self, *args, **kwargs)
   4375         b = self._hold
   4376         self._hold = True  # we've already processed the hold
-> 4377         l = self.plot(*args, **kwargs)
   4378         self._hold = b  # restore the hold
   4379 

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in plot(self, *args, **kwargs)
   4139             lines.append(line)
   4140 
-> 4141         self.autoscale_view(scalex=scalex, scaley=scaley)
   4142         return lines
   4143 

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in autoscale_view(self, tight, scalex, scaley)
   1961                 y1 += delta
   1962             if not _tight:
-> 1963                 y0, y1 = ylocator.view_limits(y0, y1)
   1964             self.set_ybound(y0, y1)
   1965 

/usr/local/lib/python2.7/site-packages/matplotlib/ticker.pyc in view_limits(self, vmin, vmax)
   1483         if minpos <= 0 or not np.isfinite(minpos):
   1484             raise ValueError(
-> 1485                 "Data has no positive values, and therefore can not be "
   1486                 "log-scaled.")
   1487 

ValueError: Data has no positive values, and therefore can not be log-scaled.

In [25]:
l.Z


Out[25]:
array([[ -2.51898929e-03 +1.56971557e-03j,
          3.47820909e+25 -9.03772211e+23j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj],
       [ -5.63896899e-04 -5.65629760e-04j,
          5.34156409e+24 +1.79858355e+25j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj],
       [ -1.37790826e-03 -1.58389551e-03j,
          6.31428766e+26 +1.44061248e+27j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj],
       ..., 
       [  4.48038124e-03 -7.70046634e-03j,
          1.74193529e+82 +8.42642812e+81j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj],
       [ -8.16179978e-04 -1.35476441e-03j,
          2.76028607e+68 -7.16687804e+67j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj],
       [ -1.57564462e-04 -2.07931914e-03j,
          9.26916046e+70 -2.98134100e+69j,
                     nan            +nanj, ...,
                     nan            +nanj,
                     nan            +nanj,
                     nan            +nanj]])

In [ ]: