Compute distances, either between all prototypes (mode = "complete") or only between prototypes' neighbours (mode = "neighbors").

protoDist(object, mode = c("complete", "neighbors"), radius = 1, ...)

Arguments

object

a somRes object.

mode

Specifies which distances should be computed (default to "complete").

radius

Radius used to fetch the neighbors (default to 1). The distance used to compute the neighbors is the Euclidean distance.

...

Not used.

Value

When mode = "complete", the function returns a square matrix which dimensions are equal to the product of the grid dimensions.

When mode = "neighbors", the function returns a list which length is equal to the product of the grid dimensions; the length of each item is equal to the number of neighbors. Neurons are considered to have 8 neighbors at most (i.e., two neurons are neighbors if they have an Euclidean distance smaller than radius. Natural choice for radius is 1 for hexagonal topology and 1 or \(\sqrt{2}\) for square topology (4 and 8 neighbors respectively).

Details

When mode="complete", distances between all prototypes are computed. When mode="neighbors", distances are computed only between the prototypes and their neighbors. If the data were preprocessed during the SOM training procedure, the distances are computed on the normalized values of the prototypes.

See also

Examples

set.seed(2343) my.som <- trainSOM(x.data = iris[,1:4], dimension = c(5,5)) protoDist(my.som)
#> 1 2 3 4 5 6 7 #> 1 0.0000000 0.3178170 0.7408293 1.1873168 1.5535594 0.4242205 0.2704839 #> 2 0.3178170 0.0000000 0.4241642 0.8716052 1.2385739 0.6765640 0.3694890 #> 3 0.7408293 0.4241642 0.0000000 0.4476473 0.8148699 1.0539550 0.7145318 #> 4 1.1873168 0.8716052 0.4476473 0.0000000 0.3673269 1.4750979 1.1335358 #> 5 1.5535594 1.2385739 0.8148699 0.3673269 0.0000000 1.8273535 1.4873385 #> 6 0.4242205 0.6765640 1.0539550 1.4750979 1.8273535 0.0000000 0.3420686 #> 7 0.2704839 0.3694890 0.7145318 1.1335358 1.4873385 0.3420686 0.0000000 #> 8 0.5694140 0.3115716 0.2962500 0.6786450 1.0298408 0.7984145 0.4577351 #> 9 1.0335849 0.7289397 0.3318952 0.2241131 0.5448079 1.2840738 0.9449666 #> 10 1.4308620 1.1205963 0.7028318 0.2747054 0.1693646 1.6836295 1.3459022 #> 11 1.0348050 1.2591381 1.5837690 1.9594793 2.2823774 0.6110457 0.8924930 #> 12 0.7578400 0.9369763 1.2376949 1.6078411 1.9314759 0.3694616 0.5677968 #> 13 0.5971279 0.5923354 0.7778170 1.1147570 1.4322971 0.5125970 0.3277878 #> 14 0.8660063 0.6286171 0.4404700 0.5973509 0.8831257 1.0088492 0.6943626 #> 15 1.2589775 0.9673679 0.5901318 0.3271829 0.4486932 1.4632733 1.1347884 #> 16 1.6408078 1.8534736 2.1486381 2.4903603 2.7871109 1.2173883 1.4842460 #> 17 1.3755262 1.5681803 1.8490598 2.1855254 2.4818605 0.9584404 1.1992039 #> 18 1.0340019 1.1585036 1.3881543 1.7019917 1.9917703 0.6777154 0.8048885 #> 19 0.8791876 0.8215290 0.8852633 1.1225141 1.3897981 0.7751266 0.6129033 #> 20 1.0814771 0.8567636 0.6390679 0.6586858 0.8605283 1.1772881 0.8866896 #> 21 2.0544193 2.2609021 2.5412032 2.8642276 3.1453950 1.6313879 1.8916124 #> 22 1.8606525 2.0561706 2.3273826 2.6460001 2.9259879 1.4403025 1.6874070 #> 23 1.5406395 1.7032690 1.9462413 2.2496035 2.5238369 1.1366351 1.3396851 #> 24 1.1838512 1.2604531 1.4294616 1.6941465 1.9544154 0.8675581 0.9329772 #> 25 1.0367296 0.9561532 0.9633482 1.1401936 1.3723707 0.9349396 0.7728872 #> 8 9 10 11 12 13 14 #> 1 0.5694140 1.0335849 1.4308620 1.0348050 0.7578400 0.5971279 0.8660063 #> 2 0.3115716 0.7289397 1.1205963 1.2591381 0.9369763 0.5923354 0.6286171 #> 3 0.2962500 0.3318952 0.7028318 1.5837690 1.2376949 0.7778170 0.4404700 #> 4 0.6786450 0.2241131 0.2747054 1.9594793 1.6078411 1.1147570 0.5973509 #> 5 1.0298408 0.5448079 0.1693646 2.2823774 1.9314759 1.4322971 0.8831257 #> 6 0.7984145 1.2840738 1.6836295 0.6110457 0.3694616 0.5125970 1.0088492 #> 7 0.4577351 0.9449666 1.3459022 0.8924930 0.5677968 0.3277878 0.6943626 #> 8 0.0000000 0.4877645 0.8894063 1.2963087 0.9473204 0.4818723 0.3170686 #> 9 0.4877645 0.0000000 0.4019441 1.7461652 1.3943448 0.8977335 0.3735323 #> 10 0.8894063 0.4019441 0.0000000 2.1234045 1.7731703 1.2734218 0.7204601 #> 11 1.2963087 1.7461652 2.1234045 0.0000000 0.3520920 0.8507098 1.4045566 #> 12 0.9473204 1.3943448 1.7731703 0.3520920 0.0000000 0.4999031 1.0554554 #> 13 0.4818723 0.8977335 1.2734218 0.8507098 0.4999031 0.0000000 0.5562842 #> 14 0.3170686 0.3735323 0.7204601 1.4045566 1.0554554 0.5562842 0.0000000 #> 15 0.6930269 0.2605406 0.2795068 1.8675400 1.5199832 1.0217625 0.4658817 #> 16 1.8543146 2.2697204 2.6219613 0.6064133 0.9191366 1.3806551 1.9067395 #> 17 1.5538600 1.9645613 2.3167698 0.3685392 0.6314393 1.0775414 1.6012172 #> 18 1.0924176 1.4796176 1.8261178 0.4265197 0.3142711 0.6105852 1.1127605 #> 19 0.6157947 0.8989165 1.2224726 0.9640214 0.6460432 0.2879389 0.5254610 #> 20 0.5454165 0.4585732 0.6915596 1.5004032 1.1630602 0.6842219 0.2290312 #> 21 2.2455574 2.6416398 2.9783114 1.0206097 1.3242334 1.7663328 2.2726587 #> 22 2.0315129 2.4232193 2.7588385 0.8338946 1.1197287 1.5511985 2.0537610 #> 23 1.6506389 2.0263130 2.3563541 0.5826310 0.7832137 1.1688552 1.6551531 #> 24 1.1405811 1.4706616 1.7862895 0.6350482 0.5219592 0.6752231 1.0973415 #> 25 0.7190423 0.9209502 1.2036693 1.0723852 0.7767204 0.4503646 0.5572813 #> 15 16 17 18 19 20 21 #> 1 1.2589775 1.6408078 1.3755262 1.0340019 0.8791876 1.0814771 2.0544193 #> 2 0.9673679 1.8534736 1.5681803 1.1585036 0.8215290 0.8567636 2.2609021 #> 3 0.5901318 2.1486381 1.8490598 1.3881543 0.8852633 0.6390679 2.5412032 #> 4 0.3271829 2.4903603 2.1855254 1.7019917 1.1225141 0.6586858 2.8642276 #> 5 0.4486932 2.7871109 2.4818605 1.9917703 1.3897981 0.8605283 3.1453950 #> 6 1.4632733 1.2173883 0.9584404 0.6777154 0.7751266 1.1772881 1.6313879 #> 7 1.1347884 1.4842460 1.1992039 0.8048885 0.6129033 0.8866896 1.8916124 #> 8 0.6930269 1.8543146 1.5538600 1.0924176 0.6157947 0.5454165 2.2455574 #> 9 0.2605406 2.2697204 1.9645613 1.4796176 0.8989165 0.4585732 2.6416398 #> 10 0.2795068 2.6219613 2.3167698 1.8261178 1.2224726 0.6915596 2.9783114 #> 11 1.8675400 0.6064133 0.3685392 0.4265197 0.9640214 1.5004032 1.0206097 #> 12 1.5199832 0.9191366 0.6314393 0.3142711 0.6460432 1.1630602 1.3242334 #> 13 1.0217625 1.3806551 1.0775414 0.6105852 0.2879389 0.6842219 1.7663328 #> 14 0.4658817 1.9067395 1.6012172 1.1127605 0.5254610 0.2290312 2.2726587 #> 15 0.0000000 2.3516788 2.0469230 1.5555180 0.9485152 0.4122360 2.7033532 #> 16 2.3516788 0.0000000 0.3056046 0.7963138 1.4048423 1.9543409 0.4143859 #> 17 2.0469230 0.3056046 0.0000000 0.4915611 1.1010452 1.6512356 0.6947122 #> 18 1.5555180 0.7963138 0.4915611 0.0000000 0.6098425 1.1603892 1.1629165 #> 19 0.9485152 1.4048423 1.1010452 0.6098425 0.0000000 0.5506592 1.7562793 #> 20 0.4122360 1.9543409 1.6512356 1.1603892 0.5506592 0.0000000 2.2972550 #> 21 2.7033532 0.4143859 0.6947122 1.1629165 1.7562793 2.2972550 0.0000000 #> 22 2.4838161 0.2485315 0.4883687 0.9454023 1.5367972 2.0777898 0.2195744 #> 23 2.0806484 0.3519411 0.2318452 0.5582924 1.1350659 1.6737731 0.6237036 #> 24 1.5091223 0.8823263 0.5978739 0.2235936 0.5720155 1.1001523 1.1989014 #> 25 0.9247886 1.4621966 1.1644495 0.6838115 0.1632056 0.5129428 1.7904188 #> 22 23 24 25 #> 1 1.8606525 1.5406395 1.1838512 1.0367296 #> 2 2.0561706 1.7032690 1.2604531 0.9561532 #> 3 2.3273826 1.9462413 1.4294616 0.9633482 #> 4 2.6460001 2.2496035 1.6941465 1.1401936 #> 5 2.9259879 2.5238369 1.9544154 1.3723707 #> 6 1.4403025 1.1366351 0.8675581 0.9349396 #> 7 1.6874070 1.3396851 0.9329772 0.7728872 #> 8 2.0315129 1.6506389 1.1405811 0.7190423 #> 9 2.4232193 2.0263130 1.4706616 0.9209502 #> 10 2.7588385 2.3563541 1.7862895 1.2036693 #> 11 0.8338946 0.5826310 0.6350482 1.0723852 #> 12 1.1197287 0.7832137 0.5219592 0.7767204 #> 13 1.5511985 1.1688552 0.6752231 0.4503646 #> 14 2.0537610 1.6551531 1.0973415 0.5572813 #> 15 2.4838161 2.0806484 1.5091223 0.9247886 #> 16 0.2485315 0.3519411 0.8823263 1.4621966 #> 17 0.4883687 0.2318452 0.5978739 1.1644495 #> 18 0.9454023 0.5582924 0.2235936 0.6838115 #> 19 1.5367972 1.1350659 0.5720155 0.1632056 #> 20 2.0777898 1.6737731 1.1001523 0.5129428 #> 21 0.2195744 0.6237036 1.1989014 1.7904188 #> 22 0.0000000 0.4045136 0.9798912 1.5714013 #> 23 0.4045136 0.0000000 0.5754035 1.1669217 #> 24 0.9798912 0.5754035 0.0000000 0.5915595 #> 25 1.5714013 1.1669217 0.5915595 0.0000000