PM Demos.pdf

PROBABILITY IN METROLOGY –
DEMONSTRATIONS OF THE PROBABILISTIC APPROACH TO MEASUREMENT
Giovanni Battista Rossi and Francesco Crenna
Università degli Studi di Genova - Italy
Abstract
Demonstrations of the potential of the probabilistic approach considered in Ref [1] are presented.
Related educational software is provided.
1. PROBABILISTIC EXPRESSION OF THE RESULT OF MEASUREMENTS BASED ON
REPEATED OBSERVATIONS
We consider the case of the measurement of some quantity, x, by repeated observations obtained
by a measuring device [2-3]. Let the measuring device be affected by
− additive random noise w ,
− a systematic deviation θ and
− limited resolution, characterised by a quantisation interval q.
The measurement process may be modelled by
y t = Q ( kx + w t + θ ) ,
(1)
where t is a discrete time index,
−
Q(.) a quantisation operator,
−
w t a stationary series of uncorrelated normal random variables, with unknown variance σ2 ,
and
−
θ a constant systematic effect.
Since the variance of the random variations is unknown, the observation process is “influenced”, so
to say, by two parameters, σ and θ . The observation process is thus characterised by
P ( y | x, σ , θ ) = ∏
t
+q 2
∫
−q 2
1/30
pw ( y t − x − θ + ξ | σ ) dξ .
(2)
Restitution may be performed by applying the Bayes Laplace rule to the vector of parameters
T
[ x,σ ,θ ] . This yields1
p ( x,σ ,θ | y ) =
∫
P ( y | x,σ ,θ ) p ( x ) p (σ ) p (θ )
X ,Σ ,Θ
P ( y | x,σ ,θ ) p ( x ) p (σ ) p (θ ) dx dσ dθ
.
(3)
The required distribution for the value of the measurand may be obtained as the marginal
distribution
p ( x | y) = ∫
Σ ,Θ
p ( x,σ ,θ | y ) dσ dθ .
(4)
Moreover, the distribution of σ may also be obtained, as
p (σ y ) = ∫
X ,Θ
p ( x,σ , Θ y ) dx dθ
(5)
For performing the calculations, we consider the discrete version of the formulae above.
After assuming a normal distribution for w, defining the cumulative normal distribution
u
2
1
Φ (u ) =
e −ξ 2dξ and considering a discrete version of variables x,σ ,θ , with discretisation
∫
2π −∞
interval ∆x , we calculate the probability of each observation y t actually obtained, for each
possible value of the triple ( x,σ ,θ ) , that is
q

 y t + 2 − kx − θ
P ( y t | x,σ ,θ ) = Φ 
σ


q



 y t − 2 − kx − θ
 − Φ
σ






.


