<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>slightlymore</title>
	<atom:link href="https://blog.slightlymore.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.slightlymore.co.uk</link>
	<description>the writings and ramblings of Clinton Montague</description>
	<lastBuildDate>Mon, 18 Feb 2019 15:08:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.6</generator>
	<item>
		<title>Making sense of Bayes rule</title>
		<link>https://blog.slightlymore.co.uk/making-sense-of-bayes-rule/</link>
					<comments>https://blog.slightlymore.co.uk/making-sense-of-bayes-rule/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Sun, 17 Feb 2019 16:28:22 +0000</pubDate>
				<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[Probability]]></category>
		<guid isPermaLink="false">http://blog.slightlymore.co.uk/?p=1965</guid>

					<description><![CDATA[Bayes rule has always seemed like witchcraft to me. But today I went through the derivation, and then thought through why it is useful. Suddenly it started making a bit more sense. Thinking about it in a machine learning setting, let&#8217;s say that we have a dataset containing cats and dogs, and their respective names. [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Bayes rule has always seemed like witchcraft to me. But today I went through the derivation, and then thought through why it is useful. Suddenly it started making a bit more sense.</p>



<p>Thinking about it in a machine learning setting, let&#8217;s say that we have a dataset containing cats and dogs, and their respective names. We would like to classify an unknown pet as either a cat or dog, given only its name. We can use Bayes rule to help us.</p>



<p>First, let&#8217;s start off by understanding where the rule comes from. We can use <a href="https://en.wikipedia.org/wiki/Conditional_probability#As_an_axiom_of_probability">conditional probability identities</a> to get some results. </p>



<p>The probability the the pet is called Rover and is a dog, is the probability the the pet is called Rover <em>given</em> that it is a dog, multiplied by the probability that it is a dog.</p>



<img src='https://s0.wp.com/latex.php?latex=P%28Rover+%5Ccap+dog%29+%3D+P%28Rover+%7C+dog%29+%5Ccdot+P%28dog%29&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover \cap dog) = P(Rover | dog) \cdot P(dog)' title='P(Rover \cap dog) = P(Rover | dog) \cdot P(dog)' class='latex' />



<p>Similarly, we have:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28dog+%5Ccap+Rover%29+%3D+P%28dog+%7C+Rover%29+%5Ccdot+P%28Rover%29&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(dog \cap Rover) = P(dog | Rover) \cdot P(Rover)' title='P(dog \cap Rover) = P(dog | Rover) \cdot P(Rover)' class='latex' />



<p>And now, because the left hand sides of both of those equations are the same, we have:</p>



<img src='https://s0.wp.com/latex.php?latex=%5CRightarrow+P%28dog+%7C+Rover%29+%5Ccdot+P%28Rover%29+%3D+P%28Rover+%7C+dog%29+%5Ccdot+P%28dog%29+&#038;bg=T&#038;fg=000000&#038;s=2' alt='\Rightarrow P(dog | Rover) \cdot P(Rover) = P(Rover | dog) \cdot P(dog) ' title='\Rightarrow P(dog | Rover) \cdot P(Rover) = P(Rover | dog) \cdot P(dog) ' class='latex' />



<p>Now for the magic &#8211; divide both sides by the probability that the pet is called Rover, and — Boom! — Bayes rule. </p>



<img src='https://s0.wp.com/latex.php?latex=%5CRightarrow+P%28dog+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+dog%29+%5Ccdot+P%28dog%29%7D%7BP%28Rover%29%7D&#038;bg=T&#038;fg=000000&#038;s=2' alt='\Rightarrow P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)}' title='\Rightarrow P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)}' class='latex' />



<p>Why is this good and useful? Because it allows us to find the probability of a label given a constraint, using known probabilities from the training data! </p>



<p>Replacing dog with the variable <em>class</em> (or label), and Rover with the variable <em>feature</em>, we have derived the following:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28class+%7C+feature%29+%3D+%5Cfrac%7BP%28feature+%7C+class%29+%5Ccdot+P%28class%29%7D%7BP%28feature%29%7D&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(class | feature) = \frac{P(feature | class) \cdot P(class)}{P(feature)}' title='P(class | feature) = \frac{P(feature | class) \cdot P(class)}{P(feature)}' class='latex' />



<p>i.e. a way of determining the class of an item given one (or more) feature constraints. How does this help with a classification machine learning problem? Well, we could calculate the probability of each class given the constrains, and select the class with the highest recorded probability. </p>



<p>Let&#8217;s finish off the pet example. We have the training data in the table below. We are given a mystery pet, which we know is called Rover. We wish to predict whether it&#8217;s a cat or a dog using only its name and the probabilities derived from this table. </p>



<table class="wp-block-table"><tbody><tr><td><strong>Kind</strong></td><td><strong>Name</strong></td></tr><tr><td>Dog</td><td>Rover</td></tr><tr><td>Dog</td><td>Max</td></tr><tr><td>Cat</td><td>Fluffy</td></tr><tr><td>Dog</td><td>Rover</td></tr><tr><td>Cat</td><td>Leo</td></tr><tr><td>Dog</td><td>Bruiser</td></tr><tr><td>Dog</td><td>John</td></tr><tr><td>Cat</td><td>Simba</td></tr><tr><td>Cat</td><td>Tigger</td></tr><tr><td>Cat</td><td>Rover</td></tr></tbody></table>





<p>Now we have <img src='https://s0.wp.com/latex.php?latex=P%28dog%29+%3D+0.5&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(dog) = 0.5' title='P(dog) = 0.5' class='latex' />, and <img src='https://s0.wp.com/latex.php?latex=P%28cat%29+%3D+0.5&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(cat) = 0.5' title='P(cat) = 0.5' class='latex' />. Of the 5 dogs, two are called Rover, so we have <img src='https://s0.wp.com/latex.php?latex=P%28Rover+%7C+dog%29+%3D+0.4&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover | dog) = 0.4' title='P(Rover | dog) = 0.4' class='latex' />. Of the 5 cats, one is called Rover, so we have <img src='https://s0.wp.com/latex.php?latex=P%28Rover+%7C+cat%29+%3D+0.2&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover | cat) = 0.2' title='P(Rover | cat) = 0.2' class='latex' />. Finally, of all the pets, three are called Rover, so <img src='https://s0.wp.com/latex.php?latex=P%28Rover%29+%3D+0.3&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover) = 0.3' title='P(Rover) = 0.3' class='latex' />. We now have everything required to make a prediction.</p>



<p>For a cat:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28cat+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+cat%29+%5Ccdot+P%28cat%29%7D%7BP%28Rover%29%7D+%5C%5C+%5C%5C++++++%3D+%5Cfrac%7B0.2+%5Ccdot+0.5%7D%7B0.3%7D+%5C%5C+%5C%5C+%3D+0.333&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(cat | Rover) = \frac{P(Rover | cat) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{0.2 \cdot 0.5}{0.3} \\ \\ = 0.333' title='P(cat | Rover) = \frac{P(Rover | cat) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{0.2 \cdot 0.5}{0.3} \\ \\ = 0.333' class='latex' />



<p>And for a dog:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28dog+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+dog%29+%5Ccdot+P%28dog%29%7D%7BP%28Rover%29%7D+%5C%5C+%5C%5C++++++%3D+%5Cfrac%7B0.4+%5Ccdot+0.5%7D%7B0.3%7D+%5C%5C+%5C%5C+%3D+0.667&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)} \\ \\      = \frac{0.4 \cdot 0.5}{0.3} \\ \\ = 0.667' title='P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)} \\ \\      = \frac{0.4 \cdot 0.5}{0.3} \\ \\ = 0.667' class='latex' />



