Accuracy Measurement Tool
The open-source tool Octave is introduced to analyze the relative error in a visualized manner.
Make the following preparations:
- Construct data: approximation and actual value. The approximation is typically the NumPy data, and the actual value is the operator output. Both values can be generated using ST cases.
- Install Octave: Download the installation package from https://www.gnu.org/software/octave/download.html.
The following describes the procedure of analyzing the relative error with Octave.
The following description involves only basic commands. For details about the tool instructions, visit https://octave.org/doc/interpreter/.
- Load data.
m = dlmread('data.csv', ',');
Load the data in the file to matrix m, where, data.csv is the name of the data file, and ',' is the file separator.
- Read data.
input = m(4:8940, 7); // Read all data in column 7. gpu_output = m(4:8940, 13); // Read all data in column 13. model_output = m(4:8940, 19); // Read all data in column 19.
- Calculate the relative error and absolute error.
gpu_diff = abs(model_output - gpu_output); // Calculate the relative error. gpu_error = diff ./ gpu_output; // Calculate the absolute error.
In the preceding command, gpu_output is the approximation, and model_output is the actual value.
- Visualize the result.
plot(input, gpu_error, 'o'); xlabel('x') //x-axis label ylabel('value'); //y-axis label title(''Diff of model and cpu or gpu); //title hold on; //Draw again. plot (x, cpu_error, 'o'); //The process of cpu_error is omitted here, which is similar to that of gpu_error. hold off; Axis([0 1 -0.002 0.002]); //x-axis and y-axis ranges legend('gpu_error','cpu_error'); //Legend
The following figure shows a visualized result example.
Figure 13-2 Visualized result using Octave