This document discusses representing uncertainty and units in software models. It proposes a type system to represent measurement uncertainty and units, as well as an algebra of operations to perform computations with uncertain data and units. Implementations are proposed for Java, OCL, and UML. The key contributions are a kernel representation for quantities that includes uncertainty, a computational kernel for operating on quantities, and domain models and examples to demonstrate representing quantities, units, and uncertainty in software models.
Adding Uncertainty and Units to Quantity Types in Software Models
1. Business Informatics Group
Institute of Software Technology and Interactive Systems
TU Wien
Favoritenstraße 9-11/188-3, 1040 Vienna, Austria
phone: +43 (1) 58801 - 18804 (secretary), fax: +43 (1) 58801 - 18896
office@big.tuwien.ac.at, www.big.tuwien.ac.at
Business Informatics Group
Adding Uncertainty and Units to Quantity Types
in Software Models
Tanja Mayerhofer, Manuel Wimmer
Business Informatics Group, TU Wien, Austria
Antonio Vallecillo
Atenea, Universidad de Málaga, Spain
Tanja Mayerhofer
2. Motivation
Uncertainty and Units in Engineering Disciplines
Engineers naturally think about uncertainty associated with measured values
and units of values
Examples
A machinist estimates that the length of a produced part lies with probability 0.5
in the interval [10.07 mm, 10.15 mm]
A calibration certificate states that with 99 percent confidence the resistance of
a standard resistor is 10.000742 Ω ± 129 μΩ
Uncertainty and units are explicitly defined in models and considered in
model-based simulations
2
phi.start = 0 rad (rotation angle)
w.start = 10 rad/s (angular velocity)
(Coupled Clutches Example of Modelica Standard Library)
3. Uncertainty and Units in Software Engineering
Very limited support for representing uncertainty and units in software models
No support for considering such properties in model-based simulations
Problem
Movement towards cyber-physical systems demands for the accurate
representation of properties of physical entities in software models
Important future application domain: Internet of Things
Analysis of huge amount sensor data
Motivation
3
Measure
value : Real
What kind of value is measured?
In which unit is the value measured?
What is the uncertainty of the
measurement method?
4. Contributions
1. Type system for representing measurement uncertainty and units
Kernel representation for quantities
2. Algebra of operations for performing computations with uncertain data
and units
Computational kernel for computing quantities
3. Implementations for Java, OCL, UML
4
5. Quantities
Definition: Quantity Kind (Dimension)
Any observable property of any object that can be measured and quantified
numerically.
Examples: Length, mass, time, force, energy, power, electric charge
Definition: Quantity
Observable property of a particular object that can be measured and
quantified numerically.
Examples: Length, mass, speed, temperature of a particular object
Definition: Quantity Value
Magnitude of a quantity expressed as a product of a number and a unit.
Example: Velocity of 3.5 m/s
5
6. Units and Dimensions Systems of Units
International System of Units (SI)
Base dimensions: Length, Mass, Time, Electric Current, Thermodynamic
Temperature, Amount of Substance, Luminous Intensity
Base units: Meter (m), Kilogram (kg), Second (s), Ampere (A), Kelvin (K), Mole
(mol), Candela (cd)
Derived dimensions: 90 dimensions derived from the base dimensions
e.g., Area, Volume, Velocity
Derived units: 90 units derived from the base units
e.g., Square Meter (m²), Cubic Meter (m³), Meter per Second (m/s)
Other Systems of Units
Centimeter-Gram-Second System (CGS)
Imperial System
United States Customary System (USCS, USC)
6B. N. Taylor and A. Thompson. The International System of Units (SI). NIST, 2008. http://www.nist.gov/pml/pubs/sp811/.
7. Units and Dimensions Representation of Units
Any unit can be derived from the base units:
𝐵1
𝑒1
∗ 𝐵2
𝑒2
… 𝐵𝑛
𝑒 𝑛
where 𝐵𝑖 represents a base unit and 𝑒𝑖 its exponent
Hence, any unit can be defined by the exponents 𝑒𝑖 of the base units:
𝑒1, 𝑒1, … , 𝑒 𝑛
Examples
7
𝑀𝑒𝑡𝑒𝑟 𝑚 = 𝑚1 ∗ 𝑘𝑔0 ∗ 𝑠0 ∗ 𝐴0 ∗ 𝐾0 ∗ 𝑐𝑑0 ∗ 𝑚𝑜𝑙0 ∗ 𝑟𝑎𝑑0 = 1, 0, 0, 0, 0, 0, 0, 0
𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 𝑚2
= 𝑚2
∗ 𝑘𝑔0
∗ 𝑠0
∗ 𝐴0
∗ 𝐾0
∗ 𝑐𝑑0
∗ 𝑚𝑜𝑙0
∗ 𝑟𝑎𝑑0
= 2, 0, 0, 0, 0, 0, 0, 0
𝑀𝑒𝑡𝑒𝑟 𝑝𝑒𝑟 𝑆𝑒𝑐𝑜𝑛𝑑 𝑚/𝑠 = 𝑚1 ∗ 𝑘𝑔0 ∗ 𝑠−1 ∗ 𝐴0 ∗ 𝐾0 ∗ 𝑐𝑑0 ∗ 𝑚𝑜𝑙0 ∗ 𝑟𝑎𝑑0 = 1, 0, −1, 0, 0, 0, 0, 0
R. Hodgson, P. J. Keller, J. Hodges, and J. Spivak. QUDT – Quantities, Units, Dimensions and Data Types Ontologies.
TopQuadrant, Inc. and NASA AMES Research Center, 2014. http://qudt.org/.
8. Units and Dimensions Conversion Between Units
Conversion of quantity values from base units 𝐵𝑖 to derived units 𝐷𝑖
Multiply the numerical value of the quantity value with conversion factor 𝑐𝑓
Add an offset 𝑜 to the resulting numerical value
Definition: 𝑥 𝐷𝑖 = (𝑥 ∗ 𝑐𝑓𝑖 + 𝑜𝑖) 𝐵𝑖
Examples:
Conversion factors and offsets can be defined relative to the base units:
𝑐𝑓𝑖: 𝑐𝑓1, 𝑐𝑓1, … , 𝑐𝑓𝑛 , 𝑜𝑖: 𝑜1, 𝑜2, … , 𝑜 𝑛
Examples:
8
𝐾𝑖𝑙𝑜𝑚𝑒𝑡𝑒𝑟 𝑘𝑚 : 𝑐𝑓 = 1000, 1, 1, 1, 1, 1, 1, 1 , 𝑜𝑓 = 0, 0, 0, 0, 0, 0, 0, 0
𝐶𝑒𝑙𝑐𝑖𝑢𝑠 °𝐶 : 𝑐𝑓 = 1, 1, 1, 1, 1, 1, 1, 1 , 𝑜𝑓 = 0, 0, 0, 0, 273.15, 0, 0, 0
𝐾𝑖𝑙𝑜𝑚𝑒𝑡𝑒𝑟 𝑝𝑒𝑟 𝐻𝑜𝑢𝑟 𝑘𝑚/ℎ : 𝑐𝑓 = 1000, 1, 3600, 1, 1, 1, 1, 1 , 𝑜𝑓 = 0, 0, 0, 0, 0, 0, 0, 0
𝑥 𝑘𝑚 = 𝑥 ∗ 1000 + 0 𝑚
𝑥 °𝐶 = (𝑥 ∗ 1 + 273.15) K
𝑥 𝑘𝑚/ℎ = (𝑥 ∗
1000
3600
+ 0) m/s
9. Units and Dimensions Model-Based Representation
Domain Model
Example Instances
9
Unit
name : String
symbol : String
dimensions : Real [8]
conversionFactor : Real [8]
offset : Real [8]
m : Unit
name = "Meter"
symbol = "m"
dimensions = <1,0,0,0,0,0,0,0>
conversionFactor = <1,1,1,1,1,1,1,1>
offset = <0,0,0,0,0,0,0,0>
km/h : Unit
name = "Kilometer per Hour"
symbol = "km/h"
dimensions = <1,0,-1,0,0,0,0,0>
conversionFactor = <1000,1,3600,1,1,1,1,1>
offset = <0,0,0,0,0,0,0,0>
10. Measurement Uncertainty Representation of Uncertainty
It is impossible to know, estimate or measure values with complete precision
The value of a quantity is only complete when it is accompanied by a
statement about the associated uncertainty
Definition: Standard Uncertainty [GUM]
Uncertainty of the result of a measurement 𝑥 expressed as a standard
deviation 𝑢
Representation: 𝑥 ± 𝑢 or (𝑥, 𝑢)
Examples:
10[GUM] JCGM 100:2008. Evaluation of measurement data – Guide to the expression of uncertainty in measurement.
Joint Committee for Guides in Metrology, 2008.
Normal distribution: (𝑥, 𝜎) with mean 𝑥, standard deviation 𝜎
Interval 𝑎, 𝑏 : Uniform or rectangular distribution is assumed
(𝑥, 𝑢) with 𝑥 =
𝑎+𝑏
2
, 𝑢 =
(𝑏−𝑎)
2 3
11. Measurement Uncertainty Model-Based Representation
Domain Model
Example Instances
11
UReal
x : Real
u : Real
1 : UReal
x = 10.0
u = 0.0014
2 : UReal
x = 2.0
u = 0.02
10 ± 0.001 2 ± 0.02
12. Quantities Model-Based Representation
Domain Model
Example Instance: 𝐿𝑒𝑛𝑔𝑡ℎ 10 ± 0.001 𝑚
12
Unit
name : String
symbol : String
dimensions : Real [8]
conversionFactor : Real [8]
offset : Real [8]
UReal
x : Real
u : Real
Quantityvalue unit
m : Unit
name = "Meter"
symbol = "m"
dimensions = <1,0,0,0,0,0,0,0>
conversionFactor = <1,1,1,1,1,1,1,1>
offset = <0,0,0,0,0,0,0,0>
ur : UReal
x = 10.0
u = 0.001
q : Quantityvalue unit
13. Example
13
Measure
time : Quantity
position : Quantity
start
SectionMeasure
/duration : Quantity
/distance : Quantity
/avgVelocity : Quantity
/avgAcceleration : Quantity
end
duration = end.time – start.time
distance = end.position – start.position
avgVelocity = distance / duration
avgAcceleration = (end.velocity – start.velocity) / duration
velocity : Quantity
Start A B C N…
Measure M0 M1 M2 M3 MN
S1 S2 S3
14. Unit Operations
14
Unit
isBaseUnit() : Boolean
isDerivedUnit() : Boolean
isUnitless() : Boolean
isDimensionless() : Boolean
isCompatibleWith(Unit u) : Boolean
equals(Unit u) : Boolean
multiplyUnits(Unit u) : Unit
divideUnits(Unit u) : Unit
powerUnits(Real s) : Unit
Query nature of unit
Combine units
Compare units
15. Unit Operations
isCompatibleWith(Unit u) : Boolean
Checks whether two units are compatible for being combined or compared
Two units are compatible, if they are of the same dimension
Specification: self.dimensions = u.dimensions
Examples
15
𝑀𝑒𝑡𝑒𝑟 𝑚 = 1, 0, 0, 0, 0, 0, 0, 0
𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 𝑚2
= 2, 0, 0, 0, 0, 0, 0, 0
𝑀𝑖𝑙𝑒 𝑚𝑙 = 1, 0, 0, 0, 0, 0, 0, 0
not compatible
not compatible
compatible
16. Unit Operations
multiplyUnits(Unit u) : Unit
When two quantity values are multiplied, their units have to be multiplied too
Specification:
result.dimensions = self.dimensions -> sum(u.dimensions)
Examples
16
𝑀𝑒𝑡𝑒𝑟 𝑚 = 1, 0, 0, 0, 0, 0, 0, 0
𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 𝑚2
= 2, 0, 0, 0, 0, 0, 0, 0
𝑀𝑒𝑡𝑒𝑟 𝑚 ∗ 𝑀𝑒𝑡𝑒𝑟 𝑚 = 1, 0, 0, 0, 0, 0, 0, 0 + 1, 0, 0, 0, 0, 0, 0, 0 = 2, 0, 0, 0, 0, 0, 0, 0
= Square Meter 𝑚2
17. Unit Operations
divideUnits(Unit u) : Unit
When a quantity value is divided by another quantity value, their units have to
be divided too
Specification:
result.dimensions = self.dimensions -> minus(u.dimensions)
Examples
17
𝑀𝑒𝑡𝑒𝑟 𝑚 = 1, 0, 0, 0, 0, 0, 0, 0
𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 𝑚2 = 2, 0, 0, 0, 0, 0, 0, 0
Square Meter 𝑚2
𝑀𝑒𝑡𝑒𝑟 𝑚
= 2, 0, 0, 0, 0, 0, 0, 0 − 1, 0, 0, 0, 0, 0, 0, 0 = 1, 0, 0, 0, 0, 0, 0, 0
= Meter 𝑚
19. Measurement Uncertainty Operations
Computations with uncertain values have to respect the propagation of
uncertainty (uncertainty analysis)
Methods for Computing Aggregated Uncertainty
Normal or Uniform distribution: Analytical solutions
General case: Monte Carlo simulations
19
A. Vallecillo, C. Morcillo, and P. Orue. Expressing Measurement Uncertainty in
Software Models. In Proceedings of the 10th International Conference on the Quality
of Information and Communications Technology (QUATIC), pages 1–10, 2016.
21. Quantity Operations
add(q : Quantity) : Quantity
Quantity values of compatible units can be added
For the addition, the summands have to be converted to the same unit
Specification:
pre: self.compatibleUnits(q.unit)
post: result.value = self.value.add(q.convertTo(self.unit).value)
and result.unit = self.unit
Example
Special care has to be taken for units with an offset (e.g., °C, °F)
Units with offsets are affine, i.e., non-multiplicative
Require affine conversions that allows multiplication and addition
21
5 𝑚 + 1 𝑘𝑚 = 5 𝑚 + 1000 𝑚 = 1005 𝑚
UReal operation aggregates uncertainty
Unit operation converts units of summands
22. Example
22
startS1 : SectionMeasure
/duration = 10.0 ± 0.0019799 s
/distance = 10.0 ± 0.0014142 m
/avgVelocity = 1.0000000392 ± 0.000489 m/s
/avgAcceleration = 0.200000008 ± 0.0632468 m/s²
end
duration = end.time – start.time
distance = end.position – start.position
avgVelocity = distance / duration
avgAcceleration = (end.velocity – start.velocity) / duration
M0 : Measure
time = 0.0 ± 0.0014 s
position = 0.0 ± 0.001 km
velocity = 0.0 m/s
M1 : Measure
time = 10.0 ± 0.0014 s
position = 10.0 ± 0.001 m
velocity = 2.0 ± 0.02 m/s
Start A B C N…
Measure M0 M1 M2 M3 MN
S1 S2 S3
23. Quantities Static Type Checking
Domain Model
23
Unit
name : String
symbol : String
dimensions : Real [8]
conversionFactor : Real [8]
offset : Real [8]
UReal
x : Real
u : Real
Quantityvalue unit
Mass Time Electric
Current
Thermodynamic
Temperature
AmountOf
Substance
Luminosity
Intensity Angle
Linear
Acceleration ForcePower
Length
Linear
Velocity Resistance…
Quantity types for base dimensions
Quantity types for derived dimensions
24. Quantities Static Type Checking
Domain Model
24
Unit
name : String
symbol : String
dimensions : Real [8]
conversionFactor : Real [8]
offset : Real [8]
UReal
x : Real
u : Real
Quantityvalue unit
Mass Time Electric
Current
Thermodynamic
Temperature
AmountOf
Substance
Luminosity
Intensity Angle
Linear
Acceleration ForcePower
Length
Linear
Velocity Resistance…
Quantity types for base dimensions
Quantity types for derived dimensions
Length
add(l : Length) : Length
minus(l : Length) : Length
multiply(l : Length) : Area
multiply(l : Area) : Volume
divideBy (t : Time) : LinearVelocity
…
25. Example
25
duration = end.time – start.time
distance = end.position – start.position
avgVelocity = distance / duration
avgAcceleration = (end.velocity – start.velocity) / duration
Start A B C N…
Measure M0 M1 M2 M3 MN
S1 S2 S3
Measure
time : Time
position : Length
start
SectionMeasure
/duration : Time
/distance : Length
/avgVelocity : LinearVelocity
/avgAcceleration : LincearAcceleration
end velocity : LinearVelocity
26. Available Implementations
Java: Reference implementation
OCL (USE Tool):
Specification of operations with
preconditions and postconditions
Support for imperative use of
operations (SOIL)
UML (Papyrus, MagicDraw):
Support for specifying quantities and
computations with quantities
Proof-of-concept prototype for executing
computations with quantities with fUML
Download: https://github.com/moliz/moliz.quantitytypes
Implementation
26
USE Tool: https://sourceforge.net/projects/useocl/ MagicDraw: http://www.nomagic.com/products/magicdraw.html
Eclipse Papyrus UML: https://eclipse.org/papyrus/
Java Example
Length initialPosition = new Length(0, 0.001, Units.Meter);
Length finalPosition = new Length(10, 0.001, Units.Meter);
Length distance = finalPosition.minus(initialPosition);
USE OCL Example
!new UReal(’ip’)
!ip.x : = 0.0
!ip.u := 0.001
!new Quantity(’initialPosition’)
!initialPosition.value := ip
...
!distance := finalPosition.minus(initialPosition)
Papyrus UML Example
27. Summary
1. Type system for representing quantities
+ Allows explicit representation of measurement uncertainty and units
+ Enables static model-level checks of quantity compatibility
2. Algebra of operations for performing computations with quantities
+ Allows computations with uncertain values
+ Supports automatic conversions between units
+ Enables domain experts to use the most appropriate units
+ Supports model-level simulations that consider data uncertainty
and units
3. Implementations for Java, OCL, UML
+ Reference implementation and formal specifications for operations on quantities
+ Showcase of integrating quantities with modeling language on the example of UML
27
28. Ongoing and Future Work
Implementation
Evolve fUML proof-of-concept implementation to full implementation
Alf implementation (textual action language for fUML)
Full integration with Papyrus and MagicDraw
Eclipse OCL implementation
Refinement of the conceptual model of quantity types
Different kinds of uncertainty (e.g., interval, different probability distributions)
Different kinds of units (e.g., length units, time units, etc.)
Representation of quantities
Useable representation of quantities
Integration with existing standards, e.g., MARTE and SysML
28
CoupledClutches in Modelica Standard Library 3.0
Rotating body J1:
Absolute rotation angle: 0 rad
Absolute angular velocity of component: 10 rad/s
For example, the Centimeter-Gram-Second System (CGS) is a variant of the metric system that has the same dimensions but uses centimeters, grams and seconds as base units.
The Imperial System used in UK also defines the same dimensions as the SI, but uses several different units: miles, feet, inches, stones, pounds, Fahrenheit degrees, etc.
In USA, the United States Customary System (also called USCS or USC) is a variant of the Imperial System that uses different units for fluids.
Since they define the same dimensions, conversions among these systems of units are possible
8th dimension: Angle; unit: Radian
There is an additional supplementary dimension in the SI, for angles. The SI committee has not yet fully agreed on the nature of this angular dimension, because it is considered dimensionless. However, it is required to represent Angular Velocity (rad/s), Angular Acceleration (rad/s2), Area Angle (m2st) and Power per Angle (W/st). Therefore we decided to incorporate it, treating angular units like normal base units. So we will consider eight base dimensions. The base unit for Angle is Radian (rad). There is also a derived unit for solid angle measurement, the Steradian (st), which corresponds to rad2.
When dealing with real-world entities, models need to take into account the inability to know, estimate or measure with complete precision the value of any quantity.
For instance, in physical systems measurement uncertainty normally arises in partially observable and/or stochastic environments, or when the system properties are not directly measurable or accessible.
On other occasions estimations are needed because the exact values are too costly to measure, or simply because they are unknown—for example, the duration of a given task in a software process or the life of a battery.
Sometimes values are based on expert judgments and estimations. Such estimates normally feature ranges, or intervals, not exact values, which determine the possible lower and upper bounds for the exact values, or are given by a probability distribution that represents a range of its variation.
This is why, in general, a measurement result that determines the value of a quantity is only complete when it is accompanied by a statement of the associated uncertainty [15, 16].
---
The GUM framework also identifies two ways of evaluating the uncertainty of a measurement,
Type A evaluation of uncertainty: the knowledge about the quantity X is inferred from repeated measured values
Type B evaluation of uncertainty: the knowledge about the quantity x is inferred from scientific judgment or other information concerning the possible values of the quantity.
In Type A evaluation, if X={x1,…,xn} is the set of measured values, then the estimated value x is taken as the mean of these values, and the associated uncertainty u as their experimental standard deviation, i.e., u^2=(1 / (n *(n-1))) Σ (xi – x)^2
In Type B evaluation of uncertainty, only lower and upper bounds [a,b] for the values of X are known, without any further information about the possible values of X within the interval. Thus, we can only assume a uniform or rectangular distribution of the values, and therefore x is calculated as the midpoint of the interval, x = (a+b)/2, and its associated variance is taken as u^2=(b-a)^2/12. Therefore, u=(b-a)/(2 sqrt{3}).
This is why uncertain values admit two implementations:
one that assumes that all the probability distributions of the individual uncertainties follow Normal or Uniform distributions allowing the application of analytic solutions to compute the aggregated uncertainty, and the other that deals with the general case where that assumption cannot hold requiring Monte Carlo simulations. Although being more specific, the first one is more efficient and represents the most usual case. The second one is more general, but requires more number crunching.