Book Review: Ancestral Machines, Michael Cobley

ancestralmachinesThis is the first book that I’ve read from Michael Cobley. I was drawn to it by reviews such as “An absolute cracker of a space opera” and “Here is a space opera which unashamedly honours the roots of the genre”. Also, it’s good to know that there are other related books by the same author in the Humanity’s Fire trilogy.

That said, I found the book overly complex, with a vast array of characters and numerous distinct plot lines that took hundreds of pages to come together. Too often, we were introduced to characters who then seemed to disappear completely. For example, two women in Captain Pyke’s close-knit crew, Dervla and Win, were introduced as integral members of his team. Once captured, the team took on impossible challenges to save them – but unfortunately, we never heard about Win again!

The most memorable character(s) of the book was the drone Rensik Estemil. Hugely intelligent and an effective fighting machine, he somehow got trapped in a mesh box (Faraday cage?!) – but escaped by casting off a mini-Rensik drone which saved the day.
Four stars

Leave a comment

Filed under Book Review

How to extend F# discriminated unions for use from C#

Some time ago, I wrote about calling C# byref methods from F#. This time, I wanted to do things in reverse – the motivation being to provide a neat way of working with F# discriminated unions from C#.

Now, some support comes for free when you define a discriminated union in F#. For example, given this union type:

type Vehicle
| Car of int // number of doors
| Lorry of double // weight in tonnes

then from C#, you could query the union case in turn like this:

if (vehicle.IsCar)
{
    var doors = ((Vehicle.Car)vehicle).Item;
    driveCar( doors );
}
else if (vehicle.IsLorry)
{
    var weight = ((Vehicle.Lorry)vehicle).Item;
    driveLorry( weight );
}

However, although the provided “Is” methods are neat, the cast and the requirement to call “.Item” are rather ugly. What you really want is the ability to get the value of the union case without casting. That’s achievable if you add these methods to the original union definition by hand:

using System.Runtime.InteropServices // for [<Out>]
type Vehicle
| Car of int // number of doors
| Lorry of double // weight in tonnes
with
    member this.TryGetCar( [<Out>] result : int byref ) =
        match this with
        | Car doors ->
            result <- doors
            true
        | _ -> false
    member this.TryGetLorry( [<Out>] result : double byref ) =
        match this with
        | Lorry weight ->
            result <- weight
            true
        | _ -> false

Now the experience is much better from C#:

int doors;
double weight;
if ( vehicle.TryGetCar( out doors ) )
{
    driveCar( doors );
}
else if ( vehicle.TryGetLorry( out weight ) )
{
    driveLorry( weight );
}

and the new methods are usable from F# as well, although you’d probably prefer to use match:

// Use TryGet approach - returns bool, int
let isCar, doors = vehicle.TryGetCar()

// Use match approach - more natural for F#
match vehicle with
| Car doors -> driveCar(doors)
| Lorry weight -> driveLorry(weight)

Leave a comment

Filed under F#, Programming

ACCU Meetup: A Visual Perspective on Machine Learning, Maksim Sipos

meetup-machine-learningMaksim gave a very interesting presentation on Machine Learning, from his perspective as a physicist.

Machine Learning, AI and NLP are some of the most exciting emerging technologies. They are becoming ubiquitous and will profoundly change the way our society functions. In this talk I hope I can provide a unique perspective, as someone who has entered the field coming from a more traditional Physics background.

Physics and Machine Learning have much in common. I will explain how the two fields relate and how a physical point of view can help elucidate many ML concepts. I will show how we can use Python code to generate illustrative visualizations of Machine Learning algorithms. Using these visual tools I will demonstrate SVMs, overfitting, clustering and dimensional reduction. I will explain how intution, common sense and careful statistics matter much when doing Machine Learning, and I’ll describe some tools used in production.

Maksim used Jupyter Notebooks for the demonstration parts of his talk. It’s a great way to show snippets of code as well as plotting charts – I’ve also been using it for a Python library that I’m working on.

