Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

ffmpeg -i "/dev/video" -filter_complex \ "[0:v]split=2[orig][copy]; \ [copy]setpts=PTS+0.5/TB[delayed]; \ [orig][delayed]blend=all_expr='if(gt(mod(sin((X*X - Y*Y)/3000 + T*2)*cos((X+Y)/2000)\,1)\,0.5)\,A\,B)', \ hue=h='360*t/10':s=2,format=yuv420p[v]" \ -map "[v]" -map 0:a -c:v libx264 -crf 18 -preset fast -c:a

34,664 görüntüleme • 1 yıl önce •via X (Twitter)

0 Yorum

Yorum bulunmuyor

Orijinal gönderinin yorumları burada görünecek

Benzer Videolar

Following many two-dimensional turbulence animations, it is time to share computer code! Implementation of a vorticity-streamfunction method with a pseudo-spectral discretization + third-order Runge-Kutta for time integration (our CFD class semester project). The MATLAB code: M = 256; % number of points N = M; Lx = 2*pi; Ly = 2*pi; nu = 5e-4; % kinematic viscosity Sc = 0.7; % Schmidt number beta = 0; % meridional gradient of Coriolis parameter ar = 0.02; %random number amplitude b = 1; % mean scalar gradient CFLmax = 0.8; tend = 200; % end time x=linspace(0,Lx,M+1); x(end)=[]; dx = Lx/M; kx=[0:M/2 -M/2+1:-1]*2*pi/Lx; y=linspace(0,Ly,N+1); y(end)=[]; ky=[0:N/2 -N/2+1:-1]*2*pi/Ly; dy = Ly/N; time = 0; index_kmax = ceil(M/3); kmax = kx(index_kmax); filter = ones(M,N); filter(index_kmax+1:2*index_kmax+3,index_kmax+1:2*index_kmax+3)=0; rng(64); [u, v, omega, psi, ddx, ddy, idel2, kk, k2]=deal(zeros(M,N)); for j=1:N ddx(:,j)=1i*kx; end for i=1:M ddy(i,:)=1i*ky; end for i=1:M for j=1:N idel2(i,j)=-kx(i)^2-ky(j)^2; end end idel2=1./idel2; idel2(1,1)=0; for i=1:M for j=1:N kk(i,j)=kx(i)^2+ky(j)^2; k2(i,j)=kx(i)^2+ky(j)^2; if kk(i,j) >= 6^2 && kk(i,j) <= 7^2 % forcing kk(i,j) = -kk(i,j); end if kk(i,j) <= 2^2 kk(i,j) = 8*kk(i,j); % large-scale dissipation end end end for i=1:M for j=1:N u(i,j) = cos(2*x(i))*sin(2*y(j))+ar*rand; v(i,j) = -sin(2*x(i))*cos(2*y(j))+ar*rand; end end uhat = fft2(u); vhat = fft2(v); omegahat = ddx.*vhat - ddy.*uhat; % make vorticity phi = rand(size(u)); phihat = fft2(phi); ncid = netcdf.create(' 'CLOBBER'); dimid_x = netcdf.defDim(ncid, 'x', M); dimid_y = netcdf.defDim(ncid, 'y', N); dimid_time = netcdf.defDim(ncid, 'time', netcdf.getConstant('NC_UNLIMITED')); varid_x = netcdf.defVar(ncid, 'x', 'NC_FLOAT', [dimid_x]); varid_y = netcdf.defVar(ncid, 'y', 'NC_FLOAT', [dimid_y]); varid_u = netcdf.defVar(ncid, 'u', 'NC_FLOAT', [dimid_x, dimid_y, dimid_time]); varid_v = netcdf.defVar(ncid, 'v', 'NC_FLOAT', [dimid_x, dimid_y, dimid_time]); varid_omega = netcdf.defVar(ncid, 'vorticity', 'NC_FLOAT', [dimid_x, dimid_y, dimid_time]); varid_phi = netcdf.defVar(ncid, 'scalar', 'NC_FLOAT', [dimid_x, dimid_y, dimid_time]); varid_dissipation = netcdf.defVar(ncid, 'dissipation', 'NC_FLOAT', [dimid_x, dimid_y, dimid_time]); varid_time = netcdf.defVar(ncid, 'time', 'NC_FLOAT', [dimid_time]); netcdf.endDef(ncid); netcdf.putVar(ncid, varid_time, 0, 1, time); netcdf.putVar(ncid, varid_x, 0, M, x); netcdf.putVar(ncid, varid_y, 0, N, y); netcdf.putVar(ncid, varid_phi, [0, 0, 0], [M, N, 1], phi); netcdf.putVar(ncid, varid_u, [0, 0, 0], [M, N, 1], u); netcdf.putVar(ncid, varid_v, [0, 0, 0], [M, N, 1], v); netcdf.putVar(ncid, varid_omega, [0, 0, 0], [M, N, 1], omega); netcdf.putVar(ncid, varid_dissipation, [0, 0, 0], [M, N, 1], 0*omega); dt = 0.5*min([dx dy]); nstep = 1; while time < tend psihat = -idel2.*omegahat; uhat = ddy.*psihat; vhat = -ddx.*psihat; u = real(ifft2(uhat)); v = real(ifft2(vhat)); omegadx = real(ifft2(ddx.*omegahat)); omegady = real(ifft2(ddy.*omegahat)); facto = exp(-nu*8/15*dt*kk); factp = exp(-nu/Sc*8/15*dt*k2); r0o = -fft2(u.*omegadx+v.*omegady)+beta*vhat; r0p = -fft2(u.*real(ifft2(ddx.*phihat))+v.*real(ifft2(ddy.*phihat)))+b*vhat; omegahat = facto.*(omegahat + dt*8/15*r0o); % update omega phihat = factp.*(phihat + dt*8/15*r0p); % update phi %%%% Substep 2 psihat = -idel2.*omegahat; uhat = ddy.*psihat; vhat = -ddx.*psihat; u = real(ifft2(uhat)); v = real(ifft2(vhat)); omegadx = real(ifft2(ddx.*omegahat)); omegady = real(ifft2(ddy.*omegahat)); r1o = -fft2(u.*omegadx+v.*omegady)+beta*vhat; r1p = -fft2(u.*real(ifft2(ddx.*phihat))+v.*real(ifft2(ddy.*phihat)))+b*vhat; omegahat = omegahat + dt*(-17/60*facto.*r0o + 5/12*r1o); phihat = phihat + dt*(-17/60*factp.*r0p + 5/12*r1p); facto = exp(-nu*(-17/60+5/12)*dt*kk); factp = exp(-nu/Sc*(-17/60+5/12)*dt*k2); omegahat = omegahat.*facto; phihat = phihat.*factp; %%%% Substep 3 psihat = -idel2.*omegahat; uhat = ddy.*psihat; vhat = -ddx.*psihat; % max(max(abs(real(ifft2(1i*ddx.*uhat+1i*ddy.*vhat))))) % divergence u = real(ifft2(uhat)); v = real(ifft2(vhat)); omegadx = real(ifft2(ddx.*omegahat)); omegady = real(ifft2(ddy.*omegahat)); r2o = -fft2(u.*omegadx+v.*omegady)+beta*vhat; r2p = -fft2(u.*real(ifft2(ddx.*phihat))+v.*real(ifft2(ddy.*phihat)))+b*vhat; omegahat = omegahat + dt*(-5/12*facto.*r1o + 3/4*r2o); phihat = phihat + dt*(-5/12*factp.*r1p + 3/4*r2p); facto = exp(-nu*(-5/12+3/4)*dt*kk); factp = exp(-nu/Sc*(-5/12+3/4)*dt*kk); omegahat = omegahat.*facto; phihat = phihat.*factp; phihat = filter.*phihat; omegahat = filter.*omegahat; time = time + dt; nstep = nstep + 1; CFL = max(max(abs(u)))/dx*dt+max(max(abs(v)))/dy*dt; if mod(nstep,20)==0 phi = real(ifft2(phihat)); omega = real(ifft2(omegahat)); dissipation = 2*nu*(real(ifft2(ddx.*uhat)).^2 + real(ifft2(ddy.*uhat)).^2 + real(ifft2(ddx.*vhat)).^2 + real(ifft2(ddy.*vhat)).^2); eta = (nu^3/mean(dissipation,'all'))^0.25; subplot(221); pcolor(x,y,omega'); title('Vorticity'); shading flat; axis equal tight; colorbar; drawnow subplot(222); pcolor(x,y,phi'); title('Scalar'); shading flat; axis equal tight; colorbar; drawnow subplot(223); pcolor(x,y,dissipation'); title('Dissipation'); shading flat; axis equal tight; colorbar; drawnow subplot(224); pcolor(x,y,u); title('u-velocity'); shading flat; axis equal tight; colorbar; drawnow fprintf(1,'step = %d time = %g dt = %g CFL = %g kmax*eta = %g %g\n', nstep, time, dt, CFL, eta.*kmax, eta.*kmax/sqrt(Sc)); [~, dim_time_len] = netcdf.inqDim(ncid,dimid_time); netcdf.putVar(ncid, varid_time, [dim_time_len], [1], time); netcdf.putVar(ncid, varid_phi, [0, 0, dim_time_len], [M, N, 1], phi); netcdf.putVar(ncid, varid_u, [0, 0, dim_time_len], [M, N, 1], u); netcdf.putVar(ncid, varid_v, [0, 0, dim_time_len], [M, N, 1], v); netcdf.putVar(ncid, varid_omega, [0, 0, dim_time_len], [M, N, 1], omega); netcdf.putVar(ncid, varid_dissipation, [0, 0, dim_time_len], [M, N, 1], dissipation); netcdf.sync(ncid); end dt = CFLmax/CFL*dt; %0.0005; end netcdf.close(ncid);

