Announcements, Machine Learning, resources, Uncategorized, Video

Machine Learning Video Lectures

I taught an introductory Machine Learning course to BS students at FAST Peshawar in Fall 2015. The feedback was quite positive so I decided to offer another course to the MS/PhD students in the next semester. The mode of teaching was also a bit different: we tried doing the pen-tablet-augmented-multimedia-slides model. The semester is still in progress but we have the core of the basics done now.

The lectures are in Urdu so might be easier to follow for those who understand the language. I will be uploading the future videos as they come up inshaallah. You can see the first video below and follow the complete collection on Vimeo here: https://vimeo.com/album/3770825

Machine Learning – Lecture 01-A (Spring 2016) from recluze on Vimeo.

Machine Learning, resources

Machine Learning Self-Study Track

I started with Machine Learning a while back and had a slightly hard time getting help from the local community. The reason was mostly because the Machine Learning community in general is way behind the state-of-the-art in industry and research. This is true for almost all fields nowadays but with Machine Learning, the issues are more pronounced due to the recent fast-paced developments in the industry.

On the other hand, once you know what to study, things are much easier than many other fields such as security. Here I would outline the plan I followed to get to where I am (which isn’t too far ahead but still a little better than what most people know, IMHO).

So, here’s my guide for getting started with Machine Learning self-study.

  1. Start with Andrew Ng’s Coursera course — Machine Learning. That’s the advice almost everyone seems to give — and it’s a great advice. The Coursera course is completely basic and eases you in the field with little pre-reqs and not much depth. Be careful though: do not think after completing the course that you are an expert in Machine Learning. It misses quite a few areas and the skills needed to be above average. It does get you started with practicals so you are likely to think you’re already done after finishing the course.
  2. So, after you complete the courser in its entirety — including the assignments — I suggest you start with Prof. Nando de Freitas’ undergrad course.  This is a much more detailed course and would get you a very different view of ML than traditional outlines. Of course, you might have to brush up on your Probability, Calculus and Linear Algebra. You can’t really do anything without these three.
  3. For the above three, I suggest the following courses:
    1. Probability: Probability for Life Sciences by UCLA’s Math Department. You can find videos for this easily.
    2. Calculus: I strongly suggest you go with Virtual University Pakistan’s Calculus-I course by Dr. Faisal Shah Khan. It’s a great course but it’s in Urdu. If you don’t know Urdu, you can find your own series. Please let me know in the comments about great resources for this.
    3. Linear Algebra: Of course, this can only be done with Gilbert Strang’s Linear Algebra course from OCW.
  4. After that, you can start with the grad course and the second grad course by Prof. Nando de Freitas. Both have very detailed video lectures.

Of course, you also need to work with tools other than Matlab. I strongly suggest the python PyData stack. The full list would be:

  1. Python PyData full stack (plus go through their yearly videos as well)
  2. Theano
  3. Torch
  4. Keras

That’s what I have till now. I might add more when I know more inshaallah.

Geek stuff, python, resources, Tutorials

AVL Tree in Python

I’ve been teaching “Applied Algorithms and Programming Techniques” and we just reached the topic of AVL Trees. Having taught half of the AVL tree concept, I decided to code it in python — my newest adventure. Bear in mind that I have never actually coded an AVL tree before and I’m not particularly comfortable with python. I thought it would be a good idea to experiment with both of them at the same time. So, I started up my python IDE (that’s Aptana Studio, btw) and started coding.

For the newbie programmer, the code itself may not be very useful since you can find better code online. The benefit is in being able to look at the process. You can take a look at the commits I made along the way over here on github. You can take a look at how I structured the code when I began and how I added bits and pieces. This abstraction should help in solving other problems as well. The final code (along with a rigorous unit test file) can be seen here: https://github.com/recluze/python-avl-tree

Design, resources, Tutorials

How to Create a Beamer Template — A Newbie’s Tutorial

I started switching full-time to Ubuntu (once again) a couple of weeks ago. Turns out, it’s in much better condition than when I last tried it. Anyway, one of the problems was finding a replacement for Powerpoint. I hate creating presentations for classes — in fact, I think they’re counter-productive — but I have no choice for the moment. So, I decided to give LibreOffice Impress a chance. That was an hour of my life down the drain. Finally, I returned to beamer. Of course, I had to write my own theme because I couldn’t use the same theme used by all the rest of the world. To cut this long and boring story short, I tried very hard to find a tutorial on writing beamer themes, couldn’t do so, learned it through experiment and decided to write the tutorial myself. Here is that tutorial.

Continue reading “How to Create a Beamer Template — A Newbie’s Tutorial”

resources, Students

CS 303 Software Engineering (NU) Administrivia