(6)
The probability of the whole vector of observations y is
P ( y | x,σ ,θ ) = ∏ P ( y t | x,σ ,θ ) .
(7)
t
This formula holds for every possible value of the vector y, but needs to be calculated only for the
specific value of y actually observed.
The joint distribution P ( x,σ ,θ | y ) may be calculated as
P ( x,σ ,θ | y ) =
P ( y | x,σ ,θ ) P ( x ) P (σ ) P (θ )
P ( y | x,σ ,θ ) P ( x ) P (σ ) P (θ )
∑
σθ
.
(8)
x, ,
Note that although we formally treat in the same way the parameters σ and θ , we obtain information from
the data only on σ . The influence of θ is accounted for by using the distribution p (θ ) for producing the
1
final result of measurement, through formula (8). In this regard, see discussion in Ref [1], Section 1.4.
2/30
Let us consider an example concerning repeated observations, from a low-resolution indicating
devices. Consider 10 repeated measurement of length, performed by a device with resolution
q = 0.1 mm .
We consider two cases,
A) the instrument is free from systematic effect and
B) the instrument is affected by an additive systematic effect, bounded within ±∆θ = ±0.05 mm .
The numerical values for this example are collected in Table 1.
Table 1 Numerical data for cases study. All data are expressed in millimeters.
Test case
q
∆θ
y1
y2
y3
y4
y5
y6
y7
y8
y9
y10
A
0.1
0
7.5
7.5
7.4
7.5
7.5
7.4
7.5
7.5
7.5
7.4
B
0.1
0.05
7.5
7.5
7.4
7.5
7.5
7.4
7.5
7.5
7.5
7.4
Since observations have a resolution limited to q, we will be hardly interested in defining the other
involved variables, x and σ , with a resolution better then, say, ∆x = q 10 . So we discretize them
accordingly.
(
)
Let us first consider case A, where θ = 0 . We need first to calculate P y t = y j x = xi ,σ = σ k ,
where indices account for amplitude discretization of involved quantities. In our example, only two
distinct values of y occur, namely y = 7.5 and y = 7.4 . The results, for both values of y, are shown
in Figure 1.
P(y=7.5 | xi, σk)
P(y=7.4 | xi, σk)
1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0
0.02
0.02
7.8
0.04
7.6
0.06
0.08
σk
7.8
0.04
7
7.4
0.08
7.2
0.1
7.6
0.06
7.4
σk
xi
a
7.2
0.1
7
xi
b
Figure 1 Graphs of P ( y = 7.5 x i ,σ k ) (a) and P ( y = 7.4 x i ,σ k ) (b), the probability of observing the values
y = 7.5 and y = 7.4 respectively, in correspondence to various possible values of x and of σ .
3/30
The distribution of the vector of observations is now
(
P ( y x i ,σ k ) = ∏ P y t = y j x = x i ,σ = σ k
t
)
and the joint final distribution is then
P ( x i ,σ k y ) =
P ( y x i ,σ k ) P ( x i ) P ( σ k )
∑ P ( y x ,σ ) P ( x ) P (σ )
i
k
i
,
(9)
k
i ,k
where y represents the set of the actually observed values. The distribution of σ is often
assumed as being proportional to σ −1 . Here we have assumed a uniform distribution instead, for
simplicity. The distribution in formula (9), which is a function of both x and σ , is shown in Figure 2.
P(xi, σk | y )
0.08
0.06
0.04
0.02
0
0.02
0.04
0.06
0.08
σk
0.1
7.4
7.2
7
7.6
7.8
xi
Figure 2 Graph of P ( x i ,σ k y ) , the probability to be assigned to the possible values of both x and σ , on the
basis of the observed values, collected in vector y .
The final measurement result, i.e., the distributionto be assigned to x,
P ( x i y ) = ∑ P ( x i ,σ k y )
k
is shown in Figure 3a.
Interestingly enough, we may also assign a posterior density to σ , by calculating
P (σ k y ) = ∑ P ( xi ,σ k y ) .
i
4/30
This result, may be useful, for instance, when performing a repeatability test, and is shown in
Figure 3b.
P(σ k|y)
P(x i|y)
0.25
0.25
0.2
0.2
Probability
Probability
0.15
0.15
0.1
0.1
0.05
0.05
0
7.3
7.35
7.4
7.45
7.5
Measurement values x i
7.55
0
7.6
0
0.01
0.02
0.03
0.04 0.05 0.06
sigma values σ k
a
0.07
0.08
0.09
b
Figure 3 Final result of measurement restitution in case A :
a) graph of P ( x i y ) , probability to be assigned to the possible values of the
measurand x, on the basis of the observed values, collected in vector y ;
b) graph of P (σ k y ) , probability distribution to be assigned to the standard deviation
σ , on the basis of the vector of observation y .
Let us now consider case B, where a systematic effect is considered. In this case we start from
P ( y t = y j | x = xi ,σ = σ k ,θ = θs )
and the final joint distribution to be calculated is
P ( xi ,σ k ,θs y ) =
P ( y xi ,σ k ,θs ) P ( xi ) P (σ k ) P (θs )
∑ P ( y x ,σ
i
i ,k ,s
k
,θs ) P ( xi ) P (σ k ) P (θs )
The distribution of the final result is
P ( xi y ) = ∑ P ( xi ,σ k ,θs y ) ,
k ,s
and the distribution for the standard deviation is
P (σ k y ) = ∑ P ( xi ,σ k ,θs y ) .
i ,s
5/30
.
(10)
0.1
These results for case B are shown in Figure 4.
P(σk|y)
P(xi|y)
0.25
0.25
0.2
0.2
Probability
Probability
0.15
0.15
0.1
0.1
0.05
0.05
0
7.3
7.35
7.4
7.45
7.5
Measurement values xi
7.55
0
7.6
0
0.01
0.02
0.03
0.04 0.05 0.06
sigma values σk
a
0.07
0.08
0.09
b
Figure 4 Final result of measurement restitution in case B :
a) graph of P ( x i y ) , probability to be assigned to the possible values of the
measurand x, on the basis of the observed values, collected in vector y ;
(
)
b) graph of P σ k y , probability distribution to be assigned to the standard deviation
σ , on the basis of the vector of observation y (the same as in case A).
The numerical values, for both cases, are summarised and presented in Table 2.
The results are also expressed with a higher number of figures, to show the potentials of the
calculation.
Table 2 Summary of results for test cases A and B.
Equivalent
coverage factor
Test case
x̂
u
A
7.47 mm
( 7.466 mm )
0.02 mm
( 0.017 mm )
0.03 mm
( 0.034 mm, p0 =0.96
B
7.47 mm
( 7.466 mm )
0.04 mm
( 0.036 mm )
0.06 mm
( 0.064 mm, p0 =0.96 )
U95
)
2.02
1.78
The numerical calculations have been performed with the demonstration code reported in
Appendix A. In the implementation, special care has been taken in the readability of the source
code, rather than in the efficiency of calculations.
For a general implementation of this procedure it is necessary a specialised software such as the
one provided by the prototypal package UNCERT, developed in the Measurement Laboratory of
the Department of Mechanics and Machine Design [3]. The package has been presented in [7]. Its
application in conjunction with the Monte Carlo method has also been studied, in collaboration with
the National Physical Institute (NPL) [4].
6/30
0.1
2. RISK ANALYSIS FOR CONFORMANCE DECISIONS
Measurement is often intended to support decisions. In particular, conformance decisions are very
common in manufacturing, environment, health and safety [6]. Let us then briefly address the task
of evaluating the risk of a faulty conformance decision, accounting for the uncertainty of
measurement.
Let x ∈ X be a critical parameter of a production process, p ( x ) its probability distribution, A ⊂ X
its conformity region (according to a given specification), B ⊆ A a safeguard region, i.e., an
acceptance region, restricted in order to reduce the risk of accepting a non conformant state of the
process, and x̂ a specific measurement value for the parameter. Note that the distribution p ( x )
may be obtained in general by the historical records on the behaviour of the process. The analysis
to follow is based on the assumption that the process will continue to behave, in the average,
according to the pattern expressed by the p ( x ) .
A typical decision strategy would be to consider the process conformant when xˆ ∈ B. Associated
with this strategy, we may consider, for example, the local consumer’s (or user’s) risk, i.e., the
probability of the process not being conformant ( x ∉ A ) in a case in which the measurement result
says it is ( x̂ ∈ B ) , that is
R ( xˆ ) = P ( x ∉ A | xˆ ) for xˆ ∈ B.
(11)
Alternatively, we may be interested in the global consumer’s risk, i.e., the average consumer’s risk
associated to the monitoring and management strategy considered. That will be
R = P ( x ∉ A, xˆ ∈ B ) .
(12)
Such risks, as well as the complementary producer’s risk may be calculated through the following
distributions:
p ( x, xˆ ) = p ( xˆ | x ) p ( x ) and
p ( x | xˆ ) =
p ( x, xˆ )
∫ p ( x, xˆ ) dx
=
p ( xˆ | x ) p ( x )
(13)
∫ p ( xˆ | x ) p ( x ) dx
.
(14)
Note that these distributions combine information from the production process, expressed through
the p ( x ) , and information on the measurement process, expressed by the p ( xˆ | x ) .
The formulae for risk evaluation are summarised in Table 3.
Table 3 Summary of risk evaluation formulae.
Consumer’s risk
Local risk
R ( xˆ ) = P ( x ∉ A | xˆ ) =
∫
X −A
Producer’s risk
p ( x | xˆ ) dx
for x̂ ∈ B.
Global risk
R = P ( x ∉ A, xˆ ∈ B ) = ∫  ∫
B

