Post Reply 
[HP 42S] [DM42] Multidimensional Scaling (MDS)
07-02-2023, 02:41 PM
Post: #1
[HP 42S] [DM42] Multidimensional Scaling (MDS)
Multidimensional Scaling is a method that places elements for which distances are given in a space of lower dimensions, normally in two dimensions (as is done by this program). It can be used to place products in a map for which distances in image dimensions are given.
Method:
The method used is described in German Wikipedia (unfortunately not in English Wikipedia) here: https://de.wikipedia.org/wiki/Multidimen...Skalierung

Instruction:
Save the matrix of distances in matrix M1 (it has to be symmetric with zeroes in the diagonal).
You can put a seed for the random number generator (used to compute eigenvectors).
XEQ ”MDS”
Result:
X-register (also Reg 03): R² of distances.
Matrix of coordinates of data points in 2-dimensional space: M2
Matrix of reproduced distances: M4

Example (from Backhaus et.al.: Multivariate Analysen, 2016, p. 613):
Distances for six margarine brands:
0 1 7 6 11 13
1 0 8 5 10 12
7 8 0 9 15 14
6 5 9 0 4 3
11 10 15 4 0 2
13 12 14 3 2 0
Save matrix in M1. Pi 3 – seed.
XEQ MDS
X-register: 0,9896 (distances in 2-dimensional space can explain the variance of distances between brands by 98.96%).
RCL “M2” -> Coordinates of brands in 2-dimensional space:
4.7924 -2.6139
3.5854 -2.9794
7.0880 4.3450
-1.6941 0.4239
-6.6191 -1.8237
-7.1527 2.6428

Use of registers (n=number of elements):
M1 (n x n), M2 (n x 2), M4 (n x n), M5 (n x 1), M6 (n x 1), Reg 00-03

Program:
Code:
00 { 414-Byte Prgm }
01▸LBL "MDS"
02 RCL "M1"
03 STO "M4"
04 DIM?
05 1ᴇ3
06 ÷
07 1
08 +
09 STO 00
10 STO 01
11 STO 02
12 INDEX "M4"
13▸LBL 00
14 RCL 01
15 RCL 02
16 STOIJ
17 RCLEL
18 X^2
19 2
20 ÷
21 +/-
22 STOEL
23 ISG 02
24 GTO 00
25 RCL 00
26 STO 02
27 ISG 01
28 GTO 00
29 RCL "M4"
30 RSUM
31 TRANS
32 STO "M2"
33 DIM?
34 STO÷ "M2"
35 RCL "M2"
36 RSUM
37 STO "M5"
38 X<>Y
39 STO÷ "M5"
40 INDEX "M5"
41 RCLEL
42 STO+ "M4"
43 RCL 00
44 STO 01
45 STO 02
46▸LBL 01
47 INDEX "M4"
48 RCL 01
49 RCL 02
50 STOIJ
51 RCLEL
52 STO 03
53 INDEX "M2"
54 1
55 RCL 01
56 STOIJ
57 RCLEL
58 STO- 03
59 1
60 RCL 02
61 STOIJ
62 RCLEL
63 STO- 03
64 INDEX "M4"
65 RCL 01
66 RCL 02
67 STOIJ
68 RCL 03
69 STOEL
70 ISG 02
71 GTO 01
72 RCL 00
73 STO 02
74 ISG 01
75 GTO 01
76 RCL 00
77 STO 01
78 1.002
79 STO 02
80 RCL "M4"
81 DIM?
82 2
83 NEWMAT
84 STO "M2"
85 R↓
86 1
87 NEWMAT
88 STO "M5"
89▸LBL 02
90 INDEX "M5"
91 RAN
92 STOEL
93 I+
94 ISG 01
95 GTO 02
96 RCL "M5"
97 FNRM
98 STO÷ "M5"
99▸LBL 03
100 CF 00
101 RCL "M4"
102 RCL "M5"
103 ×
104 STO "M6"
105 RCL "M5"
106 DOT
107 X<0?
108 SF 00
109 RCL "M6"
110 FNRM
111 STO÷ "M6"
112 RCL "M6"
113 STO "M5"
114 R↓
115 RCL 04
116 X<>Y
117 FS? 00
118 +/-
119 STO 04
120 -
121 ABS
122 1ᴇ-8
123 X<Y?
124 GTO 03
125 RCL 04
126 SQRT
127 STO× "M5"
128 RCL "M5"
129 ENTER
130 TRANS
131 ×
132 STO- "M4"
133 1
134 RCL 02
135 INDEX "M2"
136 STOIJ
137 RCL "M5"
138 PUTM
139 ISG 02
140 GTO 03
141 RCL 00
142 STO 01
143 STO 02
144▸LBL 04
145 INDEX "M2"
146 RCL 01
147 1
148 STOIJ
149 RCLEL
150 J+
151 RCLEL
152 RCL 02
153 2
154 STOIJ
155 R↓
156 R↓
157 RCLEL
158 -
159 X^2
160 STO 03
161 X<>Y
162 J-
163 RCLEL
164 -
165 X^2
166 STO+ 03
167 INDEX "M4"
168 RCL 01
169 RCL 02
170 STOIJ
171 RCL 03
172 SQRT
173 STOEL
174 ISG 02
175 GTO 04
176 RCL 00
177 STO 02
178 ISG 01
179 GTO 04
180 RCL "M1"
181 RCL "M4"
182 -
183 FNRM
184 RCL "M1"
185 INDEX "M5"
186 RCLEL
187 -
188 FNRM
189 ÷
190 X^2
191 +/-
192 1
193 +
194 STO 03
195 CF 00
196 CLV "M5"
197 CLV "M6"
198 END
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)