<p dir="auto">Why the MDS that is supplied does not supports weights in addition to the dissimilarity matrix?</p>
<p dir="auto">Hi!</p>
<p dir="auto">My name is Charles, and I would like to share my very first contribution to open-source project.</p>
<h4 dir="auto">Smacof from sklearn rules ! It only lacks the weighting</h4>
<p dir="auto">I regularly need the use of SMACOF algorithm, for sensor localization. In this field (and others), the weighting is mandatory to give more or less importance to pairwise distances. I send you to a well-known paper about it : <a href="https://scholar.google.fr/scholar?q=distributed+weighted-multidimensional+scaling+for+node+localization+in+sensor+networks&amp;btnG=&amp;hl=en&amp;as_sdt=0%2C5" rel="nofollow">Costa2006</a></p>
<p dir="auto">So far I have been using a wrapping of smacof in R with rpy2, because it features the weighting. But everytime I update R or rpy2 I get errors, about types, etc.</p>
<p dir="auto">You added a very good implementation of smacof in the pull request <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="4292384" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/797" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/797/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/797">#797</a>. The idea of adding the weighting was proposed, but was not done, was there maybe a reason about it ?</p>
<h4 dir="auto">How to feature it</h4>
<p dir="auto">Today I tried to modify the source code of sklearn, and my tests on sensor localization, by adding weighting have shown consistent results so far.<br>
The idea could be to add a weight parameter at the fit method:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.manifold import MDS

smacof = MDS(n_components=2, dissimilarity='precomputed')

# Let D be a n_sample x n_sample euclidean distance matrix
# and weighting be a n_sample x n_sample weight matrix
smacof.fit(D, weight=weight) 
pl.scatter(*smacof.embedding_.T) # maps the sensors"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">manifold</span> <span class="pl-k">import</span> <span class="pl-v">MDS</span>

<span class="pl-s1">smacof</span> <span class="pl-c1">=</span> <span class="pl-v">MDS</span>(<span class="pl-s1">n_components</span><span class="pl-c1">=</span><span class="pl-c1">2</span>, <span class="pl-s1">dissimilarity</span><span class="pl-c1">=</span><span class="pl-s">'precomputed'</span>)

<span class="pl-c"># Let D be a n_sample x n_sample euclidean distance matrix</span>
<span class="pl-c"># and weighting be a n_sample x n_sample weight matrix</span>
<span class="pl-s1">smacof</span>.<span class="pl-en">fit</span>(<span class="pl-v">D</span>, <span class="pl-s1">weight</span><span class="pl-c1">=</span><span class="pl-s1">weight</span>) 
<span class="pl-s1">pl</span>.<span class="pl-en">scatter</span>(<span class="pl-c1">*</span><span class="pl-s1">smacof</span>.<span class="pl-s1">embedding_</span>.<span class="pl-v">T</span>) <span class="pl-c"># maps the sensors</span></pre></div>
<h4 dir="auto">What to change?</h4>
<p dir="auto">Not that much actually! The way it was coded only need few modifications in the _smacof_single() function.</p>
<p dir="auto">As you can see in the <a href="https://www.google.fr/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=5&amp;ved=0ahUKEwiW3fX07vfMAhUCJ5oKHRRJBqEQFghCMAQ&amp;url=http%3A%2F%2Fstatistics.ucla.edu%2Fsystem%2Fresources%2FBAhbBlsHOgZmSSJYMjAxMi8wNS8xNi8xNV8xNl8yOF8yMDdfTXVsdGlkaW1lbnNpb25hbF9TY2FsaW5nX1VzaW5nX01ham9yaXphdGlvbl9TTUFDT0ZfaW5fUi5wZGYGOgZFVA%2FMultidimensional%2520Scaling%2520Using%2520Majorization%3A%2520SMACOF%2520in%2520R.pdf&amp;usg=AFQjCNHAKeBatnwzXQqrRefrWGwdD5KqAA" rel="nofollow">algorithm description</a>, it needs to compute the matrix V and its pseudo inverse, for the final update (eq. (14)). And also, it needs to modify B, by weighting the <code class="notranslate">ratio</code> variable (=s_ij eq. (11) ).</p>
<p dir="auto">Are you interested in adding this feature to your main branch?</p>
<p dir="auto">Best,<br>
Charles</p>