Monday, July 07, 2008

Thoughts on Cuba

1. You can graph a countries poverty versus its populations niceness based on the number of hats people wear when they return.



2. The Chinese are coming. My hotel was full of Chinese business people. They spoke fluent Spanish. Chinese people are investing in Cuba and are serious about the country. All the hotel staff came out to bid goodbye to a visiting Chinese MP. Cuban security were present, hawkish men with identical cream shirts. I saw no Chinese security. This shows how comfortable/safe the Chinese politician felt in Cuba.



3. Cubans are the only people on earth who clap when their plane takes off. Other people clap when the plane lands safely but they are just glad to get out.

Thursday, July 03, 2008

Delta Airlines needs a Splashscreen

Delta have a little linux computer for each seat that shows films and plays games and such. These go tits up often. When they do you get to see the Linux boot process for a few minutes. On my last flight you got to watch it over and over again all flight.
Instead of showing the boot process Delta should show a splashscreen with some sort of image/ad.

It is fairly easy to do this . Of course they should actually stop linux from freezing and such but this is a simple change.

Guinness and Red Bull

The bubonic plague wiped out 1/3 of Europe's population but the depopulated continent meant that peasants had more bargaining power and this hastened the end of the feudal system. So in spite of nearly destroying civilisation and killing millions in crippling pain the black death had some beneficial effects.

I cannot say this about the cocktail of Guinness and red bull.



This is now pretty much the national drink of Jamaica. The barman did not bat an eyelid, or try drive a stake through my pitch black heart, when I ordered it. There are even songs about it



I am not going to even describe what this tastes like. I think if I had gone up and grave robbed an Indian burial ground I would have caused less desecration.

Tuesday, June 10, 2008

Gardner's constant

Gardner's constant is the transcendental number e^{\pi \sqrt{163}}. It is given as the integer 262,537,412,640,768,744 in his April 1975 Scientific American Column. So Lets see what programming langugaes have the accuracy to give this result?

So with these figures what will your programming languages will give Gardner's constant?

e=2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354021234078498193343210681701210056278802351930332247450158539047304199577770935036604169973297250886876966403555707162268447162560798826517871341951246652010305921236677194325278675398558944896970964097545918569563802363701621120477427228364896134225164450781824423529486363721417402388934412479635743702637552944483379980161254922785092577825620926226483262779333865664816277251640191059004916449982893150566047258027786318641551956532442586982946959308019152987211725563475463964479101459040905862984967912874068705048958586717479854667757573205681288459205413340539220001137863009455606881667400169842055804033637953764520304024322566135278369511778838638744396625322498506549958862342818997077332761717839280349465014345588970719425863987727547109629537415211151368350627526023264847287039207643100595841166120545297030236472549296669381151373227536450988890313602057248176585118063036442812314965507047510254465011727211555194866850800368532281831521960037356252794495158284188294787610852639
pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796782354781636009341721641219924586315030286182974555706749838505494588586926995690927210797509302955321165344987202755960236480665499119881834797753566369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548161361157352552133475741849468438523323907394143334547762416862518983569485562099219222184272550254256887671790494601653466804988627232791786085784383827967976681454100953883786360950680064225125205117392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287467764657573962413890865832645995813390478027590099465764078951269468398352595709825822620522489407726719478268482601476990902640136394437455305068203496252451749399651431429809190659250937221696461515709858387410597885959772975498930161753928468138268683868942774155991855925245953959431049972524680845987273644695848653836736222626099124608051243884390451244136549762780797715691435997700129616089441694868555848406353422072225828488648158456028506016842739452267467678895252138522549954666727823986456596116354886230577456498035593634568174324112515076069479451096596094025228879710893145669136867228748940560101503308617928680920874760917824938589009714909675985261365549781893129784821682998948722658804857564014270477555132379641451523746234364542858444795265867821051141354735739523113427166102135969536231442952484937187110145765403590279934403742007310578539062198387447808478489683321445713868751943506430218453191048481005370614680674919278191197939952061419663428754440643745123718192179998391015919561814675142691239748940907186494231961567945208095146550225231603881930142093762137855956638937787083039069792077346722182562599661501421503068038447734549202605414665925201497442850732518666002132434088190710486331734649651453905796268561005508106658796998163574736384052571459102897064140110971206280439039759515677157700420337869936007230558763176359421873125147120532928191826186125867321579198414848829164470609575270695722091756711672291098169091528017350671274858322287183520935396572512108357915136988209144421006751033467110314126711136990865851639831501970165151168517143765761835155650884909989859982387345528331635507647918535
sqrt163=Math.sqrt(163)
gard=262537412640768744

