예제 #1
0
def Ethrs(freq, network):
  """
  for each mode in network, computes all possible Ethrs from pairing present. Returns them in a similiar form to network.K

  This algorithm returns Ethrs only for daughter modes (defined as NOT the largest natural frequency in the network)

  expect freq to be a list of peak frequencies (observed), one for each mode in network

  This algorithm may also be inefficient...
  """

  Ethrs = []
  for m in range(len(network)):
    Ethrsm = []
    wm, ym, Um = network.wyU[m]
    abs_wm = abs(wm)
    for i, j, kmij in network.K[m]: # iterate over all possible couplings
      wi, yi, Ui = network.wyU[i]
      wj, yj, Uj = network.wyU[j]
      abs_wi = abs(wi)
      abs_wj = abs(wj)
      if (abs_wm > abs_wi) and (abs_wm > abs_wj): # parent mode
        Ethrsm.append( (m, i,j, kmij, ms.compute_Ethr(-freq[m], wi, wj, yi, yj, kmij) ) ) # minus sign due to FFT convention
      elif (abs_wm > abs_wi): # j is the parent
        Ethrsm.append( (j,i,m, kmij, ms.compute_Ethr(-freq[j], wm, wi, ym, yi, kmij) ) )
      elif (abs_wm > abs_wj): # i is the parent
        Ethrsm.append( (i,j,m, kmij, ms.compute_Ethr(-freq[i], wm, wj, ym, yj, kmij) ) )
      elif (abs_wi > abs_wj): # i is the parent
        Ethrsm.append( (i,j,m, kmij, ms.compute_Ethr(-freq[i], wm, wj, ym, yj, kmij) ) )
      else: # j is the parent
        Ethrsm.append( (j,i,m, kmij, ms.compute_Ethr(-freq[j], wm, wi, ym, yi, kmij) ) )

    Ethrsm.sort(key=lambda l: l[-1])
    Ethrs.append( Ethrsm )

  return Ethrs
예제 #2
0
def Ethr(system, freqs=None, triples=None):
  """ 
  returns a dictionary
    key, value = triple, Ethr
  """
  if not freqs:
    freqs = system.compute_3mode_freqs()
  if not triples:
    triples = system.network.to_triples()

  Ethrs = {}
  for triple in triples:
    modeo, modei, modej, k = triple
    modeNoo = system.network.modeNoD[modeo.get_nlms()]
    Ethrs[triple] = ms.compute_Ethr(freqs[modeNoo], modei.w, modej.w, modei.y, modej.y, k)

  return Ethrs
예제 #3
0
  def compute_3mode_freqs(self):
    """
    compute all analytic frequencies for this network
    """
    network = self.network
    modes = {}

    g0 = network.find_G0() # find G0
    for modeNo, O in zip(g0, self.compute_linear_freqs(g0)): # compute linear frequencies and assign them
      modes[modeNo] = O

    gi = g0
    while len(modes.keys()) < len(network):
      gip1, couplings = network.find_Gip1(gi) # get daughters
      Ethrs = []
      for o, i, j, k in couplings: # compute all Ethrs for these daughters
        Oo = modes[o] # parent frequency
        wi, yi, _ = network.wyU[i]
        wj, yj, _ = network.wyU[j]
        Ethrs.append( ( compute_Ethr(Oo, wi, wj, yi, yj, k), (o, i, j, k), (wi,wj,yi,yj) ) ) # compute_Ethr imported from mode_selection
    
      Ethrs.sort(key=lambda l: l[0]) # sort the couplings by dynamical relevance so we pick the most important terms first
    
      for Ethr, (o, i, j, k), (wi,wj,yi,yj) in Ethrs: # iterate through and define each daughter's frequency
        if modes.has_key(i) and modes.has_key(j): # both freqs already defined
          pass
        elif modes.has_key(i): # only one freq defined. The other frequency oscillates to cancel the time-dependence
          modes[j] = -(modes[o] + modes[i])
        elif modes.has_key(j):
          modes[i] = -(modes[o] + modes[j])
        else: # modes oscillate at 3 mode stability solutions (our best guess)
          D = modes[o] + wi + wj
          modes[i] = wi - D/(1+yj/yi)
          modes[j] = wj - D/(1+yi/yj)

      gi = gip1

    return [modes[modeNo] for modeNo in sorted(modes.keys())]
