Howdy!
I've continued to be quiet recently as I am back at college so a lot of my time is taken trying to understand the material.
This semester I am taking Simulation and Data Mining. The maths is a lot heavier that last semester. Most of it is covered in the form of proofs in the Simulation course. In addition I am re-learning Java programming, pretty much from scratch so when as I understand the maths bits I then try to code it up in Java or implement it in an assignment solution.
We learned about Welford's One Pass Algorithm during the week and it turns out that it should be implemented in an assignment.The algorithm is an efficient way of calculating mean, variance and standard deviation for a sample on the fly.Normally if we were working on paper or in excel we would store the data first and then run back through it, calculating the individual parts of the equation first and then adding those up to get the final answers. This algorithm allows us to compute mean and variance as we iterate through a loop.
The real value from a computer resource point of view is that we don't have the memory overhead of storing the individual bits of the formula first for calculation after.
I wasted a lot of time searching the net yesterday in a hungover state trying to find a way to code it up, as I thought that one of the variables was dependent on the the other two and so would not compute properly. Hopefully this blog entry will help anyone searching for it in plain English.
Standard equations
The fomula for the mean is:
The sum of the individual observations divided by n, the number of observations.
The formula for the variance is:
Standard deviation is simply the square root of s above.
As you can imagine in the above you would have to store values first, then send them through a loop to store the individual differences, and then finally do aggregated calculation. Very costly in terms of memory and code.
Welfords One Pass Algorithm
Welfords algorithm gets around this by calculating the minor changes on the fly. This removes the need to store data and simply looks at the delta's.
The algorithm is below; I have used a general notation which you can apply to whatever language you need.
int n = 0;
double xbar = 0.0; //mean
double var = 0.0; //Variance
double x = 0.0; //Next Observation
double d = 0.0; // Difference
For every observation:
{
x = getNextData();
n++;
d = x - xbar;
v = v + (d^2);
xbar = xbar + d/n;
}
v = v/n ***
*** I made this correction after trying to run this algorithm a second time on a different machine.
One problem I had was that if you are working through an array, the first array index is 0, which caused the entire equation to return NaN; but when I added 1 to it to change the indexing it seemed to work.
You can also calculate the covariance quite easily as well
Covariance is simply (the sum of (x*y) - (the sum of x times the sum of y) / n)/n-1
You can collect x*y as you iterate through the loop
sum of X times sum y can be calculated after the fact!
Sunday, February 19, 2012
Thursday, December 15, 2011
Exam update
Ok so I haven't blogged in a long time!
Have my first exam (Project management and Decision analytics) tomorrow and then probability and stats on Monday then I am free till the new year.
Will try and blog something worthwhile over Christmas!
Have my first exam (Project management and Decision analytics) tomorrow and then probability and stats on Monday then I am free till the new year.
Will try and blog something worthwhile over Christmas!
Friday, August 5, 2011
European Crisis Part 1
Just heard a report that Sarkozy is having separate meetings with the Germans and the Spanish over the next few days.
Now I understand that this is probably the way these things get done and maybe Sarkozy is playing the facilitator, but to my mind this send a message that the solution is purely being driven by Germany and France and that the other countries are waiting to be told what to do.
If we are trying to sell the idea of Europe as a unified state that is not purely driven by a Franco-Saxon agenda then this is not the way to go.
Now I understand that this is probably the way these things get done and maybe Sarkozy is playing the facilitator, but to my mind this send a message that the solution is purely being driven by Germany and France and that the other countries are waiting to be told what to do.
If we are trying to sell the idea of Europe as a unified state that is not purely driven by a Franco-Saxon agenda then this is not the way to go.
Wednesday, June 29, 2011
Big day today for Europe - Greek Austerity Vote
Its a big day today for Europe.
I know its a big day for Greece but its potentially a pivotal day for Ireland as well.
If the Greeks do not vote through the austerity measures then they have as good as defaulted. At that point it makes more sense for them to leave the single currency. That way they can set their interest rates, devalue their currency and address some of their problems without the straightjacket they are in now.
Notice I say leave the single currency. Their is no pressure on them to leave the common market.
If they do vote in favor then I can only imagine that the streets of Athens would be a no-go zone for the next week.
For Ireland ( a country that was more than willing not to blindly accept Europe in two referendums) this could be a big moment. If Greece defaults then we will be in the firing line along with Portugal as the next to go down.
And with Greece blazing a trail (particularly if they leave the single currency)then we have a precedent to play with. It could strengthen our bargaining position against Europe and force the ECB into accepting a policy of restructuring. Of course if we are allowed then we may be in technical default as well.
If Greece accepts the Austerity measures then we will continue to kick the can down the road, but I don't see how it helps all of us in the long run. The problem remains in place, to be born by taxpayers that are rapidly running out of patience. If Greece does accept Austerity then it will be at the expense of voters in other countries; and those whose economies are relatively sound but experiencing cuts and unemployment may lose patience with the process. Indeed that could easily become an election platform for the opposition.
Ending this post prematurely as the vote is on right now: 20 For / 18 Against so far!
Update: Motion in Favour passed by 4 votes. Will be interesting to see the counterfactuals in years to come
I know its a big day for Greece but its potentially a pivotal day for Ireland as well.
If the Greeks do not vote through the austerity measures then they have as good as defaulted. At that point it makes more sense for them to leave the single currency. That way they can set their interest rates, devalue their currency and address some of their problems without the straightjacket they are in now.
Notice I say leave the single currency. Their is no pressure on them to leave the common market.
If they do vote in favor then I can only imagine that the streets of Athens would be a no-go zone for the next week.
For Ireland ( a country that was more than willing not to blindly accept Europe in two referendums) this could be a big moment. If Greece defaults then we will be in the firing line along with Portugal as the next to go down.
And with Greece blazing a trail (particularly if they leave the single currency)then we have a precedent to play with. It could strengthen our bargaining position against Europe and force the ECB into accepting a policy of restructuring. Of course if we are allowed then we may be in technical default as well.
If Greece accepts the Austerity measures then we will continue to kick the can down the road, but I don't see how it helps all of us in the long run. The problem remains in place, to be born by taxpayers that are rapidly running out of patience. If Greece does accept Austerity then it will be at the expense of voters in other countries; and those whose economies are relatively sound but experiencing cuts and unemployment may lose patience with the process. Indeed that could easily become an election platform for the opposition.
Ending this post prematurely as the vote is on right now: 20 For / 18 Against so far!
Update: Motion in Favour passed by 4 votes. Will be interesting to see the counterfactuals in years to come
Tuesday, June 21, 2011
Hello to my Iranian readers!
سلام
Apparently I have had some page views from Iran, so welcome to the blog, and I look forward to any feedback you might have!
regards
Damien
Apparently I have had some page views from Iran, so welcome to the blog, and I look forward to any feedback you might have!
regards
Damien
Repossessions
Was Listening to Liveline last week
A man who had his house repossessed has vowed to picket the house for the rest of his life, presumably unless he is reinstated into the property on reasonable terms.
Part of his reasoning is that he should never have been given the mortgage in the first place. Thats quite a true statement. I wonder if at the time, had he been turned down for a mortgage, would he have gone on Joe Duffy to bemoan the fact that he couldn't get financing.
Hearing the phrase, "they shouldn't have given me the money" hardly ignites sympathy in peoples minds, but it is nonetheless a correct statement; so why did they? Our personal solvency laws provide that the borrower remains liable for the full value of the mortgage, even if the house is sold.
In the US the borrower can hand back the keys which closes out the mortgage. This should mean that borrowers would be more discerning as they would stand to lose money as well.
Here the borrower is on the hook for the full amount, which means that the lender can do less due diligence and still make a reasonable assumption that they will get back the bulk of their money. In addition, they have an incentive to sell the house and realize the funds ASAP, rather than hold out for an offer that is a reasonable market price, which would reduce some of the outstanding debt of the borrower.
We are going to see more of this behavior as the number of repossessions rise, not less. There is a substantial danger that we will marginalize those people and their children and in doing so reduce society's respect for personal property.
A man who had his house repossessed has vowed to picket the house for the rest of his life, presumably unless he is reinstated into the property on reasonable terms.
Part of his reasoning is that he should never have been given the mortgage in the first place. Thats quite a true statement. I wonder if at the time, had he been turned down for a mortgage, would he have gone on Joe Duffy to bemoan the fact that he couldn't get financing.
Hearing the phrase, "they shouldn't have given me the money" hardly ignites sympathy in peoples minds, but it is nonetheless a correct statement; so why did they? Our personal solvency laws provide that the borrower remains liable for the full value of the mortgage, even if the house is sold.
In the US the borrower can hand back the keys which closes out the mortgage. This should mean that borrowers would be more discerning as they would stand to lose money as well.
Here the borrower is on the hook for the full amount, which means that the lender can do less due diligence and still make a reasonable assumption that they will get back the bulk of their money. In addition, they have an incentive to sell the house and realize the funds ASAP, rather than hold out for an offer that is a reasonable market price, which would reduce some of the outstanding debt of the borrower.
We are going to see more of this behavior as the number of repossessions rise, not less. There is a substantial danger that we will marginalize those people and their children and in doing so reduce society's respect for personal property.
Friday, June 3, 2011
Mays Beer Post
Its a cracking day out there and i've been stuck inside so I wandered up to Sweeneys Off Licence in Phibsboro to pick up some beers for June, only to realise I hadn't posted in May!
A salute to Polish Beers!
I was in Poland during May so I decided to do a special bit on the country's beers. I started early with Jboy and went through 3 of the better known ones here. This was actually a good idea as the tipple of choice over there was Vodka, and while it was excellent, its hard to write a review after 3 of them
Lech 5.2%
Lech is the first beer I'm trying and I have to say I'm quite impressed! It pours with a golden colour and a head that quickly dissipates. The first impression is crisp and mild honey tones. It finishes with a nice smoky flavour. I always thought Lech was going to be a very generic beer but this would make a good alternative to Heineken
Zywiec 5.6%
Zywiec is more golden in colour than Lech and far less carbonated. I can only describe the aroma as mealy. If I got this from a tap I would even suspect it was slightly off but I am reliably informed this is the way it should smell. Flavour wise it was more hoppy ad bitter than Lech and with a very dry finish
Tyskie 5.6%
Same as the other two Tyskie shows a classic golden colour but the flavour has a lot more bite. There was even a faint white wine smell that I was unable to shake. Quite Bitter
Bierhalle Pils 5.2%
This is the only beer that I actually properly tasted in Poland. The beer hall was in a shopping area in Lodz. They Brewed 3 of their own beers with more to come and even had waitresses dressed in the German beer hall style. Since i was with a group the beer came in a barrel that could be poured by the customer which was a nice touch!
The beer itself was slightly cloudy with a lovely light honey scent. The flavour relfected this with additional corriander and smoky tones.
Also Ran
After I came back I was pretty well behaved for the rest of the month, but I did try a few more:
Flying Dog Double Pale Ale
Flying Dog are going up in my opinion. They modelled themselves after the writings of Hunter S. Thompson and the artwork on the label is always psychadelic.
The double pale ale is a belgian style, with a very high alcohol content. It would be similar to Delerium Nocturnum in flavour. Amber in Colour and a wonderful berry smell. The flavour is a mixture of hops and Citrus. Definetly worth a look but one at a time!
Raging Bitch IPA
Another Flying Dog offering and an IPA to boot. I am on record as saying I don't like IPA's but after a good experience with this and Jagged Edge I am going to give this style another go. This one poured a lovel Amber colourand had a bitter but orangey finish. Quite dry as an after-taste.
Jagged Edge IPA
The final taste for May was Jagged Edge IPA. The Amber colour was once again in evidence but with a less pronounced bitter scent and flavour. The finish was citrusy and I find this style of Fruit flavoured finish makes an IPA more attractive.
Just a reminder to anyone who is reading the blog.
Deveneys in Dundrum is running its Beer Festival again this year in the Tripod. Tickets are on sale now so go buy them, its a great festival and a fantastic way to expand your knowledge!
Official Festival Site
Ruth Deveneys Beer Blog
A salute to Polish Beers!
I was in Poland during May so I decided to do a special bit on the country's beers. I started early with Jboy and went through 3 of the better known ones here. This was actually a good idea as the tipple of choice over there was Vodka, and while it was excellent, its hard to write a review after 3 of them
Lech 5.2%
Lech is the first beer I'm trying and I have to say I'm quite impressed! It pours with a golden colour and a head that quickly dissipates. The first impression is crisp and mild honey tones. It finishes with a nice smoky flavour. I always thought Lech was going to be a very generic beer but this would make a good alternative to Heineken
Zywiec 5.6%
Zywiec is more golden in colour than Lech and far less carbonated. I can only describe the aroma as mealy. If I got this from a tap I would even suspect it was slightly off but I am reliably informed this is the way it should smell. Flavour wise it was more hoppy ad bitter than Lech and with a very dry finish
Tyskie 5.6%
Same as the other two Tyskie shows a classic golden colour but the flavour has a lot more bite. There was even a faint white wine smell that I was unable to shake. Quite Bitter
Bierhalle Pils 5.2%
This is the only beer that I actually properly tasted in Poland. The beer hall was in a shopping area in Lodz. They Brewed 3 of their own beers with more to come and even had waitresses dressed in the German beer hall style. Since i was with a group the beer came in a barrel that could be poured by the customer which was a nice touch!
The beer itself was slightly cloudy with a lovely light honey scent. The flavour relfected this with additional corriander and smoky tones.
Also Ran
After I came back I was pretty well behaved for the rest of the month, but I did try a few more:
Flying Dog Double Pale Ale
Flying Dog are going up in my opinion. They modelled themselves after the writings of Hunter S. Thompson and the artwork on the label is always psychadelic.
The double pale ale is a belgian style, with a very high alcohol content. It would be similar to Delerium Nocturnum in flavour. Amber in Colour and a wonderful berry smell. The flavour is a mixture of hops and Citrus. Definetly worth a look but one at a time!
Raging Bitch IPA
Another Flying Dog offering and an IPA to boot. I am on record as saying I don't like IPA's but after a good experience with this and Jagged Edge I am going to give this style another go. This one poured a lovel Amber colourand had a bitter but orangey finish. Quite dry as an after-taste.
Jagged Edge IPA
The final taste for May was Jagged Edge IPA. The Amber colour was once again in evidence but with a less pronounced bitter scent and flavour. The finish was citrusy and I find this style of Fruit flavoured finish makes an IPA more attractive.
Just a reminder to anyone who is reading the blog.
Deveneys in Dundrum is running its Beer Festival again this year in the Tripod. Tickets are on sale now so go buy them, its a great festival and a fantastic way to expand your knowledge!
Official Festival Site
Ruth Deveneys Beer Blog
Subscribe to:
Posts (Atom)









