示例#1
0
文件: models.py 项目: ShariqM/birdy
    def __init__(self):
        OscillatorModel.__init__(self)
        self.oscillator = NormalOscillator()

        self.control_params = dict()
        self.control_params['alpha'] = ControlParameter('alpha', [-1.25, 0.20], -0.41769)
        self.control_params['beta'] = ControlParameter('beta', [-0.75, 0.75], -0.346251775)
示例#2
0
def find_admissible_controls(output_file=None,
                             alphamin=-1.25,
                             alphamax=0.25,
                             alphastep=0.01,
                             betamin=-1.50,
                             betamax=1.50,
                             betastep=0.01):

    no = NormalOscillator()

    stime = time.time()
    alpharng = np.arange(alphamin, alphamax, alphastep)
    betarng = np.arange(betamin, betamax, betastep)

    nrows = len(alpharng)
    ncols = len(betarng)
    print '# of (alpha,beta) pairs: %d' % (nrows * ncols)

    all_pairs = np.zeros([nrows, ncols, 2])
    all_dv_rms = np.zeros([nrows, ncols]) * np.nan
    all_ff = np.zeros([nrows, ncols]) * np.nan

    sim_duration = 0.010
    step_size = 1e-6
    steady_state_point = 0.005
    steady_state_index = int(steady_state_point / step_size)

    for i, alpha in enumerate(alpharng):
        for j, beta in enumerate(betarng):
            all_pairs[i, j, :] = [alpha, beta]
            output = no.simulate(0.0,
                                 0.0,
                                 duration=sim_duration,
                                 dt=step_size,
                                 alpha=alpha,
                                 beta=beta)
            dv = np.diff(output[:, 1])
            dv_rms = dv[steady_state_index:].std(ddof=1)
            all_dv_rms[i, j] = dv_rms

            #compute power spectrum
            fftx = fft(output[:, 0])
            ps_f = fftfreq(len(output[:, 0]), d=step_size)
            findx = (ps_f > 100.0) & (ps_f < 8000.0)

            #estimate fundamental frequency from log power spectrum in the simplest way possible
            ps = np.abs(fftx[findx])
            peak_index = ps.argmax()
            all_ff[i, j] = ps_f[findx][peak_index]

    etime = time.time() - stime
    print 'Elapsed Time: %0.2f s' % etime

    if output_file is not None:
        hf = h5py.File(output_file, 'w')
        hf['all_pairs'] = all_pairs
        hf['all_dv_rms'] = all_dv_rms
        hf['all_ff'] = all_ff
        hf.close()
示例#3
0
 def __init__(self):
     self.oscillator = NormalOscillator()
     self.sample_rate = 1000.0
     self.waveform_sample_rate = 1e5
     self.alpha = list()
     self.beta = list()
     self.mu = list()
     self.sigma1 = list()
     self.sigma2 = list()
示例#4
0
def find_fixedpoints_normal(xmin=-10.0,
                            xmax=10.0,
                            xstep=1e-3,
                            alpha=-0.41769,
                            beta=-0.346251775,
                            plot=False):

    no = NormalOscillator()

    xrng = np.arange(xmin, xmax + xstep, xstep)
    nullx = np.array([no.nullcline_x(xval, alpha, beta) for xval in xrng])

    xp = zip(xrng, nullx, np.abs(nullx))
    xp.sort(key=operator.itemgetter(-1))

    top3 = np.array(xp[:3])

    f = lambda x: no.nullcline_x(x, alpha, beta)
    df = lambda x: no.nullcline_dx(x, alpha, beta)

    zero_tol = 1e-6
    x_tol = 1e-4
    roots = list()
    for k, xi in enumerate(top3[:, 0]):
        try:
            xz = newton(f, xi, fprime=df, maxiter=100)
        except RuntimeError:
            continue
        xz_val = no.nullcline_x(xz, alpha, beta)
        #print 'xz=%0.9f, xz_val=%0.9f' % (xz, xz_val)
        if np.abs(xz_val) < zero_tol:
            is_duplicate = False
            for x, xv in roots:
                if np.abs(x - xz) < x_tol:
                    is_duplicate = True
            if not is_duplicate:
                #print 'Root: x=%0.6f, f(x)=%0.6f' % (xz, xz_val)
                roots.append([xz, xz_val])
    roots = np.array(roots)

    if plot:
        plt.figure()
        plt.plot(xrng, nullx, 'k-')
        plt.plot(top3[:, 0], top3[:, 1], 'rx')
        plt.plot(roots[:, 0], roots[:, 1], 'go')
        plt.title('Fixed Point Surface for dv')
        plt.xlabel('x')
        plt.axis('tight')

    return roots
示例#5
0
文件: dp.py 项目: ShariqM/birdy
    def control_oscillator(self, states, dt=1e-3, oscillator_dt=1e-6):

        no = NormalOscillator()

        output = list()

        oscillator_x = 0.0
        oscillator_v = 0.0

        for alpha, beta in states:
            params = {'alpha': alpha, 'beta': beta}
            ostates = no.run_simulation(params,
                                        dt,
                                        oscillator_dt,
                                        initial_x=oscillator_x,
                                        initial_v=oscillator_v)
            oscillator_x = ostates[-1, 0]
            oscillator_v = ostates[-1, 1]
            output.extend(ostates[:, 0])

        return output