Saturday, 13th March, 2010

Musically Inclined

So this particular week has been an odd one. Hence a diversion into a mad world.

On the one hand, I’m getting nitty-gritty in my course, writing a lexical analyser in C, bashing my head against Haskell, and Mathsing it up in general during the day.

But by night… Music! Lots of music! Firstly, I picked up a new guitar from The Guitar Shop in Beverley. I bloody love it, Vintage V300-MH. Sounds gorgeous, and the price ain’t to be sniffed at.

I showed my face for the first time at Band Soc here at uni. Had a great time jamming with a couple other folks, listening to some pretty cool improvised stuff.

Then I went to two gigs: Grammatics at StereoYork. I’ve already seen Grammatics once, so I knew I was in for a good night. I’ve liked their music from the first chord I heard them play. But their new material is brilliant. I’m itching to get my grubby little mitts on their new album, when ever it comes out. Sadly, I do not recollect their support band, but they definitely put on a show and a half!

Next one was in Derwent Bar at the Uni, Who had a good line up, and the gig was put on by BandSoc

Animals in Dangerous Situations. All I could do is laugh, not at them, but with them. Their music was very much like Flight of The Concords, but so explicit and obscene it just got more immature and more funny.

Man is Slapped was one man with a keyboard and a few other assorted insturments. Definitely not my usual style, and I was all ready to be disappointed. Instead I was totally blown away. Loved every second of his set.

And finally, the head liners were Ah Good The Sea. They are very much my style of music. Thoroughly enjoyed it. It was quite odd to think to myself “They’re vaguely reminiscent of Radiohead…” Only for not 5 minutes later the drummer to give up drumming and do a Radiohead cover, before taking his place back behind the drums.

Long story short, I’d recommend seeing the bands mentioned here.

Thursday, 4th March, 2010

Faffing with Haskell

Recently, there’s been a peak in the relative interest in languages such as Haskell, Scala, Erlang and Lisp-Like languages. Primarily because there’s a fresh interest in functional languages in general. Obviously, I thought I’d give it a poke.

Personally, I thought it would be a good idea to try and do some Eulering in it. It’s list comprehension syntax is very close to that of Python’s, however, it’s type strictness seems a little extreme at this point. Ahh well, growing pains. Where would we be without them?

Problem 1

Simplistic and easy:

sum [n | n <- [1..999], n `mod` 3 == 0 || n `mod` 5 == 0]

Very, very similar to the Python variation.

Problem 5

Once again, a very simple problem, and a very similar solution to the Python solution.

foldr (\a b -> (a*b) `div` (gcd a b)) 1 [1..20]

Problem 20

Decided to not try to get around the type system in order to do this one. I decided to actually form a list of integers from an integer the “correct”, mathematical way; as opposed to bodging my way through a type system.

factorial :: Integer -> Integer
factorial n = product [1..n]
	
listFromInteger :: Integer -> [Integer]
listFromInteger 0 = []
listFromInteger n = (n `mod` 10) : listFromInteger ((n - (n `mod` 10)) `div` 10)
	
main = do
    putStrLn (show (sum $ listFromInteger $ factorial 100))

I swish my mathematical-ness at you!

Problem 29

Once again, vastly similar code…

import Data.Set
	
exponents :: (Integral a) => a -> Set a
exponents n = Data.Set.fromList [(\a b -> a^b) a b | a <- [2..n], b <- [2..n]]
	
main = do
    putStrLn (show (Data.Set.size $ exponents 100))

Meh.

Problem 45

Yet again, nearly identical code. Runs marginally faster, if my memory serves me well.

import Data.Set
	
hexs = Data.Set.fromList [(\n -> 2*n*(2*n - 1)) n | n <- [1..1000000]]
pent = Data.Set.fromList [(\n -> n*(3*n - 1)) n | n <- [1..1000000]]
	
main = do
          putStrLn (show (Data.Set.map (`div` 2) (Data.Set.intersection hexs pent)))

