Skip to content

Commit

Permalink
remove results and move to new branch "results"
Browse files Browse the repository at this point in the history
  • Loading branch information
saguileran committed Jan 13, 2023
1 parent eaf9784 commit c27adbc
Show file tree
Hide file tree
Showing 96 changed files with 140 additions and 228 deletions.
300 changes: 74 additions & 226 deletions birdsong.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion birdsongs/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .utils import *

class Optimizer(Syllable, object):


def __init__(self, obj, method_kwargs):
self.obj = obj
self.obj0 = obj
Expand Down Expand Up @@ -30,7 +32,7 @@ def residualCorrelation(self, p):
# return syllable_synth.scoreFF -np.mean(syllable_synth.correlation+syllable_synth.Df+syllable_synth.scoreSKL)

# making peackeable
def residualCorrelation_p(p): return Optimizer, (p.a,)
#def residualCorrelation_p(p): return Optimizer, (p.a,)
# print("pickling a C instance...")


Expand Down
64 changes: 63 additions & 1 deletion birdsongs/syllable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ class Syllable(object):
fs = sampling rate
t0 = initial time of the syllable
"""
def __getstate__(self):
state = self.__dict__.copy()
#del state[''] # remove the unpicklable progress attribute
return state
def __setstate__(self, state):
self.__dict__.update(state)
# restore the progress from the progress integer
#self.progress = make_progress(self.progress_int)

def __init__(self, birdsong=None, t0=0, Nt=200, llambda=1.5, NN=0, overlap=0.5, flim=(1.5e3,2e4), n_mels=4, umbral_FF=1, tlim=[], sfs=[], no_syllable=0, ide="", file_name="total synth"):
## The bifurcation can be cahge modifying the self.f2 and self.f1 functions
## ------------- Bogdanov–Takens bifurcation ------------------
Expand Down Expand Up @@ -212,7 +221,7 @@ def AlphaBeta(self):
self.beta = np.dot(b, t_par);


## ------------------------- BIRDS -------------------------
def MotorGestures(self, alpha, beta, gamma, ovfs=20, prct_noise=0): # ovfs:oversamp
t, tmax, dt = 0, int(self.s.size)*ovfs-1, 1./(ovfs*self.fs) # t0, tmax, td
# pback and pin vectors initialization
Expand Down Expand Up @@ -282,6 +291,59 @@ def ODEs(v):
delattr(self,"alpha"); delattr(self,"beta")

return synth


## --------------- Anphibius -------------------------
def MotorGesturesAnphibius(self, alpha, beta, gamma, ovfs=20, prct_noise=0): # ovfs:oversamp
t, tmax, dt = 0, int(self.s.size)*ovfs-1, 1./(ovfs*self.fs) # t0, tmax, td
# pback and pin vectors initialization
pi, pb, out = np.zeros(tmax), np.zeros(tmax), np.zeros(int(self.s.size))
# initial vector ODEs (v0), it is not too relevant
v = 1e-4*np.array([1e2, 1e1, 1]); self.Vs = [v];
# ------------- BIRD PARAMETERS -----------
c, L, r = 3.43E+02, 2.50E-02, 6.50E-01
# , Ch, MG, MB, RB, Rh = BirdData['value'] # c, L, r, c, L1, L2, r2, rd
# BirdData = pd.read_csv(self.paths.auxdata/'ZonotrichiaData.csv')
# - Trachea:
# r: reflection coeficient [adimensionelss]
# L: trachea length [m]
# c: speed of sound in media [m/s]
def ODEs(v):
dv, [x, y, pout] = np.zeros(3), v # (x, y, pout)'
# ----------------- direct implementation of the EDOs -----------
# dv[0] = y
# dv[1] = (-self.alpha[t//ovfs]-self.beta[t//ovfs]*x-x**3+x**2)*self.p["gm"].value**2 - (x**2*y+x*y)*self.p["gm"].value
dv[0] = self.f1(x, y, alpha[t//ovfs], beta[t//ovfs], gamma)
dv[1] = self.f2(x, y, alpha[t//ovfs], beta[t//ovfs], gamma)
# ------------------------- trachea ------------------------
pbold = pb[t] # pressure back before
# Pin(t) = Ay(t)+pback(t-L/C) = envelope_Signal*v[1]+pb[t-L/C/dt]
pi[t] = (.5*self.envelope[t//ovfs])*dv[1] + pb[t-int(L/c/dt)]
pb[t] = -r*pi[t-int(L/c/dt)] # pressure back after: -rPin(t-L/C)
pout = (1-r)*pi[t-int(L/c/dt)] # pout
# ---------------------------------------------------------------
dv[2] = (pb[t]-pbold)/dt # dpout
return dv
# ----------------------- Solving EDOs ----------------------
while t < tmax: # and v[1] > -5e6: # labia velocity not too fast
v = rk4(ODEs, v, dt); self.Vs.append(v) # RK4 - step
out[t//ovfs] = v[-1] # output signal (synthetic)
t += 1;
# ------------------------------------------------------------
self.Vs = np.array(self.Vs)
# define solution (synthetic syllable) as a Syllable object
synth = Syllable(Nt=self.Nt, llambda=self.llambda, NN=self.NN, overlap=0.5, flim=self.flim, sfs=[out, self.fs])

synth.id = self.id+"-synth"
synth.Vs = self.Vs
synth.alpha = self.alpha
synth.beta = self.beta
synth.timesVs = np.linspace(0, len(self.s)/self.fs, len(self.s)*ovfs)

delattr(self,"alpha"); delattr(self,"beta");

return synth


# def Enve(self, out, fs, Nt):
# time = np.linspace(0, len(out)/fs, len(out))
Expand Down
Binary file not shown.
Binary file removed examples/results/AllSongAndSyllable-2-2.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed examples/results/Birdsong-XC11293.png
Diff not rendered.
Binary file removed examples/results/Figure 10.png
Diff not rendered.
Binary file removed examples/results/Figure 2 (2).png
Diff not rendered.
Binary file removed examples/results/Figure 23.png
Diff not rendered.
Binary file removed examples/results/Figure 24.png
Diff not rendered.
Binary file removed examples/results/Figure 26.png
Diff not rendered.
Binary file removed examples/results/Figure 5.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed examples/results/Vs.png
Diff not rendered.
Binary file removed examples/results/alpha.png
Diff not rendered.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed examples/results/result.png
Diff not rendered.

0 comments on commit c27adbc

Please sign in to comment.