Update Sep 08, 2011: Lectures are now available on the Lecture Server. Please get the updates there.

This is a (hopefully) temporary location for posting the contents that I want communicated to the students of CS303 Software Engineering course. These will be posted to the lecturer server as soon as I get access inshaallah. For the time being, bookmark this page and keep checking for updates.

CS303- Course Outline – Fall 2011
Slideset-01
Slideset-02

Linux, resources, Tutorials

Varnish Cache for WordPress on cPanel

Varnish is an extremely easy to configure server cache software that can help you counter the ‘slashdot effect’ — high traffic over a small period of time. The way Varnish does this is by sitting between the client and the webserver and providing cached results to the client so that the server doesn’t have to process every page. It’s better than memcache etc because the request never gets to the webserver. You can avoid one of the bottlenecks this way. In this tutorial, we’ll cover how to setup Varnish on a VPS (or dedicated server) where you have root access and are running your site using cPanel/WHM. It also applies to situations where you don’t have cPanel/WHM. You can just skip the cPanel portion if that’s the case. So, let’s get started.

Continue reading “Varnish Cache for WordPress on cPanel”

resources, Tutorials

Enabling Voicemail for A2billing

So you’ve setup a2billing and have everything working out, all the DIDs are forwarded to a2billing and all the call plans are set. All you’re missing is a voicemail system. Wait no more. Here’s how to enable voicemail for a2billing users.

First, you need to change the A2billing class to enable it to forward unavailable or unattended calls to the voicemail. For that, edit the [a2billing-home]/common/lib/Class.A2billing.php file file. The two functions that need changing are the call_did and call_sip_buddies. In version 1.8.5, the changes are around line 1160 and 1330. You can just search for the following code to reach there. (Remember, there are two instances that need changing.)

//# Ooh, something actually happend!
if ($dialstatus == "BUSY") {

Now, it needs to be changed so that the caller is redirected to the voicemail if the dialstatus is CHANUNAVAIL, CONGESTION or NOANSWER. Note that we need to get rid of the existing checks for these statuses and introduce our own code. The complete code would be as follows:

$answeredtime."-DIALSTATUS=".$dialstatus."]"); 
$lang = "en";
if (($dialstatus =="CHANUNAVAIL") || ($dialstatus == "CONGESTION") ||($dialstatus == "NOANSWER") || ($dialstatus =="BUSY") )
{
	// The following section will send the caller to VoiceMail with the unavailable priority.
	$did_ext_number = substr($this->destination, 4);
	// get the actual did 
	// BAD but a hack for now 
	$db_host = $this->config['database']['hostname']; 
	$db_user = $this->config['database']['user']; 
	$db_pass = $this->config['database']['password'];
	$db_sele = $this->config['database']['dbname'];
	
	mysql_connect($db_host, $db_user, $db_pass);
	@mysql_select_db($db_sele) or die( "Unable to access database");				
	$query = "select S.name, D.did, C.language from cc_sip_buddies S, cc_card C , cc_did_destination E, cc_did D 
				where S.id_cc_card =C.id and E.id_cc_card = C.id and E.id_cc_did = D.id and 
				S.name =  '$did_ext_number';";
				
	$result = mysql_query($query);
	$did_number = $did_ext_number; 
	if ($row = mysql_fetch_array($result)){		  
		if($dialstatus =="BUSY")
			$did_number = "b".$row["did"]; 
		else
			$did_number = "u".$row["did"]; 
		
		// set the language 
		$lang = $row["language"]; 
	}
	
	$this -> write_log("[STATUS] CHANNEL UNAVAILABLE - DIVERT TO VOICEMAIL ($did_number)");
	$lang_str = "LANGUAGE()=$lang";
	$agi->exec (Set, $lang_str); 
	$agi-> exec(VoiceMail,$did_number);
} 


// the old code for BUSY is commented out 
//# Ooh, something actually happend!
/* if ($dialstatus  == "BUSY") {
	$answeredtime = 0;
	if ($this->agiconfig['busy_timeout'] > 0)
		$res_busy = $agi->exec("Busy ".$this->agiconfig['busy_timeout']);
	$agi-> stream_file('prepaid-isbusy', '#');
} elseif ($this->dialstatus == "NOANSWER") {
	$answeredtime = 0;
	$agi-> stream_file('prepaid-noanswer', '#');
} else
*/ 

if ($dialstatus == "CANCEL") {
	$answeredtime = 0;
} elseif ($dialstatus == "ANSWER") {
	$this -> debug( DEBUG, $agi, __FILE__, __LINE__, "-> dialstatus : $dialstatus, answered time is ".$answeredtime." n");
} elseif ($k+1 == $sip_buddies+$iax_buddies) {
	$prompt="prepaid-dest-unreachable";
	$agi-> stream_file($prompt, '#');
}