Only major difference to note here is that a set is not a built in primitive, but found in a library. Not really a major issue.

Done! :-D

Sunday, 21th February, 2010

Project Euler Problem 56

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

Considering natural numbers of the form, ab, where a, b <=100, what is the maximum digital sum?

Noting that Python has pretty swift large number handling, and built in sets, this is one of the easier ones to bash out. Seriously quick and hacky:

exponents = set()
# Generate a set of all the exponents
for a in xrange(101):
    for b in xrange(101):
        exponents.add(a**b)  
	
max = 0
# Find the maximum sum of the digits.
for exp in exponents:
    sumi = sum([int(x) for x in str(exp)]) # sum of digits
    if sumi > max:
        max = sumi
	
print max

It’s not pretty, it’s not quick, and there’s very little actual maths behind it, but it works in an acceptable time.

tuna@Pythagoras:~/Code/Python/Euler$ time python euler56.py 
XXXXXX
	
real	0m0.680s
user	0m0.604s
sys	0m0.004s

Done! :-D

Tuesday, 16th February, 2010

BBC News Statistics

Recently, I’ve begun to notice some deficiencies with the reporting of “studies” and “surveys” by the BBC. I have never taken any of the statistics or probability theory courses here at university, so in effect, I am a layman on these matters. Regardless, I shall post my opinions on these issues.

Violence against women is justified, says pupil study

Page last updated at 14:59 GMT, Monday, 15 February 2010 According to the BBC News Website, at this time of writing.

It’s a good headline, bold and shocking, it gets your attention and will probably trigger a reaction in any one you read it to. But not that informative.

I’ll get the non-stats criticisms out of the way very quickly. The article only gentle implies that it is possible to give reasons for doing an unreasonable action. Reasons, as given by real people are rarely reasonable, and almost always biased. Ignoring this little issue, we’ll move on.

The majority of the pupils said it was justified if the woman had an affair, or if she was late in making the tea.

The “majority” 51% is a majority. If there are 4 choices, only 26% is a majority. Granted, in this case, it was essentially a dichotomy; justified or not justified. Still, they’re not actually representing their data here. They’re making very ambiguous statements, and not really doing anything about it.

The study by a researcher from Edinburgh Napier University …

This must scream out to most people that this article must be taken with a grain of salt. A single researcher, at a single institution. I see the peer review a mile off, the control groups and the repeated surveys in other major cities. That’ll give it the credibility needed to be published to the entirety of the public. That is, published by a news organisation that many hold in very high esteem, and take a good majority of what is published as fact.

The research involved 89 primary seven children at five Glasgow primaries.

89 Children? Wolfram|Alpha’s current population statistics pin Scotland’s population at 5.17 million people. I do not know what portion of them are children, but this is a painfully small sample size, in a very localised area.

The author of the article neglects to say how deprived the areas near the schools are, if they’re comprehensive or public, co-educational or other pertinent facts that may help the reader form a reasoned judgement. Simplistic “facts”, held up to generate shock.

Men ‘need better-fitting condoms’

Page last updated at 01:23 GMT, Tuesday, 16 February 2010 According to the BBC News Website, at this time of writing.

Simple headline, and directly quotes from the research. Doesn’t appear to be crying out for attention.

Men are twice as likely to take the condom off midway through sex due to a poor fit, a poll of 436 in Sexually Transmitted Infections journal reveals.

Due to poor fit? Who determines what is poor fit? Can a man who is not thoroughly educated in the matters really deduce what constitutes a poor fit? Either way, it’s not bad, but it does leave some questions unanswered.

Sexual Transmitted Infections Journal is a peer-reviewed paper, so if they published this paper, there must be some merit to it. That is to say, this article, which is based on the paper published in the journal, must inherit some of the credibility. Huzzah, the BBC doing it right.

Sadly, the BBC does not do it right too much. Although they acknowledge at the beginning of the article to having a sample size of 436, which is tiny, they still proceeds to publish this article without too much worry as to the veracity of the source of the information.

