I have a question on something that is seemingly simple but i can't figure out where i may have gone wrong.
I am working on EEG signal analysis and modelling . My task is to test the accuracy of Interpolation of an EEG data with all working electrodes against an EEG data that is produced with broken/damaged electrodes.
The test of accuracy is given by a factor called RDM and its following formula (According to Meijs, et. al 1989)
% Relative difference measure
function rdm = calc_rdm(m1, m2)
rdm = norm((m1/M1)-(m2/M2));
This function works well with regular integers and floating point values with rand too! But when i enter my data( column vectors of same dimensions), until the line m1/M1 and m2/M2 , everything works fine . At the subtraction is where i get values like e-17 instead of a 0! Here is a Minimum Working Example:
m1= m2 =
For simplicity, i set both vectors to the same values. After checking the code step by step, i figure that the subtraction of the two matrices gives these values!
Welcome to the world of floating point calculation. Computers store values in binary, which sometimes requires rounding. This rounding can result in values being different in the last bit, where they should be the same. This then results in a value on the order of when it should be 0.
This is the reason why you shouldn't always use == to test for equality, and why functions like uniquetol and ismembertol exist.
1e-17 is 0.00000000000000001, that's not large!. That's 15 orders of magnitude smaller than the numbers you started with and only about 50 times larger than the precision of these numbers (eps(0.001) is ~2e-19). What you get is expected, floating point numbers have limited precision and when you combine them small inaccuracies add up. For example, see:
>>0.1 + 0.1 + 0.1 - 0.3
When the magnitude of the result is so much smaller than the numbers you started with, you can consider it 0.