adding uncertainty and units to quantity types in software models
TRANSCRIPT
Business Informatics GroupInstitute of Software Technology and Interactive Systems TU WienFavoritenstraße 9-11/188-3, 1040 Vienna, Austriaphone: +43 (1) 58801 - 18804 (secretary), fax: +43 (1) 58801 - [email protected], www.big.tuwien.ac.at
Business Informatics Group
Adding Uncertainty and Units to Quantity Types in Software Models
Tanja Mayerhofer, Manuel WimmerBusiness Informatics Group, TU Wien, Austria
Antonio VallecilloAtenea, 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
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
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
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)
B. 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: … where represents a base unit and its exponent
Hence, any unit can be defined by the exponents of the base units:
Examples
𝑀𝑒𝑡𝑒𝑟 (𝑚 )=𝑚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: :, : Examples:
,
,
,
𝑥𝑘𝑚=(𝑥 ∗1000+0 )𝑚273.15) K0) m/s
9
Units and Dimensions Model-Based Representation
Domain Model
Example Instances
Unitname : Stringsymbol : Stringdimensions : Real [8]conversionFactor : Real [8]offset : Real [8]
m : Unitname = "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 : Unitname = "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>
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 ,
11
Measurement Uncertainty Model-Based Representation
Domain Model
Example Instances
UReal
x : Realu : Real
1 : UReal
x = 10.0u = 0.0014
2 : UReal
x = 2.0u = 0.02
1 0±0.001 2±0.02
12
Quantities Model-Based Representation
Domain Model
Example Instance:
Unitname : Stringsymbol : Stringdimensions : Real [8]conversionFactor : Real [8]offset : Real [8]
UReal
x : Realu : Real
Quantityvalue unit
m : Unitname = "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.0u = 0.001
q : Quantityvalue unit
13
Example
Measuretime : Quantityposition : Quantity
startSectionMeasure
/duration : Quantity/distance : Quantity/avgVelocity : Quantity/avgAcceleration : Quantity
end
duration = end.time – start.timedistance = end.position – start.positionavgVelocity = distance / durationavgAcceleration = (end.velocity – start.velocity) / duration
velocity : Quantity
Start A B C N…
Measure M0 M1 M2 M3 MN
S1 S2 S3
14
Unit Operations
Unit
isBaseUnit() : BooleanisDerivedUnit() : BooleanisUnitless() : BooleanisDimensionless() : Boolean
isCompatibleWith(Unit u) : Booleanequals(Unit u) : Boolean
multiplyUnits(Unit u) : UnitdivideUnits(Unit u) : UnitpowerUnits(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𝑀𝑒𝑡𝑒𝑟 (𝑚 )= ⟨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 compatiblecompatible
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
𝑀𝑒𝑡𝑒𝑟 (𝑚 )= ⟨1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ⟩𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 (𝑚2 )= ⟨2 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ⟩
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
𝑀𝑒𝑡𝑒𝑟 (𝑚 )= ⟨1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ⟩𝑆𝑞𝑢𝑎𝑟𝑒 𝑀𝑒𝑡𝑒𝑟 (𝑚2 )= ⟨2 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ⟩
18
Measurement Uncertainty Operations
UReal
add(r : UReal) : URealminus(r : UReal) : URealmultiply(r : UReal) : URealdivideBy(r : UReal) : URealpower(s : Real) : UReal…
lessThan(r : UReal) : BooleanlessThanOrEquals(r : UReal) : BooleangreaterThan(r : UReal) : Boolean…
Arithmetic operations
Comparison operations
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
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.
20
Quantity Operations
Quantity
compatibleUnits(q : Quantity) : Boolean
convertTo(u : Unit) : QuantityconvertToSIUnits() : QuantityconvertFromSIUnits() : Quantity
add(q : Quantity) : Quantityminus(q : Quantity) : Quantitymultiply(q : Quantity) : QuantitydivideBy(q : Quantity) : Quantity…
lessThan(q : Quantity) : BooleanlessThanOrEquals(q : Quantity) : BooleangreaterThan(q : Quantity) : Boolean…
Arithmetic operations
Comparison operations
Unit conversion operations
Unit comparison
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
5𝑚+1𝑘𝑚=5𝑚+1000𝑚=1005𝑚
UReal operation aggregates uncertainty
Unit operation converts units of summands
22
Example
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.timedistance = end.position – start.positionavgVelocity = distance / durationavgAcceleration = (end.velocity – start.velocity) / duration
M0 : Measuretime = 0.0 ± 0.0014 s position = 0.0 ± 0.001 kmvelocity = 0.0 m/s
M1 : Measuretime = 10.0 ± 0.0014 s position = 10.0 ± 0.001 mvelocity = 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
Unitname : Stringsymbol : Stringdimensions : Real [8]conversionFactor : Real [8]offset : Real [8]
UReal
x : Realu : Real
Quantityvalue unit
Mass Time ElectricCurrent
ThermodynamicTemperature
AmountOfSubstance
LuminosityIntensity Angle
LinearAcceleration ForcePower
Length
LinearVelocity Resistance…
Quantity types for base dimensions
Quantity types for derived dimensions
24
Quantities Static Type Checking
Domain Model
Unitname : Stringsymbol : Stringdimensions : Real [8]conversionFactor : Real [8]offset : Real [8]
UReal
x : Realu : Real
Quantityvalue unit
Mass Time ElectricCurrent
ThermodynamicTemperature
AmountOfSubstance
LuminosityIntensity Angle
LinearAcceleration ForcePower
Length
LinearVelocity Resistance…
Quantity types for base dimensions
Quantity types for derived dimensions
Length
add(l : Length) : Lengthminus(l : Length) : Lengthmultiply(l : Length) : Areamultiply(l : Area) : VolumedivideBy (t : Time) : LinearVelocity…
25
Example
duration = end.time – start.timedistance = end.position – start.positionavgVelocity = distance / durationavgAcceleration = (end.velocity – start.velocity) / duration
Start A B C N…
Measure M0 M1 M2 M3 MN
S1 S2 S3
Measuretime : Timeposition : Length
startSectionMeasure
/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
USE Tool: https://sourceforge.net/projects/useocl/ MagicDraw: http://www.nomagic.com/products/magicdraw.html Eclipse Papyrus UML: https://eclipse.org/papyrus/
Java ExampleLength 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
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
Thank you!
Questions?
Manuel [email protected]
Antonio [email protected]
Tanja [email protected]
Contact
Business Informatics Group
Addendum:
Implementation of Quantity Types for fUML
31
fUML Implementation
Types
32
fUML Implementation
Operations: Realized as function behaviors (syntactical elements)
…
……
fUML Implementation
33
Operation Implementations fUML execution model is extended with Execution classes for all quantity
operations (built-in extension mechanism) Operations of Execution classes are implemented with Java
Execution
+ execute() : void
OpaqueBehaviorExecution
+ doBody(input : ParameterValue [*], output : ParameterValue [*]) : void+ execute() : void
BasicBehaviors
QuantityFunctions
…
QuantityMinusExecution
doBody(input : ParameterValue [*], output : ParameterValue [*]) : void+
34
fUML Implementation
Example
Classes
Behavior
35
fUML Implementation
Example
Values