Women say some rape victims should take blame - survey

Page last updated at 14:04 GMT, Monday, 15 February 2010 According to the BBC News Website, at this time of writing.

Wow. That’s an attention seeking headline if I ever saw one. At least they note it’s a survey, not a study or portray it as fact.

Most of the start of the article is simply raw summations of the figures dumped, for example:

The main reasons were being too embarrassed or ashamed (55%), wanting to forget it had happened (41%) and not wanting to go to court (38%).

This would not be to bad in and of itself, however, there’s little actually said at the start of the article about the source of these figures. You have to dig a tiny bit deeper into the article. Specifically, the crucial information is given in the 17th paragraph. Given that a lot of people will simply glance at the headline, and the first few paragraphs, this really isn’t good enough. There’s little possibility of the casual reader being able to make a reasoned judgement as the the reliability of these numbers.

The online survey, titled Wake Up To Rape, polled 1,061 people aged 18 to 50, comprising 712 women and 349 men.

Most people will know that online surveys are self-selecting by their nature. You choose to fill out the survey, you choose because you have something to say on the subject. Perhaps those who found the questionnaire were rape victims, many rape victims do blame themselves before seeking professional help. Many people who were unaffected by rape would’ve simply passed it by. In the process, taking valuable data away from the survey.

Also, they have a slightly skewed result set. The results for those from women would be more reliable than those for me, simply because more women answered. This could lend itself to more views about rape from women being put forward.

Once again the sample size demon rears it’s ugly head. 1,061 people in a country of over 60 million is not an acceptable sample size. Especially when combined with the self-selecting nature of the survey, and the skew in the genders.

An Amnesty International report five years ago found that a significant minority of British people laid the blame for rape at victims themselves.

Once again, the BBC using ambiguous language for what appears to be simple shock value. More so because of the prevalence of data earlier in the article. How large must a minority be to be significant? 1%? 5%? 15%?

The rest of the article is simply quoting spokespeople for various government institutions.

Survey Complete!

So, I’ve done my survey of some relevant articles on the BBC News website. Given that BBC News is using similar tactics, I’ll use there here:

A study, published earlier today by a largely unverified source states that 100% of BBC News articles have statistical flaws in their data.

Only 33% of the articles showed any real statistical merit, but those ones were correlated with the articles which had non-provocative headlines.

Almost all of the articles used statistics from a very small sample size.

By the way, the sample size was 3, self-selecting articles on the BBC News Website.

Do you get it now BBC News? Misusing statistics is not big, it’s not hard, and it’s the opposite of clever. Especially when it appears to be primarily based on drawing traffic to your site through shock-tactics.

Oh, and cite your sodding sources correctly next time. Googling for “Sexually Transmitted Infections Journal” is not cool.

Done! :-D

Saturday, 21th November, 2009

Messing with Omegle

Most of you probably know what Omegle is. It’s a chat site. But there’s a difference. You’re connected to a random person, and it’s completely anonymous.

One past time I’ve had of late is getting some of the creepiest internet folk to talk about all sorts of insane stuff.

A fine example happened last night

