Skip to content

Commit

Permalink
for v2 of paper, datasets are smaller and add fluid flow examples
Browse files Browse the repository at this point in the history
  • Loading branch information
BethanyL committed Apr 16, 2018
1 parent bec93c7 commit 4554fc4
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data/DiscreteSpectrumExample.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

numICs = 200*200*21/20;
numICs = 5000;
filenamePrefix = 'DiscreteSpectrumExample';

x1range = [-.5, .5];
Expand Down
3 changes: 3 additions & 0 deletions data/DiscreteSpectrumExampleFn.m
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions data/FluidFlowBox.m
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions data/FluidFlowBoxFn.m
Original file line number Diff line number Diff line change
@@ -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



25 changes: 25 additions & 0 deletions data/FluidFlowOnAttractor.m
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions data/FluidFlowOnAttractorFn.m
Original file line number Diff line number Diff line change
@@ -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



8 changes: 4 additions & 4 deletions data/Pendulum.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

numICs = 200*200*21/20;
numICs = 5000;
filenamePrefix = 'Pendulum';

x1range = [-3.1,3.1];
Expand All @@ -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
10 changes: 5 additions & 5 deletions data/PendulumFnPotential.m → data/PendulumFn.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


7 changes: 7 additions & 0 deletions data/weaklyNL.m
Original file line number Diff line number Diff line change
@@ -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);
];

0 comments on commit 4554fc4

Please sign in to comment.