Thursday, 4 August 2016

Thoughts on Labour Cardiff leadership competition hustings

While, unfortunately, not a lot of new information was presented in these hustings it rather sums up how the debate has gone in general thus far. It is telling that the hashtag "#IAgreeWithJeremy" has been trending for a couple of hours now as primarily that was the theme of the debate. To understand this, you have to understand the history of the competition  as it started out with a leadership coup - a deliberate attempt to force Jeremy Corbyn to resign through media smears and coordinated resignations. Smith's attempts to emulate Corbyn's policies in this light come across as a cynical attempt to convert Corbyn supporters as Corbyn is currently set to win the leadership contest by a landslide just as he did last year. So from this point on-wards I will focus on the differences between the two candidates:

The EU was a primary point on which the candidates disagreed. Corbyn is of the opinion that we should respect the outcome of the brexit referendum whereas Smith believes that we should hold a second referendum with the option of pulling out before triggering article 50. While many of us were pro-remain (including myself) there are a few issues with Smith's stance - primarily if he is talking about a snap election (which is highly speculatory in itself), it's worth noting that two thirds of constituencies across the UK voted  to leave. Unfortunately this means that in the context of a general election, the single most divisive subject in recent political history will be significantly stacked against Labour simply because of the first past the post electoral system. The other issue that I have with it is that I believe Smith must know this - he also knows that whether or not to respect the referendum is a divisive issue in the Labour party. This is a classic "wedge" strategy, designed to split the pro-Corbyn vote. In light of all this, I am strongly of the opinion that Labour is much better positioned, in the context of a snap election, to campaign on a platform of ensuring and even improving worker's rights and providing a substantial fiscal stimulus to offset the negative financial aspects of the referendum.

There are other points of contention over Brexit such as the controversial TTIP trade deal which, in a leaked draft which was published on the BBC website, indicated that certain public health services including hospitals, if they have been privatised, effectively cannot be brought back into public ownership. If a future government does move back to a single-payer system, then the private company would be allowed to sue the government on the basis of lost profits because of unfair competition. This is effectively a form of "ratchet mechanism" ensuring that public services are run more and more by the private sector. In 2014, David Cameron was very fond of the TTIP trade deal stating that he would put "rocket boosters" on it - so presumably it is the case that the Conservatives are in favour of this kind of ratchet mechanism which puts road up blocks to single-payer health systems. Labour should be putting across the point that they will negotiate trade deals which will not undermine our valuable public services.

A moral obligation of us all, I believe, is to ensure that EU citizens who have settled in the UK and UK citizens settled in the EU should have their rights protected. I believe Labour is much better positioned to do this if they make this a negotiating target rather than going into a general election with a promise to deliver an extremely unpopular referendum.

A problem I had with Smith in particular was that he is too willing to pay anti-immigration sentiments lip service. It came across as though he wanted to appeal to those on the right but does not seem to have any particular idea about what to propose simply saying that he "would not put a finite number on it" when speaking of immigration caps. This seems both at odds with his stance on the EU but this kind of rhetoric is also the kind of thing that has enabled the infamous post-Brexit racism. By contrast, Corbyn channeled Diane Abbot drawing attention to the issue that the immigration policies for those outside the EUs are so restrictive that they stop families from re-uniting.

Another point of significant disagreement was over the trident nuclear deterrent. It is of course not particularly clear how functional it actually is as a deterrent and does cost a large amount with estimates of around £205 billion in costs at a time when we're making massive spending cuts in other areas. Cynically I'd suggest that our biggest nuclear threat is most likely to be Donald Trump acting on his "first strike" nuclear policy and sparking a war - of course that doesn't help us so much as the dead reckoning system on the trident missiles relies on US satellites to calibrate, it is not a particularly independent weapon. The immediate callousness of politicians and their willingness to "push the button" comes across to me as oddly remorseless. It is also the case that primarily our national threats are greatly dispersed, our primary military involvement is in the Middle East and our war against ISIS for which nuclear weapons are grossly inappropriate.

On anti-Semitism within the Labour party, Smith said that he thinks the party should take a zero-tolerance approach and act immediately. Corbyn is of the stance that members should be allowed due process, under his leadership members have indeed been suspended rather swiftly. The socialist Jewish outlet Jewish Voice tweeted:
Fiscal stimulus is another area where they disagree somewhat - while they both agree  that spending packages are necessary, Corbyn proposes a £500bn package involving the creation of a national investment bank whereas Smith is slightly more conservative in suggesting a £300bn spending package.

In general I felt that the hustings largely just reflected the overall debate that we've had so far with fairly little deviance between. In my estimation the crowd seemed to respond more positively toward Corbyn than towards Smith. Some of the points Smith made, particularly on immigration, echoed back to a recent episode of newsnight where he considered "small-c conservatism" to be something he advocated.

