Showing posts with label mathematics. Show all posts
Showing posts with label mathematics. Show all posts

Tuesday, June 29, 2010

QOTD

It's not that people cannot think mathematically. It's that they have enormous trouble doing it in a de-contextualized, abstract setting.

-- Keith Devlin

From In Math You Have to Remember, In Other Subjects You Can Think About It

Tuesday, June 22, 2010

Masters to Graduate Diploma

In 2008 I commenced a coursework Masters in mathematics at the University of Queensland. I have downgraded this to a Graduate Diploma and should officially graduate in a few weeks.

My original goal for commencing postgraduate study was to improve my knowledge in programming languages and make the current research more accessible. Unfortunately the local universities teach very little (relevant) theoretical computing science, so I enrolled in mathematics with a focus on discrete mathematics, logic and abstract algebra. After the first year I discovered that there is no real future in programming language research here in Brisbane. I had achieved my goal in the context of the courses available and so switched my study to statistics as data analytics is both interesting and hopefully more viable locally.

To complete the Masters I need to do the equivalent of four courses in research. As I am enrolled in a coursework masters, I pay 2-3 times the standard undergraduate fees. The last course cost $2010. Therefore there is approximately $8000 in fees remaining.

I would enjoy the remaining Masters research component if could find the right supervisor and topic. However employment as a researcher now generally requires a PhD, not a Masters and while a PhD is longer, it also has no fees. So if the circumstances were right to do the Masters research it makes more sense to consider a PhD anyway.

The value proposition for completing the Masters is too low. I have fulfilled the requirements for a Graduate Diploma and so will finish with that.

Tuesday, April 13, 2010

Math is not linear

Sunday, March 21, 2010

Embedding LaTeX in Blogger take 2

After further consideration on Embedding LaTeX in Blogger I have the following concerns in using jsLaTeX.

  • LaTeX images not rendered in RSS readers

  • Stability of all the components over (a long) time

jsMath improves on point 2, but looks way too hard to host on Blogger. So I am falling back to using images generated by the CodeCogs online equation editor hosted on Picasa, which is where Blogger uploads images. I put the LaTeX source in the img alt attribute.

Blogger resizing images
After adding a few equations through the standard Blogger mechanism, I noticed that they weren't as clear when previewing. The following two equations are the same image hosted on Picasa, but embedded with different src urls.



This is using the Blogger generated url in the image tag and has size 400 x 285 pixels.



This is using the Picasa generated url and has the original size of 415 x 296 pixels.

Notice how the first image is both smaller and blurry. It seems that Blogger is automatically resizing it. Unfortunately this means a little more work for each equation as it requires generating the link in Picasa and replacing the Blogger generated image tag.

Computing variance

Given a list of n numbers x_1,x_2,...,x_n, the variance is defined as

\frac{1}{n}\sum_{i=1}^n{\left(x_i - \bar{x}\right)^2}\quad\quad\quad\text{(1)}

where \bar{x} is the arithmetic mean.

\bar{x} = \frac{1}{n}\sum_{i=1}^n{x_i}

Expression 1 stated in words is the average squared difference of each data point from the mean. Implemented as an algorithm, this requires two passes over the data set. The first to calculate the mean and the second to sum the squared differences.

Let's derive the more commonly used expression for variance.

\begin{align*}<br />\frac{1}{n}\sum_{i=1}^n{\left(x_i - \bar{x}\right)^2} & =  \frac{1}{n}\sum_{i=1}^n{\left({x_i}^2 - 2x_i\bar{x} + \bar{x}^2\right)} \\<br />& = \frac{1}{n}\left(\sum_{i=1}^n{x_i}^2 - 2\bar{x}\sum_{i=1}^n{x_i} + n\bar{x}^2\right) \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - 2\bar{x}^2 + \bar{x}^2 \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - \bar{x}^2 \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - \left(\frac{1}{n}\sum_{i=1}^n{x_i}\right)^2 && \text{(2)}<br />\end{align*}

