60 likes | 77 Views
This tutorial explains the five scales of measurement (nominal, ordinal, interval, ratio, absolute) and provides examples for each. It also discusses the problems with the Lines of Code (LoC) measure and how to calculate number of nodes in a control flow graph (CFG).
E N D
Tutorial 2, Q1 solution The five scales: • Nominal scale serves only for classification. The order of the classes is unimportant as is the difference between them. A renaming of classes is a valid transformation of scales. Example: blood types. • The Ordinal Scale is for classification where the order is important but the difference between classes is arbitrary. Any monotonic transformation is meaningful. Example: top ten whatevers. • Interval scale: order important and differences between classes meaningful. Any affine transformation (S' = kS + c) is meaningful, as in the conversion from C to F. Eg. temperature in Celsius (F = (9/5)*C + 32). • Ratio scale: as interval scale but also has meaningful zero. Any Linear transformation (S' = kS) is meaningful as in conversion of currencies. • The Absolute scale is just used for counting. Meaningful zero and differences between values. Only the identity transformation is valid. Eg. Lines of Code (given a particular definition of LoC).
Tutorial 2, Q1 solution • “100 C is the boiling point of water" is a meaningful. Degrees C is an interval scale since each degree is equal but the zero is arbitrary. Transformation to Fahrenheit scale is example of an affine transformation which is valid for interval scales. • “Today is twice as hot as yesterday" is unlikely to be meaningful as weather temperature is measured in C or F which are not ratio scales (which would be required for “twice" to be meaningful). Differences are meaningful however, so if today is 10 degrees C, and yesterday was 5 degrees C, then it would be meaningful to say that today is 5 degrees hotter than yesterday. • The FT index is an example of an indirect measure (calculated from the value of lots of different shares). The calculation is made such that the resulting value is on a ratio scale. The zero is meaningful (the shares have value) and the differences are equal. • Depending on its precise definition, Line of Code is probably an absolute scale so the sentence is meaningful. Transformations which convert between lines of code measures for different languages may be empirically substantiated but are not valid for an absolute scale. • Elapsed time is a ratio scale made by subtracting two points in time. Points in time are measured on interval scale (eg. 3/10/2002 10:11:30). Transformations of elapsed time such as 1 month = 20 working days are valid for elapsed time (ratio scale). But (31 Jan 1997) = 31 * (1st Jan 1997) is not valid since date is an interval scale. • Cost is a ratio scale. Assuming we are talking about something like cost of maintenance per year, then the sentence is meaningful. • Complexity however defined is likely to be at least an ordinal scale so the sentence is OK.
Tutorial 2 Q2 Solution Check the notes for week two. There are lots of problems with the Lines of Code LoC measure: Do blank lines count? What about comments? Compiler directives? Declarations? Procedure headings? Imports, exports? What about side effects in expressions – you can get lots of effects in a single expression, for example in Java you can write X = i++,j++,k++,--p,t=t*4 ; This assigns to X, but has also 5 side effects.
Control Flowgraphs Loop Atomic Sequence Conditional Start or Stop node
S C S A A A S C A L A A Tutorial 2, Q3 solution Draw the CFG: • IF(...)THEN x:=1 ELSE x:=2 FI ; y:=50 ; IF (...) THEN z:=1 ELSE DO WHILE (...) z:=z+1 OD FI ; y:=0
S C S A A A S C A L A A Tutorial 2, Q3 solution 12 10 To calculate number of nodes: M(S(C(A,A),S(A,S(C(A,L(A)),A)))) = M(C(A,A))+M(S(A,S(C(A,L(A)),A)))-1 = M(A) +M(A) + M(A) +M(S(C(A,L(A)),A)) -1 -1 = 2 + 2 + 2 + M(C(A,L(A))) + M(A) -1 -1 -1 = 2 + 2 + 2 + M(A) + M(L(A)) +2 -1 -1 -1 = 2 + 2 + 2 + 2 + M(A) +1 +2 -1 -1 -1 = 2 + 2 + 2 + 2 + 2 +1 +2 -1 -1 -1 = 10 For number of edges: M(S(C(A,A),S(A,S(C(A,L(A)),A)))) = M(C(A,A)) + M(S(A,S(C(A,L(A)),A))) = M(A) + M(A) + 2 + M(A) + M(S(C(A,L(A)),A)) = 1 + 1 + 2 + 1 + M(C(A,L(A))) + M(A) = 1 + 1 + 2 + 1 + M(A) + M(L(A)) + 2 + 1 = 1 + 1 + 2 + 1 + 1 + M(A) + 2 + 2 + 1 = 1 + 1 + 2 + 1 + 1 + 1 + 2 + 2 + 1 = 12 4 4 8 7 1 1 2 2 1 2 7 6 6 5 1 2 3 3 1 2 1 2