Page 1 of 1

updating OpenSim models using API

Posted: Mon Dec 09, 2024 5:12 pm
by modenaxe
Hello,
I have noticed that when I switch OpenSim version, for example from 4.4 to 4.5, and update a model, for example using the MATLAB API, I obtain a model with slightly different parameters.

For example, if I run like this simple code on the RajagopalLaiUhlrich2023 model:

Code: Select all

import org.opensim.modeling.*;
osimModel = Model('RajagopalLaiUhlrich2023.osim');
osimModel.print('RajagopalLaiUhlrich2023_osim4.5.osim');
all the SimmSplines in the model will be modified from:

Code: Select all

<SimmSpline name="function">
	<x> 0 0.174533 0.349066 0.523599 0.698132 0.872665 1.0472 1.22173 1.39626 1.5708 1.74533 1.91986 2.0944</x>
	<y> 0.00113686 -0.00629212 -0.105582 -0.253683 -0.414245 -0.579047 -0.747244 -0.91799 -1.09044 -1.26379 -1.43763 -1.61186 -1.78634</y>
</SimmSpline>
to very close, but not identical, values:

Code: Select all

<SimmSpline name="function">
	<x> 0 0.1745329999999999937 0.3490659999999999874 0.52359900000000003661 0.6981319999999999748 0.87266500000000002402 1.0471999999999999087 1.2217299999999999827 1.3962600000000000566 1.5707999999999999741 1.745330000000000048 1.9198599999999999 2.0943999999999998174</x>
	<y> 0.0011368599999999999539 -0.0062921200000000000047 -0.1055819999999999953 -0.25368299999999999184 -0.41424499999999997435 -0.57904699999999997839 -0.74724400000000001931 -0.91798999999999997268 -1.0904400000000000759 -1.2637899999999999689 -1.4376299999999999635 -1.6118600000000000705 -1.7863400000000000389</y>
</SimmSpline>
Model files are attached.
SimmSpline models.zip
(70.83 KiB) Downloaded 7 times
I assume this will have a negligible numerical impact, but regardless I was wondering if there is an explanation for this behaviour, and ideally, a way to avoid it?

Thank you,

Luca

Re: updating OpenSim models using API

Posted: Tue Dec 10, 2024 4:29 pm
by tkuchida
Please see Ayman's reply to Issue #3404: https://github.com/opensim-org/opensim-core/issues/3404. The underlying issue is that the floating-point representation of a number is an approximation. In theory, floats could be rounded before being serialized, though this would require a single set of logic that could distinguish between meaningful and meaningless nonzero decimal places in all scenarios.