I am obviously not a mathematician, but I do recognize that some mathematical formulas come in handy.  Take the Bayesian Rating system for example.  Elegant in it’s design, yet when I looked at the formulas, I struggled to understand the complex mathematical formulas.

But do not fear.  I managed to work it out, and this post will explain how you can do it.  I just want to warn you — I am not a mathematician.  Use this at own risk.

There is a common formula that you’ll see all over the web.  It is as follow.

br = ( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes)

The fields are :-

  • avg_num_votes: The average number of votes of all items that have num_votes>0
  • avg_rating: The average rating of each item (again, of those that have num_votes>0)
  • this_num_votes: number of votes for this item
  • this_rating: the average rating of this item

So programatically, how do we implement it?  Let me show you.

Continue reading

This morning I presented the communion message at Central Life Christian Church.


[ Download ] enclosure

Today I had the privilege of speaking during communion at Central Life Christian Church.

Listen to it here.


[ Download ] enclosure

I wrote this little template to show to read & write a session cookie in Perl.  This code will generate an md5 hash session key if there is none, and keep it for the duration of the session.

#!/usr/bin/perl
 
use strict;
use CGI;
use CGI::Cookie;
use Digest::MD5 qw (md5_hex);
 
my $cgi = new CGI;
 
# == read cookies
my $id;
my %cookies = CGI::Cookie->fetch;
if($cookies{'id'})
{
	$id = $cookies{'id'}->value;
}
 
# == If the cookie is corrupt or missing, create a new session
if($id !~ /^[a-z0-9]{32}$/)
{
	$id = lc(md5_hex ((rand * time * $$ . $ENV{REMOTE_ADDR} . $ENV{USER_AGENT})));
}
 
# == create a cookie
my $cookie = CGI::Cookie->new(-name => 'id',-value => $id, -httponly => 1);
 
# == print the header
print $cgi->header(-cookie=>$cookie);
 
# ======================================================================
 
print $cgi->start_html();
print $cgi->h1($id);
 
print $cgi->end_html();

No known species of reindeer can fly. BUT there are 300,000 species of living organisms yet to be classified, and while most of these are insects and germs, this does not COMPLETELY rule out flying reindeer which only Santa has ever seen.

There are 2 billion children (persons under 18) in the world. BUT since Santa doesn’t (appear) to handle the Muslim, Hindu, Jewish and Buddhist children, that reduces the workload to 15% of the total – 378 million according to the Population Reference Reference Bureau. At an average (census) rate of 3.5 children per household, that’s 91.8 million homes. One presumes there’s at least one good child in each.

Santa has 31 hours of Christmas to work with, thanks to the different time zones and the rotation of the earth, assuming he travels east to west (which seems logical). This works out to 822.6 visits per second. This is to say that for each Christian household with good children, Santa has 1/1000th of a second to park, hop out of the sleigh, jump down the chimney, fill the stockings, distribute the remaining presents under the tree, eat whatever snacks have been left, get back up the chimney, get back into the sleigh and move on to the next house. Assuming that each of these 91.8 millions stops are evenly distributed around the earth (which, of course, we know to be false but for the purposes of our calculations we will accept), we are now talking about .78 miles per household, a total trip of 75-1/2 million miles, not counting stops to do what most of us must do at least once every 31 hours, plus feeding and etc.

This means that Santa’s sleigh is moving at 650 miles per second, 3,000 times the speed of sound. For purposes of comparison, the fastest man-made vehicle on earth, the Ulysses space probe, moves at a poky 27.4 miles per second – a conventional reindeer can run, tops, 15 miles per hour.
The payload on the sleigh adds another interesting element. Assuming that each child gets nothing more than a medium-sized lego set (2 pounds), the sleigh is carrying 321,300 tons, not counting Santa, who is invariably described as overweight. On land, conventional reindeer can pull no more than 300 pounds. Even granting that “flying reindeer” (see point #1) could pull TEN TIMES the normal amount, we cannot do the job with eight, or even
nine. We need 214,200 reindeer. This increases the payload – not even counting the weight of the sleigh – to 353,430 tons. Again, for comparison – this is four times the weight of the Queen Elizabeth Cunard Liner.

353,000 tons travelling at 650 miles per second creates enormous air resistance – this will heat the reindeer up in the same fashion as spacecraft re-entering the earth’s atmosphere. The lead pair of reindeer will absorb 14.3 QUINTILLION joules of energy. Per second. Each. In short, they will burst into flame almost instantaneously, exposing the reindeer behind them, and create deafening sonic booms in their wake. The entire reindeer team will be vaporized within 4.26 thousandths of a second. Santa, meanwhile, will be subjected to centrifugal forces 17,500.06 times greater than gravity. A 250-pound Santa (which seems ludicrously slim) would be pinned to the back of his sleigh by 4,315,015 pounds of force.

In conclusion – If Santa ever DID exist, he’s dead now. Merry Christmas everyone.

My chatbot project is coming along nicely.  My engine (called AIMLPerl) is now almost fully AIML 1.0 compliant.

The last few weeks have been a great time to develop the code, and improve the engine.  I had some trouble in the beginning to get Program D running, so my own attempt at building an AIML engine is proving to be quite positive.

My own bot (Cylina) is making slower progress than I would have hoped.  The advances in my AIMLPerl script will allow Cylina’s AIML code to also expand and include new features.

The one main feature that AIMLPerl supports, is the ability to log the bot onto an IRC channel.  This has helped me to improve the bot’s knowledge, by reviewing the logs, and tweaking the rules further.  But tweaking rules is one thing… IRC is a totally different ball game.  Here’s what I’ve learnt so far from running Cylina on IRC.

  • IRC is notorious for using shorthand.  I have to end up using various substitutions or multiple rules just for the bot to understand what is being said.
  • People can’t spell.
  • People can’t type, leaving out words in sentences, leaving the context open ended ( thus confusing the bot).
  • They only want one thing (and my bot is not programmed for R rated content)
  • Non-english speaking individuals are having a particular tough time, using the wrong words in the wrong order, etc.

So if you’d like to give Cylina a try, log onto IRC through this link.  If the script is running, she’ll be online.  Simply look for “CylinaBot”.  There is usually a rule base refresh once a week.  Please keep in mind that all conversations are logged.

Getting started with AIML

 

Moving speech by Obama.

A few weeks ago, someone asked me something, something very specific that this person would not have known. I realised they obtained this information from LinkedIn.
A few times in the past, recruitment agencies would seek me out to find out if we had job openings. They are relentless.
It made me think – what is the value of LinkedIn? A social media platform for business, or yo build your career? Perhaps, but like Facebook, these guys are in the information business.
So from today, my LinkedIn profile no longer exist. My facebook profile is for close friends and family only. My twitter and website are the public facing entities.
So on that note, I am gone from LinkedIn.

@echo off
 
:: Set the folder and path were the script is running from
set ME=%~d0%~p0
 
:: set the param variable, and remove any " tags that may be in it
set PARAM=%1
SET PARAM=%PARAM:"=%

Dit laat my altyd lag.  Ben Kruger verdien ‘n oscar hiervoor!