From 4554fc4b8a43c833eb27e2f1c0fa7a8a1e2d8d2d Mon Sep 17 00:00:00 2001 From: Bethany Lusch Date: Mon, 16 Apr 2018 16:02:44 -0700 Subject: [PATCH] for v2 of paper, datasets are smaller and add fluid flow examples --- data/DiscreteSpectrumExample.m | 2 +- data/DiscreteSpectrumExampleFn.m | 3 ++ data/FluidFlowBox.m | 26 +++++++++++ data/FluidFlowBoxFn.m | 48 ++++++++++++++++++++ data/FluidFlowOnAttractor.m | 25 ++++++++++ data/FluidFlowOnAttractorFn.m | 42 +++++++++++++++++ data/Pendulum.m | 8 ++-- data/{PendulumFnPotential.m => PendulumFn.m} | 10 ++-- data/weaklyNL.m | 7 +++ 9 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 data/FluidFlowBox.m create mode 100644 data/FluidFlowBoxFn.m create mode 100644 data/FluidFlowOnAttractor.m create mode 100644 data/FluidFlowOnAttractorFn.m rename data/{PendulumFnPotential.m => PendulumFn.m} (77%) create mode 100644 data/weaklyNL.m diff --git a/data/DiscreteSpectrumExample.m b/data/DiscreteSpectrumExample.m index fa6342a..c118963 100644 --- a/data/DiscreteSpectrumExample.m +++ b/data/DiscreteSpectrumExample.m @@ -1,5 +1,5 @@ -numICs = 200*200*21/20; +numICs = 5000; filenamePrefix = 'DiscreteSpectrumExample'; x1range = [-.5, .5]; diff --git a/data/DiscreteSpectrumExampleFn.m b/data/DiscreteSpectrumExampleFn.m index 042601b..9404709 100644 --- a/data/DiscreteSpectrumExampleFn.m +++ b/data/DiscreteSpectrumExampleFn.m @@ -1,6 +1,7 @@ function X = DiscreteSpectrumExampleFn(x1range, x2range, numICs, tSpan, mu, lambda, seed) % Koopman example from 3.4.2 (pg 51) of the DMD book +% (Dynamic Mode Decomposition by Kutz, Brunton, Brunton, and Proctor) % nonlinear dynamical system in two variables, but with 3D Koopman % observables, have linear dynamical system @@ -18,6 +19,8 @@ X = zeros(numICs*lenT, 2); count = 1; +% in order to solve more accurately than ode45, map into 3D linear system +% and use exact analytic solution for j = 1:numICs Y0 = [x1(j); x2(j); x1(j)^2]; c1 = Y0(1); diff --git a/data/FluidFlowBox.m b/data/FluidFlowBox.m new file mode 100644 index 0000000..52fb461 --- /dev/null +++ b/data/FluidFlowBox.m @@ -0,0 +1,26 @@ + +numTest_ICs = 5000; +filenamePrefix = 'FluidFlowBox'; + +x1range = [-1.1,1.1]; +x2range = [-1.1,1.1]; +x3range = [0,2.42]; +tSpan = 0:0.01:1; +max_x3 = 2.5; + +seed = 1; +X_test = FluidFlowBoxFn(x1range, x2range, x3range, numTest_ICs, tSpan, seed, max_x3); +filename_test = strcat(filenamePrefix, '_test_x.csv'); +dlmwrite(filename_test, X_test, 'precision', '%.14f') + +seed = 2; +X_val = FluidFlowBoxFn(x1range, x2range, x3range, numTest_ICs, tSpan, seed, max_x3); +filename_val = strcat(filenamePrefix, '_val_x.csv'); +dlmwrite(filename_val, X_val, 'precision', '%.14f') + +for j = 1:20 + seed = 2+j; + X_train = FluidFlowBoxFn(x1range, x2range, x3range, numTest_ICs, tSpan, seed, max_x3); + filename_train = strcat(filenamePrefix, sprintf('_train%d_x.csv', j)); + dlmwrite(filename_train, X_train, 'precision', '%.14f') +end diff --git a/data/FluidFlowBoxFn.m b/data/FluidFlowBoxFn.m new file mode 100644 index 0000000..ee9f932 --- /dev/null +++ b/data/FluidFlowBoxFn.m @@ -0,0 +1,48 @@ +function X = FluidFlowBoxFn(x1range, x2range, x3range, numICs, tSpan, seed, max_x3) + + +% try some initial conditions for x1, x2 +rng(seed) + +b = 0; +mu = 0.1; +omega = 1; +lambda = -10; +A = -mu; +dynsys = @(t,x) weaklyNL(x,b,mu,omega,lambda,A); + +lenT = length(tSpan); + +X = zeros(numICs*lenT, 3); +count = 1; + +for j = 1:10*numICs + % randomly start from x1range(1) to x1range(2) + x1 = (x1range(2)-x1range(1))*rand+x1range(1); + + % randomly start from x2range(1) to x2range(2) + x2 = (x2range(2)-x2range(1))*rand+x2range(1); + + % randomly start from x3range(1) to x3range(2) + x3 = (x3range(2)-x3range(1))*rand+x3range(1); + + + ic = [x1; x2; x3]; + + [T, temp] = ode45(dynsys, tSpan, ic); + + if max(temp(:,3)) > max_x3 + sprintf('traj goes too big: %.15f', max(temp(:,3))) + continue + else + X(1+(count-1)*lenT : lenT + (count-1)*lenT,:) = temp; + + if count == numICs + break + end + count = count + 1; + end +end + + + diff --git a/data/FluidFlowOnAttractor.m b/data/FluidFlowOnAttractor.m new file mode 100644 index 0000000..acb340f --- /dev/null +++ b/data/FluidFlowOnAttractor.m @@ -0,0 +1,25 @@ + +numTest_ICs = 5000; +filenamePrefix = 'FluidFlowOnAttractor'; + +Rrange = [0,1.1]; +Trange = [0,2*pi]; +tSpan = 0:0.05:6; + + +seed = 1; +X_test = FluidFlowOnAttractorFn(Rrange, Trange, numTest_ICs, tSpan, seed); +filename_test = strcat(filenamePrefix, '_test_x.csv'); +dlmwrite(filename_test, X_test, 'precision', '%.14f') + +seed = 2; +X_val = FluidFlowOnAttractorFn(Rrange, Trange, numTest_ICs, tSpan, seed); +filename_val = strcat(filenamePrefix, '_val_x.csv'); +dlmwrite(filename_val, X_val, 'precision', '%.14f') + +for j = 1:20 + seed = 2+j; + X_train = FluidFlowOnAttractorFn(Rrange, Trange, numTest_ICs, tSpan, seed); + filename_train = strcat(filenamePrefix, sprintf('_train%d_x.csv', j)); + dlmwrite(filename_train, X_train, 'precision', '%.14f') +end diff --git a/data/FluidFlowOnAttractorFn.m b/data/FluidFlowOnAttractorFn.m new file mode 100644 index 0000000..d2cd533 --- /dev/null +++ b/data/FluidFlowOnAttractorFn.m @@ -0,0 +1,42 @@ +function X = FluidFlowOnAttractorFn(Rrange, Trange, numICs, tSpan, seed) + + +% try some initial conditions for R, T +rng(seed) + +b = 0; +mu = 0.1; +omega = 1; +lambda = -10; +A = -mu; +dynsys = @(t,x) weaklyNL(x,b,mu,omega,lambda,A); + +lenT = length(tSpan); + +X = zeros(numICs*lenT, 3); + +count = 1; +for j = 1:2*numICs + % randomly start from Rrange(1) to Rrange(2) + R = (Rrange(2)-Rrange(1))*rand+Rrange(1); + + % randomly start from Trange(1) to Trange(2) + T = (Trange(2)-Trange(1))*rand+Trange(1); + + x1 = R*cos(T); + x2 = R*sin(T); + x3 = x1^2 + x2^2; + + ic = [x1; x2; x3]; + + [T, temp] = ode45(dynsys, tSpan, ic); + + X(1+(count-1)*lenT : lenT + (count-1)*lenT,:) = temp; + if count == numICs + break + end + count = count + 1; +end + + + diff --git a/data/Pendulum.m b/data/Pendulum.m index 331acd9..668bbd7 100644 --- a/data/Pendulum.m +++ b/data/Pendulum.m @@ -1,5 +1,5 @@ -numICs = 200*200*21/20; +numICs = 5000; filenamePrefix = 'Pendulum'; x1range = [-3.1,3.1]; @@ -9,18 +9,18 @@ max_potential = .99; seed = 1; -X_test = PendulumFnPotential(x1range, x2range, round(.1*numICs), tSpan, seed, max_potential); +X_test = PendulumFn(x1range, x2range, round(.1*numICs), tSpan, seed, max_potential); filename_test = strcat(filenamePrefix, '_test_x.csv'); dlmwrite(filename_test, X_test, 'precision', '%.14f') seed = 2; -X_val = PendulumFnPotential(x1range, x2range, round(.2*numICs), tSpan, seed, max_potential); +X_val = PendulumFn(x1range, x2range, round(.2*numICs), tSpan, seed, max_potential); filename_val = strcat(filenamePrefix, '_val_x.csv'); dlmwrite(filename_val, X_val, 'precision', '%.14f') for j = 1:10 seed = 2+j; - X_train = PendulumFnPotential(x1range, x2range, round(.7*numICs), tSpan, seed, max_potential); + X_train = PendulumFn(x1range, x2range, round(.7*numICs), tSpan, seed, max_potential); filename_train = strcat(filenamePrefix, sprintf('_train%d_x.csv', j)); dlmwrite(filename_train, X_train, 'precision', '%.14f') end diff --git a/data/PendulumFnPotential.m b/data/PendulumFn.m similarity index 77% rename from data/PendulumFnPotential.m rename to data/PendulumFn.m index 7ed3318..efea58a 100644 --- a/data/PendulumFnPotential.m +++ b/data/PendulumFn.m @@ -1,4 +1,4 @@ -function X = PendulumFnPotential(x1range, x2range, numICs, tSpan, seed, max_potential) +function X = PendulumFn(x1range, x2range, numICs, tSpan, seed, max_potential) % try some initial conditions for x1, x2 @@ -27,15 +27,15 @@ [T, temp] = ode45(dynsys, tSpan, ic); X(1+(count-1)*lenT : lenT + (count-1)*lenT,:) = temp; - if count == numICs - break - end + if count == numICs + break + end count = count + 1; end end if count < numICs - sprintf('oops, potential energy too small for IC box') + sprintf('oops, potential energy too small for IC box') end diff --git a/data/weaklyNL.m b/data/weaklyNL.m new file mode 100644 index 0000000..cd1e587 --- /dev/null +++ b/data/weaklyNL.m @@ -0,0 +1,7 @@ +function dy = weaklyNL(y,b,mu,omega,lambda,A) + +dy = [ + mu*y(1) - omega*y(2) + A*y(1)*y(3); + omega*y(1) + mu*y(2) + A*y(2)*y(3) + b; + lambda*(y(3)-y(1).^2-y(2).^2); +]; \ No newline at end of file