X −A
R * ( xˆ ) = P ( x ∈ A | xˆ ) =
∫ p ( x | xˆ ) dx
A
for x̂ ∉ B.
p ( x, xˆ ) dx  dxˆ

7/30
R* = P ( x ∈ A, xˆ ∉ B ) =
∫
X −B
 ∫ p ( x, xˆ ) dx  dxˆ
 A

As an application example, consider the inspection of a workpiece having some critical length x to
be checked for conformance with a specification expressed by the tolerance region
A = [ x0 - a, x0 + a ] , a>0, and let the acceptance region be B = [ x0 - b, x0 + b ] , 0 < b ≤ a. Suppose
further that the production process may be described by a Gaussian probability distribution centred
on the nominal value x0 , with variance σ 2 , and assume that the measurement system has a
standard uncertainty u and may be considered Gaussian also. Then, after introducing the standard
1
(
)
Gaussian distribution ϕ ( ξ ) = ( 2π ) 2 exp ξ 2 2 , we have
-
1  ( x - x0 )  1  ( xˆ - x ) 
ϕ
.
 ϕ
σ  σ  u  u 
p ( x, xˆ ) = p ( x ) p ( xˆ | x ) =
It is convenient to re-parameterise as
p ( x, xˆ ) = p ( x | xˆ ) p ( x ) =
where x = xˆ
σ2
σ 2 + u2
+ x0
1  ( x - x )  1  ( xˆ - x0 ) 
ϕ
,
 ϕ
σ  σ  σ'  σ' 
(15)
u2
σ 2u 2
2
,
=
and σ ' = σ 2 + u 2 .
σ
2
2
2
2
σ +u
σ +u
Such formulae enable the direct calculation of the risks.
For example, in the case of the consumer’s risk, we obtain, for the local risk,
R ( xˆ ) =
x0 − a
∫
−∞
p ( x | xˆ ) dx +
−a
+∞
∫ p ( x | xˆ ) dx =
x0 +a
+∞
1 x−x
1 x−x
∫−∞ σ ϕ  σ  dx + +∫a σ ϕ  σ  dx
and, for the global risk,
+∞
 x0 − a

R = ∫  ∫ p ( x, xˆ ) dx + ∫ p ( x, xˆ ) dx  dxˆ =
 −∞
x0 − b 
x0 +a

x0 +b
+∞
 x0 − a

ˆ
ˆ
p
x
|
x
d
x
+
p
x
|
x
d
x

 p ( xˆ ) dxˆ =
(
)
(
)
∫  −∞∫
∫
x0 − b 
x0 +a

x0 +b
x0 +b
1 
∫ R ( xˆ ) σ ' ϕ 
x0 − b
xˆ − x0
σ'

 dxˆ.

For the evaluation of the local risk, we calculate
 −a − x 
 +a − x 
R ( xˆ ) = Φ 
 + 1− Φ 
.
 σ 
 σ 
8/30
(16)
For evaluation of the global risk we discretise the interval B, considering the points i ∆b ,
−M ≤ i ≤ +M , and we calculate the local risk R ( xˆ ) on such points. Then we calculate the global
risk as
 
∆b
∆b



  i ∆b + 2 − x0 
 i ∆b − 2 − x0  
R ≅ ∑ R ( i ∆b )  Φ 
 − Φ
 .
σ'
σ'
i=-M
 


 


 
 