guess=e**(pi*sqrt163)

puts "Gardiners constant is 262537412640768744 \n guess #{guess}\n"

Ruby does not give this result by a fair margin.

Obviously Haskell, matlab, mathematica and such are the proper languages for these problems. The Haskell compiler for OS X seems to require you to blow Satan to get it to work though*.

Your language may give a give some weird answers but are you going to believ someone called Hermite?

*Don Stewart pointed out you don't have to felate beelzbub to get Haskell. So if you don't want to get his scaley member down your gullet try here

Monday, June 09, 2008

Apéry's constant using monte Carlo methods

Apéry's Constant (1.20205690315...) "arises naturally in a number of physical problems, including in the second- and third-order terms of the electron's gyromagnetic ratio using quantum electrodynamics."

I described how to use monte carlo methods to estimate mathematical constants here and here. A passion for mathematics select three positive integers at random the odds of them having no common divisor are 1 in 1.202056....

So her is a ruby program that does not work for calculating this

def findCD(num1, num2, num3, cd)
if num1 % cd==0 && num2 % cd==0 && num3 % cd==0
return cd
elsif cd < ([num1,num2,num3].max)/2
findCD(num1, num2, num3, cd+1)
else
return 0
end
end

i=1
factor =0
N=1000

while (i < N)
x=rand(1000)
y=rand(1000)
z=rand(1000)

ans=findCD(x,y,z,2)
if ans >0
factor=factor+1
end
end

ans=(factor).quo(N)

puts "Apéry's Constant estimated as #{ans}" ;

The first problem is that my find common divisor algorithm is idiotic. There are all sorts of clever ways of doing this.

The second one is that computers have trouble creating random integers. The integers go up forever but a computers numbers don't. How do you ask a computer to give you one of any infinite one of the integers? rand(1,000,000) will not do it.

Sunday, June 08, 2008

Using a Random Number Generator to estimate e

After this post I started to wonder what other constants can be estimated using probabalistic methods.

You can estimate e = 2.7182818 using
monte carlo methods. The sum S = X1 + X2 + ... + Xn > 1 averages as the eth element. So if you rand(0,1)+rand(0,1)+... until they are greater then 1. If you average the number of elements needed it approximates e.


This code is dog ugly and probably bug riddled but it might give you some idea how the calculation is done.

i=0
N=1000000
number=0
total=0
p=0
k=1
while k < N

i=i+rand
p=p+1
if i>1
total=total+p
number=number+1
p=0
i=0
end

k=k+1
end
total=total.quo(number)
puts "e is #{total}"


If you know of a better way to use iterators to carry out this calculation please comment.

Testing Random Number Generators with π

"Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine that you throw darts at that dart board randomly. Then the ratio of the number of darts that fall within the circle to the total number of darts thrown is the same as the ratio of the area of the circle to the area of the square dart board. The area of a circle with unit radius is just π square unit. The area of the dart board is 4 square units. The ratio of the area of the circle to the area of the square is π / 4."

I got the book Digital dice the other day

It is about using monte carlo methods to solve probability problems that are hard to solve analytically. The first example given is how to estimate pi based on the % of darts that fall inside a cirle that is inside a square with the side length of twice the circles radius.

I decided to try out some languages to see how they got on with this problem. The aim is to test
1. Accuracy for mante carlo simulations
2. Ease of writing
3. Speed
in order of importance

If a language cannot accurately estimate π using this method then it indicates its random number generator (RNG) might not be very good. To test the RNG propery you need to do chi square tests and such as described in Seminumerical Algorithms by Knuth but i think its funny you can use π to test a RNG.

Perl

$N=10000000;

$p=0;
$k=1;
while ($k<$N){
$x=rand();
$y=rand();
if (($x*$x)+($y*$y)<1){
$p=$p+1;
}
$k=$k+1;
}
$ans=((4*$p)/$N);
print "ans".$ans;


Ruby

N=10000000

p=0
k=1
while k < N
x=rand
y=rand
if (x*x)+(y*y)<1
p=p+1
end
k=k+1
end
ans=(4*p).quo(N)
puts "pi is #{ans}"


