Help with mdscale starting configuration?
2 views (last 30 days)
Show older comments
I am having a hard time using mdscale.
Basically, I have a series of distance matrices that I want to reconstruct into Cartesian coordinates. Due to missing values, I can't use cmdscale. This is all well and good, because that's what mdscale is for.
However, mdscale only has two possible options that will work with regards to the starting configuration. One is ('Start','random'), which I don't want. I want it to start at the same point every time.
The problem is, I do not understand how to pass a specific starting configuration into mdscale! The documentation only says this:
"An n-by-p matrix of initial locations, where n is the size of the matrix D and p is the number of columns of the output matrix Y. In this case, you can pass in [] for p and mdscale infers p from the second dimension of the matrix. You can also supply a three-dimensional array, implying a value for 'Replicates' from the array's third dimension."
But, to be blunt, this doesn't make any $%*&$*%(& sense!
Okay, so an n-by-p matrix, where n is the size of D and p is the number of columns in Y. I am doing two-dimensional analysis, so p is 2. Let's say my matrix D is 6x6. So I need a 6 by 2 matrix ... but what values do I use?! What does it mean "matrix of initial locations"? Is it all zeros with a 1 where I want to start? This is incredibly confusing, and it bothers me that nowhere in the Matlab documentation for mdscale do they even give an example of how to use a starting configuration beside 'random' (or cmdscale).
Can anybody help me here? If I just want it to start at the 1st cell of my input matrix, for example, how do I define this n-by-p starting configuration matrix?
0 Comments
Answers (2)
Tom Lane
on 10 May 2013
You could set R=rand(6,2) outside the function, and try using that as the 'Start' argument each time you run the function. This would be random at first, but then you could use it repeatedly.
The idea is that the function apparently needs a set of 6 2-D points, which it will try to modify iteratively to match up to the distance matrix you supply.
I would imagine that, if you had some idea of a reasonable set of coordinates to come close to matching your distance matrix, that would help. But it appears that the function is willing to try generating points at random, so perhaps it will perform reasonably well even if you generate your own points at random.
Peter Perkins
on 11 May 2013
You want to reconstruct the cartesian coordinates of six points from their 6x6 distance matrix. What would such a reconstruction look like? In MATLAB, at least in this case, it would be a 6 (points) -by- two (dimensions) matrix. Each row is the two coordinates of a point -- (x,y) if you will. The 6z2 matrix you pass into mdscale is simply your initial guess at that. It's the same kind of thing that mdscale returns when it's done. As Tom says, your guess might be rand(6,2), or you might have some better idea of what the coordinates ought to be.
I'm not sure what you mean by
the 1st cell of my input matrix
but the matrix of initial locations that you pass in has to be a set of six (x,y) coordinates.
2 Comments
Peter Perkins
on 14 May 2013
Edited: Peter Perkins
on 14 May 2013
First, to always get the same output, either
- type "rng(0)" or something like it before running mdscale, or
- create a matrix initialLocations = rand(6,1) and always pass that same thing into mdscale as the initial locations
But to your other questions: You need six points to start the optimization that mdscale carries out. This might sound like circular reasoning. When you start out what you have is a 6x6 distance matrix, and you don't have a 6x2 matrix of six (x,y) coordinates to which those distances correspond -- that's the answer that you want mdscale to spit out. But the process of finding that answer is nothing more than an optimization problem. Here's what mdscale does inside:
- starting from some initial set of six (x,y) coordinates ...
- compute the 6x6 distance matrix among those six points
- compare that to the desired distance matrix (the one you gave it)
- if close enough, stop
- if not, adjust the six locations to improve the comparison
- repeat (2)-(5)
mdscale needs either you, or the rand function, to do step (1) before it can do anything. So if you have some idea what the final answer might look like, that's a good starting point. If not, things usually work out (albeit more slowly) from random locations.
Hope this helps.
See Also
Categories
Find more on Analysis of Variance and Covariance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!