The big take-away was that the audience should think of machine learning as very accessible – although there are hard problems left to research, there are a lot of materials available on the internet and much can be understood readily, especially from a visual perspective.

Leave a comment

Filed under Meetup

Tech Book: Algorithms in a Nutshell, Heineman, Pollice & Selkow

algorithmsinanutshellI really enjoyed reading this book, probably the best endorsement I can give for a technical book. The authors introduced the common computer science algorithms that you would expect in a good desktop reference, giving each a block of pseudo code, some analysis of algorithmic complexity and implementation trade-offs, and finally a proper implementation in a standard programming language (usually Java). The later chapters cover slightly more advanced techniques, typically with a practical example. My favourite was their randomised algorithm for estimating a solution to the famous “n-queens” problem (developed by Knuth in 1975).
Five Stars

Leave a comment

Filed under Tech Book

How to use the Digital Crown in a Watch Face App

I’ve written before that, having lived with the Apple Watch for a while, I felt the watch faces lacked variety. So, I wrote a watch face app, which I now use for the majority of the time.

For my next watch face, I thought it would be pretty cool to recreate the look of my beloved Tissot watch. One of its best features is that extra functionality is controlled by twisting/pressing the bezel. It supports date/time/stopwatch/timer – or you can hide the digital display altogether. Although WatchKit doesn’t allow you to capture a button press, you can use the digital crown to scroll between choices – so I thought I’d offer a couple of date formats as well as the option to hide the date altogether. tissot

Add a Picker control onto your storyboard and connect it to a WKInterfacePicker in your InterfaceController. There are a number of styles that you can choose, but for my purposes, I chose the default List style:
screen-shot-2017-01-12-at-19-09-55
Then it’s a matter of populating the picker’s list of items – for example, this code could go in function awake(withContext):

            let blankLine = WKPickerItem()
            blankLine.title = ""
            
            let currentDate = Date()
            let dayDateMonthLine = WKPickerItem()
            dayDateMonthLine.title = "\(currentDate.dayOfWeek()) \(currentDate.dayOfMonth()) \(currentDate.monthAsString())"
            let dateMonthYearLine = WKPickerItem()
            dateMonthYearLine.title = "\(currentDate.dayOfMonth()) \(currentDate.monthAsString()) \(currentDate.year())"
            
            InfoPicker.setHidden( false )
            InfoPicker.setItems( [ blankLine, dayDateMonthLine, dateMonthYearLine, blankLine ] )
            InfoPicker.focus()

I set the focus on the picker so that the digital crown is immediately responsive (otherwise, you’d have to select the picker first on the touch screen). I also put a blank line before and after the date formats, to make the usage more natural. The code above also uses some extension methods on Date.

Tissot style watch face

Seeing how good this looks, I think Apple are missing a trick. All of their analogue Apple Watch faces are round – I hope they ship a couple of rectangular faces in the next Watch OS upgrade.

2 Comments

Filed under Programming, Swift

IET Meetup: A Cloud Enabled World, Neil Lewis (Hitachi)

meetup-cloud-enabled-worldThis evening’s presentation at the Institute of Engineering and Technology was sponsored by Hitachi on the subject of The Cloud.

As the Public Cloud is seeing explosive growth for modern internet based business and their web native applications, how can traditional IT originations with a more traditional IT landscape benefit from some of these trends whilst maintaining their legacy?

Neil Lewis explained that, despite years at the forefront of Data Services, Hitachi Data Systems is now re-positioning itself as a Cloud Solutions provider, rather than solely provisioning private infrastructure and software support to enterprises. Whether they can compete with Amazon Web Services or Microsoft Azure, time will tell – but Hitachi have decided to adapt rather than see their business model become irrelevant.
screen-shot-2017-01-11-at-21-02-13

Leave a comment

Filed under Meetup, Technology

Artificial Intelligence Primer, David Kelnar

IAmWire.com published this excellent post on artificial intelligence.

The last 10 years have been about building a world that is mobile-first. In the next 10 years, we will shift to a world that is AI-first.” (Sundar Pichai, CEO of Google, October 2016)

