public class ClassicalMultidimensionalScaling
Public Class ClassicalMultidimensionalScaling
public ref class ClassicalMultidimensionalScaling
type ClassicalMultidimensionalScaling = class end
Instantiation
New instances of class ClassicalMultidimensionalScaling can be initialized by calling method Analyze(DoubleMatrix, NullableInt32), which implements the classical multidimensional scaling algorithm.
Given a matrix of proximities, say , let
be the matrix of its squared elements, and
define the transformed matrix of proximities as
where is the centering matrix.
Let be the number of positive eigenvalues
of matrix
.
If the configuration dimension is not specified to method
Analyze(DoubleMatrix, NullableInt32),
it is set equal to
if
;
otherwise, an exception is thrown.
If the configuration dimension is specified to method
Analyze(DoubleMatrix, NullableInt32), then it must be less than or equal to
; otherwise, an exception is thrown.
Results
Let be the
eigenvalues of
in decreasing order, and let
be the corresponding eigenvectors.
If the dimension is equal to , then
the configuration is given by matrix:
which can be inspected through property Configuration.
Goodness of fit
The goodness of fit of such configuration is given by the formula
and is accessible through property GoodnessOfFit.
In the following example, a classical multidimensional scaling analysis is performed on a matrix of proximities.
using System;
namespace Novacta.Analytics.CodeExamples
{
public class ClassicalMultidimensionalScalingExample0
{
public void Main()
{
// Create a matrix of proximities among cities.
int numberOfCities = 10;
string[] cities = [
"Atlanta",
"Chicago",
"Denver",
"Houston",
"Los Angeles",
"Miami",
"New York",
"San Francisco",
"Seattle",
"Washington DC"];
var proximities = DoubleMatrix.Dense(
numberOfRows: numberOfCities,
numberOfColumns: numberOfCities,
data: [
0, 587, 1212, 701, 1936, 604, 748, 2139, 2182, 543,
587, 0, 920, 940, 1745, 1188, 713, 1858, 1737, 597,
1212, 920, 0, 879, 831, 1726, 1631, 949, 1021, 1494,
701, 940, 879, 0, 1374, 968, 1420, 1645, 1891, 1220,
1936, 1745, 831, 1374, 0, 2339, 2451, 347, 959, 2300,
604, 1188, 1726, 968, 2339, 0, 1092, 2594, 2734, 923,
748, 713, 1631, 1420, 2451, 1092, 0, 2571, 2408, 205,
2139, 1858, 949, 1645, 347, 2594, 2571, 0, 678, 2442,
2182, 1737, 1021, 1891, 959, 2734, 2408, 678, 0, 2329,
543, 597, 1494, 1220, 2300, 923, 205, 2442, 2329, 0],
storageOrder: StorageOrder.RowMajor);
// Add city names to the matrix of proximities.
for (int i = 0; i < numberOfCities; i++)
{
var city = cities[i];
proximities.SetRowName(i, city);
proximities.SetColumnName(i, city);
}
// Define the dimension of the configuration of points in the target space.
// Passing null, the dimension of the configuration is automatically selected.
int? configurationDimension = null;
// Execute a classical MDS analysis.
var metricMds =
ClassicalMultidimensionalScaling.Analyze(
proximities,
configurationDimension);
// Display the configuration.
Console.WriteLine("City coordinates:");
Console.WriteLine(metricMds.Configuration);
// Display the goodness of fit.
Console.WriteLine("Goodness of fit:");
Console.WriteLine(metricMds.GoodnessOfFit);
}
}
}
// Executing method Main() produces the following output:
//
// City coordinates:
// [Atlanta] -718.759381 142.994269 35.102499 -1.22496264 7.40947762 -1.5046461 6.58357404e-06
// [Chicago] -382.055766 -340.839623 29.6022277 -8.23788477 12.0242975 2.33830156 6.58357404e-06
// [Denver] 481.602336 -25.2850406 53.3938021 1.33927902 -15.6658897 0.952696317 6.58357404e-06
// [Houston] -161.466258 572.769911 1.45257147 -1.76231781 0.671865645 -2.70076208 6.58357404e-06
// [Los Angeles] 1203.73802 390.100291 -18.6350654 14.9748641 3.16920061 1.65614881 6.58357404e-06
// [Miami] -1133.52708 581.907309 -32.2688418 -2.37568536 -2.97185365 2.04718777 6.58357404e-06
// [New York] -1072.23569 -519.02423 -34.3418782 -14.2538571 -6.44732888 -0.270908782 6.58357404e-06
// [San Francisco] 1420.60332 112.589202 -7.75475501 -18.120276 0.805412307 -0.869519732 6.58357404e-06
// [Seattle] 1341.72248 -579.739278 -23.6507873 5.96145265 1.4286322 -0.614379418 6.58357404e-06
// [Washington DC] -979.621992 -335.47281 -2.89977264 23.6993879 -0.423813627 -1.03411834 6.58357404e-06
//
//
// Goodness of fit:
// 0.9963038236716906
Configuration | Gets the configuration of points in the target space. |
GoodnessOfFit | Gets the goodness of fit at the Configuration. |
Analyze | Executes a metric multidimensional scaling analysis. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
ToString | Returns a string that represents the current object. (Inherited from Object) |