Saturday, November 11, 2017

The personal recommender
we want a guide, a local expert when we visit a new place. if we are doing something routine, we don't need any help. if we are in a new place or we are experiencing something new, we appreciate information. we do this today by flipping brochures, maps and ads. we use a scratch pad and a pen to put together a list. we know our tastes and we know how to find a match in the new environment. Booking a travel itinerary  involves a recommender from the travel website. we get choices for our flight searches and hints to add a hotel and a car. Some such websites involve intelligent listings based on past purchases, reward program memberships and even recommendations based on a collaborative filtering technique from other travelers. We appreciate these valuable tips on the otherwise mundane listing of flights and hotels ordered by price.
Therefore information is valuable when we explore. it is similar to wearing google eyeglasses or anything that hones our senses. Maps do this in the form of layers overlaid over the geographic plot but the data is merely spatial and improved with annotations. It is not temporal as in what events are happening at a venue next to a hotel. It also does not give a time based activity recordings that we can rewind and forward to see peak and low traffic. such data would be gigantic to store statically with maps. besides they may not be relevant all the time as business change.
A recommender on the other hand can query many data sources over the web. for example, it can query credit card statements to find patterns in spending and use it to highlight related attractions in a new territory. wouldn't it be helpful to have our login pull up restaurants that match our eating habits  instead of cluttering up the map with all those in the area ? similarly, wouldn't it be helpful to use our social graph to annotate venues that our friends visited ? The recommender may be uniquely positioned to tie in a breadth of resources from public and private data sources. many web applications such as deli.cio.us and kayak make data available for browsing and searching.
This recommender is empowered to add a personal touch to any map or dataset by correlating events and activities to the user's profile and history. By integrating signing in credentials across banks, emails, bills, and other agencies, the recommender gets to know more about our habits and becomes more precise in the recommendations. Moreover, the recommender can keep learning more and more about us and it accrues habits and recommendations and improves it with feedback loop.
The recommender is also enabled to query trends and plot charts to analyze data in both spatial and temporal dimensions. it could list not only the top 5 in any category but also the items that remained in the top 5 week after week. These and such other aggregation and analysis techniques indicate tremendous opportunity for the recommender to draw the most appealing and intuitive information layer over any map.
The recommender is also not limited to standard querying operators and can employ a variety of statistical models and machine learning algorithms to better judge on our behalf. By using different ways to determine correlations, a recommender becomes closer to truth.
The personal coder
Everybody could do with their own assistant. Speech recognition based software such as Alexa, Siri and Cortana are able to understand simple commands. While they know how to locate an item of interest they can only serve what is readily available either in context of the device or online from the world wide web. Instructions like a one-word genre of music is automatically translated to playing that music from the genre in the collection available to it.
These assistants are being made smarter to understand the relevance of the instruction and to narrow down the execution of the command to improve satisfaction. Some of these techniques have utilized artificial intelligence and the abilities to group, sort, rank, learn with neurons and make recommendations. There is definitely a lot of improvements on the horizon here given that we have just recently started making this territory mainstream.
However, I introduce the notion of a personal automation assistant, when we are not just looking for one item and we have more than one task to sequence, then giving repeated instructions itself becomes a chore. Try saying play violin ten times and you need an integrator along with a command to play it once. Similarly, if you need the result of one task to be taken as the input for the second, then we require a script that knows how to integrate between two actions. Expand the definition of instructions to be able to do assorted tasks such as turn on the toaster or strand music to the bathroom via heterogeneous systems and you need a software solution integrator to write code to make that automation.
Fortunately, nowadays devices and applications can work independently while allowing scriptable programmatic access for remote invocation. Even the language of interaction has become standard and easy to be invoked over what are called REST based APIs. These APIs follow well defined conventions and executing a task merely translates to making one or more API calls in the correct form and order. These APIs can be further explored for their corresponding resource with the help of a technique that makes them readable like a book. Therefore, the availability of standard API and their invocations is straightforward task of mix and match which can be folded into the portfolio of tasks that these assistants perform. Hence the notion of a personal coder.
It may behoove us to note that coding is one of the natural and immensely expansive capability that can be added to the assistant. There are many more roles other than a coder that an be folded into repertoire of tasks that the assistant may assume. Professionals such as accounting, transcribing, remote management are merely describable as automatable tasks and consequently roles for the assistant. Finally, ‘the’ becomes equivalent to an irreplaceable assistant.
The emphasis made here is about making API calls over the HTTP by picking the right API and supplying the right parameters as an example for the coding assistant. Scripts that are as easily written as a single curl command are probably more suited for this kind of assistant. For complex operations, we naturally want manual intervention. Another way to look at improving the assistant's capabilities is to make more data sources available for the already smooth-running operations of the assistant. For example, Google used to ship search appliances that worked on the customer's premise for their proprietary data. We could now use a similar concept for the voice activated assistant.

