function [X, t] = file_creation_2(A, B, g, t0, tf, N, Nh, N_samples, control_index, add_noise, path, mode) % Creates train/test dataset % Inputs : % A : Matrix of the ODE system % B : Matrix of linear combination % g : Linear part in the ODE system % choices : choices for functions % t0 : Initial time % tf : Final time % N : Number of input/output parameters % Nh : Resolution of the grid % N_samples : Number of samples desired % add_noise : Boolean, for adding noise or not % path : path to the folder where we create the dataset % mode : 'test' or 'train' % % Outputs : % X : Dataset % y : Labels % t : time interval if add_noise noise = random('Normal', 0, 1e-0, [N,Nh+1]); else noise = 0; end % Iterate over the samples for i=0:N_samples-1 % Generate random initial condition y0 = randi(20,1)*rand(N,1); % Solve the system of ODEs using Backward Euler [t, X] = backward_euler(A, g, y0, t0, tf, Nh); % Add noise X = X + noise; % Apply the linear combination of the inputs C = X' * B; C = C'; % Open the target and input files to write the solutions fileID2 = fopen(strcat(path, 'files_', num2str(N), '/', mode, '/target/file_', num2str(i), '.txt'),'w'); fileID3 = fopen(strcat(path, 'files_', num2str(N), '/', mode, '/input/file_', num2str(i), '.txt'),'w'); for j = 1:N if j == control_index % Write in the files... for t_=1:Nh+1 % ... the input. fprintf(fileID3, '%f1 ', X(j,t_)); end else % Write in the files... for t_=1:Nh+1 % ... the target. fprintf(fileID2, '%f2 ', X(j,t_)); end end fprintf(fileID2,'\n'); fprintf(fileID3,'\n'); end fclose(fileID2); fclose(fileID3); end not_control_indexes = []; for j = 1:N if j ~= control_index not_control_indexes = [not_control_indexes, j]; end end % Plot a sample of the inputs and the targets figure plot(t, X(not_control_indexes(1), :), '-r', t, X(not_control_indexes(2), :), 'b-', t, X(control_index, :), 'c--'); title(mode) legend('sample\_output1', 'sample\_ouput2', 'sample\_label1') grid; return