<p>So our model has made a prediction that the pet is a dog &#8211; which sounds good to me! </p>



<h2 class="wp-block-heading">OK, so can we trick it?</h2>



<p>From the pet dataset above, it might seem that dog was given the highest probability because there are more dogs called Rover than cats called Rover. OK, so can we fool it by introducing a new category, fish, which are all called Rover? </p>



<p>Let&#8217;s try, by using the above dataset, but adding a single fish which belongs to a joker who decided to call it Rover. That means that we now have <img src='https://s0.wp.com/latex.php?latex=P%28dog%29+%3D+0.45&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(dog) = 0.45' title='P(dog) = 0.45' class='latex' />, <img src='https://s0.wp.com/latex.php?latex=P%28cat%29+%3D+0.45&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(cat) = 0.45' title='P(cat) = 0.45' class='latex' />, and <img src='https://s0.wp.com/latex.php?latex=P%28fish%29+%3D+0.09&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(fish) = 0.09' title='P(fish) = 0.09' class='latex' />.</p>



<p>Notice how <img src='https://s0.wp.com/latex.php?latex=P%28Rover+%7C+dog%29&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover | dog)' title='P(Rover | dog)' class='latex' /> does not change — given a dog, there is still a probability of 0.4 that it will be called Rover. Similarly,  <img src='https://s0.wp.com/latex.php?latex=P%28Rover+%7C+cat%29&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover | cat)' title='P(Rover | cat)' class='latex' /> remains the same. Now we can also do the same for a fish <img src='https://s0.wp.com/latex.php?latex=P%28Rover+%7C+fish%29+%3D+1&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover | fish) = 1' title='P(Rover | fish) = 1' class='latex' /> — there&#8217;s only one fish, and its name is Rover. Finally we have <img src='https://s0.wp.com/latex.php?latex=P%28Rover%29+%3D+0.36&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(Rover) = 0.36' title='P(Rover) = 0.36' class='latex' /></p>



<p>So the question is, will it trick the system? Let&#8217;s run the numbers.</p>



<p>For a dog:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28dog+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+dog%29+%5Ccdot+P%28dog%29%7D%7BP%28Rover%29%7D+%5C%5C+%5C%5C++++++%3D+%5Cfrac%7B+0.4+%5Ccdot+0.45+%7D%7B0.36%7D+%3D+0.5+&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)} \\ \\      = \frac{ 0.4 \cdot 0.45 }{0.36} = 0.5 ' title='P(dog | Rover) = \frac{P(Rover | dog) \cdot P(dog)}{P(Rover)} \\ \\      = \frac{ 0.4 \cdot 0.45 }{0.36} = 0.5 ' class='latex' />