Friday, November 10, 2017

We were discussing modeling. A model articulates how a system behaves quantitatively. Models use numerical methods to examine complex situations and come up with predictions. Most common techniques involved for coming up with a model include statistical techniques, numerical methods, matrix factorizations and optimizations.  
Sometimes we relied on experimental data to corroborate the model and tune it. Other times, we simulated the model to see the predicted outcomes and if it matched up with the observed data. There are some caveats with this form of analysis. It is merely a representation of our understanding based on our assumptions. It is not the truth. The experimental data is closer to the truth than the model. Even the experimental data may be tainted by how we question the nature and not nature itself.  This is what Heisenberg and Covell warn against. A model that is inaccurate may not be reliable in prediction. Even if the model is closer to truth, garbage in may result in garbage out
Any model has a test measure to determine its effectiveness. since the observed and the predicted are both known, a suitable test metric may be chosen. for example the sum of squares of errors or the F-measure may be used to compare and improve systems.
#codingexercise 
implement the fix centroid step of k-means
bool fix_centroids(int dimension, double** vectors, int* centroids, int* cluster_labels, int size, int k)

{
    bool centroids_updated = false;
    int* new_centroids = (int*) malloc(k * sizeof(int));
    if (new_centroids == NULL) { printf("Require more memory"); exit(1);}
    for (int i = 0; i < k; i++)
    {
        int label = i;
        double minimum = 0;
        double* centroid = vectors[centroids[label]];
        for (int j = 0; j < size; j++)
        {
             if (j != centroids[label] && cluster_labels[j] == label)
             {
                double cosd = get_cosine_distance(dimension, centroid, vectors[j]);
                minimum += cosd * cosd;
             }
        }

        for (int j = 0; j < size; j++)
        {
             if (cluster_labels[j] != label) continue;
             double distance = 0;
             for (int m = 0; m < size; m++)
             {
                if (cluster_labels[m] != label) continue;
                if (m == j) continue;
                double cosd = get_cosine_distance(dimension, vectors[m], vectors[j]);
                distance += cosd * cosd;
             }

             if (distance < minimum)
             {
                 minimum = distance;
                 new_centroids[label] = j;
                 centroids_updated = true;
             }
        }
    }

    if (centroids_updated)
    {
        for (int j = 0; j < k; j++)
        {
            centroids[j] = new_centroids[j];
        }
    }
    free(new_centroids);
    return centroids_updated;

}

Thursday, November 9, 2017

we were discussing modeling in general terms. We will be following slides from Costa, Kleinstein and Hershberg on Model fitting and error estimation.
A model articulates how a system behaves quantitatively. Models use numerical methods to examine complex situations and come up with predictions. Most common techniques involved for coming up with a model include statistical techniques, numerical methods, matrix factorizations and optimizations.  
Sometimes we relied on experimental data to corroborate the model and tune it. Other times, we simulated the model to see the predicted outcomes and if it matched up with the observed data. There are some caveats with this form of analysis. It is merely a representation of our understanding based on our assumptions. It is not the truth. The experimental data is closer to the truth than the model. Even the experimental data may be tainted by how we question the nature and not nature itself.  This is what Heisenberg and Covell warn against. A model that is inaccurate may not be reliable in prediction. Even if the model is closer to truth, garbage in may result in garbage out
#codingexercise
assign clusters to vectors as part of k-means:
void assign_clusters(int dimension, double** vectors, int* centroids, int* cluster_labels, int size, int k)

{

    for (int m = 0; m < size; m++)

    {

        double minimum = get_cosine_distance(dimension, vectors[centroids[cluster_labels[m]]], vectors[m]);

        for (int i = 0; i < k; i++)

        {

             double* centroid = vectors[centroids[i]];

             double distance = get_cosine_distance(dimension, centroid, vectors[m]);

             if (distance < minimum)

             {

                 cluster_labels[m] = i;

             }

        }

    }

}

Wednesday, November 8, 2017

We were discussing the difference between data mining and machine learning given that there is some overlap. In this context, I want to attempt explaining modeling in general terms. We will be following slides from Costa, Kleinstein and Hershberg on Model fitting and error estimation.
A model articulates how a system behaves quantitatively. It might involve equations or a system of equations using variables to denote the observed. The purpose of the model is to give a prediction based on the variables. In order to make the prediction somewhat accurate, it is often trained on a set of data before being used to predict on the test data. This is referred to as model tuning. Models use numerical methods to examine complex situations and come up with predictions. Most common techniques involved for coming up with a model include statistical techniques, numerical methods, matrix factorizations and optimizations.  Starting from the Newton's laws, we have used this kind of technique to understand and use our world.
Sometimes we relied on experimental data to corroborate the model and tune it. Other times, we simulated the model to see the predicted outcomes and if it matched up with the observed data. There are some caveats with this form of analysis. It is merely a representation of our understanding based on our assumptions. It is not the truth. The experimental data is closer to the truth than the model. Even the experimental data may be tainted by how we question the nature and not nature itself.  This is what Heisenberg and Covell warn against. A model that is inaccurate may not be reliable in prediction. Even if the model is closer to truth, garbage in may result in garbage out.

