Thursday, June 23, 2016

Triple Your Productivity

Link: http://mdi.com.pk/training/triple-your-productivity/

There are literally hundreds of ways to improve your productivity. But if you are looking for a quantum difference where you can virtually triple your productivity, then it is necessary to use a 3-step approach. Using all 3 steps and using these simultaneously is what can produce the remarkable difference.

First of all, it is useful to remember that productivity is not about doing more work although this is sometimes necessary.
Productivity is about getting better outcomes in a shorter period of time.
Here are the 3 steps necessary to really get on a different productivity trajectory:

Step 1 – One hour for the most important task
Every day, identify the one task that just has to be done before the day ends. Start working on this and do not worry about anything else that is not an emergency. At the end of the day, if you haven’t done anything else, you have at least finished the most important task for that day.
Of course, the trick is to know what is that one task that has to be completed. Only you know that. The good news however is that once you have gotten over this one task, there is a surge in energy and focus as you decide that you might as well stay ahead of the curve on that day.

Step 2 – Avoid one distraction type every day
For many people these days, this is stuff like email, Whatsapp messages, text messages, phone calls, etc. Identify one distraction type – perhaps this is email – and on that day, treat email very differently compared to usual. You might not check your email for 2 hours at a stretch in the office – or reply to email only during certain hours. Whatever strategy you choose, it must reinforce your ability to complete Step 1 above.

Step 3 – Get away from your desk for a while
Go for a walk or just go to another room in the office to chat with a colleague for a few minutes (but do not distract them for too long!). Just distance yourself away from your computer and your smart phone. It feels good to be un-wired once in a while.

9 Key Soft Skills To Work On

When you think about self-development or development of a team in terms of soft skills, there are 9 key soft skills that one can consider to be essential and that are usually missing from many executives. These soft skills are spread across 3 categories – professionalism, critical thinking and followership…
Category a – Professionalism
1. Self-assessment – being self-aware and able to candidly assess one’s own strengths and weaknesses as well as one’s performance against desired standards.
2. Personal responsibility – the ability to focus on what one can control directly – e.g. personal behavior – and managing the response to factors outside one’s own control.
3. Positive attitude – maintaining and conveying a positive and enthusiastic outlook in interaction with others. This is particularly important in situations where there is complexity, uncertainty and difficulty.
4. People skills – ability to interact and communicate effectively with individuals and groups and a key part of this is presenting, listening and empathy.

Category b – Critical thinking
5. Learning – having a curious mind, questioning assumptions and constantly striving to acquire new information to build one’s knowledge and skills.
6. Problem-solving and decision-making  – ability to consult, identify and consider multiple options to choose the course of action that can lead to problem resolution and an effective outcome.

Category c – Followership
Everyone knows and talks about leadership but how many people know what followership is?
7. Adaptability – knowing the importance of molding oneself to better align with the needs of the organization rather than expecting the organization to change to suit the individual.
8. Teamwork – ability to work well in groups and teams and knowing how to balance self-interest with team interest. This also implies being able work with shared goals and celebrating the success of others.
9. Service orientation – calibrating around what you have to offer rather than what you expect or want from others. This implies genuine concern and respect for the needs of others whether they are customers or colleagues.

Thursday, May 7, 2015

K-Means and Expectation Maximization (EM) implemented on n-Dimensional UCI dataset

Please find my full source code from the link.... K-Means and EM project with UCI sample