Smith also advocated "good, old fashioned socialist policies" although I do not think "old fashioned socialism" is really something many want to get behind.

Smith has a long way to go to win this contest in my estimation, and this charade continues to do more damage to the Labour Party than it is ever likely to resolve.

Sunday, 10 April 2016

A hybrid representative/direct democratic model

There are some problems with the way that we currently implement representative democracy in parliamentary democracies in many countries, including the UK. Part of the issue with this is that your representative is not always going to align with your viewpoint. For instance, I am currently in a constituency with a Conservative MP who is very loyal to the party line and who I am unlikely to change the views of by writing to them. For instance, in a previous post I made, I advocated for proportional representation - however, my MP has come out in favour of FPTP. In some sense, that means that my representative cannot effectively represent my views because of an ideological divide.

Now when you look at direct democracy, where voters can vote on propositions/bills directly, that has some benefits in the sense that it directly acts on a voter's viewpoint. Although it does have some problems such as tyranny of the majority and people who do not vote on particular bills or don't have the time to keep up to date on every little detail of every issue (i.e. most people) end up not having their views represented properly.

The idea that one of my colleagues suggested to me was this: For a particular bill, an MP would have as many votes as the amount of people in their constituency - when an MP votes, they cast all of those votes on their constituents' behalf. However, if a constituent wishes to, they have the option of voting a different way to their MP. So for instance if your MP is voting to cut welfare, then you would have the option of voting the opposite way to them. This also means that if you aren't interested in a particular issue, then you're still represented by your MP. This may also help to balance out "tyranny of the majority" since the representatives are still likely to cast most of the votes on most issues.

The main argument against such a system seems to be that historically it would have been difficult to administer. These days, however, setting up an electronic software system to do it is easily within the realms of possibility. It seems like it would be a good candidate for giving citizens more of a say in the way that their country is run without some of the drawbacks of direct democracy and to help give people power to counter other forms of democratic deficit.

I've had trouble finding any systems that work like this in practice, so if you know of any, let me know! This hybrid democratic model may well be worth voting for.

Thursday, 10 March 2016

People under Proportional Representation 11% happier than those under First Past the Post systems

Having recently come across the fact that Denmark had (although now it would appear to be Switzerland!) the highest happiness rating in the world and that it uses a proportional representation - and it certainly seems like having your voice heard could somehow correspond to happiness - I decided to investigate whether there was a link between proportional representation systems and happiness. To do this, I gathered data from the 2015 world happiness report, which countries use the List PR system (from IDEA, 10/03/2016) and which countries use FPTP (from IDEA, 10/03/2016).

Briefly, proportional representation is a system whereby the number of representatives selected for parliament is proportional to the amount of people who voted for that party. First past the post is a constituency based system whereby members of parliament are selected based on a vote taken in some geographical location; in this system a single MP runs for a particular area. If you live in the UK or USA then you are under first past the post.

Read more on FPTP vs PR

I made a reasonable attempt to make sure as much data as possible could be linked to either of these systems although a significant number of countries did not take part in the world happiness report and so were ignored. The means of the happiness scores were compared in this analysis.

Findings: PR had an 11.56% higher happiness rating than FPTP and 4.8% higher than all countries combined.

