This sandbox is intended for saving drafts of long, complex posts, especially posts whose composition takes a long time. It serves to localize to one thread the front-page "bumps" caused by edits to drafts of such posts, so that they may be easily ignored. Also, it helps to guard against losing longly-composed posts due to system crashes.

When you are happy with your draft here, you may simply copy the code and paste it to the desired location.

Proper Use of the Sandbox

  1. Do not post a new answer! We wish all the answers on this page to be owned by the Community user (so that only a non-sentient bot is informed of edits to these answers). Posting a new answer will make you the owner, meaning that you will be notified whenever another user makes an edit to that answer.

    The sandbox has been closed to prevent the creation of new answers. There are more than enough existing answers for users to edit over, and this will greatly reduce the frequency at which we request that the answers be disassociated from specific users.

  2. Do not delete answers! Deleting seems like a reasonable option, but there are no "hard deletions" on Stack Exchange, and users will sufficient privileges will still see your supposedly deleted postings. Deleted answers will be undeleted and cleared for the use of others.

  3. Do look for an answer which indicates that it is free and then edit it to your heart's content. If none appears available, take over the one that has been left unchanged the longest (which will appear at the bottom of the page if you order answers by "activity").

  4. Do not expect your draft to remain untouched for days. There are no guarantees that your draft will be the latest revision if you return days later. While users will try not to step over others' toes, it may happen that an unfinished draft is edited out. Your draft will, however, still exist as a revision of the answer it was made in. If your drafting is expected to take place over a longer period of time, either

    • take note of the URL of the answer provided by clicking the share button, or
    • save a copy of your draft locally (or even "in the cloud").
  5. Do clear your draft when you are finished. This includes removing all $\LaTeX$ from your answers. Replacing all code with a simple statement like

    This answer is free for anyone to use

    is sufficient. Periodically users may go through and free up answer slots that have not been edited in, say, over one month. But you can aid in the smooth running of this sandbox by clearing away your drafts when you are finished with them.

  6. Do not "claim" multiple answers concurrently. Since this post is closed, the answers are a limited resource. If you really must compose several long, complex posts at the same time, you can still use a single answer, separating the different drafts using Markup: horizontal rules (---) and/or headings (# Header 1 #) are natural choices.

  7. Do not create new such sandboxes. The point of having a unique such sandbox is that it minimizes the noise on the front page when the sandbox is edited. If there were multiple sandboxes they will frequently occupy numerous front page slots, pushing other topics off the front page, and increasing noise.

share

closed as off-topic by Arthur Fischer Sep 18 '14 at 10:37

  • This question does not appear to be about Mathematics Stack Exchange or the software that powers the Stack Exchange network within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

8  
I have added a [sandbox] tag to allow people ignore it more easily (via software support of ignoring tags), and since it seems that we have two sandboxes now, a tag may seem a bit more in place here. –  Asaf Karagila Jul 18 '12 at 8:35
18  
(+1) For thinking outside the (sand)box. –  cardinal Jul 18 '12 at 19:40
13  
At the suggestion of the moderators, I have gone and changed the associated owners of all the answers here to the Community user. This way, the original owners will not receive excess pings for each time another user uses the draft space for their work. Enjoy! –  Grace Note Oct 5 '12 at 14:45
2  
To prevent crashes I've found the "Bookmarks to disable/enable MathJax", provided in here, pretty useful. –  leo Dec 17 '12 at 18:03
20  
This "sandbox" is being closed to prevent the creation of new answers. To start a draft, simply edit one of the existing free answers. –  Arthur Fischer Sep 18 '14 at 10:37

17 Answers 17

This answer is free to be used.

share

This answer is free to be used

share

This answer is free for anyone to use!

share

This answer is free to be used.

share

This answer is free to be used

share

This answer is free for anyone to use

share

This answer is free to be used.

share

This answer is free to be used.

share

Explanation of the "findClosestCentroid" procedure (ex7.pdf, 1.1.1): Let us assume that $$x^{(i)}$$ and $$c_j$$ are row vectors ($$1 \times n$$ matrices). $$x^{(i)}$$ is a example data and $$c_j$$ is a centroid

If we use 'for'-loops over $$m$$ and $$k$$ then we will calculate the difference vectors $$x^{(i)}-c_j$$

and then norm of these vectors to get a single number

$$||x^{(i)}-c_j||$$

When using only a loop over $$m$$ we can vectorize these steps and get a $$k \times n$$ matrix

$$\left( \begin{array}{ccc} x^{(i)}&-&c_1 \\ &\cdots& \\ x^{(i)}&-&c_k \end{array} \right) \tag{1} $$

applying the 'norm' function will not work because it will calculate the 'norm' of the matrix instead the 'norm' of its row vectors. One workaround is to calculate the product

$$\left( \begin{array}{ccc} x^{(i)}&-&c_1 \\ &\cdots& \\ x^{(i)}&-&c_k \end{array} \right) \left( \begin{array}{ccc} x^{(i)}&-&c_1 \\ &\cdots& \\ x^{(i)}&-&c_k \end{array} \right)^T \tag{2} $$

or to use the sqsum function. This product gives $$\left( \begin{array}{ccc} \|x^{(i)}&-&c_1\|^2 \\ &\cdots& \\ \|x^{(i)}&-&c_k\|^2 \end{array} \right) \tag{3} $$

The 'min' function can be used to find the row number of the smalles value.

If we transpose this vector we get a row vector $$(\|x^{(i)}-c_1\|^2, \ldots, \|x^{(i)}-c_k\|^2) \tag{4}$$

From this row vector we can also get the column index of the column with the smallest value if we use a slighly different call of the 'min' function. We will see later that getting the index of the smallest value from the row vector is more useful for us. So we end up with a number

$$ c(i) \tag{5}$$

for this vector.

So how can we eliminate the 'for' loop over the m samples ? We simply concatenate all matrices (1) for i ids 1 to m to one single matrix

$$\left( \begin{array}{ccc} x^{(1)}&-&c_1 \\ &\cdots& \\ x^{(1)}&-&c_k \\ &\vdots& \\ x^{(i)}&-&c_1 \\ &\cdots& \\ x^{(i)}&-&c_k \\ &\vdots& \\ x^{(m)}&-&c_1 \\ &\cdots& \\ x^{(m)}&-&c_k \\ \end{array} \right) \tag{11} $$ We can calculte the sqaure of the norms analogous to (2) and get a vector similar to (3)

$$\left( \begin{array}{ccc} \|x^{(1)}&-&c_1\|^2 \\ &\cdots& \\ \|x^{(1)}&-&c_k\|^2\\ &\vdots& \\ \|x^{(i)}&-&c_1\|^2 \\ &\cdots& \\ \|x^{(i)}&-&c_k\|^2\\ &\vdots& \\ \|x^{(m)}&-&c_1\|^2 \\ &\cdots& \\ \|x^{(m)}&-&c_k\|^2\\ \end{array} \right) \tag{13} $$

Now we reshape the matrix to get

$$\left( \begin{array}{ccc} \|x^{(1)}-c_1\|^2, &\ldots,& \|x^{(1)}-c_k\|^2\\ &\vdots&\\ \|x^{(i)}-c_1\|^2, &\ldots,& \|x^{(i)}-c_k\|^2\\ &\vdots&\\ \|x^{(m)}-c_1\|^2, &\ldots,& \|x^{(m)}-c_k\|^2\\ \end{array} \right) \tag{14}$$

and after applying the 'min' function we are done end end up with $$\left( \begin{array}{c} c(1) \\ \vdots \\ c(i) \\ \vdots\\ c(m) \end{array} \right) \tag{15}$$

share

This answer is free to be used

share