PT:average absoulte residuals
This commit is contained in:
parent
ea33affc84
commit
135739b8af
40
scripts/createFit.m
Normal file
40
scripts/createFit.m
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
function [fitresult, gof] = createFit(SA, FY)
|
||||||
|
%CREATEFIT(SA,FY)
|
||||||
|
% Create a fit.
|
||||||
|
%
|
||||||
|
% Data for 'untitled fit 1' fit:
|
||||||
|
% X Input: SA
|
||||||
|
% Y Output: FY
|
||||||
|
% Output:
|
||||||
|
% fitresult : a fit object representing the fit.
|
||||||
|
% gof : structure with goodness-of fit info.
|
||||||
|
%
|
||||||
|
% See also FIT, CFIT, SFIT.
|
||||||
|
|
||||||
|
% Auto-generated by MATLAB on 04-Jan-2024 14:49:41
|
||||||
|
|
||||||
|
|
||||||
|
%% Fit: 'untitled fit 1'.
|
||||||
|
[xData, yData] = prepareCurveData( SA, FY );
|
||||||
|
|
||||||
|
% Set up fittype and options.
|
||||||
|
ft = fittype( 'fourier8' );
|
||||||
|
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
|
||||||
|
opts.Display = 'Off';
|
||||||
|
opts.MaxFunEvals = 100000;
|
||||||
|
opts.MaxIter = 50000;
|
||||||
|
opts.StartPoint = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7.29927003160889];
|
||||||
|
|
||||||
|
% Fit model to data.
|
||||||
|
[fitresult, gof] = fit( xData, yData, ft, opts );
|
||||||
|
|
||||||
|
% % Plot fit with data.
|
||||||
|
% figure( 'Name', 'untitled fit 1' );
|
||||||
|
% h = plot( fitresult, xData, yData );
|
||||||
|
% legend( h, 'FY vs. SA', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
|
||||||
|
% % Label axes
|
||||||
|
% xlabel( 'SA', 'Interpreter', 'none' );
|
||||||
|
% ylabel( 'FY', 'Interpreter', 'none' );
|
||||||
|
% grid on
|
||||||
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
%% please open Magic Formular APP first
|
%% please open Magic Formular APP first
|
||||||
clear
|
clear
|
||||||
n = 20; % <=60
|
n = 20
|
||||||
|
mkdir('similarityData');
|
||||||
%%
|
%%
|
||||||
directoryPath = "..\sorted_data";
|
directoryPath = "..\sorted_data";
|
||||||
subdirectories = getSubdirectories(directoryPath);
|
subdirectories = getSubdirectories(directoryPath);
|
||||||
@ -23,6 +24,7 @@ for i=1:length(subdirectories)
|
|||||||
measurement = measurements(n);
|
measurement = measurements(n);
|
||||||
|
|
||||||
[SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement);
|
[SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement);
|
||||||
|
FY = smoothdata(FY, "gaussian",100);
|
||||||
if i < length(subdirectories)/3
|
if i < length(subdirectories)/3
|
||||||
plot(SA, FY, 'LineWidth', 1)
|
plot(SA, FY, 'LineWidth', 1)
|
||||||
elseif i <= length(subdirectories)/3*2
|
elseif i <= length(subdirectories)/3*2
|
||||||
@ -30,9 +32,27 @@ for i=1:length(subdirectories)
|
|||||||
else
|
else
|
||||||
plot(SA, FY, '-.','LineWidth', 1)
|
plot(SA, FY, '-.','LineWidth', 1)
|
||||||
end
|
end
|
||||||
|
SAA{i} = SA;
|
||||||
|
FYY{i} = FY;
|
||||||
hold on
|
hold on
|
||||||
end
|
end
|
||||||
legend(subdirectoryNames{:})
|
legend(subdirectoryNames{:})
|
||||||
title("Similarities, n=",n)
|
title("Similarities, n=",n)
|
||||||
xlabel("Slip Angle")
|
xlabel("Slip Angle")
|
||||||
ylabel("FY")
|
ylabel("FY")
|
||||||
|
%% without plot
|
||||||
|
for n=1:60
|
||||||
|
for i=1:length(subdirectories)
|
||||||
|
fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat");
|
||||||
|
parser = tydex.parsers.FSAETTC_SI_ISO_Mat();
|
||||||
|
measurements = parser.run(fileMeasurement);
|
||||||
|
measurement = measurements(n);
|
||||||
|
|
||||||
|
[SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement);
|
||||||
|
FY = smoothdata(FY, "gaussian",100);
|
||||||
|
SAA{i} = SA;
|
||||||
|
FYY{i} = FY;
|
||||||
|
end
|
||||||
|
file_name = ['similarityData\nEqu' num2str(n) '.mat'];
|
||||||
|
save(file_name, 'SAA', 'FYY');
|
||||||
|
end
|
||||||
|
58
scripts/similarities2.m
Normal file
58
scripts/similarities2.m
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
clear;
|
||||||
|
clc;
|
||||||
|
% Use the dir function to get information about files and directories
|
||||||
|
directoryPath = ".\similarityData";
|
||||||
|
|
||||||
|
% Get a list of all files in the directory
|
||||||
|
files = dir(fullfile(directoryPath, '*.mat')); % You can adjust the file extension as needed
|
||||||
|
|
||||||
|
% Extract file names
|
||||||
|
fileNames = {files.name};
|
||||||
|
|
||||||
|
for n=1:length(fileNames)
|
||||||
|
% fit the curve of 43075 , 8 inch
|
||||||
|
filePath = fullfile(directoryPath, fileNames(n));
|
||||||
|
load(filePath)
|
||||||
|
[fitresult, gof] = createFit(SAA{8},FYY{8});
|
||||||
|
residual = [];
|
||||||
|
|
||||||
|
% Evaluate the fitted curves
|
||||||
|
for i=1:length(SAA)
|
||||||
|
y_fit = fitresult(SAA{i});
|
||||||
|
% Calculate residuals
|
||||||
|
residual = [residual, mean(abs(FYY{i} - y_fit))];
|
||||||
|
end
|
||||||
|
residuals{n} = residual;
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1:length(residual)
|
||||||
|
residuals_sum{i} = 0;
|
||||||
|
num = length(fileNames);
|
||||||
|
for j=1:length(fileNames)
|
||||||
|
if isnan(residuals{j}(i))
|
||||||
|
num = num - 1;
|
||||||
|
residuals{j}(i) = 0;
|
||||||
|
end
|
||||||
|
residuals_sum{i} = residuals{j}(i) + residuals_sum{i};
|
||||||
|
end
|
||||||
|
residuals_mean{i} = residuals_sum{i}/num;
|
||||||
|
end
|
||||||
|
% figure()
|
||||||
|
% idx = linspace(1,length(SAA),length(SAA));
|
||||||
|
% for i=1:length(fileNames)
|
||||||
|
% plot(idx, residuals{i}, "-*")
|
||||||
|
% hold on;
|
||||||
|
% end
|
||||||
|
% title("Residuials")
|
||||||
|
% legend(fileNames)
|
||||||
|
% xlabel("order of the tires(8 is our traget tire)")
|
||||||
|
|
||||||
|
figure()
|
||||||
|
idx = linspace(1,length(SAA),length(SAA));
|
||||||
|
y = cell2mat(residuals_mean)
|
||||||
|
plot(idx, y, "-*")
|
||||||
|
title("Average Absolute Residuials")
|
||||||
|
legend(fileNames)
|
||||||
|
xlabel("order of the tires(8 is our traget tire)")
|
||||||
|
xticks(idx)
|
||||||
|
grid on
|
Loading…
x
Reference in New Issue
Block a user