Happiness of different electoral systems (NOTE: Non-zeroed graph! Pay attention to scale - I can't figure out how to fix it and feel kind of sick anyway so...)
However, there is the caveat that the difference between the happiness given by the two systems does not exceed the standard deviation.

Countries with FPTP include the United States, the United Kingdom, Canada and India
Countries with PR include Switzerland, Denmark, Sweden, Iceland, Austria and Russia

Other notable countries include Germany who have their own system

So what does this say? It seems to suggest that countries with proportional representation systems are more likely to be happy. Certainly this is a correlation and not a causation - although a plausible cause is that people who feel they are adequately represented in government are more likely to be happy although there are likely to be many confounding factors including the country's history. It seems to be the case that Proportional Representation tends towards creating coalition governments who tend to have to come to consensus based policies rather than guided by ideology or party bias.

Download the data

Sunday, 24 January 2016

The frustrating, fragmented state of programming for mobile devices

If you want to program for a mobile device, you'll find a frustrating set of trade-offs. To introduce this topic, I'll introduce some of the major platforms for the mobile ecosystem.

The native platforms:

Android SDK 

If you go this route, you're stuck with Java. The Android SDK for whatever reason is tied completely to the Java programming language, despite Oracle using it as a rod to try and beat Google with. The API that it provides is fairly usable and there are a large number of tools which make this quite an easy process. However, this is only if you intend to target Android devices and nothing else.

Android NDK

It's curious that Google doesn't put more work into this, it seems that they try to do everything to discourage developers from using it. This is partly because applications which are developed this way will not make architecture agnostic executables. Nonetheless, the NDK has a lot of potential as a LLVM compatible compile target which could support a number of languages targeting it. However, the Google supported libraries with this are limited, it is essentially the case that you call NDK code from an SDK developed application putting limits on what you can do with it. There are some positives in that you can at least write applications using SDL, for instance, this way.

iOS SDK 

Again this is a similar situation as with the Android SDK. You have a couple of options here, you can choose to write applications using Apple's latest and greatest Swift language or you can choose to use Objective-C. Because Objective-C is compatible with C, it is also possible to write applications in C (just like with Android).  Again, though, choosing to use the native libraries ties you to that target platform.

Windows Phone

C# or something. I'm not really familiar but I assume that it's pretty good and again totally analogous with the iOS and Android situations.


What you probably notice here is that all of the provider supported phone platforms have basically zero interoperability with one another.

This goes fairly deep as Google's version of Java does not rely on standard .class files full of Java Byte Code, but instead packages code into its own Dex format (which incidentally is not compatible with any platform bar Android). The consequence of this is that, while the platform is very well optimised with Java code, no other languages in the Java ecosystem are compatible with it (which rules out Clojure, Scala, JPython, JRuby, and so on).

So we've ascertained that the standard toolkits are incompatible with one another. What are we to do? Well there are a number of cross platform SDKs:

Xamarin 

Xamarin is the most popular/best marketed cross platform framework for mobile development. It has the major advantage of creating applications with a "native" look and feel, but unfortunately is not free. It also has the caveat of only supporting C# and since it is a closed platform solution, it is unlikely to gain any developer support in terms of supporting other languages. It also seems to only provide a thin layer of abstraction between Android and iOS, meaning that you'll still have to write a large amount of platform dependent code unless you can shoehorn it into their forms framework.

Qt 

Qt has been around for a long, long time on the desktop and you can program mobile applications with it, too. Applications that you create with it will have a native look and feel, and indeed it's open source so you can use it for free. Again though, it does very little to provide developers any flexibility in terms of the tools they can use with their project and you will be using their QtQuick QML and ECMAScript/JS dialect to write your applications.

JavaScript/HTML5

There are ways to bundle your webpage into an app if you want to. Cordova is one such technology although its documentation is for whatever reason mindbogglingly obtuse to for something which you would want to use to simplify your workflow. There is also the caveat that such applications cannot resemble the native UI, and they will by necessity be running in some kind of VM which may harm battery life (although I cannot confirm this). Attempts at simplifying this include PhoneGap and Intel's XDK - even then these are not exactly seamless

LibGDX 

LibGDX is a Java framework primarily for games which targets Android, iOS, the web (using GWT) and the desktop. It does what it does very well, giving a unified interface to create games for many platforms. However, it has the caveat that it is domain specific (you can see this as a strength or a weakness). It also has a user interface library which you can use to create stylised (but very non-native looking) UIs. This is a strong candidate if you're a game programmer who wants to target multiple devices.

---------

While there are a plethora of solutions for creating different kinds of applications for the mobile platform, some of them even interoperable with desktops, it's striking that there's also no highly unified, open way of creating mobile applications which allows you to use your own tooling, your own choice of language - essentially what I'm trying to get at here is that while there are several highly targeted platforms for mobile development, they are all quite tied down by their limitations. This is not the same on the desktop where you can have a new language, for instance Nim, which can be made compatible with all of your existing libraries through foreign function interfaces or you can develop native-look applications with any of a multitude of free libraries which have wrappers for a vast amount of programming languages.

Even Java, the venerable advocate of portability, has been torn apart by this situation where under Android its implementation is highly non-standard, its implementation is far behind the language specification (Java 8's first stable release was in March 2014 and is still not supported even though it is the platform's major language; the JEPs for the language dating as far back as 2011) and its ecosystem is barely supported at all (with the notable exception of its IDEs). Nobody seems to be attempting to write backends for other major programming languages which target the Android Dex bytecode format. There is, for instance, no Dex backend for LLVM (at least not that I can find).


It's hard to tell what the future holds - I imagine that in the distant future it might turn out that WebAssembly is used as a standard target running in a small VM on phones. Ultimately it would be good if the companies involved could band together and attempt to standardise the situation somehow but of course they have vested interests in trying to make developers focus on one platform or the other. It's important to remember that the reason this happened on the desktop is because the x86 architecture became dominant and everybody just targeted that. In this brave new world of hardware agnostic phone OS vendors that is no longer possible. Of course it's a good thing that hardware vendors can be competitive in the mobile devices industry, but the fact that the abstractions don't play nice together is problematic.

It is worrying that the major player with regards to cross-platform compatibility seems to be Xamarin with their closed, pricey, solution that still requires you to write a lot of device dependent code. Frustratingly it seems that the best solutions at the moment are either to write your application n many times for the platforms you wish to target or use the web as a target since that is also supported everywhere - Qt probably offers the best trade off between these solutions as it stands and LibGDX is great if you're interested in implementing a game.

Wednesday, 23 December 2015

Nimble Explorer

Nimble Explorer is a small website I've knocked up which allows you to search for packages for the Nim language contained in the its package manager Nimble. It's written almost entirely in JavaScript and Nimble, making use of JSONP to retrieve the Nimble's JSON file from Github with a backend which caches the JSON file for browsers which do not support JSONP properly as a fall-back.

It uses Fuse.js to power its search, and explorer.js (the front-end JS file for nimble-explorer) enhances this somewhat by implementing a search narrowing mechanism (specified by space separated words) and searching for tags. The search mechanism was quite easy to work with, although required some tweaking before it worked sensibly.

At this point it's quite usable, and will even work in many browsers in Google's cached version of the page (which is useful in case Linode, my host, decides to perform some surprise maintenance).

This is also the first time I've set up a web deployment mechanism using Git and it's working very smoothly which is nice

Monday, 23 November 2015

HOG+SVM for gun detection in CCTV images

I have made a small collection of training data (currently around 18 images images, in two sets of 9 of people with guns and people without guns) and have made a basic implementation which attempts to guess whether somebody has a gun using support vector machines based off of 128x128 CCTV camera stills of people either carrying a gun or not carrying a gun. The present implementation appears to overfit the data so I will attempt to resolve this; it always correctly classifies everything in the training set but usually errs to the side of false negatives when  classifying test data from casual observation.

Progress to be made on this:

Collect more images (ideally 50 with guns, and I can take the rest of the images from pre-existing person reid datasets like ViPER - edit: may need some images from scenes in which guns appear in case the detector becomes influenced by the lighting/other composition of the scene.)

Find out how to regularise(?)/prevent overfitting in the model I've come up with

Formalise the analysis stage.

The source code for this version of the program can be found here:

http://pastebin.com/nz5cQx3k

To be honest, you can get rid of that opencv dependency.

Sunday, 22 November 2015

An eye for guns

In my upcoming series of posts, I will be exploring ways to automatically detect armed attackers in CCTV feeds using Python and OpenCV. Of course I'm sure the motivation for this given the recent terrorist attacks in Paris, Mali and others is obvious. The scope of this is currently quite broad, so I will attempt to narrow it down to some key points:


  • Reliable detection of an AK-47/Kalashnikov rifle from a low quality video feed.
    •  The motivation for this should be self explanatory
  • Suspicious body language detection
    •     There is some reason to believe that body language can be indicative of unusual behaviour. Being able to detect this may lead to effective tracking of suspicious individuals before they are capable of executing an attack
  •  Suspicious dress behaviour
    •  The attackers in Paris dressed in dark clothing and attacked at night. This could prove challenging, however in combination with body language detection a useful detector could be produced.

Goal one:
AK-47 detection in a still image - this will hopefully lend itself to progress in a real-time video detection scheme. More specifically, this should be a gun currently being carried by somebody rather than just in some luggage. This may be extended to potential containers for an AK-47 as they must be transported somehow.

Literature dump: 
http://www.sciencedirect.com/science/article/pii/S1877050915014076

http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=7253863&url=http%3A%2F%2Fieeexplore.ieee.org%2Fiel7%2F7227935%2F7253613%2F07253863.pdf%3Farnumber%3D7253863
http://cvgl.stanford.edu/teaching/cs231a_winter1415/prev/projects/CS231AGun.pdf

http://airccse.org/journal/ijcseit/papers/2212ijcseit16.pdf

http://staffnet.kingston.ac.uk/~ku33185/MEDUSA.html
... + more but lazy.

Edit: The MEDUSA project looks like a promising source of information, although appears like it may have been underfunded.

Youtube has a large collection of videos involving potential attackers and mock attacks which may contain highly useful training data for supervised learning based detectors.

Labelling data may prove difficult. I will have to evaluate whether it is worth doing it myself, generating the data (3D images can be effectively be used for object recognition in combination with domain adaptation techniques).

I would ultimately like to come up with some affordable way to disable firearms within a room - although my initial thoughts on this remind me of a children's TV show where the contestants would be covered in some kind of gunk - thinking about the way custard works - perhaps a more hardy non-newtonian fluid could be used to jam a rifle? 

Should I be successful in any of these topics, they shall of course be free and open to all so that hopefully these systems can be implemented to help prevent terrorist attacks in major cities and for those who are otherwise interested in learning about computer vision applications. A hefty research grant of course would not go amiss.