def adiabatic(tp, BW, beta, resolution=resolution): ''' Make Adiabatic Pulse Shape based on Hyperbolic Secant pulse .. math:: \\text{sech} \\left( \\beta (t - \\frac{t_p}{2}) \\right) ^{1+i(\pi BW / \\beta)} Args: tp (float): pulse length BW (float): pulse bandwidth beta (float): truncation factor resolution (float): pulse resolution Returns: tuple: tuple containing: t (*numpy.ndarray*): Time axes pulse (*numpy.ndarray*): Pulse shape ''' beta = float(beta) / tp mu = np.pi * BW / beta t = np.r_[0.:tp:resolution] pulse = (np.sech(beta * (t - 0.5 * tp)))**(1. + 1.j * mu) return t, pulse
def adiabatic(peakb1 = 0.2, bw = 2000, beta = 1000., T = 0.01, Ts = 0.00001, blochsim = True): T = 2*np.round(T/Ts/2)*Ts N = T/Ts t = np.arange(Ts, T, Ts) - np.round(N/2)*Ts #time from -t/2 to t/2 b1 = peakb1 * np.sech(beta*t) freq = bw/2 * np.tanh(beta*t) phase = np.cumsum(freq)*2*np.pi*Ts phase = phase-phase(np.round(N/2)) #zero phase half-way phase = np.mod(phase+np.pi,2*np.pi)-np.pi #limit to -pi to pi if blochsim: t = t-t[0] #start t at 0 for plots figure(1) print('Adiabatic silver-hoult pulse (beta = '+str(beta)+' Hz) ') subplot(3,1,1) plot(t,b1); xlable('Time(s)'); ylabel('B1(G)') title(tt) subplot(3,1,2) plot(t,phase); xlabel('Time(s)'); ylabel('Phase(rad)') subplot(3,1,3) plot(t,freq); xlabel('Time(s)'); ylabel('Freq(hz)') #add in if 0: gr = 0*b1 tp = Ts t1 = 0.6; t2 = 0.1 df = np.arange(-3*bw, 3*bw, bw/20.) dp = 0 mode = 0 mx,my,mz = bloch(0) # finish this
def __init__(self, wavenumber=1, depth=1, length=10, g=1): self.wavenumber = k = wavenumber self.depth = h = depth self.frequency = sigma = np.sqrt(g * k * np.tanh(k * h)) self.group_velocity = cg = g / (2 * sigma) * (k * h * np.sech(k * h)**2 + np.tanh(k * h)) self.S = g * k**2 / sigma**2 * cg * (1 + np.tanh(k * h)**2)
def dv(x): pot = 'Eckart' if pot == 'Morse': a, x0, De = 1.02, 1.4, 0.176 d = (1.0-np.exp(-a*(x-x0))) v0 = De*d**2 ddv = 2.0 * De * (-d*np.exp(-a*((x-x0)))*a**2 + (np.exp(-a*(x-x0)))**2*a**2) elif pot == 'Double_well': eta = 1.3544 v0 = x**4/16.0/eta - x**2/2.0 ddv = 3./4./eta * x**2 - 1.0 elif pot == 'Harmonic': v0 = x**2/2.0 ddv = 1.0 elif pot == 'Eckart': D = 16.0 #a = 1.3624d0 a = 1.0 v0 = D/np.cosh(a*x)**2 dv = -2.0 * a * D * np.sech(a*x)**2 * np.tanh(a*x) ddv = 6.0*D*a**2*np.sinh(a*x)**2/np.cosh(a*x)**4-2.*D*a**2/np.cosh(a*x)**2 else: print("ERROR: there is no such potential.") return v0,dv,ddv
def forcing(t, u, perturbation_params=[1, 0.15, 0.5]): """ Returns vector field for a perturbation at time t, for an array of points in phase space. Number of model parameters: 3. perturbation_params = [perturbation_type, amplitude, frequency] Functional form: v = (, ), with u = (x, y) Parameters ---------- t : float fixed time-point of vector field, for all points in phase space. u : array_like, shape(n,) points in phase space to determine vector field at time t. perturbation_params : list of floats, [perturbation_type, amplitude, frequency] vector field parameters Returns ------- v : array_like, shape(n,) vector field corresponding to points u, in phase space at time t """ x, y = u.T perturbation = np.zeros(u.shape) # Perturbation parameters perturbation_type, amplitude, freq = perturbation_params if perturbation_type == 1: perturbation = perturbation + np.array( [0, amplitude * np.sin(freq * t)]) elif perturbation_type == 2: perturbation = perturbation + np.array( [0, amplitude * np.sech(t) * np.sin(freq * t)]) return perturbation
def d_tan_hyperbolic(input_stimulus): # Returns the derivative of the tan_hyperbolic fxn. d_hyp_value = (np.sech(input_stimulus)) ** 2 return d_hype_value
def tanhgrad(z): gard = np.sech(z)**2 return grad
def dtanh(x, scale=1.0): return scale * (np.sech(x)**2)
def make_kdv_dataset(name='kdv', test_split=0.1, device='cpu', verbose=False, long_data=False): torch.set_default_dtype(torch.float64) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False rng = np.random.get_state() np.random.seed(1) ndata = 100 M = 50 width = 10. dt = 0.001 N = 500 a = -6. b = 1. if long_data: np.random.seed(100) ndata = 5 test_split = 1.0 N = 5000 t_eval = np.arange(0, N + 1) * dt x = width * np.arange(M) / M np.sech = lambda a: 1 / np.cosh(a) kdv1d = KdV1d(width=width, ndiv=M, a=a, b=b, device='cpu') u_results = [] for i in range(ndata): if verbose: print('generating KdV dataset,', i, '/', ndata, end='\r') k1, k2 = np.random.uniform(0.5, 2.0, 2) d1 = np.random.uniform(0.2, 0.3, 1) d2 = d1 + np.random.uniform(0.2, 0.5, 1) x = width * np.arange(M) / M u0 = 0 u0 += (-6. / a) * 2 * k1**2 * np.sech(k1 * (x - width * d1))**2 u0 += (-6. / a) * 2 * k2**2 * np.sech(k2 * (x - width * d2))**2 shift = np.random.randint(0, M) u0 = np.concatenate([u0[M:], u0[:M]], axis=-1) if np.random.randint(0, 2) == 1: u0 = u0[::-1].copy() u_result = kdv1d.dvdmint(u0, t_eval) u_result = u_result.reshape(-1, 1, M) u_results.append(u_result) u_results = np.stack(u_results, axis=0) data = {} dudt = kdv1d.dudt(u_results.reshape(-1, 1, M)).reshape(u_results.shape) energy = kdv1d.get_energy(u_results.reshape(-1, 1, M)).reshape( u_results.shape[:2]) ntrain = int(ndata * (1 - test_split)) data['u'] = u_results[:ntrain] data['test_u'] = u_results[ntrain:] data['dudt'] = dudt[:ntrain] data['test_dudt'] = dudt[ntrain:] data['energy'] = energy[:ntrain] data['test_energy'] = energy[ntrain:] data['dt'] = dt data['t_eval'] = t_eval data['dx'] = kdv1d.dx data['M'] = M data['model'] = kdv1d np.random.set_state(rng) return data
#put in dataframe training_df = pd.DataFrame(columns=["f_1", "f_2", "labels", "outputs"]) training_df.f_1 = [x for x in vectors[0]] training_df.f_2 = [x for x in vectors[1]] training_df.labels = labels #%% Definitions GAMMA = 0.01 # output layer g_output = lambda a: 1 / (1 + np.e**-a) g_output_deriv = lambda a: g_output(a) * (1 - g_output(a)) # hidden layer g_hidden = lambda b: np.tanh(b) g_hidden_deriv = lambda b: np.sech(b)**2 y_fun = lambda a: g_hidden(a) z_fun = lambda b: g_output(b) E = lambda y, t: 0.5 * (y - t)**2 delta_w_output = lambda y, z, t, b: GAMMA * (t - z) * g_output_deriv(b) * y delta_w_hidden = lambda x, z, t, w, a, b: GAMMA * (t - z) * g_hidden_deriv( b) * w * g_hidden_deriv(a) * x hidden_w = [0, 0] output_w = [0, 0]
runfile('C:/Users/Reizkian Yesaya/.spyder-py3/E X P E R I M E N T.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/untitled1.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/E X P E R I M E N T.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') P alpha runfile('C:/Users/Reizkian Yesaya/.spyder-py3/E X P E R I M E N T.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') alpha runfile('C:/Users/Reizkian Yesaya/.spyder-py3/E X P E R I M E N T.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') alpha runfile('C:/Users/Reizkian Yesaya/.spyder-py3/E X P E R I M E N T.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') ## ---(Sat Nov 17 21:15:55 2018)--- runfile('C:/Users/Reizkian Yesaya/.spyder-py3/Navier Stokes.Eq_Fahrudin Nugroho.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/untitled0.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') import numpy as np np.sech(0) np.cosh(0) 1/(np.sech(0)) 1/(np.cosh(0)) runfile('C:/Users/Reizkian Yesaya/.spyder-py3/untitled0.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/Simple3Dplot.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/Laplace.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/untitled7.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/Heat.eq_Spectral.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') runfile('C:/Users/Reizkian Yesaya/.spyder-py3/untitled7.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') ## ---(Tue Nov 20 07:40:16 2018)--- runfile('C:/Users/Reizkian Yesaya/.spyder-py3/FFT.py', wdir='C:/Users/Reizkian Yesaya/.spyder-py3') import numpy as np np.fft.fft(100) np.fft.fft(y)
def d_tanh(input_stimulus, slope_param=1.0): # Returns the derivative of the tan_hyperbolic fxn. d_hyp_value = slope_param * np.square((np.sech(input_stimulus))) return d_hype_value
def dtanh(z): return np.sech(z)**2
def nonlinTanh(self, x, deriv=False): if (deriv == True): return 1 / (np.sech(x)**2) return np.tanh(x)