This only requires a single pass over the data set, computing the incremental sum of the values and the incremental sum of their squares. However, if the terms in the subtraction are large and close enough, catastrophic cancellation can occur. Essentially the precision of the floating point representation is exceeded, yielding unacceptable results. See Algorithms for calculating variance and Theoretical explanation for numerical results for examples (they are calculating the sample variance which is slightly different). More detailed information on catastrophic cancellation can be found in What Every Computer Scientist Should Know About Floating Point Arithmetic (1991).

A more numerically stable (but computationally expensive) single pass algorithm was published by Knuth in The Art of Computer Programming, volume 2. Define \bar{x}_n and s_n as the mean and sum of squared differences of the the first n values respectively.

\begin{align*}<br />s_0 & = 0\\<br />\\<br />s_{n+1} & = \sum_{i=1}^{n+1}\left(x_i-\bar{x}_{n+1}\right)^2\\<br />& = s_n + \left(x_{n+1}-\bar{x}_n\right)\left(x_{n+1}-\bar{x}_{n+1}\right)\quad\quad\quad(3)<br />\end{align*}

For m > 0 values, the variance is then \frac{s_m}{m}.

Derivation of Equation 3
This is really just a more verbose version of one-pass algorithm to compute sample variance. First up is the running mean.

\begin{align*}<br />\bar{x}_0 & = 0\\<br />\\<br />\bar{x}_{n+1} & = \frac{n\bar{x}_n + x_{n+1}}{n+1}\\<br />& = \frac{\left(n+1\right)\bar{x}_n-\bar{x}_n+x_{n+1}}{n+1}\\<br />& = \bar{x}_n + \frac{x_{n+1}-\bar{x}_n}{n+1} && \quad &&& (4)\\<br />\end{align*}

If you think of the mean visually i.e. a horizontal line through the data on a scatter plot, then it is intuitive that the sum of the distances between each point and the mean is zero.

\sum_{i=1}^n\left(x_i-\bar{x}_n\right) & = \sum_{i=1}^nx_i-n\left(\frac{1}{n}\sum_{i=1}^nx_i\right)=0\quad\quad\quad(5)

Now define \gamma as the difference of consecutive incremental means, along with a few useful variations.

\begin{align*}<br />\gamma & = \bar{x}_{n+1} - \bar{x}_n && \quad &&& (6)\\<br />\\<br />\gamma & = \bar{x}_n + \frac{x_{n+1}-\bar{x}_n}{n+1} - \bar{x}_n && &&& \text{by (4)}\\<br />\gamma & = \frac{x_{n+1}-\bar{x}_n}{n+1} \\<br />\left(n+1\right)\gamma & = x_{n+1}-\bar{x}_n && &&& (7)\\<br />\\<br />x_{n+1}-\bar{x}_{n+1} & = x_{n+1}-\bar{x}_n+\bar{x}_n-\bar{x}_{n+1} \\<br />& = \left(n+1\right)\gamma-\gamma && &&& \text{by (7, 6)} \\<br />& = n\gamma && &&& (8)\\<br />\end{align*}

The pieces are now all in place to derive equation 3.

\begin{align*}<br />s_{n+1} & = \sum_{i=1}^{n+1}\left(x_i-\bar{x}_{n+1}\right)^2\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_{n+1}\right)^2 + \left(x_{n+1}-\bar{x}_{n+1}\right)^2\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_n+\bar{x}_n-\bar{x}_{n+1}\right)^2 + \left(n\gamma\right)^2 && \quad &&& \text{by (8)}\\<br />& = \sum_{i=1}^{n}\left(\left(x_i-\bar{x}_n\right)-\gamma\right)^2+n^2\gamma^2 && &&& \text{by (6)}\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_n\right)^2 -2\gamma\sum_{i=1}^{n}\left(x_i-\bar{x}_n\right)+n\gamma^2+n^2\gamma^2\\<br />& = s_n-0+n\gamma^2\left(1+n\right) && &&& \text{by (5)}\\<br />& = s_n+\left(x_{n+1}-\bar{x}_n\right)n\gamma && &&& \text{by (7)}\\<br />& = s_n+\left(x_{n+1}-\bar{x}_n\right)\left(x_{n+1}-\bar{x}_{n+1}\right) && &&& \text{by (8)}<br />\end{align*}

Friday, March 12, 2010

Embeding LaTeX in Blogger