+M
(17)
For the consumer’s risks we proceed in a similar way.
We conclude with some numerical examples, considering two cases, A and B, characterised by the
same nominal value x0 = 0, and different values of the normalised parameters σ a , related to the
degree of control of the process, and u a , related to the quality of the measurement process.
Calculations may be performed, for example, by the software code presented in Appendix B. We
have studied two different decision strategies, namely
− b = a , i.e., no safeguard factor applied, and
− b = a − 2u , i.e., the acceptance region has been reduced by 2u.
Results are summarised in Table 4.
Table 4 Results from risk calculations.
Production process
Measurement
process
Global user’s risk
Global producer’s risk
Test case
Distribution
σ a
Distribution
u a
b=a
b = a - 2u
b=a
b = a − 2u
A
Normal
15 8
Normal
18
7.1 10-3
1.8 10 -4
1.4 10 -2
9.5 10-2
B
Normal
3 6
Normal
16
1.8 10 -4
5.6 10-6
2.4 10 -3
4.5 10-2
In Figure 5 we present some graphs of p ( x | xˆ ) , the key distribution for risk evaluation, and of the
specific risk versus the result of measurement, in order to give a visual feeling of the support that
the probabilistic approach can provide. Note how the probabilistic approach provides an explicit
evaluation of the risk and allows for the optimisation of the decisions.
A systematic application of this probabilistic approach requires a specific software. We have
develop one prototype such package, MEAS RISK, which has been applied to several test cases,
including both scalar and vector measurement, such as the results from chemical analysis [6].
The package has also been presented in [8]
9/30
Specific risk
1
0.9
0.9
0.8
0.8
0.7
0.7
0.6
0.6
Probability
Probability
Specific risk
1
0.5
0.5
0.4
0.4
0.3
0.3
0.2
0.2
0.1
0.1
0
−2
−1.5
−1
−0.5
0
0.5
1
1.5
0
−2
2
−1.5
−1
−0.5
0.9
0.9
0.8
0.8
0.7
0.7
0.6
0.6
0.5
0.4
0.3
0.3
0.2
0.2
0.1
0.1
−0.5
0
1.5
2
1.5
2
0.5
0.4
−1
1
Specific risk
1
Probability
Probability
Specific risk
1
−1.5
0.5
(b) Specific risk, case A, b =a-2u
(a) Specific risk, case A, b =a
0
−2
0
x^
x^
0.5
1
1.5
0
−2
2
x^
−1.5
−1
−0.5
0
0.5
1
x^
(c) Specific risk, case B, b =a
(d) Specific risk, case B, b =a-2u
(e) Distribution p ( x, xˆ ) , for case A
(f) Distribution p ( x, xˆ ) , for case B
Fig 5 Sample results from risk evaluation.
In graphs a-d the local risk for each value of x̂ is presented. Vertical lines indicate the conformity limits ±a:
for x̂ ≤ b the product is accepted, and so the consumer’s risk is shown;
for x̂ > b the product is discarded and so producer’s risk is shown.
In graphs e-f the conjoint probability distribution p ( x, xˆ ) is shown for both cases.
10/30
3. CALCULATION OF THE PROBABILITIES FOR A SIMPLE RELATIONAL STRUCTURE
Since the notion of probabilistic (or random) relation and of probabilistic relational system are
rather new in the statistic and probabilistic literature [5], we consider here, in more detail, the
simple example presented in [1] for illustrating such concepts. The example has been constructed
in order to be as simple as possible and thus is not intended to represent any real measurement
situation.
Let us consider a set A including only three elements A = {a, b, c} .
A binary relation on A is simply a subset of the Cartesian product A × A and a weak order is a
binary relation which is strongly complete and transitive. So, the collection of all the possible weak
order relations on A is presented in Table 5, second column.
Table 5 - An illustrative example of a probabilistic order structure on A = {a,b,c}
Relational
System Weak order relations
Ai
i
mi ( a ) mi ( b )
mi ( c )
P ( Ai )
(example)
A1
a
b
c
3
2
1
0.2
A2
a
c
b
3
1
2
0.2
A3
b
a
c
2
3
1
0.0
A4
b
c
a
1
3
2
0.0
A5
c
a
b
2
1
3
0.0
A6
c
b
a
1
2
3
0.0
A7
a∼b
c
2
2
1
0.1
A8
a∼c
b
2
1
2
0.1
A9
b∼c
a
1
2
2
0.0
A10
a
b∼c
2
1
1
0.3
A11
b
a∼c
1
2
1
0.0
A12
c
a∼b
1
1
2
0.0
A13
a∼b∼c
1
1
1
0.1
In a deterministic framework, only one of such relations would be true, whilst in a probabilistic
framework we assign a probability distribution over the set of all such relations. Since in this way
only weak orders may have non-null probability, we call this a probabilistic weak-order relation.
Again an example of one such assignment is presented in Table 5 (column 2, the various orders,
and column 6, their probabilities).
An order system on A, denoted by A = ( A, ) , is simply the association of A with a suitable weak
order over it: there are as many order systems on A as the weak orders that we may define on A.
So the probability assignment above may also be regarded as a probability assignment to the
order relational systems Ai = ( A, i ) , or, briefly, a probabilistic weak-order system: see in Table 5,
column 1, the various orders systems, corresponding to the orders of column 2, and in column 6,
their probabilities. This is the input of our procedure.
We now associate to each order system Ai one (and only one) numerical values to the elements
of A, in agreement with it. This has been done in columns 3-5 of the Table.
11/30
We introduce now the vector random variable x = [ x a , x b , x c ] , which is characterised by the joint
probability matrix
Px = [ px , jkl ] , where px, jkl = P [ xa = j , xb = k, xc = l ]
(18)
with j , k, l = 1,2,3 .
The assignment of the values of the matrix Px may be done with the following rule
−
Ai , for which mi ( a ) = j , mi ( b ) = k , mi ( c ) = l , then
if their exists a relational system
px, jkl = P [ xa = j , xb = k , xc = l ]
= P ( Ai ) ,
−
(19)
otherwise px, jkl = 0 .
It is now possible to calculate the matrices of the relational probabilities, namely
= P[am
−
P = [p
−
P∼ = [ p∼,mn ] , where p∼,mn = P[am ∼ an ] = P [ xam = xan ] ,
−
PX = [ pX,mn ] , where pX,mn = P[am X an ] = P [ xam ≥ xan ] .
,mn
] , where p
,mn
an ] = P [ xam > xan ] ,
(20)
The calculations may be done with the code in Appendix C and the corresponding results are
presented in Table 6.
(
Table 6 – Matrix of probabilities: a) P ( ai
)
(
c) P ( ai X a j ) = P x ai ≥ x a j
a
a
-
b 0.0
b
c
a
a
0.8 0.8
-
c 0.0 0.3
-
b
c
-
a
a
(a)
-
b 0.2
0.4
c 0.2 0.4
-
)
)
0.2 0.2
b 0.2
0.3
(
a j ) = P x ai > xa j ; b) P ( ai ∼ a j ) = P x ai = x a j ;
b
1.0 1.0
-
c 0.2 0.7
-
(b)
c
0.7
-
(c)
Moreover, from the matrix Px it is also possible to calculate the marginal distributions of the scalar
random variables x a , xb and x c . The resulting distributions are presented in Table 7.
Table 7 - Marginal probability distributions P ( xi = j )
1
2
3
xa
0.1
0.5
0.4
xb
0.7
0.3
0.0
xc
0.7
0.3
0.0
12/30
REFERENCES
[1] Rossi G B, Probability in Metrology, in Pavese F, Forbes A B, (Eds) Advances in Data Modeling
for Measurements in metrology and Testing Fields, Birkhauser-Springer, Boston, 2008
[2] Rossi G B, A probabilistic model for measurement processes, Measurement, 34, 2, 2003, pp.
85-99
[3] Rossi G B, Crenna F, Codda M, Metrology software for the expression of measurement results
by direct calculation of probability distributions, in Ciarlini P, Cox M G, Pavese F, and Rossi G B
(Eds.): Advanced Mathematical Tools in Metrology VI, Series on Advances in Mathematics for
Applied Sciences vol. 66, ISBN 981-238-904-0 World Scientific, Singapore, 2004
[4] - Rossi G B, Crenna F, Cox M, Harris P, Combining direct calculation and the Monte Carlo
method for the probabilistic expression of measurement results, in Ciarlini P, Filipe E, Forbes A B,
Pavese F, Perruchet C, Siebert B R L (Eds.) Advanced Mathematical and Computational Tools in
Metrology VII, World Scientific, 2006, ISBN 981-256-674-0, pp. 221-228
[5] – Rossi G B, A probabilistic theory of measurement, Measurement 39 (2006) 34-50
[6] – Rossi G B, Crenna F, A probabilistic approach to measurement based decisions,
Measurement 39 (2006) 101-119
[7] UNCERT – A Package for the Probabilistic Expression of Measurement Results, Counting on
IT, 16 2004
[8] A Package for analysing risks related to measurement uncertainty in conformance decisions,
Counting on IT, 18 2005
13/30
APPENDIX A
A CODE FOR THE CALCULATIONS IN SECTION 1
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
***** PM_Demos_1 *****
A code for probabilistic expression of the result of measurements based
on repeated observations.
INPUT
q
dx
xmin,xmax
sigmamin
sigmamax
thetamin
thetamax
y
Y
-->
-->
-->
-->
-->
-->
-->
-->
-->
quantisation interval for instrumental indications
discretisation interval for the measurand x
minimum and maximum values for x vector
minimum value for sigma vector
maximum value for sigma vector
minimum value for theta vector
maximum value for theta vector
vector of instrument indications
length of vector y
COMPUTATION
sw
--> case selection
x
--> vector of the possible values of the measurand
X
--> length of vector x
Px
--> prior probability distribution for the measurand
sigma --> vector of the possible standard-deviation values
Psigma--> prior probability distribution for sigma
S
--> length of vector sigma
theta --> vector of the possible values for the systematic deviation
Ptheta--> prior probability distribution for theta
T
--> length of vector theta
OUTPUT
Py_given_x_sigma_theta
--> probability of each instrument
indication y, given x, sigma and theta (formula 6)
Pyvect_given_x_sigma_theta --> probability of the vector of
indications y, given x, sigma and theta (formula 7)
Px_sigma_theta_given_yvect --> joint probability distribution
for x, sigma and theta, given the vector of indications (formula 8)
px
--> marginal probability distribution for x
psigma
--> marginal probability distribution for sigma
xhat
--> measurement value
u
--> standard uncertainty
U
--> expanded uncertainty with coverage probability 0.95
pxc
--> coverage probability
pactual
--> actual coverage probability
kf
--> coverage factor
14/30
% INPUT
%
% Clear screen, workspace and close all figures
%
clc
clear all
close all
%
% Interface for test case selection
%
disp('*******************************************************************')
disp('PROBABILISTIC EXPRESSION OF MEASUREMENT RESULTS ')
disp('*******************************************************************')
disp(' ');disp('Code PM_Demos_1');disp(' ')
disp('*******************************************************************')
disp(' ')
disp('Select a test case: ')
disp('1 - Case A Random variations only ')
disp('2 - Case B Random variations plus additive systematic effect')
disp('3 - Exit')
disp(' ')
sw=input('Your choice ');
if ( sw<0 || sw>2)
return
end
%
% Input values
%
% Quantisation interval and discretisation intervals
%
q=0.1;
dx=q/10;
%
% Instrument indications
%
y=[7.5,7.5,7.4,7.5,7.5,7.4,7.5,7.5,7.5,7.4];
Y=length(y);
%
% Prior probability distribution for the measurand
%
xmin=7.1;xmax=7.8;
x=xmin:dx:xmax;
X=length(x);
Px=ones(1,X)/sum(ones(1,X));
%
% Prior probability distribution for sigma
%
sigmamin=0.01;sigmamax=0.1;
sigma=sigmamin:dx:sigmamax;
S=length(sigma);
Psigma=ones(1,S)/sum(ones(1,S));
%
% Prior probability distribution for theta
%
switch sw
case 1
thetamin=0;thetamax=0;
case 2
thetamin=-.05;thetamax=.05;
end
theta=thetamin:dx:thetamax;
T=length(theta);
Ptheta=ones(1,T)/sum(ones(1,T));
15/30
% COMPUTATION
%
% Calculation of the probability of the individual observations, given x,
% sigma and theta, according to formula (6).
% The result is the 4D matrix Py_given_x_sigma_theta.
%
Py_given_x_sigma_theta=zeros(S,X,T,Y);
for k=1:S %loop on possible sigma values
for i=1:X %loop on possible x values
for s=1:T %loop on possible systematic deviations values
for t=1:Y %loop on actual instrument indications
Py_given_x_sigma_theta(k,i,s,t)=...
normcdf(+q/2,y(t)-x(i)-theta(s),sigma(k))-...
normcdf(-q/2,y(t)-x(i)-theta(s),sigma(k));
end
end
end
end
%
% Calculation of the probability of the whole vector of observations,
% given x, sigma and theta, according to formula (7).
% The calculation consists in taking the product along the 4th dimension
% of the matrix, that corresponds to y values.
% The result is the 3D matrix Pyvect_given_x_sigma_theta.
%
Pyvect_given_x_sigma_theta=prod(Py_given_x_sigma_theta,4);
%
% Evaluation of the joint final probability for x,sigma,s, given the
% vector y, according to formula (8).
%
% Calculation of the numerator
%
for k=1:S %loop on possible sigma values
for i=1:X %loop on possible x values
for s=1:T %loop on possible systematic deviations values
Px_sigma_theta_given_yvect(k,i,s)=...
Pyvect_given_x_sigma_theta(k,i,s)*Psigma(k)*Px(i)*Ptheta(s);
end
end
end
%
% Normalisation
%
normfact=sum(sum(sum(Px_sigma_theta_given_yvect)));
Px_sigma_theta_given_yvect=Px_sigma_theta_given_yvect/normfact;
%
% Marginal distribution for the measurand x
%
px=sum(sum(Px_sigma_theta_given_yvect,1),3);
%
% Marginal distribution for the standard deviation sigma
%
psigma=sum(sum(Px_sigma_theta_given_yvect,2),3);
%
% Calculation of the measurement value
%
xhat=x*px';
%
% Calculation of the standard uncertainty
%
u=sqrt( (x-xhat).^2*px' );
%
% Calculation of the expanded uncertainty, with nominal coverage
16/30
% probability p0=0.95
%
pxc=cumsum(px);
[a,b]=find(pxc>.975);
lim=min(b);
U=(x(lim)-xhat);
%
% Calculation of the equivalent coverage factor
%
kf=U/u;
%
% Since we deal with the discrete distribution, the resulting coverage
% probability is not exactly equal to p0. This is its actual value.
%
pactual=2*pxc(min(b))-1;
%
17/30
% OUTPUT
%
clc
disp('**********************************************************')
disp('PROBABILISTIC EXPRESSION OF THE RESULT OF MEASUREMENTS')
disp('
BASED ON REPEATED OBSERVATIONS')
disp('**********************************************************')
disp(' ');disp('
Code PM_Demos_1');disp(' ')
disp('**********************************************************')
disp(' ')
switch sw
case 1
disp('TEST CASE A')
disp('Random variations only')
case 2
disp('TEST CASE B')
disp('Random variations plus additive systematic effect')
end
disp(' ')
disp(['Measurement value
',num2str(xhat)])
disp(['Standard uncertainty u
',num2str(u)])
disp(['Expanded uncertainty U (0.95) ',num2str(U)])
disp(['Equivalent coverage factor k ',num2str(kf)])
disp(['Actual coverage level
',num2str(pactual)])
figure
surf(x,sigma,Py_given_x_sigma_theta(:,:,1))
set(gca,'ydir','reverse');v=axis;v(3)=.01;axis(v);
ylabel('\sigma_k');xlabel('x_i')
title('P(y=7.5 | x_i, \sigma_k)');colormap('gray')
figure
surf(x,sigma,Py_given_x_sigma_theta(:,:,3))
set(gca,'ydir','reverse');v=axis;v(3)=.01;axis(v);
ylabel('\sigma_k');xlabel('x_i')
title('P(y=7.4 | x_i, \sigma_k)');colormap('gray')
switch sw
case 1
figure
surf(x,sigma,Px_sigma_theta_given_yvect)
set(gca,'ydir','reverse');v=axis;v(3)=.01;axis(v);
ylabel('\sigma_k');xlabel('x_i')
title('P(x_i, \sigma_k | \bfy\rm)');colormap('gray')
case 2
figure;[a,b]=find(theta==0);
surf(x,sigma,Px_sigma_theta_given_yvect(:,:,b))
set(gca,'ydir','reverse');v=axis;v(3)=.01;axis(v);
ylabel('\sigma_k');xlabel('x_i');
title('P(x_i, \sigma_k | \bfy\rm)');colormap('gray')
end
figure
bar(x,px,.5)
title('P(x_i|\bfy\rm)');xlabel('x_i');ylabel('Probability ')
v=[7.3 7.6 0 .3]; axis(v);
figure
bar(sigma,psigma,.2);title('P(\sigma_k|\bfy\rm)')
xlabel('\sigma_k');ylabel('Probability ')
v=[0 .1 0 .25];axis(v)
18/30
APPENDIX B
A CODE FOR THE CALCULATIONS IN SECTION 2
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
***** PM_Demos_2 *****
A code for risk analysis in conformance decisions
INPUT
a
b
k
u
sigma
-->
-->
-->
-->
-->
conformity threshold (bilateral and symmetric)
acceptance threshold b<=a (bilateral and symmetric)
scale factor
measurement uncertainty
production process standard deviation
COMPUTATION
xtilde
--> auxiliary variable
sigma_tilde --> standard deviation of xtilde
sigma_prime --> combined process and measurement standard deviation of
OUTPUT
x
xhat
R_c
R_p
r_c
r_p
-->
-->
-->
-->
-->
-->
measurand values
measurement values
consumer's global risk
producer's global risk
consumer's local risk
producer's local risk
19/30
% INPUT
%
% Clear screen, workspace and close all figures
%
clc
clear all
close all
%
% Interface for test case selection
%
disp('************************************************************************')
disp('
RISK ANALYSIS AND CONFORMACE DECISIONS')
disp('************************************************************************')
disp(' ');disp('Code PM_Demos_2');disp(' ')
disp('************************************************************************')
disp(' ')
disp('Select a test case: ')
disp('1 - Example A with b=a
')
disp('2 - Example A with b=a-2u')
disp('3 - Example B with b=a
')
disp('4 - Example B with b=a-2u')
disp('5 - Exit')
disp(' ')
sw=input('Your choice ');
%
% Checking the validity of the choice
if ( sw<0 || sw>4)
return
end
%
20/30
% COMPUTATION
%
% Definition of the problem according to the test case selected
%
switch sw
case 1
a=1; u=a/8; b=a; sigma=sqrt(15)/8;
case 2
a=1; u=a/8; b=a-2*u; sigma=sqrt(15)/8;
case 3
a=1; u=1/6; b=a; sigma=sqrt(3)/6;
case 4
a=1; u=1/6; b=a-2*u; sigma=sqrt(3)/6;
end
%
% Calculation of sigma tilde
%
sigma_tilde=sqrt( u^2*sigma^2/(u^2+sigma^2) );
%
% Calculation of sigma prime
%
sigma_prime=sqrt( u^2+sigma^2 );
%
% CONSUMER'S RISK EVALUATION
%
% Calculation of the vector of possible measurement values, xhat,
% by discretisation of the acceptance interval
%
dx=.001;
xhat_c=-b:dx:b;
%
% Calculation of the auxiliary vector xtilde
%
xtilde=xhat_c*sigma^2/(u^2+sigma^2);
%
% Evaluation of the local risk, according to formula 16.
% Note that integration is done outside the conformity interval
% The MatLab functions normpdf(x,mean,sigma) and normcdf(a,mean,sigma)
% have been used.
%
r_c=( normcdf(-a,xtilde,sigma_tilde)+( 1-normcdf(a,xtilde,sigma_tilde) ) );
%
% Evaluation of global risk, according to formula 17.
%
R_c=sum( (r_c).*( normcdf( xhat_c+dx/2,0,sigma_prime )-normcdf( xhat_cdx/2,0,sigma_prime ) ) );
%
% PRODUCER'S RISK EVALUATION
%
% Calculation of the vector of possible measurement values, xhat,
% by dicretisation of the interval outside acceptance
%
xhat_p=[-5*b:dx:-b b:dx:5*b];
%
% Calculation of the auxiliary vector xtilde
%
xtilde=xhat_p*sigma^2/(u^2+sigma^2);
%
% Evaluation of the local risk.
% Note that integration is done inside the conformity interval
% The MatLab functions normpdf(x,mean,sigma) and normcdf(a,mean,sigma)
% have been used.
%
21/30
r_p=( normcdf( a,xtilde,sigma_tilde ) - normcdf( -a,xtilde,sigma_tilde ) );
%
% Evaluation of global risk
%
R_p=sum( (r_p).*( normcdf( xhat_p+dx/2,0,sigma_prime ) -...
normcdf( xhat_p-dx/2,0,sigma_prime ) ) );
%
22/30
% OUTPUT
%
% Display figures
%
clc
disp('************************************************************************')
disp('
RISK ANALYSIS AND CONFORMANCE DECISIONS')
disp('************************************************************************')
disp(' ');disp('Code PM_Demos_2');disp(' ')
disp('************************************************************************')
disp(' ')
switch sw
case 1
disp('TEST CASE A with b=a
')
case 2
disp('TEST CASE A with b=a-2u')
case 3
disp('TEST CASE b with b=a')
case 4
disp('TEST CASE B with b=a-2u')
end
disp(' ')
disp('--------------------------- Input data summary -------------------------')
disp(['Production process, normal distribution with standard deviation =
',num2str(sigma)])
disp(['Measurement process, normal distribution with standard deviation =
',num2str(u)])
disp(['Overall standard deviation = ',num2str(sigma_prime)])
disp(['Conformity threshold = ',num2str(a)])
disp(['Acceptance threshold = ',num2str(b)])
disp('---------------------------- Results summary ---------------------------')
disp(['GLOBAL CONSUMER''S RISK = ',num2str(R_c)])
disp(['GLOBAL PRODUCER''S RISK = ',num2str(R_p)])
%
% Graphics: specific risk
%
% Creating a matrix for specific risk with:
% first row : measurement vales
% second row: probability values
%
specific(1,:)=[xhat_p xhat_c];
specific(2,:)=[r_p r_c];
%
% Obtaining the indexes for a sorted plot along the measurement values
%
[s,i]=sort(specific(1,:));
specific=specific(:,i);
%
% Creates the figure
%
figure
plot( specific(1,:),specific(2,:) )
title('Specific risk','FontSize',12)
xlabel('{}_{^{\fontsize{12}x}}^{\^}','FontSize',12)
ylabel('Probability','FontSize',12)
%set axis limits
axis([-2 2 0 1]);
%
% Draw the conformity threshold
%
h=line([-a -a],[0,1]);
set(h,'Linestyle','-');set(h,'Color','r');
h=line([a a],[0,1]);
23/30
set(h,'Linestyle','-');set(h,'Color','r');
%
% Graphics: Conjoint probability distribution P(x,xhat)
%
% Generating a vector of measurand values with
% a wider discretisation for graphical purposes
%
dx=0.1;
x=-2*a:dx:2*a;
N=length(x);
%
% The same vector is used for measurement values
%
xhat=x';
%
% Auxiliary vector xtilde
%
xtilde=xhat*( sigma^2/(sigma^2+u^2) );
%
% Creation of a set of matrices with with x along columns and xtilde along rows
%
X=repmat(x,N,1);
XT=repmat(xtilde,1,N);
%
% Evaluation of the conjoint probability using matrix operations
%
Pxxhat=normpdf( X,XT,sigma_tilde ).*normpdf( XT,0,sigma_prime );
%
% Creation of the figure
%
figure
h=surfl(x,xhat,Pxxhat);set(gca,'Fontname','Times')
s=colormap('gray');s=abs(s-1);colormap(s);
set(h,'linestyle','none');set(h,'Facecolor','interp');set(gca,'Ydir','reverse')
title('Conjoint probability p(x,{}_{^{\fontsize{12}x}}^{\^})','FontSize',12)
xlabel('x','FontSize',12)
ylabel('{}_{^{\fontsize{12}x}}^{\^}','fontsize',12)
zlabel('Probability density','FontSize',12)
24/30
APPENDIX C
A CODE FOR THE CALCULATIONS IN SECTION 3
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
**** PM_Demos_3 ****
Calculation of the relational probabilities of simple third order
structures.
INPUT
N
--> Dimension:3
Px
--> matrix [NxNxN] of the joint probability of the random
variables xa, xb and xc
OUTPUT
Px
--> (as above)
Pab
--> matrix [NxN] of the marginal bidimensional distribution of the
variables xa and xb
Pac
--> matrix [NxN] of the marginal bidimensional distribution of the
variables xa and xc
Pca
--> matrix [NxN] of the marginal bidimensional distribution of the
variables xc and xa
P_marginal --> matrix [NxN] of the marginal distributions of the random
variables xa, xb and xc
P_xl_gt_xm --> matrix [NxN] of the probabilities that xm > xl, for
l,m=1,...N
P_xl_eq_xm --> matrix [NxN] of the probabilities that xm = xl, for
l,m=1,...N
P_xl_ge_xm --> matrix [NxN] of the probabilities that xm >= xl, for
l,m=1,...N
IMPLEMENTATION
The Code constitutes of five functions:
PM_Demos_3
: the main code,
Bi_Marginal_3
: calculation of marginal bidimensional joint distributions,
from the joint distribution Px,
Marginal_3
: calculation of the marginal distributions
P_relational_gt : calculation of the relational (order)
probabilities,
P_relational_eq : calculation of the relational (equivalence) probabilities.
25/30
%-------------------------------------------------------------------------function PM_Demos_3
%-------------------------------------------------------------------------% This functions is the main code.
%
% INPUT
%
% Clear screen, workspace and close all figures
%
clc
clear all
close all
%
% Assign matrix Px
%
N=3;
x=1:3;
Px=zeros(N,N,N);
Px(1,1,1)=0.1;
Px(2,1,1)=0.3;
Px(2,1,2)=0.1;
Px(2,2,1)=0.1;
Px(3,1,2)=0.2;
Px(3,2,1)=0.2;
%
% CALCULATIONS
%
% Calculation of the marginal bidimensional joint distributions
%
Pbm=Bi_Marginal_3(N,Px);
%
% Calculation of the marginals distributions
%
P_marginal=Marginal_3(N,Px);
%
% Calculation of the relational probabilities
%
P_xl_gt_xm=zeros(N,N);
P_xl_eq_xm=zeros(N,N);
P_xl_ge_xm=zeros(N,N);
for i=1:N
for j=1:N
if i~=j
aus=Pbm(i,j,:,:);
aus=reshape(aus,N,N);
P_xl_gt_xm(i,j)= P_relational_gt(N,aus);
P_xl_eq_xm(i,j)= P_relational_eq(N,aus);
else
P_xl_eq_xm(i,j)=1.0;
end
P_xl_ge_xm(i,j)=P_xl_gt_xm(i,j)+P_xl_eq_xm(i,j);
end
end
%
% OUTPUT
%
clc
format compact
disp('************************************************************************')
disp(' CALCULATION OF THE RELATIONAL PROBABILITIES OF SIMPLE ORDER STRUCTURES')
disp('************************************************************************')
disp('Code PM_Demos_3');
disp('************************************************************************')
26/30
disp('Probability matrix Px for Xc=1')
disp('Xb=
1
2
3')
disp(Px(:,:,1))
disp('Probability matrix Px for Xc=2')
disp('Xb=
1
2
3')
disp(Px(:,:,2))
disp('Probability matrix Px for Xc=3')
disp('Xb= 1
2
3')
disp(Px(:,:,3))
disp('Probability matrix for a and b values')
Pab=Pbm(1,2,:,:);Pab=reshape(Pab,N,N);disp(Pab)
disp('Probability matrix for b and c values')
Pbc=Pbm(2,3,:,:);Pbc=reshape(Pbc,N,N);disp(Pbc)
disp('Probability matrix for c and a values')
Pca=Pbm(3,1,:,:);Pca=reshape(Pca,N,N);disp(Pca)
disp('Marginal probability matrix:')
disp(P_marginal)
disp('Relational probabilities: ')
disp('Greater than: ');disp(P_xl_gt_xm)
disp('Equal to: ');disp(P_xl_eq_xm)
disp('Less than or equal to:');disp(P_xl_ge_xm)
%
% End of the main code
%
27/30
%-------------------------------------------------------------------------function [Pbm]=Bi_Marginal_3(N,Px)
%-------------------------------------------------------------------------% Calculation of marginal bidimensional joint distributions, from the joint
% distribution Px.
%
% INPUT
% Dimension: N=3
% Px = matrix [NxNxN] of the joint probability of the random variables xa,
% xb and xc
%
% OUTPUT
% Pbm = matrix [NxNxNxN] of the bi-marginal distributions of the variables
% xa, xb, xc:
% Pbm (i,j,:,:)= matrix [NxN] of the bi-marginal distributions of the
% variables xi and xj
%
Pbm=zeros(N,N,N,N);
for i=1:(N-1)
for j=(i+1):N
k=6-i-j;
Pbm(i,j,:,:)= sum(Px,k);
end
end
for j=1:(N-1)
for i=(j+1):N
aus=Pbm(j,i,:,:);
aus=reshape(aus,N,N);
Pbm(i,j,:,:)= aus';
end
end
%
28/30
%-------------------------------------------------------------------------function [P_marginal]=Marginal_3(N,Px)
%-------------------------------------------------------------------------% Calculation of the marginals P_marginal(l,m)
% where l is the index of the variables and m is the index of the values
%
% INPUT
% Dimension: N=3
% Px = matrix [NxNxN] of the joint probability of the random variables xa,
% xb and xc
%
% OUTPUT
% P_marginal = matrix [NxN] of the marginal distributions of the variables
% xa, xb, xc
%
P_marginal=zeros(N,N);
for l=1:N
for m=1:N
if
l==1
for j=1:N
for k=1:N
P_marginal(l,m)=P_marginal(l,m)+Px(m,j,k);
end
end
elseif l==2
for i=1:N
for k=1:N
P_marginal(l,m)=P_marginal(l,m)+Px(i,m,k);
end
end
elseif l==3
for i=1:N
for j=1:N
P_marginal(l,m)=P_marginal(l,m)+Px(i,j,m);
end
end
end
end
end
%
29/30
%-------------------------------------------------------------------------function [P_a_gt_b]=P_relational_gt (N,Pab)
%-------------------------------------------------------------------------% Calculation of the probability that the random variable xa is greater than
% xb, given the joint probability distribution Pab
%
% INPUT
% Dimension: N
% Pab = matrix [NxN] of the joint probability of the random variables xa
% and xb
%
% OUTPUT
% P_a_gt_b = probability that xa is greater than xb
%
P_a_gt_b=0;
for j=1:(N-1)
for i=(j+1):N
P_a_gt_b=P_a_gt_b+Pab(i,j);
end
end
%
%-------------------------------------------------------------------------function [P_a_eq_b]=P_relational_eq (N,Pab)
%-------------------------------------------------------------------------% Calculation of the probability that the random variable xa is equal to xb,
% given the joint probability distribution Pab
%
% INPUT
% Dimension: N
% Pab = matrix [NxN] of the joint probability of the random variables xa
% and xb
%
% OUTPUT
% P_a_eq_b = probability that xa is equal to xb
%
P_a_eq_b=0;
for i=1:N
P_a_eq_b=P_a_eq_b+Pab(i,i);
end
30/30