Connecting to server…
You’re now chatting with a random stranger. Say hi!
Stranger: i wanna fuck you in the ass baby
You: Have you tried taking an English class?
You: I’m quite serious, you can’t form even simple sentences.
Stranger: well
Stranger: all i know is fuck and ass
Stranger: so i put them together
You: Do you see what I’m talking about? No punctuation, grammar is all wrong. You are saying sentence fragments.
Stranger: I can put together whole sentences, but why should i bother?
Stranger: dick and ass
You: You should bother because it makes it easier to read for the other person. Wouldn’t you like to convey your wish for anal sex more clearly?
You: You would have a much higher success rate if you were clear.
Stranger: If we had something meaningful to talk about i would make an effort
Stranger: dot
You: We do have something meaningful to talk about! Your abuse of the English language.
Stranger: language is just a way to get ideas across
You: We could talk about anything! And going to English classes you’d meet a lot of ladies. Many of whom may like anal sex.
Stranger: language is flawed
Stranger: and weak
You: This whole universe is flawed. Do you see humanity just giving up?
Stranger: you are missing the point mr language barrier
Stranger: we are heading into telepathy
Stranger: and collective consciousness
Stranger: do you really think grammar will stop us
You: No, but our thoughts will have structure. That will help us convey our ideas from one individual to another.
You: In general, one thought naturally leads onto the next. There’s structure to it, it’s a form of grammar, despite being very loosely structured.
Stranger: nah
Stranger: thoughts arent logical
Stranger: unless they are
You: Mine are very logical. One thought leads naturally to the next.
Stranger: but logic is just one side of it
You: I could trace my execution perfectly.
Stranger: u sure could
Stranger: with male straight lines
Stranger: you need intuition for it to work
Stranger: naturally
You: Intuition is merely an illusion, caused by thoughts that you were unaware of being brought into your concsiousness.
Stranger: lol
Stranger: enjoy 3d
You: What is 3d?
Stranger: the third dimension
Stranger: look man
You: What about the third dimension? And why would I enjoy it?
Stranger: you have this self righteous arrogance about you
Stranger: you obviously know everything
Stranger: so why do i need to explain?
You: I do not know everything. I do not know enough.
You: Therefore, there are things that will need explaining to me.
You: Who better to explain them than you?
Stranger: and how do you know that you dont know enough
Stranger: logic?
You: If I knew everything, I would know that I know everything, since that would be in the set of things that I know.
You: I do not know that I know everything, hence it is not in the set of things that I know.
Stranger: is that logic?
You: Most likely.
Stranger: the language barrier will be broken
Stranger: but i see what you mean with the importance of spelling and grammar
You: That maybe true, however, the sheer
You: Sorry, I was retyping that last sentence.
You: The sheer volume of thoughts could have a negative effect on some individuals, causing psychological problems, or even physical problems within the brain.
You: Which could, in turn, lead to suicide or simply death.
You: Even if the “language barrier” is broken, it could be a catastrophic event.
Stranger: that is such a scientific way to look at it
Stranger: 0% spirituality
Stranger: consciousness = brain?
You: In effect, the concsiousness is an effect of the interplay of chemicals and neuron impluses in the brain.
Stranger: that is true
Stranger: but there is also a soul
Stranger: brain is part of the body
You: But there is no evidence for a soul.
Stranger: wait ill type this out for ya
You: I will wait.
Stranger: There are many religions that see the soul or consciousness as eternal and not something that dies with the body. The brain can be seen as sophisticated machinery which consciousness operates through.
You: However, no religions; or any one else for that matter; have provided compelling evidence for the soul, or for concsiousness being distinct from a person’s brain.
Stranger: the ancient egyptians have this in their hieroglyphs.
Stranger: the chakra system
Stranger: do you believe in reincarnation?
You: Reincarnation is an odd thought. The probability of my current “being” being reconstructed in it’s current state at any point in the future is almost infinitesimally small. However, if this current universe lasts long enough, then that probability beings to increase.
Stranger: why would it increase depending on the age of the universe?
You: So in a way, I do think that it’s possible, but very unlikely. Also, this universe is thought to be closed.
You: Well, let’s say the probability of me not reincarnating on a given day is x/(x+1), where x is a very, very large number
Stranger: again logic
You: The more days that progress, that will actually tend towards being more probably.
You: Apologies, I meant probable.
Stranger: life isnt an equation
You: Logic is the only tool we have to attack an issue of this magnitude
Stranger: or not just an equation
Stranger: we have intuition as well
You: But as I’ve previously said, I don’t think that intuition is anything real. Simply thought processes which we are not concsiously aware of until they’re required.
Stranger: yeah well put, and can be seen like that
Stranger: or are you just filling in the blanks with logic
You: The only way we can tackle these problems reasonably is to think about them very carefully. Take what we know to be true and go from there. One cannot even be sure that one’s own eyes exist!
Stranger: everything that exists exists
You: That is true; but it is also a tautology.
Stranger: it doesnt matter
You: It does matter, it’s an example of an irrelevant statement. For example, “That dog is a dog.”, or “The white paint is white”.
You: It adds no previously unknown knowledge to the system.
Stranger: everything is just as it is, the way that it is
You: At this current time, yes that is true. However, how do you know that “everything” exists?
Stranger: everything exists because i know that the universe is a big place with loads of things in it
You: How do you know that this universe is not simply a simulation? That you are not just a “brain in a vat” so to speak?
Stranger: well it kinda is
Stranger: at least here
You: Indeed, but what about the rest of our environment. How do you prove that everything is not simulated?
Stranger: you probably have a perfectly logical explanation for everything, i could too man. i just feel like ive surpassed that. feels like going back to the good old days
Stranger: well you cant
Stranger: or you dont have to
Stranger: because there is only one reality but infite ways to perceive that one reality
You: I don’t have a logical explanation for very much, actually. I would really like to have an explanation for a lot of things.
You: But we have no way to test that we have only one reality.
Stranger: you dont have to test it
Stranger: my intuition tells me that its true
You: We, as a species, limited by our reality, have no way to test it.
You: The limitations of our reality stop us from testing reality.
Stranger: if you could see the one reality through gods eyes then thats the test of reality
Stranger: some things are just universal truths
You: Some things are universal truths, but there are unprovable statements.
You: Within any system powerful enough, there exist unprovable statements within that system.
You: For example, the assertion that there exists a God. The assertion that there is only one reality. The assertion that this reality is real, not simulated.
You: The assertion that anything other than one’s own thought process exists.
Stranger: everyone has a unique reality tunnel
You: Everyone has the potential to percieve reality differently, assuming that they exist.
Stranger: you know about synchronicity?
You: From en.wikipedia.org: “Synchronicity is the experience of two or more events that are causally unrelated occurring together in a meaningful manner. To count as synchronicity, the events should be unlikely to occur together by chance.”
Stranger: yupp
Stranger: you ever experience it?
You: You mean, a coincidence?
Stranger: nah i mean a synchronicity
You: I’m fairly sure that I must’ve at some point, but I can’t think of a specific example at this time.
Stranger: you know when its a synchronicity
You: From the Wikipedia definition, it seems pretty close to being a coincidence.
Stranger: yeah its close
You: “Coincidence is the noteworthy alignment of two or more events or circumstances without obvious causal connection.”
Stranger: its not coincidence man
Stranger: it has to do with instinct and intuition
Stranger: ah u cant even explain this, just trust me, dont put the in teh same category
You: I will be away for a short while.
Stranger: its like magic
Stranger: ok
You: So, what actually makes an event synchronicity, as opposed to coincidence?
Stranger: well you know it, since there is that connection to it in a way. it is just like noooo waaay.
Stranger: i dont even know how to explain that
You: So, any two events could be synchronicity, given a high enough improbability?
You: As long as those two or more events are ‘meaningful’ ?
Stranger: yeah, usually something that you are thinking and then that happens
Stranger: its like a continuation in the external world of your internal thought processes
You: And it couldn’t be that you were thinking about something, and hence your thought process was sensitized to that thing, so you were simply more likely to notice it?
You: For example, thinking about rabbits, then seeing a rabbit.
Stranger: nah
Stranger: its not
Stranger: its more like
You: Or must it be signficantly more improbable than that?
Stranger: you are starving and need food
Stranger: you are thinking of how to get food to survive
Stranger: and then you just sit there and think food food
Stranger: and the cash machine breaks down and a 100 dollar bill pops out
Stranger: and you are the only one there
Stranger: and it happened just as you looked at it
Stranger: its like that
You: So what does a chance happening actually prove? And either way, even if you weren’t thinking about food, and a $100 bill came out of the ATM, wouldn’t you be surprised regardless?
Stranger: dont overanalyze my poor example
Stranger: it proves that there is something more than logic at work
You: That’s not true. There could be a perfectly logically explanation for something implausible happening, you just happened to walk past the ATM at the correct time.
Stranger: yupp
Stranger: and the universe gave you exactly what you needed
Stranger: the universe loves you
You: What about when the universe takes something away that you need?
Stranger: then there is a lesson
You: Through some highly unlikely improbable circumstance, that has nothing to do with you, or anything you’ve done.
You: That is to say, there was nothing you could’ve done in advance to stop it.
You: Would there really be a lesson in bad luck?
Stranger: thats too small
Stranger: and you know it
You: How do you mean too small?
Stranger: something was taken away for some reason
Stranger: well not just bad luck
Stranger: bad luck doesnt exist in this version of reality :P
Stranger: everything is just the way it is supposedto be all the time
Stranger: but there are lessons in everything, idk man. im wading up to my neck through this
You: So, for example, you’re away from home, all the way around the world. And a meteor hits your house, and efectively destroys the city you live in. There’s a lesson in there? I’d call that pretty big example.
Stranger: going nuts? nah, duality
Stranger: well, maybe it was time for you to get a new body :P
Stranger: i dont know man. i dont have all the answers
Stranger: i know some crazy voodoo shit
You: I think that the universe having a concsiousness that is concerned with us to be highly unlikely. We’re insignificant.
Stranger: according to this theory, we all made the universe together
Stranger: not just humans
Stranger: feedback loop
You: So, you’re saying our concsiousness’ combined created this universe, and not that our concsiousness’ simply reside in it.
Stranger: we create the reality we livein and the reality creates us
Stranger: the more we become in touch with it
Stranger: the better reality is at knowing what we need
Stranger: and the faster it manifests in our reality
You: But one must’ve existed before the other. The loop would never start if one did not exist.
Stranger: or it was wholebut got divived
Stranger: or the universe wanted to experience itself
Stranger: or we are all one consciousness experienceing itself subjectively
Stranger: theres no such thing as death life is only a dream and we are the imagionation of ourselves
Stranger: heres tom with the weather
You: I like the ending of that set of fragments.
Stranger: hehee
Stranger: they are fractals now woooooooooop
Stranger: sry man i gotta sleep
Stranger: its 3 in the morning hre
You: 02:14 here
Stranger: hehe
Stranger: where u from?
You: And I do like fractals.
You: I am in the UK
Stranger: swedenfag here
Stranger: fractals in nature
You: Mountains, clouds, fern leaves, acorns. There’s a lot of examples of fractals in nature
Stranger: into the microcosm and the macrocosm
Stranger: fractals everywhere
You: Each galaxy is like it’s own fractal. Lots of solar systems orbiting a black hole. Each solar system, lots of planets, planetoids orbiting a sun. Many planets have moons orbiting them.
Stranger: i think that consciouensess is a fractal
You: How so?
Stranger: well since we are eternal and every point in our timeline is the center or the present for us
You: But we don’t know if we’re eternal. We could be closer to one end of our line than the other.
You: But if we are truly eternal, than your statement is correct, but I don’t think that makes it a fractal.
Stranger: anything you do changes the fractal
Stranger: man, i gotta say
Stranger: you are a very intelligent guy
Stranger: me not so much
Stranger: had a very nice talk with you :)
You: It was nice to talk to you too.
You: I do need to sleep soon too, I have to be up early today.
Stranger: whats your name?
You: My name is Dan, yourself?
Stranger: Nikola
You: That’s a pretty awesome name, if I do say so myself.
Stranger: oh well, enjoy those trippy synchronicites xD thx
You: I’ll try, though I’m not nearly as spiritual as yourself. :-)
You: Good night, sir or madam.
Stranger: in l’akesh
Stranger: (you are another me)
Stranger: night
Your conversational partner has disconnected.
or save this log or send us feedback.

fun, eh? Assfuckery to spirituality. I am good!

Done! :-D