The goal is to include mathematical equations in blog posts. My plan was to create images from the output of MacTeX. Apart from being painfully slow to crop and upload with multiple distinct equations, the LaTeX source would not be contained in the post.

Embedding LaTeX in HTML led me to jsLaTeX. Option 4 from Solutions for JavaScript Hosting in Blogger solved the Blogger hosting issue. After some CSS shenanigans we have Bayes rule right here, right now.

\mathbb{P}(B_j|A) = \frac{\mathbb{P}(A|B_j)\mathbb{P}(B_j)}{\sum_{i=1}^n\mathbb{P}(A|B_i)\mathbb{P}(B_i)}

It is easier to write simple equations in the CodeCogs online equation editor first as Blogger preview doesn't seem to execute the JavaScript to render them.

Edit 23/03/2010: No longer using jsLaTeX, see Embedding LaTeX in Blogger take 2.

Friday, February 12, 2010

QOTD

The role of the proof for mathematics is similar to that for orthography or even calligraphy for poetry. A person, who had not mastered the art of the proofs in high school, is as a rule unable to distinguish correct reasoning from that which is misleading. Such people can be easily manipulated by the irresponsible politicians.

-- V.I. Arnold

From: The antiscientifical revolution and mathematics

Tuesday, September 8, 2009

Learning - context and details

My mathematics lecturers often try and introduce a new topic with a motivating example. I think this is a great idea. I am a slow learner and find that an initial concrete example is the best way to approach a new abstract concept. I realise that this can sometimes pose challenges further on, i.e. in generalising from the concrete to the abstract, but this way seems to work the best for me.

Unfortunately, there are many times that the motivating example is not that motivating. I view teaching as often building a bridge from the student's current position to where you want to take them. To achieve that, requires providing an initial high-level context in terms that the student can relate to.

As an example, earlier this year I studied introductory linear algebra that included eigenvectors. Kudos to the lecturer for trying to motivate with a modern example (search engine page rank). Even though I am a professional programmer, this example didn't really work for me and I finished the subject with only a vague idea about them.

Recently I read this article which introduced them with simple physical examples. The second paragraph of the current wikipedia page nicely related it back to matrices and vectors and it all fell into place.

Some mathematical ideas are represented as a sequence of steps, e.g. calculating Maximum Likelihood Estimators in statistics. Once a good motivating example is done to provide context, things can proceed between two extremes.

  1. Present high-level steps and then dig down into the details of each step

  2. Work through the details of each individual step and bring it all together at the end
In the latter approach, I sometimes miss the high-level steps if I get lost in all the detailed algebra and reasoning underlying each step. Can't see the forest for the trees. I prefer the former approach as it provides more purpose and is therefore more motivating. It also makes it easier to isolate difficult sections that can be returned to later, so as not to get bogged down and lost for the remainder of the discussion/lecture.

I wish I had utilised these ideas better in my Intro to Functional Programming talk a few weeks ago.

Saturday, August 22, 2009

LaTex resources

A few weeks ago I decided to bite the bullet and learn LaTeX. To make it happen I foolishly decided to type up my stats assignment (due yesterday) in it. Made for a very busy week, with my Bris FP talk, work, etc.

Anyway the following sites were useful.

Thursday, August 13, 2009

Zoho Writer LaTeX equation editor

I think the LaTeX support in Zoho Writer's equation editor is a fantastic idea. Although, I don't know what would happen to the LaTeX source when exporting for backup purposes.

UPDATE:
Document can be exported as LaTeX.

I ran into the following issues with the equation editor.

  • The sigma representing a sum is tipped backwards at an angle when used in the denominator of a fraction. Changing to italics seems to straighten it up.

  • I couldn't figure out how to change the font.

  • When exporting to PDF, the equations looked a little blurry compared to text.
So I will stick with TexShop on the Mac for the moment. However, the Zoho editor is very useful for finding the LaTeX commands for mathematical symbols.

Thursday, May 21, 2009

Future of Computing