Some part of Expectation Maximization code is as follows:
------------------------------------------------------------ 

 /// <summary>
    /// Run K-Mean untill clusters not change and centroid converged
    /// </summary>
    public class EM
    {
        /// <summary>
        /// A set of n dimentional points
        /// </summary>
        private DataSet _dataSet;

        /// <summary>
        /// Entry point of EM algorithm
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="K"></param>
        /// <param name="distanceMethod"></param>
        /// <param name="centroidMethod"></param>
        public static void Run(DataSet dataSet, int K, int distanceMethod = 1, int centroidMethod = 1)
        {
            var clusters = new Cluster[K];

            if (K > dataSet.DataPoints.Count)
            {
                throw new Exception("Clusters are more thn data points choosen");
            }

            ChooseRandomCentroids(dataSet.DataPoints, clusters);

            int _iteration = 1;

            while (true)
            {
                Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                Console.WriteLine("@@@@@@@@@@@@ Iteration: {0} @@@@@@@@@@@@@@@@", _iteration++);
                Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

                clusters.ToList().ForEach(c => c.ClusterPoints.Clear());

                // Step 1: Find Euclidean Distances
                List<double[]> table = new List<double[]>();
                foreach (var dataPoint in dataSet.DataPoints)
                {
                    List<double> row =new List<double>();

                    foreach (var cluster in clusters)
                    {

                        var theDistance = DistanceMeasure.SquaredEuclideanDistance(dataPoint, cluster.Centroid);
                        row.Add(theDistance);
                    }

                    table.Add(row.ToArray());

                }

                // Step 2: E-Step
                foreach (var row in table)
                {
                    var sum = row.Sum();
                    //calculation step
                    var row2 = (double[]) row.Clone();
                    for (int j = 0; j < row.Length; j++)
                    {
                        row2[row.Length-1-j] = row[j] / sum;
                    }
                    //copy back
                    for (int j = 0; j < row.Length; j++)
                    {
                        row[j] = row2[j];
                    }
                   
                }

                // Step 3: M-Step
                foreach (var row in table)
                {
                    for (int j = 0; j < row.Length; j++)
                    {
                        row[j] *= row[j];
                    }
                }

                for (int i = 0; i < table[0].Length; i++)
                {
                    for (int j = 0; j < dataSet.DataPoints.Count; j++)
                    {
                        var dataPoint = DataPoint.Clone(dataSet.DataPoints[j]);

                        for (int k = 0; k < dataPoint.Vector.Length; k++)
                        {
                            dataPoint.Vector[k] *= table[j][i];
                        }
                        clusters[i].ClusterPoints.Add(dataPoint);
                    }
                }

                for (int i = 0; i < clusters.Length; i++)
                {
                    var cluster = clusters[i];
                    var dimensions = cluster.ClusterPoints[0].Dimensions;
                    var newCentroid = new DataPoint { Vector = new double[dimensions] };


                    double sum1 = 0, sum2 = 0;
                    for (int j = 0; j < table.Count; j++)
                    {
                        sum1 += table[j][i];
                    }

                    for (int k = 0; k < dimensions; k++)
                    {
                        sum2 = cluster.ClusterPoints.Sum(x => x.Vector[k]);

                        newCentroid.Vector[k] = sum2 / sum1;
                    }


                    cluster.OldCentroid = cluster.Centroid;
                    cluster.Centroid = newCentroid;

                      Console.Write(cluster.ToString());

                }

                bool allClustersConverged = true;
                foreach (var cluster in clusters)
                {
                    allClustersConverged = allClustersConverged & cluster.IsConverged();
                }

                if (allClustersConverged)
                    break;

            }
        }

        /// <summary>
        /// Used to choose K (# of clusters) initial points
        /// </summary>
        /// <param name="points"></param>
        /// <param name="clusters"></param>
        private static void ChooseRandomCentroids(IList<DataPoint> points, Cluster[] clusters)
        {
            if (points.Count < 2)
            {
                throw new Exception("Points are insufficient to start the algorithm");
            }
            if (clusters != null && clusters.Length < 2)
            {
                throw new Exception("Clusters are insufficient to start the algorithm");
            }

            Random rand = new Random();
            HashSet<int> results = new HashSet<int>();
            while (results.Count < clusters.Length)
            {
                results.Add(rand.Next(1, points.Count));
            }

            //randomly choose first points and choose second which extream distance from first
            for (int j = 0; j < results.Count; j++)
            {
                clusters[j] = new Cluster {Centroid = points[j]};
            }

        }