<jupyter_start><jupyter_text>Simple example to demonstrate the effect of forcing in the mode-locking regions<jupyter_code>%matplotlib inline
%load_ext autoreload
%autoreload 2

from __future__ import division
import numpy as np

import matplotlib.pyplot as plt

from pygrfnn import GrFNN, Zparam
from pygrfnn.network import Model
from pygrfnn.vis import tf_simple

from daspy import Signal
from daspy.processing import onset_detection_signal
from pyrhythm.library import get_pattern


P = get_pattern('Bossa')

sr = 16000.0

hop_size = 256
x,_ = P.as_signal(sr=sr, reps=8, tempo=60)
x = Signal(x, sr=sr)
x = x.normalize()*10/hop_size  # empirical relationship
t = np.linspace(0,len(x)/sr,len(x))


s = onset_detection_signal(x, hop_size=hop_size, win_len=4096)
ts = np.linspace(0,len(s)/s.sr,len(s))

# plt.plot(ts,s)

zp = Zparam(alpha=0.0001, beta1=-2, beta2=0)
g = GrFNN(zp, 
          z0=0,
          w=1,
          frequency_range=(0.325, 12), 
          num_oscs=200, 
          stimulus_conn_type='allfreq')
m = Model()
m.add_layer(g, input_channel=0)


z0 = [g.z.copy() for g in m.layers()]    # reset states
output_dir = '/Users/jorgeh/Documents/CCRMA/research/ismir2015/frameworkPaper/figs/effectOfForcing'

for gain in [0.25, 1]:

    # reset
    for z, l in zip(z0, m.layers()):
        l.z = z.copy()    
    
    # run it
    m.run(gain*s, ts, 1/s.sr)

    # show TFR
    tf_simple(np.abs(g.Z), ts, g.f, x=gain*s, title="g = {}".format(gain), 
              cmap='binary',
#               vmin=0, 
#               vmax=0.2
             )
    
    # NOTE: tikz_save can't handle the color bar, so if you uncomment this, you'll need to go to the source code
    # in pygrfnn.vis and comment out the line lines `cb = plt.colorbar(im, ax=axTF, cax=axCB)` and 
    # `cb.ax.yaxis.set_ticks_position('left')`
#     tikz_save('{}/{}.tikz'.format(output_dir


onset_detection_signal?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12923397602918185, 'fraction_numerical': 0.0297029702970297, 'mean_word_length': 3.2666666666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '437267', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 791, 'n_tokens_neox': 737, 'n_words': 172, 'path': 'notebooks/others/Effect Of Forcing.ipynb', 'repo_name': 'jorgehatccrma/pygrfnn', 'size': '1919'}