mdsj
Class StressMinimization
public class StressMinimization
extends java.lang.Object
Stress Minimization.
Computes a configuration of objects in low-dimensional
Euclidean space w.r.t. to the given set of distances between these objects.
The implementation is based on majorization. See de Leeuw, J. (1977),
Applications of convex analysis to multidimensional scaling,
in Barra; Brodeau, F. & Romie, G. et al., Recent developments in statistics,
pp. 133-145.
Note that positions are interpreted row-wise, i.e., when there are n
objects and d
desired output dimensions, the position matrix will be
of size [d][n]
. The dimensionality of the output is derived from
d
.
StressMinimization(double[][] d, double[][] x) - Creates a new stress minimizer with the given parameters.
|
StressMinimization(double[][] d, double[][] x, double[][] w) - Creates a new stress minimizer with the given parameters.
|
double[][] | getDissimilarities() - Returns the matrix of dissimilarities.
|
double | getNormalizedStress() - Computes the weighted stress of the current positions.
|
double[][] | getPositions() - Returns the matrix of positions.
|
double | getStress() - Computes the weighted stress of the current positions.
|
double[][] | getWeights() - Returns the matrix of weights.
|
String | iterate() - Performs a single step of the iterative stress minimization.
|
String | iterate(int n) - Performs a given number of steps of the iterative stress minimization.
|
String | iterate(int iter, int timeout, int threshold) - Performs some steps of the iterative stress minimization.
|
static void | majorize(double[][] x, double[][] d, double[][] w, int iter) - Majorization method for distance scaling.
|
static String | majorize(double[][] x, double[][] d, double[][] w, int iter, int threshold, int timeout) - Majorization method for distance scaling.
|
static double | normalizedStress(double[][] d, double[][] w, double[][] x) - Computes the weighted normalized stress of a configuration corresponding
to a given matrix of distances.
|
void | setDissimilarities(double[][] d) - Sets the dissimilarity to a given matrix.
|
void | setPositions(double[][] x) - Sets the positions to a given matrix.
|
void | setWeights(double[][] w) - Sets the weights to a given matrix.
|
static double | stress(double[][] d, double[][] w, double[][] x) - Computes the weighted stress of a configuration corresponding to a given
matrix of distances.
|
static double[][] | weightMatrix(double[][] D, double exponent) - Gives a weight matrix derived from a given matrix of
distances.
|
StressMinimization
public StressMinimization(double[][] d,
double[][] x)
Creates a new stress minimizer with the given parameters. All weights
are uniformly set to 1
.
d
- a matrix of dissimilaritiesx
- a matrix of positions
StressMinimization
public StressMinimization(double[][] d,
double[][] x,
double[][] w)
Creates a new stress minimizer with the given parameters.
d
- a matrix of dissimilaritiesx
- a matrix of positionsw
- a matrix of weights
getDissimilarities
public double[][] getDissimilarities()
Returns the matrix of dissimilarities.
getNormalizedStress
public double getNormalizedStress()
Computes the weighted stress of the current positions.
Given dissimilarities d[i][j]
and weights
w[i][j]
, the result is
nstress=sum_{i,j} w[i][j]*(d[i][j]-|x[*][i]-x[*][j]|)^2/sum_{i,j} w[i][j]*(d[i][j])^2
,
the weighted sum of squared residuals between desired and actual
Euclidean distances, normalized into the range between 0 and 1.
getPositions
public double[][] getPositions()
Returns the matrix of positions.
getStress
public double getStress()
Computes the weighted stress of the current positions.
Given dissimilarities d[i][j]
and weights
w[i][j]
, the result is
stress=sum_{i,j} w[i][j]*(d[i][j]-|x[*][i]-x[*][j]|)^2
,
the weighted sum of squared residuals between desired and actual
Euclidean distances.
getWeights
public double[][] getWeights()
Returns the matrix of weights.
iterate
public String iterate()
Performs a single step of the iterative stress minimization.
iterate
public String iterate(int n)
Performs a given number of steps of the iterative stress minimization.
iterate
public String iterate(int iter,
int timeout,
int threshold)
Performs some steps of the iterative stress minimization.
The iteration terminates as soon as
at least one of
the conditions holds (non-exclusive OR):
- the number of steps has reached
iter
- the running time is above
timeout
milliseconds - the relative change of the iterates is below
10^(-threshold)
The relative change is the Euclidean distance of two successive iterates, divided
by the absolute magnitude (Frobenius metric) of the last iterate.
When any of the parameters is set to zero or below, it is ignored.
iter
- maximum number of stepstimeout
- maximum running time in millisecondsthreshold
- negative logarithm
majorize
public static void majorize(double[][] x,
double[][] d,
double[][] w,
int iter)
Majorization method for distance scaling. Starts with an initial
configuration and generates a sequence of configurations with
non-increasing stress. The stress value does not need to be explicitly
computed.
It is most suitable to use the two-dimensional solution of classical
scaling as initial coordinates.
x
- initial coordinatesd
- square matrix of distancesw
- square weight matrixiter
- number of iteration steps
majorize
public static String majorize(double[][] x,
double[][] d,
double[][] w,
int iter,
int threshold,
int timeout)
Majorization method for distance scaling. Starts with an initial
configuration and generates a sequence of configurations with
non-increasing stress. The stress value does not need to be explicitly
computed.
It is most suitable to use the two-dimensional solution of classical
scaling as initial coordinates.
x
- matrix of positionsd
- matrix of dissimilaritiesw
- matrix of weightsiter
- maximum number of iterations (ignored if below 1)threshold
- relative change of iterates (ignored if below 1)timeout
- maximum milliseconds for iteration (ignored if below 1)
normalizedStress
public static double normalizedStress(double[][] d,
double[][] w,
double[][] x)
Computes the weighted normalized stress of a configuration corresponding
to a given matrix of distances. The weights are given by a square matrix.
d
- the matrix of distancesw
- weight matrixx
- coordinate matrix
- the stress of the configuration
setDissimilarities
public void setDissimilarities(double[][] d)
Sets the dissimilarity to a given matrix.
setPositions
public void setPositions(double[][] x)
Sets the positions to a given matrix.
setWeights
public void setWeights(double[][] w)
Sets the weights to a given matrix.
stress
public static double stress(double[][] d,
double[][] w,
double[][] x)
Computes the weighted stress of a configuration corresponding to a given
matrix of distances. The weights are given by a square matrix.
d
- the matrix of distancesw
- weight matrixx
- coordinate matrix
- the stress of the configuration
weightMatrix
public static double[][] weightMatrix(double[][] D,
double exponent)
Gives a weight matrix derived from a given matrix of
distances. The weight determines how much a pair i
, j
contributes to the stress objective function.
weight[i][j]=d[i][j]^exponent
. Thus, negative exponents down-weight
large distances and up-weight small ones. exponent=0
assigns all
distances equal. Most frequently, exponent=-2
.
D
- square matrix of distancesexponent
- weighting exponent