#codingexercise
Get Tanimoto coefficient between two vectors

double get_tanimoto_coefficient(int dimension, double* vec1, double* vec2)
{
double numerator = 0;
double denominator = 0;
double dotProduct = 0;
double magnitude = 0;
int i, j;
    for (i = 0; i < dimension; i++) dotProduct += vec1[i] * vec2[i];

numerator = dotProduct;
    for (i = 0; i < dimension; i++) magnitude += vec1[i] * vec1[i];
denominator += magnitude;
    magnitude = 0;
    for (i = 0; i < dimension; i++) magnitude += vec2[i] * vec2[i];
denominator += magnitude;
denominator -= dotProduct;
if (denominator == 0) return 0;
return numerator/denominator;
}

Tanimoto coefficient looks awfully similar to cosine distance but they have very different meanings and have little similarity other than expression syntax 

Tuesday, November 7, 2017

We were discussing the difference between data mining and machine learning given that there is some overlap. In this context, I want to attempt explaining modeling in general terms. We will be following slides from Costa, Kleinstein and Hershberg on Model fitting and error estimation.
A model articulates how a system behaves quantitatively. It might involve equations or a system of equations using variables to denote the observed. The purpose of the model is to give a prediction based on the variables. In order to make the prediction somewhat accurate, it is often trained on a set of data before being used to predict on the test data. This is referred to as model tuning. Models use numerical methods to examine complex situations and come up with predictions. Most common techniques involved for coming up with a model include statistical techniques, numerical methods, matrix factorizations and optimizations.  Starting from the Newton's laws, we have used this kind of technique to understand and use our world.


#codingexercise
Describe the k-means clustering technique
void kmeans(int dimension, double **vectors, int size, int k, int max_iterations)
{
     if (vectors == NULL || *vectors == NULL || |size == 0 || k == 0 || dimension  == 0) return;

     int* cluster_labels = initialize_cluster_labels(vectors, size, k);
     int* centroids = initialize_centroids(vectors, size, k);
     bool centroids_updated = true;
     int count = 0;
     while(centroids_updated)
     {
         count++;
         if (count > max_iterations) break;
         assign_clusters(dimension, vectors, centroids, cluster_labels, size, k);
         centroids_updated = fix_centroids(dimension, vectors, centroids, cluster_labels, size, k);
     }

     print_clusters(cluster_labels, size);
     free(centroids);
     free(cluster_labels);
     return;
}

Monday, November 6, 2017

We were enumerating the differences between data mining and machine learning. Data Mining is generally used in conjunction with a database. Some of the algorithms included with models and predictions used with data mining fall in the following categories:
Classification algorithms - for finding similar groups based on discrete variables
Regression algorithms - for finding statistical correlations on continuous variables from attributes
Segmentation algorithms - for dividing into groups with similar properties
Association algorithms - for finding correlations between different attributes in a data set
Sequence Analysis Algorithms - for finding groups via paths in sequences

Some of the machine learning algorithms such as from MicrosoftML package includes:
fast linear  for binary classification or linear regression
one class SVM for anomaly detection
fast trees for regression
fast forests for churn detection and building multiple trees
neural net for binary and multi-class classification
logistic regression for classifying sentiments from feedback

Applications of machine learning are generally for :
1) making recommendations with collaborative filtering
2) discovering groups using clustering and unsupervised methods as opposed to neural networks, decision trees, support vector machines and bayesian filtering which are supervised learning methods
3) searching and ranking as used with pagerank for web pages
4) text document filtering
5) modeling decision trees and
6) for evolving intelligence such as with genetic programming and elimination of weakness

#codingexercise
Get cosine similarity between two vectors

double get_cosine_distance(int dimension, double* vec1, double* vec2)
{
    double distance = 0;
    double magnitude = 0;
    int i, j;
    for (i = 0; i < dimension; i++) distance += vec1[i] * vec2[i];
    for (i = 0; i < dimension; i++) magnitude += vec1[i] * vec1[i];
    magnitude = sqrt(magnitude);
    distance /= magnitude;
    magnitude = 0;
    for (i = 0; i < dimension; i++) magnitude += vec2[i] * vec2[i];
    magnitude = sqrt(magnitude);
    distance /= magnitude;
    return distance;
}