<p>For a cat:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28cat+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+cat%29+%5Ccdot+P%28cat%29%7D%7BP%28Rover%29%7D+%5C%5C+%5C%5C++++++%3D+%5Cfrac%7B+0.2+%5Ccdot+0.45+%7D%7B0.36%7D+%3D+0.25+&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(cat | Rover) = \frac{P(Rover | cat) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{ 0.2 \cdot 0.45 }{0.36} = 0.25 ' title='P(cat | Rover) = \frac{P(Rover | cat) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{ 0.2 \cdot 0.45 }{0.36} = 0.25 ' class='latex' />



<p>For a fish:</p>



<img src='https://s0.wp.com/latex.php?latex=P%28fish+%7C+Rover%29+%3D+%5Cfrac%7BP%28Rover+%7C+fish%29+%5Ccdot+P%28cat%29%7D%7BP%28Rover%29%7D+%5C%5C+%5C%5C++++++%3D+%5Cfrac%7B+1+%5Ccdot+0.09+%7D%7B0.36%7D+%3D+0.25+&#038;bg=T&#038;fg=000000&#038;s=2' alt='P(fish | Rover) = \frac{P(Rover | fish) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{ 1 \cdot 0.09 }{0.36} = 0.25 ' title='P(fish | Rover) = \frac{P(Rover | fish) \cdot P(cat)}{P(Rover)} \\ \\      = \frac{ 1 \cdot 0.09 }{0.36} = 0.25 ' class='latex' />



<p>So no! Even though a fish is most likely to be called Rover, there are many more dogs, so there are many more chances for the pet to be a dog than there are for it to be a fish. The model still correctly (according to intuition, at least) predicts that the pet is a dog. </p>



<p>And this is what leads to the often contradictory and surprising results from the theorem. You know the ones &#8211; results like if a doctor tests for a rare disease (say, 1 in 10000 people), and the test is 99% accurate, and you test positive, chances are high that you actually do not have the disease. That&#8217;s because the disease is so rare, that the number of opportunities for a false positive outweighs the number of opportunities for a true positive. </p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/making-sense-of-bayes-rule/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Starting machine learning</title>
		<link>https://blog.slightlymore.co.uk/starting-machine-learning/</link>
					<comments>https://blog.slightlymore.co.uk/starting-machine-learning/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Sat, 16 Feb 2019 15:07:41 +0000</pubDate>
				<category><![CDATA[Machine Learning]]></category>
		<guid isPermaLink="false">http://blog.slightlymore.co.uk/?p=1963</guid>

					<description><![CDATA[For a few years now, I&#8217;ve been sitting here wishing that I knew machine learning. Yearning for a job where I was looking at data and writing algorithms to find patterns and make predictions. But the problem is exactly that. I&#8217;ve been sitting and wishing, not learning and doing. True, I did a course on Coursera a [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>For a few years now, I&#8217;ve been sitting here wishing that I knew machine learning. Yearning for a job where I was looking at data and writing algorithms to find patterns and make predictions.</p>



<p>But the problem is exactly that. I&#8217;ve been <em>sitting and wishing</em>, not learning and doing. True, I did a course on Coursera a few years ago, but that hardly cuts the mustard. So I&#8217;ve decided that now it&#8217;s my time. I would really like to get into it, and so here&#8217;s my commitment to myself to do it. </p>



<p>I don&#8217;t mean just watching videos and reading books, or even creating pretty visualisations or learning how to throw something together using Scikit Learn. I want to know what&#8217;s going on so that I can make good and informed decisions, communicate them, and (perhaps one day!) become a data scientist. </p>



<p>One of the best ways that I know to be sure that I know material, and can talk about it confidently, is to talk about it. So that&#8217;s what I&#8217;ll be doing. Talking about it. Writing about what I&#8217;ve learnt, am learning, insights that I&#8217;ve had. Consolidating my knowledge. Who knows, there may be some cool visualisations too.</p>



<p>What I must remember along this journey (<strong>huge</strong> note to self) is that if this is going to be successful, I need to just do it. The aim is not to write lecture notes or a book. This is reinforcement learning (pardon the pun), and it&#8217;ll only work if I reinforce the learning &#8211; i.e. just write. As such, if you&#8217;re reading this, please don&#8217;t expect any kind of order! </p>



<p>To get started, I&#8217;ll be working my way through <a href="https://www.springer.com/gb/book/9783319348865">An Introduction To Machine Learning</a>. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/starting-machine-learning/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Deriving the quadratic formula</title>
		<link>https://blog.slightlymore.co.uk/deriving-the-quadratic-formula/</link>
					<comments>https://blog.slightlymore.co.uk/deriving-the-quadratic-formula/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Sat, 01 Nov 2014 16:05:32 +0000</pubDate>
				<category><![CDATA[Maths]]></category>
		<guid isPermaLink="false">http://blog.slightlymore.co.uk/?p=1804</guid>

					<description><![CDATA[[latex size=4]x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}[/latex]

Everyone can reel it off, it was banged into us at school. Where does the quadratic formula come from, and how can you get at it?]]></description>
										<content:encoded><![CDATA[<p>This afternoon I decided to practice <a href="http://en.wikipedia.org/wiki/Completing_the_square">completing the square</a> (I&#8217;m afraid that I&#8217;m rediscovering my inner nerd and am now studying for a math degree). After a few examples, I decided to go a bit more general and derive the quadratic formula. I guess that doing things like this is something which I&#8217;m going to have to get used to. </p>
<p>I figured that this is also a good excuse to practice my <img src='https://s0.wp.com/latex.php?latex=%5CLaTeX&#038;bg=T&#038;fg=000000&#038;s=3' alt='\LaTeX' title='\LaTeX' class='latex' /> skills and write it out. </p>
<p>We want to find the general solution of the equation: </p>
<p><img src='https://s0.wp.com/latex.php?latex=ax%5E2+%2B+bx+%2B+c+%3D+0&#038;bg=T&#038;fg=000000&#038;s=4' alt='ax^2 + bx + c = 0' title='ax^2 + bx + c = 0' class='latex' /></p>
<p>Start off by dividing through by <img src='https://s0.wp.com/latex.php?latex=a&#038;bg=T&#038;fg=000000&#038;s=4' alt='a' title='a' class='latex' /></p>
<p><img src='https://s0.wp.com/latex.php?latex=x%5E2+%2B+%5Cfrac%7Bb%7D%7Ba%7Dx+%2B+%5Cfrac%7Bc%7D%7Ba%7D+%3D+0&#038;bg=T&#038;fg=000000&#038;s=4' alt='x^2 + \frac{b}{a}x + \frac{c}{a} = 0' title='x^2 + \frac{b}{a}x + \frac{c}{a} = 0' class='latex' /></p>
<p>then complete the square</p>
<p><img src='https://s0.wp.com/latex.php?latex=%5Cbig%28x+%2B+%5Cfrac%7Bb%7D%7B2a%7D%5Cbig%29%5E2+-+%5Cfrac%7Bb%5E2%7D%7B4a%5E2%7D+%2B+%5Cfrac%7Bc%7D%7Ba%7D+%3D+0&#038;bg=T&#038;fg=000000&#038;s=4' alt='\big(x + \frac{b}{2a}\big)^2 - \frac{b^2}{4a^2} + \frac{c}{a} = 0' title='\big(x + \frac{b}{2a}\big)^2 - \frac{b^2}{4a^2} + \frac{c}{a} = 0' class='latex' /></p>
<p>rearrange to leave the square on the left</p>
<p><img src='https://s0.wp.com/latex.php?latex=%5Cbig%28x+%2B+%5Cfrac%7Bb%7D%7B2a%7D%5Cbig%29%5E2+%3D+%5Cfrac%7Bb%5E2%7D%7B4a%5E2%7D+-+%5Cfrac%7Bc%7D%7Ba%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='\big(x + \frac{b}{2a}\big)^2 = \frac{b^2}{4a^2} - \frac{c}{a}' title='\big(x + \frac{b}{2a}\big)^2 = \frac{b^2}{4a^2} - \frac{c}{a}' class='latex' /></p>
<p>simplify the RHS</p>
<p><img src='https://s0.wp.com/latex.php?latex=%5Cbig%28x+%2B+%5Cfrac%7Bb%7D%7B2a%7D%5Cbig%29%5E2+%3D+%5Cfrac%7Bb%5E2+-+4ac%7D%7B4a%5E2%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='\big(x + \frac{b}{2a}\big)^2 = \frac{b^2 - 4ac}{4a^2}' title='\big(x + \frac{b}{2a}\big)^2 = \frac{b^2 - 4ac}{4a^2}' class='latex' /></p>
<p>take the square root of both sides</p>
<p><img src='https://s0.wp.com/latex.php?latex=%5Cbig%28x+%2B+%5Cfrac%7Bb%7D%7B2a%7D%5Cbig%29+%3D+%5Cpm+%5Csqrt%7B%5Cfrac%7Bb%5E2+-+4ac%7D%7B4a%5E2%7D%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='\big(x + \frac{b}{2a}\big) = \pm \sqrt{\frac{b^2 - 4ac}{4a^2}}' title='\big(x + \frac{b}{2a}\big) = \pm \sqrt{\frac{b^2 - 4ac}{4a^2}}' class='latex' /></p>
<p>simplify the RHS</p>
<p><img src='https://s0.wp.com/latex.php?latex=%5Cbig%28x+%2B+%5Cfrac%7Bb%7D%7B2a%7D%5Cbig%29+%3D+%5Cpm+%5Cfrac%7B%5Csqrt%7Bb%5E2+-+4ac%7D%7D%7B2a%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='\big(x + \frac{b}{2a}\big) = \pm \frac{\sqrt{b^2 - 4ac}}{2a}' title='\big(x + \frac{b}{2a}\big) = \pm \frac{\sqrt{b^2 - 4ac}}{2a}' class='latex' /></p>
<p>make <img src='https://s0.wp.com/latex.php?latex=x&#038;bg=T&#038;fg=000000&#038;s=4' alt='x' title='x' class='latex' /> the subject</p>
<p><img src='https://s0.wp.com/latex.php?latex=x++%3D+-+%5Cfrac%7Bb%7D%7B2a%7D+%5Cpm+%5Cfrac%7B%5Csqrt%7Bb%5E2+-+4ac%7D%7D%7B2a%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='x  = - \frac{b}{2a} \pm \frac{\sqrt{b^2 - 4ac}}{2a}' title='x  = - \frac{b}{2a} \pm \frac{\sqrt{b^2 - 4ac}}{2a}' class='latex' /></p>
<p>and, boom &#8211; the quadratic formula! </p>
<p><img src='https://s0.wp.com/latex.php?latex=%5CRightarrow+x+%3D+%5Cfrac%7B-b+%5Cpm+%5Csqrt%7Bb%5E2+-+4ac%7D%7D%7B2a%7D&#038;bg=T&#038;fg=000000&#038;s=4' alt='\Rightarrow x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}' title='\Rightarrow x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}' class='latex' /></p>
<p>If I could go back in time and tell my younger self one thing, it would be to play with maths &#8211; don&#8217;t just do the homework. It&#8217;s all very well being able to follow a process (and essentially being a calculator), but knowing and understanding where something comes from unearths the true beauty of maths. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/deriving-the-quadratic-formula/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generative art experiment 5</title>
		<link>https://blog.slightlymore.co.uk/generative-art-experiment-5/</link>
					<comments>https://blog.slightlymore.co.uk/generative-art-experiment-5/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Wed, 24 Apr 2013 19:48:13 +0000</pubDate>
				<category><![CDATA[Visual programming]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1655</guid>

					<description><![CDATA[I&#8217;ve played with visualising the forces between particles that repel each other before, but I thought I&#8217;d have a little play around with how I could use that to create something that actually looked good (to me at least!) I put it together on codepen (which is my new favourite tool, by the way) so [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve played with visualising the forces between particles that repel each other before, but I thought I&#8217;d have a little play around with how I could use that to create something that actually looked good (to me at least!)</p>
<p>I put it together on <a href="http://codepen.io/iblamefish/pen/tfpIc">codepen</a> (which is my new favourite tool, by the way) so feel free to fork it and see what you can do with it!</p>
<p>It takes a little while to draw, but it&#8217;s quite interesting seeing it building up. </p>
<h2>The javascript code</h2>
<pre>
var WIDTH = 800,
	HEIGHT = 500,
	PARTICLES = [],
	STARTING_COUNT = 600,
	MAX_PARTICLES = 600,
	DAMPING = 0.05,
	CURRENT_FRAME = 0,
 PADDING = 10;

var canvas = document.getElementsByTagName ('canvas')[0];
canvas.width = WIDTH;
canvas.height = HEIGHT;

var ctx = canvas.getContext ('2d');

function random (min, max) {
	return (Math.random() * (max - min) + min);
}


function _particleTimer () {
	addParticle (random(0, WIDTH), random(0, HEIGHT));
	if (PARTICLES.length < STARTING_COUNT) setTimeout(_particleTimer, 0);
}


function init () {
	_particleTimer();
	animate();
}


function addParticle (x, y) {
	PARTICLES.push ({
		position: {
			x: x || random(0, WIDTH),
			y: y || random (0, HEIGHT)
		},
		force : {
			x: 0,
			y: 0
		},
		vel : {
			x: 0,
			y: 0
		}
	});
}

function animate () {
	while (PARTICLES.length > MAX_PARTICLES) PARTICLES.shift ();


	CURRENT_FRAME++;
  

	
	
	var force = {x : 0, y: 0};
	for (var i = 0; i < PARTICLES.length; i++) {
		var p1 = PARTICLES[i];
	

		for (var j = i + 1; j < PARTICLES.length; j++) {
			var p2 = PARTICLES[j];

			// length vector
			force.x = p2.position.x - p1.position.x;
			force.y = p2.position.y - p1.position.y;

			var magnitude = mag (force);

			var actingDistance = 50-magnitude;

			if ((actingDistance > 0) && (magnitude > 0)) {
				var red = 0;
				var green = 255;

				var color = green - actingDistance * (green / 2);
				if (color < 0) color = 0;
				if (color > 255) color = 255;

    if (color < 115 &#038;&#038; color > 10) {
			  	ctx.save ();
			  	ctx.strokeStyle = 'hsla(' + color + ', 100%, 50%, 0.05)';
				  ctx.strokeWidth = 1;
			  	ctx.beginPath ();
			  	ctx.moveTo (p1.position.x, p1.position.y);
				  ctx.lineTo (p2.position.x, p2.position.y);
			  	ctx.stroke();
				  ctx.closePath();
			  	ctx.restore ();
    }

				force.x *= DAMPING * actingDistance / magnitude;
				force.y *= DAMPING * actingDistance / magnitude;
				p1.force.x -= force.x;
				p1.force.y -= force.y;

				p2.force.x += force.x;
				p2.force.y += force.y;
			}
		}
		draw (p1);
		update (p1);
	}
 if (CURRENT_FRAME > 1500) {
   alert('finised drawing!');
   document.getElementById("message").innerHTML = 'Done!';
 } else {
   setTimeout(animate, 0);
 }
}

function mag (vector) {
	return Math.sqrt (vector.x * vector.x + vector.y * vector.y);
}

function update (particle) {
	with (particle) {
		vel.x += force.x;
		vel.y += force.y;
		vel.x *= 0.8;
		vel.y *= 0.8;

		position.x += vel.x;
		position.y += vel.y;

		force.x = 0;
		force.y = 0;

		if (position.x > WIDTH - PADDING) {
			position.x = random(PADDING, WIDTH - PADDING);
		}
		if (position.x < PADDING - 3) {
			position.x = random(PADDING, WIDTH - PADDING);
		}
		if (position.y > HEIGHT - PADDING) {
			position.y = random(PADDING, HEIGHT - PADDING);
		}
		if (position.y < PADDING-3) {
			position.y = random(HEIGHT, HEIGHT - PADDING);
		}
	}
}

function draw (particle) {
	ctx.save ();
 ctx.globalCompositeOperation = 'xor';
	ctx.translate (particle.position.x, particle.position.y);
	ctx.fillStyle = "rgba(255,255,255,0.1)";

 ctx.fillRect (0, 0, 1, 1);
	ctx.restore ();
}

init();
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/generative-art-experiment-5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>The awesometer</title>
		<link>https://blog.slightlymore.co.uk/the-awesometer/</link>
					<comments>https://blog.slightlymore.co.uk/the-awesometer/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Sun, 31 Mar 2013 17:31:47 +0000</pubDate>
				<category><![CDATA[Data vis]]></category>
		<category><![CDATA[Hacking]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1649</guid>

					<description><![CDATA[I wondered the other day &#8211; where is the most awesome place on earth RIGHT NOW? That made me think two things: we overuse the word awesome it would be cool to use this as an excuse to use the Twitter streaming API So I fired up npm, installed ntwitter and within minutes had simple program [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I wondered the other day &#8211; where is the most awesome place on earth RIGHT NOW? That made me think two things:</p>
<ol>
<li>we overuse the word awesome</li>
<li>it would be cool to use this as an excuse to use the Twitter streaming API</li>
</ol>
<p>So I fired up npm, installed <a href="https://github.com/AvianFlu/ntwitter">ntwitter</a> and within minutes had simple program that printed out to the console time there was a tweet (with a location) that had the word &#8216;awesome&#8217; in it. I then got it to store them in a MySQL database as well, and excitedly got to work hacking together a PHP script to read the tweets from the last hour and output them as JSON.</p>
<p>It was an amazing moment when I loaded up the page and saw it working properly for the first time. Unsurprisingly, the place where awesome is mentioned most often is in the US, but it&#8217;s interesting to watch the red moves across the country through the night.</p>
<p><a href="http://awesometer.slightlymore.co.uk/">Visit the awesometer!</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/the-awesometer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generative art experiment 4: colourful roots</title>
		<link>https://blog.slightlymore.co.uk/generative-art-experiment-4/</link>
					<comments>https://blog.slightlymore.co.uk/generative-art-experiment-4/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Tue, 26 Feb 2013 13:42:07 +0000</pubDate>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Visual programming]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1632</guid>

					<description><![CDATA[It&#8217;s been a while since I&#8217;ve posted about anything interesting that I&#8217;ve made in Processing. Time to put an end to that! Allow me to present &#8220;colourful roots&#8221;. It started off as a simple particle system with the usual fade effect, but when I let the particle shrink and stay fully opaque, I was delighted [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve posted about anything interesting that I&#8217;ve made in Processing. Time to put an end to that! Allow me to present &#8220;colourful roots&#8221;. It started off as a simple particle system with the usual fade effect, but when I let the particle shrink and stay fully opaque, I was delighted to see what it looked like!</p>
<h3>The processing code</h3>
<pre class="lang:default decode:true ">// canvas colour
int background_color = color(70, 70, 70);
// particle colours
color[] colors = {
      color (227, 211, 31), // yellow
      color (227, 31, 123), // pink
      color (31, 188, 227) // blue
    };
// colour of the stroke around the particles
color stroke_color = color(0, 70); // black, 70% alpha

// should the mouse draw particles when moved?
Boolean INTERACTIVE = true;
// should the canvas be cleared on each particle iteration
Boolean CLEAR = false;

//-----------------------------------------------------------------//
//-----------------------------------------------------------------//
//-----------------------------------------------------------------//
//-----------------------------------------------------------------//
ArrayList particles;

// reset on mouse click
void mouseClicked () {
  setup();
  mouseMoved();
}

// save on press spacebar
void keyPressed () {
  if (keyCode == RETURN || keyCode == ENTER) {
    save("Colourful entrails " + year() + "-" + month() + "-" + day() + " " + hour() + ":" + minute() + ":" + second() + ".png");
  }
}

// add particles on mouse move
void mouseMoved () {
  if (!INTERACTIVE) return;
  int count = int(random(2, 5)); 
  while(count-- &gt; 0) {
    addParticle(new PVector(mouseX, mouseY));
  }
}

void setup() {
  size(800, 400, P2D);
  blendMode(ADD);
  stroke(stroke_color);  
  background(background_color);

  particles = new ArrayList();

  // create a particle which'll go around making particles if it's not interactive  
  if (!INTERACTIVE) {
    Particle generator = new Particle(new PVector(width/2, height/2));
    generator.size = 10000;
    while(generator.isAlive()) {
      int count = int(random(2,5));
      generator.update();
      while (count-- &gt; 0) {
        addParticle(generator.position);
      }
    }
  }
}

// add a new particle to the particles arraylist with specified position
void addParticle (PVector position) {
  // clone the vector 
  PVector position_clone = new PVector(position.x, position.y);
  particles.add(new Particle(position_clone));
}

void draw() {
  // keep track of dead particles - they'll be removed after the loop
  ArrayList dead = new ArrayList();

  if (CLEAR) {
    fill(background_color);
    rect(0, 0, width, height);
  }

  // go through each of the particles and update/draw
  ListIterator it = particles.listIterator();
  while (it.hasNext()) {
    Particle particle = (Particle) it.next();
    // only draw if it's alive
    if (particle.isAlive()) {
      particle.update();
      particle.draw();
    } else { // otherwise add to dead list
      dead.add(particle);
    }
  }
  // remove all dead particles
  particles.removeAll(dead);
}

// a tad messy, building it up as i go along
class Particle 
{
  PVector position;
  PVector velocity;
  PVector force;
  float size;
  color c;
  int life;

  Particle (PVector p) {
    life = 0;
    position = p;
    size = random(30, 50);
    velocity = new PVector(random(2, 5), 0);
    rotate2D(velocity, random(0, TWO_PI));
    c = colors[int(random(colors.length))];
    force = new PVector(0, 1);
  }

  void update () {
    life++;
    if (life == 20) {
      velocity.mult(1.1);
    }
    if (life &lt; 20) {
      size *= 0.99;
    } else {
      size *= 0.95;
    }

    position.add(velocity);
    velocity.rotate(random(-QUARTER_PI, QUARTER_PI));
  }
  void draw () {
    pushMatrix();
    translate(position.x, position.y);
    fill (c);
    ellipse(0, 0, size, size);
    popMatrix();
  }
  Boolean isAlive() {
    return size &gt;= 1;
  }
}

void rotate2D(PVector v, float theta) {
  float xTemp = v.x;
  v.x = v.x*cos(theta) - v.y*sin(theta);
  v.y = xTemp*sin(theta) + v.y*cos(theta);
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/generative-art-experiment-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Photographing the Moon</title>
		<link>https://blog.slightlymore.co.uk/photographing-the-moon/</link>
					<comments>https://blog.slightlymore.co.uk/photographing-the-moon/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Tue, 31 Jan 2012 20:57:21 +0000</pubDate>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[Side projects]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1529</guid>

					<description><![CDATA[I&#8217;ve recently become obsessed with the night sky. I think that it was Jupiter turning up in October last year which did it. Since then I&#8217;ve looked up for Jupiter on a nightly basis, and have become interested in what else is up there too. While I don&#8217;t know what most of the constellations are, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve recently become obsessed with the night sky. I think that it was Jupiter turning up in October last year which did it. Since then I&#8217;ve looked up for Jupiter on a nightly basis, and have become interested in what else is up there too. While I don&#8217;t know what most of the constellations are, I&#8217;m beginning to know to look for certain things based on other things in the sky, which is pretty cool.</p>
<p>Anyway, I charged up my camera battery and thought that I&#8217;d start taking pictures of space. Yesterday I got a couple of blurry overexposed pictures, but today I tweaked the settings a little and ended up with the picture shown above. I&#8217;m really impressed.</p>
<p><a href="http://www.flickr.com/photos/slightlymore/6797534991/in/photostream"><img decoding="async" alt="" src="http://farm8.staticflickr.com/7169/6797518819_edc86ea73c.jpg" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/photographing-the-moon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generative art experiment 3.5: Lord of the targets</title>
		<link>https://blog.slightlymore.co.uk/generative-art-experiment-3-5-lord-of-the-targets/</link>
					<comments>https://blog.slightlymore.co.uk/generative-art-experiment-3-5-lord-of-the-targets/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Mon, 30 Jan 2012 21:00:02 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1522</guid>

					<description><![CDATA[void setup () { smooth(); size(500,900); render (); } void render () { fill (0, 0); background(255, 100, 0); for (int i = 0; i &#60; random(50, 200); i++) { drawRings (); } } void drawRings () { float radius = random (20, width/1.4); float x = random (0, width); float y = random (0, [&#8230;]]]></description>
										<content:encoded><![CDATA[<pre class="lang:default decode:true ">void setup () 
{
  smooth();
  size(500,900);
  render ();
}

void render () 
{
  fill (0, 0);
  background(255, 100, 0);
  for (int i = 0; i &lt; random(50, 200); i++)
  {
    drawRings ();
  }
}

void drawRings ()
{

  float radius = random (20, width/1.4);
  float x = random (0, width);
  float y = random (0, height);
  for (int i = 0; i &lt; radius; i++)
  {
    float w = random (50, 100);
    float redness = random (5, 200);

    for (int j = 0; j &lt; w; j++)
    {
      stroke (redness, 0, 0, i);
      ellipse (x, y, i, i);
      i++;
    }
  }
}

void mouseClicked () 
{
  render();
}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/generative-art-experiment-3-5-lord-of-the-targets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generative art experiment 3: Lord of the rings</title>
		<link>https://blog.slightlymore.co.uk/generative-art-experiment-3-lord-of-the-rings/</link>
					<comments>https://blog.slightlymore.co.uk/generative-art-experiment-3-lord-of-the-rings/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Mon, 30 Jan 2012 20:16:53 +0000</pubDate>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[Visual programming]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1510</guid>

					<description><![CDATA[void setup () { smooth(); size(500,900); render (); } void render () { fill (0, 0); background(255, 100, 0); for (int i = 0; i &#60; random(50, 200); i++) { drawRings (); } } void drawRings () { float radius = random (20, width/1.4); float x = random (0, width); float y = random (0, [&#8230;]]]></description>
										<content:encoded><![CDATA[<pre lang="java">void setup () 
{
  smooth();
  size(500,900);
  render ();
}

void render () 
{
  fill (0, 0);
  background(255, 100, 0);
  for (int i = 0; i &lt; random(50, 200); i++)
  {
    drawRings ();
  }
}

void drawRings ()
{

  float radius = random (20, width/1.4);
  float x = random (0, width);
  float y = random (0, height);
  for (int i = 0; i &lt; radius; i++)
  {
    float redness = random (50, 200);
    stroke (redness, 0, 0, i);
    ellipse (x, y, i, i);
  }
}

void mouseClicked () 
{
  render();
}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/generative-art-experiment-3-lord-of-the-rings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generative art experiment 2: Pinkchalk spiral</title>
		<link>https://blog.slightlymore.co.uk/generative-art-experiment-2-pinkchalk-spiral/</link>
					<comments>https://blog.slightlymore.co.uk/generative-art-experiment-2-pinkchalk-spiral/#respond</comments>
		
		<dc:creator><![CDATA[Clinton Montague]]></dc:creator>
		<pubDate>Thu, 12 Jan 2012 14:13:28 +0000</pubDate>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[Visual programming]]></category>
		<guid isPermaLink="false">http://slightlymore.co.uk/?p=1485</guid>

					<description><![CDATA[float oldx = -999; float oldy = -999; float x; float y; int colour = 0; void setup () { smooth(); size (600, 600); drawit (); } void drawit () { background(155); oldx = -999; oldy = -999; colour = 0; int spirals = floor(random(500)); println("drawing" + spirals); for (int i = 0; i &#60; [&#8230;]]]></description>
										<content:encoded><![CDATA[<pre lang="java">
float oldx = -999;
float oldy = -999;
float x;
float y;
int colour = 0;

void setup ()
{
  smooth();
  size (600, 600);

  drawit ();
}

void drawit ()
{
  background(155);
  oldx = -999;
  oldy = -999;
  colour = 0;
  int spirals = floor(random(500));
  println("drawing" + spirals);
  for (int i = 0; i &lt; spirals; i++)
  {

    stroke (colour, 0, random(colour), 10);
    strokeWeight(random(i / 10));
    spiral ();
    colour+=255/spirals;
  }
}

void spiral ()
{
  float variance = random(360);
  float angle = variance;
  float r = 0;
  float endangle = random(1500) + variance;
  float inc = random (1.6) - 0.8;
  while (abs(angle) &lt; endangle)
  {

  x = cos(radians(angle)) * r + random(10);
  y = sin(radians(angle)) * r + random(10);
  if (abs(oldx) &gt; -999)
  {
    line (x + width/2, y+ height/2, oldx + width/2, oldy + height/2);
  }
  oldx = x + cos(radians(angle));
  oldy = y + sin(radians(angle));
  angle+=inc;
  r+=.1;
}
}
void draw () 
{
}
void keyPressed () 
{

  if (keyCode == DOWN)
  {
    drawit ();
  }
  if (keyCode == RETURN || keyCode == ENTER)
  {
    saveFrame ("frame-####.tiff");
  }
}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.slightlymore.co.uk/generative-art-experiment-2-pinkchalk-spiral/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
