Skip to content

Commit

Permalink
monoMDS could crash with huge input dissimilarites
Browse files Browse the repository at this point in the history
monoMDS needed to set a guard dissimilarity which is longer than
observed dissimilarity, and this could fail if observed dissimilarities
were huge (in the issue #152 dissimilarities were of magnitude 2e85),
and this could crash monoMDS.

Fixes issue #152 reported in github.
  • Loading branch information
prminchin authored and Jari Oksanen committed Jan 8, 2016
1 parent 23eef1a commit 62fc1cb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/monoMDS.f
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ SUBROUTINE monoMDS (NOBJ, NFIX, NDIM, NDIS, NGRP,
C 1.01 April 6, 2011 - added argument STRS(NGRP) to return the stress
C for each of the NGRP groups of dissimilarities
C i.e., from each separate regression.
C 1.02 January 7, 2016 - fixed bug in MONREG so that huge
C dissimilarities are correctly handled in
C creating the initial partition for monotone
C regression with primary tie treatment.
C
C Written by Dr. Peter R. Minchin
C Department of Biological Sciences
Expand Down Expand Up @@ -596,9 +600,9 @@ SUBROUTINE CLCSTP (STEP,IT,SFGR,STRESS,COSAV,ACOSAV,SRATIO,
C
ELSE
FACTR1=4.0**COSAV
FACTR2=1.6/( (1.0+(MIN(1D0,SRATAV))**5) *
FACTR2=1.6/( (1.0+(MIN(1.0,SRATAV))**5) *
. (1.0+ACOSAV-ABS(COSAV)) )
FACTR3=SQRT(MIN(1D0,SRATIO))
FACTR3=SQRT(MIN(1.0,SRATIO))
STEP=STEP*FACTR1*FACTR2*FACTR3
ENDIF
RETURN
Expand Down Expand Up @@ -900,7 +904,9 @@ SUBROUTINE MONREG (DISS,DIST,DHAT,IIDX,JIDX,IWORK,N,ITIES)
IF (I.LT.N) THEN
DNEXT=DISS(I+1)
ELSE
DNEXT=DISS(I)+1.0
C---Bug fix January 7, 2016: correctly handles huge dissimilarities
C DNEXT=DISS(I)+1.0
DNEXT=DISS(I)*2.0
END IF
IF (ABS(DNEXT-DISS(I)).GT.TOLER) THEN
C---NTIE is the number of DISS values in the current group of tied values
Expand Down

0 comments on commit 62fc1cb

Please sign in to comment.