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.

Constructor Summary

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.

Method Summary

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.

Constructor Details

StressMinimization

public StressMinimization(double[][] d,
                          double[][] x)
Creates a new stress minimizer with the given parameters. All weights are uniformly set to 1.
Parameters:
d - a matrix of dissimilarities
x - a matrix of positions

StressMinimization

public StressMinimization(double[][] d,
                          double[][] x,
                          double[][] w)
Creates a new stress minimizer with the given parameters.
Parameters:
d - a matrix of dissimilarities
x - a matrix of positions
w - a matrix of weights

Method Details

getDissimilarities

public double[][] getDissimilarities()
Returns the matrix of dissimilarities.
Returns:
the matrix

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.
Returns:
the normalized stress

getPositions

public double[][] getPositions()
Returns the matrix of positions.
Returns:
the matrix

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.
Returns:
the stress

getWeights

public double[][] getWeights()
Returns the matrix of weights.
Returns:
the matrix

iterate

public String iterate()
Performs a single step of the iterative stress minimization.
Returns:
iteration report

iterate

public String iterate(int n)
Performs a given number of steps of the iterative stress minimization.
Parameters:
n - the number of steps
Returns:
iteration report

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.
Parameters:
iter - maximum number of steps
timeout - maximum running time in milliseconds
threshold - negative logarithm
Returns:
iteration report

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.
Parameters:
x - initial coordinates
d - square matrix of distances
w - square weight matrix
iter - 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.
Parameters:
x - matrix of positions
d - matrix of dissimilarities
w - matrix of weights
iter - 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)
Returns:

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.
Parameters:
d - the matrix of distances
w - weight matrix
x - coordinate matrix
Returns:
the stress of the configuration

setDissimilarities

public void setDissimilarities(double[][] d)
Sets the dissimilarity to a given matrix.
Parameters:
d - the matrix

setPositions

public void setPositions(double[][] x)
Sets the positions to a given matrix.
Parameters:

setWeights

public void setWeights(double[][] w)
Sets the weights to a given matrix.
Parameters:

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.
Parameters:
d - the matrix of distances
w - weight matrix
x - coordinate matrix
Returns:
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.
Parameters:
D - square matrix of distances
exponent - weighting exponent
Returns:
weight matrix