Scheme
I cannot figure out how to get random numbers with scheme. There is code to do it here but I am not going to write my own rand function.

C

int main(void)
{
long N=10000000;
double x=0;
double y=0;
double p=0;
int k=1;

while (k < N){
x=( (double)rand() / ((double)(RAND_MAX)+(double)(1)) );
y=( (double)rand() / ((double)(RAND_MAX)+(double)(1)) );
if ((x*x)+(y*y)<1){
p=p+1;
}
k=k+1;
}

double mypi=((4*p)/N);

printf ("my pi %f \n",mypi);
return 0;
}


(less then sign) is < (thanks Helium).
I should use srand here to make it reproducible. Or more to be really fair run the test a few times and collect the average error. This is how the Digital dice runs the test with matlab. Anyway I wont tell you what language worked out the best. If you have any suggestions or code please comment.

Sign Language

If you want to speak to someone you need to share a language. Because languages have different phonemes it can be difficult to pronounce a foreign language.
So how about if we all had a base of sign language that we could communicate with? The advantage is simple movements do not have a local accent that localises them.
So how many words do you need to know?

Language word usage follows zipfs law. Which means a suprisingly low number of words cover a high percentage of our speech.

There are 850 words in basic english which implies you can communicate basic information with about this many words.

Newspeak the artificial language in the novel 1984 was simplified to the extent to make coherent political thought impossible. The point of here is to search for a simple universal language is for emergency situations or for providing an anchor for language learning so such a Newspeak nightmare is not a worry.

One way of looking for a basic subset of language is to find the common subset of all languages. This has been studied as the semantic metalanguage. There follows a list of the words (in english) that occur in all known languages and their international sign language equivalant.

Semantic primitives

The English exponents of the 61 Semantic Primitives (addition of LONG is proposed)

substantives
I,
YOU
SOMEONE
PEOPLE
SOMETHING/THING
BODY

mental predicates
THINK
KNOW
WANT
FEEL
SEE
HEAR
BE
speech
SAY
WORD
TRUE
actions, events and movement
DO
HAPPEN
MOVE
PUT
GO
existence and possession
THERE
IS
HAVE
life
TIME
WHEN/TIME
BEFORE
A LONG TIME
A SHORT TIME
FOR SOME TIME
MOMENT
space
WHERE/PLACE
HERE
ABOVE
BELOW
FAR
NEAR
SIDE
INSIDE
TOUCHING

"logical" concepts
NOT
Maybe
CAN
BECAUSE
IF
intensifier
VERY
augmentor
MORE
quantifiers
ONE
TWO
SOME
ALL
MANY/MUCH
evaluators
GOOD
BAD
descriptors
BIG, SMALL, (LONG)
taxonomy, partonomy
KIND OF, PART OF;
similarity
LIKE
determiners
THIS
SAME
OTHER

Friday, May 30, 2008

Irish Foreign Aid

Ireland has said it will give .7% of gdp to foreign aid by 2012. This will be about 1.4 billion dollars

So what can you do with 1.4 billion a year that will help the worlds poor the most? I believe Ireland should fight worms. Intestinal worms are a big easily fixed problem.
“Thirty percent of children in developing countries are moderately or severely undernourished, and nutritional supplements or treatments for intestinal parasites can be an inexpensive way to raise school attendance and increase physical and mental capacity.
Children who are better nourished in their first years of life stay in school longer and learn more each year they are there. In areas where malnutrition or worm infestations are common, nutritional supplements or treatments for intestinal parasites offer an inexpensive way to raise attendance and physical and mental capacity.

A school-based de-worming program in Kenya had even more remarkable results with benefits at least 450 times higher than the costs.
Most opportunities will not be as rewarding, but it is safe to assume the benefits are around 25 times higher than the costs in many cases. “

So the 1.4 billion a year spent of eradicating intestinal worms in third world children would be worth at least 35 billion to these countries.

Leishmaniasis, Trypanosomiasis and Malaria are other serious parasitic infections that are easily prevented. There is a description here on the effects of intestinal worms on children in the third world.

Worms are not sexy, you look up intestinal worms on google and the first site deals with pets. But if we give ourselves on achievable goal with our money, one that has proven huge benefits to people I think our money will be better spent then on many vague diffuse projects. Ireland got its snakes removed for us, why not become the country that removes the worms from everyone else?

Wednesday, May 28, 2008

Logic attack