Computational Fluid Dynamics group

226,231 görüntüleme • 3 yıl önce

[Backpropagation] by Hand✍️ [1] Forward Pass ↳ Given a multi layer perceptron (3 levels), an input vector X, predictions Y^{Pred} = [0.5, 0.5, 0], and ground truth label Y^{Target} = [0, 1, 0]. [2] Backpropagation ↳ Insert cells to hold our calculations. [3] Layer 3 - Softmax (blue) ↳ Calculate ∂L / ∂z3 directly using the simple equation: Y^{Pred} - Y^{Target} = [0.5, -0.5, 0]. ↳ This simple equation is the benefit of using Softmax and Cross Entropy Loss together. [4] Layer 3 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W3 and ∂L / ∂b3 by multiplying ∂L / ∂z3 and [ a2 | 1 ]. [5] Layer 2 - Activations (green) ↳ Calculate ∂L / ∂a2 by multiplying ∂L / ∂z3 and W3. [6] Layer 2 - ReLU (blue) ↳ Calculate ∂L / ∂z2 by multiplying ∂L / ∂a2 with 1 for positive values and 0 otherwise. [7] Layer 2 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W2 and ∂L / ∂b2 by multiplying ∂L / ∂z2 and [ a1 | 1 ]. [8] Layer 1 - Activations (green) ↳ Calculate ∂L / ∂a1 by multiplying ∂L / ∂z2 and W2. [9] Layer 1 - ReLU (blue) ↳ Calculate ∂L / ∂z1 by multiplying ∂L / ∂a1 with 1 for positive values and 0 otherwise. [10] Layer 1 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W1 and ∂L / ∂b1 by multiplying ∂L / ∂z1 and [ x | 1 ]. [11] Gradient Descent ↳ Update weights and biases (typically a learning rate is applied here). 💡 Matrix Multiplication is All You Need: Just like in the forward pass, backpropagation is all about matrix multiplications. You can definitely do everything by hand as I demonstrated in this exercise, albeit slow and imperfect. This is why GPU's ability to multiply matrices efficiently plays such an important role in the deep learning evolution. This is why NVIDIA is now close to $1 trillion in valuation. 💡Exploding Gradients: We can already see the gradients are getting larger as we back-propagate up, even in this simple 3-layer network. This motivates using methods like skip connections to handle exploding (or diminishing) gradients as in the ResNet. I did the calculations entirely by hand. Please let me know if you spot any error or have any questions!

Tom Yeh

64,645 görüntüleme • 2 yıl önce