/* 
// AGAIN, the old code for the statuses is commented out 
if (($dialstatus  == "CHANUNAVAIL") || ($dialstatus  == "CONGESTION"))
	continue;
*/ 

Find the similar code in the other function and change that too.

Now, we need to change the asterisk voicemail configuration to recognize the DID as a mailbox. For that, first enable asterisk realtime. (It’s a simple matter of compiling asterisk and then compiling asterisk-addons.) After that is done, change the /etc/asterisk/res_mysql.conf file as follows:

[general]
dbhost = 127.0.0.1
dbname = a2billingdb
dbuser = [asteriskuser]
dbpass = [yourpassword]
dbport = 3306
dbsock = /tmp/mysql.sock

Also, in the /etc/asterisk/extconfig.conf add the following line:

voicemail =>mysql,a2billingdb,voicemail_users

This will make sure that the voicemail application tries to find the list of mailboxes in the voicemail_users table in the a2billingdb. Let’s create that table:

CREATE TABLE `voicemail_users` (
`uniqueid` int(11) NOT NULL auto_increment,
`customer_id` int(20) NOT NULL default '0',
`context` varchar(50) NOT NULL default '',
`mailbox` varchar(20) NOT NULL default '0',
`password` varchar(20) NOT NULL default '8888',
`fullname` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`pager` varchar(50) NOT NULL default '',
`stamp` timestamp(14) NOT NULL,
PRIMARY KEY (`uniqueid`),
KEY `mailbox_context` (`mailbox`,`context`)
) TYPE=MyISAM;

… and synchronize it with the rest of the a2billing database so that the users can use their DID and SIP secret for their mailboxes.

insert into voicemail_users(customer_id,context,mailbox, password, fullname, email)
select S.id_cc_card, 'default', D.did, S.secret, concat(C.lastname,' ',C.firstname) fullname, C.email
from cc_sip_buddies S, cc_card C , cc_did_destination E, cc_did D
where S.id_cc_card =C.id 
and E.id_cc_card = C.id 
and E.id_cc_did = D.id;

You might want to add the following cronjob to perform this synchronization automatically.

0 * * * * mysql -ua2billinguser -p[yourpassword] -D a2billingdb -e "truncate table voicemail_users; insert into voicemail_users(customer_id,context,mailbox, password, fullname, email) select S.id_cc_card, 'default', D.did, S.secret, concat(C.lastname,' ',C.firstname) fullname, C.email from cc_sip_buddies S, cc_card C , cc_did_destination E, cc_did D where S.id_cc_card =C.id  and E.id_cc_card = C.id  and E.id_cc_did = D.id ;"

That should fix the whole voicemail recording business. However, we still need to enable the voicemail interface provided by FreePBX. Since the ARI does not support asterisk realtime, we need to change the login.php file in /var/www/html/admin/includes folder. Search out the code where the authentication is being done. The code first tries to autenticate using the configuration file. It then tries SIP authentication (whatever that is). After that, we insert our own DB authentication like so:

// check database login:  recly 
if(!$auth){
	// BAD but a hack for now 
	$db_host = "localhost"; 
	$db_user = "a2billinguser"; 
	$db_pass = "[yourpassword]";
	$db_sele = "a2billingdb";

	mysql_connect($db_host, $db_user, $db_pass);
	@mysql_select_db($db_sele) or die( "Unable to access database");

	$query = "select * from `voicemail_users` where mailbox = '$username' and password= '$password'"; 
	$result = mysql_query($query);

	if ($row = mysql_fetch_array($result)){		  
		$auth = true; 
		$extension = $row["mailbox"]; 
		$outboundCID = "";
		$displayname = $row["fullname"];
		$vm_password = $row["password"];
		$category = "";
		$context = $row["context"]; 
		$voicemail_enabled = "1";
		$voicemail_email_address = $row["email"];
		$voicemail_pager_address = $row["pager"];
		$voicemail_email_enable = "yes";
		$voicemail_email = array('');
		$default_page = $ARI_DEFAULT_USER_PAGE;
	}
}
// the original login failure lines follow 

// let user know bad login
if (!$auth) {
	$_SESSION['ari_error'] = _("Incorrect Username or Password");
}

And that should enable you to login using your ARI. One final thing: You might also want to enable your users to check their mailbox. For that, change the dialplan in extensions_a2billing.conf:

[a2billing]
exten => 9999,1,VoicemailMain()
exten => _X.,1,Answer
exten => _X.,n,Wait(1)
exten => _X.,n,DeadAGI(a2billing.php|1)
exten => _X.,n,Hangup

Now your users can dial 9999 and check up on their voicemail.