Reasoning with First order logic can be hard
Unfortunately, a more complex algorithm can get caught in infinite loops that are known to be impossible to guard against completely. (to be more precise, it is NP complete)”

This means that is someone creates a new web app. “Do I really think this?” where you input your beliefs. “Grass is green” “cows eat grass”->output “Cows eat something that is green” you can attack it.
Denial of Service via Algorithmic Complexity describes Attacks“. Where by sending data that they know has worst case analysis time (eg. a sort in exactly the wrong order, entries that hash to the same bucket) an attacker can massively slow down your system.

First order logic decisions are NP-complete. In the same way as hash tables can be attacked if a system reasons about first order logic maliciously crafted inputs could be used to tie up the systems resources.

Tuesday, May 20, 2008

Everything Tube

Youtube takes in videos, allows you to easily add them to your blog. There is some searching and idiotic comments on the site but the big deal is

1. Take in data
2. Store it forever
3. Make it easy to embed in another website

What other kinds of data can this be done with?
1. Chess viewer
2. Chemicals viewer
3. Music
4. Other games draughts, dice games etc
5. Sound
6. Knitting patterns
7. Aresti aerobatic symbols
8. Dances
9. Motion/gesture
10. CAD
11. Electronic design
12. Crystallography
13. Knot diagrams
14. All sorts of physics notations. None of which I understand
15. weather data
16. Molecular biology
17. Biomedical data, ecg’s stuff like that
18. Astronomy
19. Astrology, tarot cards, homeopath recipes, crap like that
20. Surveys. Caves, mountain routes etc
21. Graphs. Google Chart kind of does this already.
22. Maths functions
23. Knowledge representation. Take in a decision tree in Yaml format and turn it into a visual tree graph.
24. Seismology

The idea is to make a "tube" website that takes in some data and makes it easy to add visualisations of it to your website. The data is already online, or at least easily placed online what youtube did was make it easily viewable. Searching on your tube website is important but the first thing to do is get it so people can show their data on their website. So what other "tubes" would be interesting/useful? Please comment your thoughts

Sunday, May 18, 2008

Bizzarre fruit

I bought a dragonfruit the other week. The next day I bought another weird fruit and the next...Nature, capitalism and immigration have brought in loads of these weird fruits into Ireland. Things you could not have bought 5 years ago. The same has happened with beer and loads of other foods. There is something very simple about fruits though, you just cut them open and eat no preparation is needed. You also realise that this is just how nature produced it with almost all other products are massively processed. So I have started a weird fruit odyessey, it is a small quest but it is fun.

Here is what I have tried so far
Sapodilla is like a sweet dry pear
Cherimoya is like a creamy melon
Sharon fruit- really nice
Dragon fruit
kumquat
bananito
plantane
passion fruit
figs- Fig rolls really do a lot with their core ingredient
Giant Chinese pear
Chow chow -I have no idea what this is but it tassted like it needed to be cooked
sour mango
prickly pear- First cactus I have eaten
Guava-Melon like not that guava tasting
papaya

Thursday, May 15, 2008

Ulysses Pact 2

The medical definition for this is
Ulysses Contract
Declarations by patients, made in advance of a situation in which they may be incompetent to decide about their own care, stating their treatment preferences or authorizing a third party to make decisions for them. (Bioethics Thesaurus)
This paper discusses the issue in relation to mental health.

How bound are you to your past self? Could you shoot the 50 year old conservative who as a tied dyed in the wool hippy 30 years previously wrote “If I ever vote republican please kill me”? If you are not bound to a contract by yourself of many years ago then how come there are 30 year mortgages?

There is a website here. Where people put quantifiable ambitions out in public. Keep wight below X, Make Y steps every day things like that. Are there common usages for Ulysses Contracts (not just the current cognitive health ones) that you could provide on another website? Is there a measurable way people change their thinking in response to an event that they could agree before the event to avoid?

Tuesday, May 13, 2008

Ulysses Pact

Some time in the future you might be crazy. You might decide to scupper your boat on some rocks because some moistened bint persuades you to. Now if you tell people to ignore you when you go crazy you have entered a Ulysses pact.
An example of this is someone making a living will in case they get dementia or car crashed into a coma where they won’t really be able to make decisions for themselves anymore. But what other events lead to known changes in cognition?

