Sunday, March 22, 2015

Blue Ocean Presentation on Xamarin Forms

Yesterday I presented two sessions at the Blue Ocean Competition on Xamarin, Azure and the C# ecosystem in general. From the reaction received after my sessions the students seemed to have really been captivated by the possibilities afforded them by using Xamarin Forms, Azure and C# to turn their ideas into real products.

As mentioned during my presentation, I created a full Xamarin Forms demo for Android, iOS and Windows Phone tied to Azure Mobile Services. The full source code I put up on my github account here. For those not use to Git, I also packaged together all of the code into a zipfile here.

I developed the demo in Visual Studio 2013 Update 4, but it should work in the 2015 preview as well.

Those looking for the Powerpoint presentation you can download it here.

Tuesday, March 03, 2015

C# Predictive Analytics with jcANALYTICS

A little over a year ago now at work I started diving into my next generation platform. I knew it would have the usual specifications: super fast and efficient, full audit handling etc. The crown jewel was to be a fully automated scheduling engine, but over time the platform itself evolved into the most dynamic platforms I know to exist. Fast forward a few months as the system was in Alpha, I started having my own questions of how to start predicting events based on data points now that I was storing much more data. With several other requirements taking precedence I put it on the back burner knowing the "brute force" method of comparing every value of every object on a per class or report was not ideal nor viable given the amount of reporting possibilities.

Last Sunday afternoon after playing around with Microsoft's Azure Machine Learning platform, I came to the realization that their solution while great for non-programmers I was left feeling as though I could do the same thing, but better in C# and because of that I could integrate it across every device even for offline native Mobile experiences.

Thinking about the question I had a while back at work, how can I predict things based on 1 (or maybe no data points)?

Breaking down the problem - the first thing is to reduce the data set. Given a thousand or millions of rows, chances are there are patterns in the data. Reducing the individual rows to what more than likely is considerably smaller would make additional processing and reporting much easier and more meaningful. Give a million rows to a C-Level executive and they'll be left wondering what they are even looking, but group the data points into maybe the top 10 most common scenarios and immediately he/she will see value.

At this point this is where I opened Visual Studio 2013 and dove into the problem at hand. An hour later I had a working reusable library: jcANALYTICS. As of right now the .NET 4.5 library does the following:

1. Reduces large datasets into groups of datasets
2. Helper methods to return the most common and least common data rows
3. Solution completer - providing an object, based on the larger dataset, fill in the blanks

As of right it is also multi-threaded (can be turned off if desired). Given 100,000 objects on my AMD FX-8350 (8x4ghz) desktop it processes in just under 5 seconds - though there is certainly room for optimization improvements.

The next big question I imagine is how will this work with my existing application? Knowing utilization of an external library takes some serious considerations (will the company cease to exist, thereby eliminating support, how much in bed will I be after integrating the framework or library etc.). Well good news - at a minimum to process a dataset just 2 lines of code.

Let's assume you've got some class object like the following:

[Serializable]
public class Users {
     public string Username { get; set; }

     public bool? HasIOS { get; set; }

     public bool? HasAndroid { get; set; }

     public bool? HasWinPhone { get; set; }

     public bool? LivesInMaryland { get; set; }
}
To make it work with jcANALYTICS, just inherit from the jcAnalyticsBaseObject class and mark the properties to analyze with the Tally attribute like so:

[Serializable]
public class Users : jcAnalyticsBaseObject {
    public string Username { get; set; }

    [Tally]
    public bool? HasIOS { get; set; }

    [Tally]
    public bool? HasAndroid { get; set; }

    [Tally]
    public bool? HasWinPhone { get; set; }

    [Tally]
    public bool? LivesInMaryland { get; set; }
}
That's it, then assuming you've got a List collection of Users you would simply use the following lines of code to process the data:

var engine = new jcAEngine< Users >();
engine.AnalyzeData(users);
After that you've got 4 helper methods to access the analyzed data:

1. GetMostCommon - Returns the most common data row
2. GetLeastCommon - Returns the least common data row
3. GetGroupItems - Returns the analyzed/reduced data points
4. GetCompleteItem - Given an object T based on the common data, fill in an properties based on the most common data that fits what was passed

I think the top 3 are self explanatory, but here's an example of the last function. Using the Users class above, assume you knew that they lived in Maryland and had a Windows Phone, but you wanted to know based on the other data whether they had an iOS and or Android device as well like so:

var incompleteItem = new Users { LivesInMaryland = true, HasWinPhone = true };
var completeItem = engine.GetCompleteItem(incompleteItem);
The engine would proceed to look at all of the data points and use the most probable values.

Going forward, my immediate objectives are to optimize the AnalyzeData method and make the library into a Portable Class Library so I can use it on any platform. Longer term I hope to continue to add more methods to analyze and produce data.

You can download the library from the NuGet Console or from here:

PM> Install-Package jcANALYTICS.Lib