예제 #4
0
  def compute_single_parent_3mode_eq(self, t=0.0, default=1e-20, tcurrent="x"):
    """
    computes the 3mode equilibrium state at t by choosing the G0-G1 triple that minimizes Ethr. Ignores all modes with genNo >1
    for modes that do not participate in the 3mode equilib, the real and imaginary parts are set to rand*default, with rand chosen separately for the real and imag parts

    if there are no couplings between G0-G1, we return the linear equilibrium state 
    """
    network = self.network
    gens, coups = network.gens()

    if not len(coups[0]): # no couplings from parents to next generation -> only one generation
      return self.compute_lin_eq(t=t, default=default)

    from nmode_state import threeMode_equilib # we import this here because it avoids conflicts when importing the module as a whole

    freqs = {}
    for modeNo, O in zip(gens[0], self.compute_linear_freqs(gens[0])): # compute linear frequencies and assign them
      freqs[modeNo] = O

    Ethr = np.infty
    for o,i,j,k in coups[0]: # these are couplings with G0 as parent (o) and G1 as children (i,j)
      Oo = freqs[o]
      wi, yi, _ = network.wyU[i]
      wj, yj, _ = network.wyU[j]
      ethr = compute_Ethr(Oo, wi, wj, yi, yj, k)
      if ethr < Ethr: # choose tuple with lowest Ethr
        Ethr = ethr
        best_tuple = (o,i,j,k)

    ### for best tuple
    (o,i,j), (Ao, Ai, Aj), ((so, co), (si, ci), (sj, cj)), (do, di, dj) = threeMode_equilib(best_tuple, freqs[best_tuple[0]], network) # get amplitudes, phases and detunings appropriate for tcurrent == "q"

    ### check whether the daughters are non-zero
    if (Ai==0) and (Aj==0):
      return self.compute_lin_eq(t=t, default=default, tcurrent=tcurrent)

    ### instantiate IC vector
    q = np.random.rand(2*len(network))*default # the vast majority are set to rand*default

    ### fill in best triple
    if tcurrent == "q":
      p = (wo-do)*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*o:2*o+2] = Ao*np.array([cp*co + sp*so, -sp*co + cp*so])

      p = (wi-di)*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*i:2*i+2] = Ai*np.array([cp*ci + sp*si, -sp*ci + cp*si])

      p = (wj-dj)*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*j:2*j+2] = Aj*np.array([cp*cj + sp*sj, -sp*cj + cp*sj])

    elif tcurrent == "x":
      p = do*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*o:2*o+2] = Ao*np.array([cp*co - sp*so, sp*co + cp*so])

      p = di*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*i:2*i+2] = Ai*np.array([cp*ci - sp*si, sp*ci + cp*si])

      p = dj*t
      cp = np.cos(p)
      sp = np.sin(p)
      q[2*j:2*j+2] = Aj*np.array([cp*cj - sp*sj, sp*cj + cp*sj])
    else:
      raise ValueError, "unknown tcurrent = %s"%tcurrent

    return q
예제 #5
0
def Hns_coup_Ethr(Hns_coup, system):
  """ 
  generates a scatter plot of the energy assoicated with each coupling as a function of the Ethr ranking scheme
    Ethr = yb*yc/(4*k**2*wb*wc)*(1 + (Oa+wb+wc)**2/(yb+yc)**2)  <== delegated to mode_selection.compute_Ethr()

  requires Hns_coup to have the form returned by nmode_state.Hns_coup()
  """
  network = system.network

  ### find three mode frequencies
  freqs = system.compute_3mode_freqs()
#  freqs.sort(key=lambda l: l[1])
#  freqs = [w for w, modeNo in freqs]

  ### generate detunings, mean and stdv of Hns_coup
  mH = []
  sH = []
  Ethrs = []
  for (i,j,k,kappa), h_ns_coup in Hns_coup.items():
    mh = nms.sample_mean(h_ns_coup)
    mH.append( mh )
    sH.append( nms.sample_var(h_ns_coup, xo=mh)**0.5 )
    wi = network.modes[i].w
    wj = network.modes[j].w
    wk = network.modes[k].w
    for (a,b,kappa) in network.K[i]: # find correct coupling coeff
      if ((j == a) and (k == b)) or ((j == b) and (k == a)):
        break
    else:
      raise ValueError("could not locate this coupling: (%d,%d,%d) in nmode_diagnostic.Hns_coup_Ethr()" % (i,j,k))

    if (abs(wi) > abs(wj)) and (abs(wi) > abs(wk)):
      Ethrs.append( ms.compute_Ethr(freqs[i], wj, wk, network.modes[j].y, network.modes[k].y, kappa) )
    elif (abs(wj) > abs(wk)):
      Ethrs.append( ms.compute_Ethr(freqs[j], wi, wk, network.modes[i].y, network.modes[k].y, kappa) )
    else:
      Ethrs.append( ms.compute_Ethr(freqs[k], wi, wj, network.modes[i].y, network.modes[k].y, kappa) )

  mH = abs(np.array(mH))

  fig = plt.figure()
  ax = fig.add_axes([0.15, 0.15, 0.6, 0.6])
  ax_Hns = fig.add_axes([0.775, 0.15, 0.175, 0.6])
  ax_Ethr = fig.add_axes([0.15, 0.775, 0.6, 0.175])

  ax.semilogy(Ethrs, mH, marker="o", markersize=2, markerfacecolor="none", markeredgecolor="b", linestyle="none")
  for Eth, m, s in zip(Ethrs, mH, sH):
    ax.plot([Eth,Eth], [m-s, m+s], color='b', alpha=0.2)

  ax_Hns.hist(mH, __compute_bins(mH, log=True), histtype="step", orientation="horizontal", log=True)
  ax_Hns.set_yscale('log')
  ax_Ethr.hist(Ethrs, __compute_bins(Ethrs), histtype="step", orientation="vertical", log=True)

  xmin, xmax = __compute_bounds(Ethrs)
  ax.set_xlim(xmin=xmin, xmax=xmax)
  ax_Ethr.set_xlim(xmin=xmin, xmax=xmax)

  ymin, ymax = __compute_bounds(mH, s=sH)
  ymin = max(ymin, 0)
  ax.set_ylim(ymin=ymin, ymax=ymax)
  ax_Hns.set_ylim(ax.get_ylim())

  ax.set_xlabel(r"$E_{thr}$")
  ax.set_ylabel(r"$|H_{abc}|$")

  ax_Hns.set_xlabel(r"count")
  plt.setp(ax_Hns.get_yticklabels(), visible=False)
  ax_Ethr.set_ylabel(r"count")
  plt.setp(ax_Ethr.get_xticklabels(), visible=False)

  return fig, ax, ax_Hns, ax_Ethr