Having witnessed the scope of AI-based projects referenced at 2016’s Intel Software Developer Conference, it’s hard to argue. The range of disciplines that have been revolutionised in the last couple of years by deep learning is deeply impressive. Step changes in speech recognition and image classification have been shown and there’s massive potential for development in other areas such as medical diagnosis. Here’s what Deep Mind Medical have to say:

We think that machine learning technology, a type of artificial intelligence, can bring huge benefits to medical research. By using this technology to analyse medical data, we want to find ways to improve how illnesses are diagnosed and treated. Our goal is to help clinicians to give faster, better treatment to their patients and all our research work is done in collaboration with doctors and professional healthcare researchers.

There could be very few jobs that remain untouched by artificial intelligence in the coming years, but hopefully there’ll still be plenty of programming jobs.

Leave a comment

Filed under Technology

How to learn Python III – Google Python Class

I recently found a link to the Google Python Class in my inbox and have been very impressed with it. Whilst I’ve already explored some Python learning materials, this class benefits from a combination of lecture videos, online resources and exercises (with solutions) that’s hard to beat.

I’ll repeat the index here for (my!) ease of reference:

  1. Introduction
  2. Strings
  3. Lists
  4. Sorting
  5. Dicts and Files
  6. Regular Expressions
  7. Utilities

The exercises in particular show the power of Python, leveraging the commands, os, re and urllib modules to great effect.

The presenter Nick Parlante is enthusiastic and expertly demonstrates how to work incrementally with Python, on top of doing a great job of teaching the syntax.

nickparlante

Leave a comment

Filed under Python

ACCU Meetup: Functional C++ (Phil Nash)

meetup-functional-cPhil Nash presented his ideas on functional C++ to a packed ACCU meeting a couple of weeks ago. He kindly provided the slides on his website.

For the uninitiated, the functional style is often quite a shock, but having written F# for some time, I’m in favour of “modelling computations as evaluations of expressions” as Phil presented it, or the declarative style as it’s often described. I wrote about Higher-Order Functions in C++ recently and Phil touched on that as well.

One of the highlights of the talk was the section on persistent data structures, which share as much of the previous state as possible whenever additional elements are added. For example, an associative binary tree could have a new element added, but retain links to the bulk of the original tree. There are challenges to stay balanced, but often the benefits can be worth it (e.g. a red-black, persistent tree that’s thread-safe because all the data is immutable). Phil also presented a Trie hybrid with hashing – a persistent tree structure, with performance similar to unordered_map, for which the hashing ensures no re-balancing is required.

The finale was a demonstration of pipelining for C++, based on std::optional (available from C++17). The recommendation was to watch Eric Niebler’s Ranges talk from CppCon 2015 for more details.

Leave a comment

Filed under C++, Meetup

Book Review: Roadside Crosses, Jeffery Deaver

roadsidecrossesRoadside Crosses is a thriller by Jeffery Deaver, featuring one of his regular characters, Kathryn Dance. However, her signature skill of kinesic analysis (the ability to read body language, making her an ace interrogator) isn’t really needed in this story – much of it is set in CyberSpace. The story includes Michael O’Neil, Kathryn’s colleague whom she has admired from afar for several books. It also introduces Jon Boling, an IT expert who is brought into the inner circle of Kathryn’s team to assist with the investigation.

A central theme is a fictional blog that dives into local issues and is a magnet for vicious, under-informed comment from locals. Originally, the author supplemented the book by maintaining the blog at thechiltonreport.com, but it’s no longer available.

I found the book had too many story lines running in parallel and it would have been better to concentrate on one or two of them. For example, Dance’s mother is accused of a mercy killing and is arrested – but that turns out to be a sub-plot that doesn’t lead anywhere. Whilst the author did tie up all the loose ends of the story lines, I thought that the actions of the killer were completely out of proportion to his stated predicament and motivation.
Three Stars

Leave a comment

Filed under Book Review