How Daughters Affect Their Legislator Fathers' Voting on Women's Issues "Parenting an additional female child increases the propensity of a member of Congress to vote liberally on women's issues, particularly reproductive rights."”
Could conservative voters enter into a Ulysses pact with a politician that if he has a female child he cannot alter his votes on reproductive rights? I am not saying here that liberalising your opinion on this topic is a bad idea just that it may not match the preferences of those who voted you into office.

Kuhn was of the belief that old scientists never really accepted new theories and in fact delayed the acceptance of new ideas. A Ulysses pact of “ignore the old people who invented the last theory” is probably too vague.

In what other areas do people bias their decision making in response to certain events?

Tuesday, May 06, 2008

The return of smoking

Tobacco Farming
Projected employment decline: -18.6%
Projected revenue decline: -16.9%
Projected output decline: -11.7%
Pity America's tobacco farmers. First they weather the decline in smoking among U.S. consumers, now they face lower prices from foreign competitors. The Feds dropped tobacco-price supports in 2005, forcing farmers to diversify or find another line of work.
The economic projections continue on an abysmal trend: From 2000 to 2007, tobacco farming revenue fell by more than 50% as output declined by 41.6%. If only tobacco farmers could find a way to convert their crop to ethanol ... “

What if smoking was not bad for you? Or at least not as bad.

For example, a 1998 Lantz, et al. study in the Journal of the American Medical Association of 3,600 adults over 7.5 years found large and significant lifespan effects: a three year loss for smoking”

Three years is less then I would have thought, what if this was reduced further. Say three reasonably unlikely things happen

1. Smoking + Virus causes cancer. HPV and measles are linked to lung cancer. “While the specific viruses at issue -- human papillomavirus (HPV) and measles -- may not directly cause lung cancer, they seem to aggravate the negative impact of tobacco, American and Israeli researchers say” Then if we prevent measles and HPV infection this might reduce lung cancer rates.

2. Radiation
In a person smoking 1 1/2 packs of cigarettes per day, the radiation dose to the bronchial epithelium in areas of bifurcation is 8000 mrem per year -- the equivalent of the dose to the skin from 300 x-ray films of the chest per year. This figure is comparable to total-body exposure to natural background radiation containing 80 mrem per year in someone living in the Boston area.”

This mp3 talks about how much radiation you get from smoking in comparison to eating bananas and other dangerous activities

The theory is that the phosphorus fertilizer used on tobacco is radioactive and breathing this in is bad. Maybe organic tobacco will be less unhealthy?

4. Genes
First-degree relatives of lung cancer patients have a 2 to 3.5 times greater risk of developing lung cancer than the general population, and tobacco smoke plays a major role, even among those with a genetic predisposition” Genetic testing is halving in costs each year. So testing to see if someone is susceptible to lung cancer should get quite cheap quite soon. You could probably get an accurate test by asking “has any of your blood relatives died of lung cancer before the age of 70?” If the answer is yes make it more difficult for this person to smoke. This would reduce the amount smoking takes off the average lifespan.

I do not smoke and I always assumed less and less people will smoke in future. I could be wrong though. If smoking is made less dangerous it could become more popular again.

Sunday, April 27, 2008

Improving Books

One thing with books that most modern entertainment lacks is that you know when it will end. You can tell as you go through a book how much remains. This reduces the uncertainty present in the plot.

You could add empty pages to the end of the book. But these would be obvious. Adding complete gibberish would also be obvious even to someone flicking to find the last page number. You could generate more realistic text using a Markov model. Shannon generated fairly reasonable looking text with a simple algorithm. Markov models will create text that bears closer inspection though. It was used to generate postmodern critical analysis that got published without anyone realising it was nonsense.

So you train up your model on the rest of the book. Then get it to produce pages of text that without some study cannot be differentiated from the real books text. Then place these pages with the occasional *the end* in them after the book ending. The ending is marked with *the end*. Now the readers who do not go to a big effort cannot tell as they read the book how much remains.

Friday, April 25, 2008

Panic

I am not one to panic unnecessarily but I think the time has come to admit we are fucked. And not kind of fucked, fucked like a passed out rabbit wearing suspenders at a furvert convention. The seas will boil, locusts will swarm, dogs and cats will live together IN SIN.

We are running out of fig rolls

Hoards of middle aged Irish men will soon be wandering the aisles muttering to themselves in the guttural Romero growl “FIGS

The next stage these shuffling zombies will start looting shops in search of their rolly fix

Mark my words society will collapse as the mid life crisis brigade start breaking into houses on the vague hope of finding fig rolls.