Some quotes from The Future of Computing: Logic or Biology, by Leslie Lamport.

  • Computers interact with users through metaphors. Metaphors are not based on logic, but they are not illogical. Metaphor and logic are not opposites. They are complementary. A good program must use good metaphors, and it must behave logically. The metaphors must be applied consistently—and that means logically.
  • Floyd and Hoare pointed the way by showing how mathematics could be applied to tiny programs. We need to learn how to extend what they did to the real world of large programs.

    Extending what they did does not mean trying to mathematically prove the correctness of million-line programs. It means learning how to apply the idea of a program as a mathematical object to the task of building large programs that we can understand, and that do what we intend them to do.
  • In addition to the task of learning how to apply mathematics to large systems, we also face the task of teaching programmers and designers to think logically. They must learn how to think about programs as mathematical objects. They must learn to think logically. We will not have understandable programs as long as our universities produce generation after generation of people who, like my former colleagues, cannot understand that programs are different from automobiles.

Tuesday, March 3, 2009

Imaginary numbers

The names imaginary numbers and real numbers seem a little ironic, given that all maths is imaginary. As an example, consider the number 3. It is not a real thing in the sense that I can't go and observe a three, like I can stone or a tree. It represents the abstraction or concept of threeness, which we have imagined and exists in our minds.

One way to think of maths is as the science of patterns. So we have a huge library of patterns, abstractions, relationships and methods of reasoning about them. When we want to talk about the "real" world, we often draw on this library to give us the vocabulary and tools to do so.

I was thinking about this stuff because I am studying linear algebra at the moment and was reading A Visual, Intuitive Guide to Imaginary Numbers and What is Experimental Mathematics?

Tuesday, October 28, 2008

Groups in Haskell

sigfpe wrote an interesting post that includes implementations of a Group in Haskell, amongst other things I don't understand, such as vector spaces and Hopf algebras.

Monday, October 13, 2008

Zermelo and set theory

I am currently studying axiomatic set theory. In the process I came across Zermelo and Set Theory, which gives details about his work and interactions with other significant mathematicians.

While interesting, it unfortunately didn't help me when working out his proof for the Schroder-Bernstein Theorem in an assignment. :-)

Wednesday, August 13, 2008

Maths Symbols in NeoOffice

I wanted to have a character (representing the integers) in a NeoOffice document on Mac OS X 10.4. I couldn't find an installed font containing the character and according to Wikipedia I need a Blackboard Bold typeface style. After a few google searches I found a jsMath font that seemed to work fine.

Tuesday, April 29, 2008

Recounting the Rationals

Recently I found the paper Recounting the Rationals via Mark Jason Dominus on Planet Haskell.

Mark suggests that the paper is a good first paper to read. Well since I am part way through my first Discrete Maths subject, I thought I would give it a go as my first mathematical paper to have a look at.

I was quite suprised that I could actually understand a fair bit of the paper as I read through it. It was interesting just how many of the concepts from my one Uni subject are brought together in this paper: rational numbers, sequences, trees, proof by contradiction, proof by induction and the notion of relatively prime.

I still need to spend some more time to finish exploring this paper and Brent Yorgey's six-part blog series about it. However a couple observations so far:

  • The sequence of rationals shown in the paper is quite elegant and fascinating.

  • The fact that the sequence can be represented as a tree is even more interesting.

  • Starting with sequences, switching to a tree perspective, doing a number of proofs on the tree and then relating the tree back to the sequences was a pretty cool technique.
So my verdict from the experience, is that it has been a good first paper to read. It is only 3 pages long. I could understand the paper at a high-level to start with and it has been interesting and challenging to explore in detail.

Monday, April 14, 2008

Online Discrete Maths Resources

MIT has some readings for their Mathematics for Computer Science course.

Carnegie Mellon University also also posted lecture notes on a wiki.

Wednesday, March 26, 2008

Lockharts Lament

Lockharts Lament is a very interesting and worthwhile read. It is about mathematics, art, society and education. Especially education. A few interesting quotes and ones that made me laugh:


"The only people who understand what is going on are the ones most often blamed and least often heard: the students. They say, “math class is stupid and boring,” and they are right."

"High School Geometry: Instrument of the Devil"

"We’re killing people’s interest in circles for god’s sake!"

"The first thing to understand is that mathematics is an art."

It is a about 25 pages long, at least read the conclusion (the last two pages).

Via Enfranchised Mind.