Euclidean distance vs Pearson correlation vs cosine similarity?

Pearson correlation and cosine similarity are invariant to scaling, i.e. multiplying all elements by a nonzero constant. Pearson correlation is also invariant to adding any constant to all elements. For example, if you have two vectors X1 and X2, and your Pearson correlation function is called pearson(), pearson(X1, X2) == pearson(X1, 2 * X2 + … Read more

Exactly what is the difference between a “closure” and a “block”?

While a block is just a piece of code that can be composed by statements and declarations but nothing else, a closure is a real first-class object, a real variable that has a block as its value. The main difference is that a block simply groups instructions together (for example the body of a while … Read more

Understanding Neural Network Backpropagation

The tutorial you posted here is actually doing it wrong. I double checked it against Bishop’s two standard books and two of my working implementations. I will point out below where exactly. An important thing to keep in mind is that you are always searching for derivatives of the error function with respect to a … Read more

Is there ever a good reason to use Insertion Sort?

From http://www.sorting-algorithms.com/insertion-sort: Although it is one of the elementary sorting algorithms with O(n2) worst-case time, insertion sort is the algorithm of choice either when the data is nearly sorted (because it is adaptive) or when the problem size is small (because it has low overhead). For these reasons, and because it is also stable, insertion … Read more

What are practical guidelines for evaluating a language’s “Turing Completeness”?

You need some form of dynamic allocation construct (malloc ornew or cons will do) and either recursive functions or some other way of writing an infinite loop. If you have those and can do anything at all interesting, you’re almost certainly Turing-complete. The lambda calculus is equivalent in power to a Turing machine, and if … Read more

Efficient implementation of binary heaps

An interesting paper/article on this topic considers the behavior of caching/paging on the overall layout of the heap; The idea being that it’s vastly more costly to pay for a cache miss or page in than nearly any other part of a datastructure’s implementation. The paper discusses a heap layout that addresses this. You’re Doing … Read more

What are vectors and how are they used in programming?

From http://www.cplusplus.com/reference/stl/vector/ Vector containers are implemented as dynamic arrays; Just as regular arrays, vector containers have their elements stored in contiguous storage locations, which means that their elements can be accessed not only using iterators but also using offsets on regular pointers to elements. But unlike regular arrays, storage in vectors is handled automatically, allowing … Read more