Thursday, June 30, 2016

Politically Correct, Green Computer Algorithms? Bullcrap!

In the last few days I've read several articles that all seem to say the same thing: computer algorithms we use today are biased towards wealthy white men, because they are made by companies in wealthy countries and predominantly by white male developers. Therefore they are inherently racist, misogynistic and wasteful. Nice journalistic metaphors were used such as: "Sea of dudes", "discriminatory code", "green algorithms", etc. I call bullshit!

Computer algorithms need to be, most of all, money makers. If Facebook or Google tweak an algorithm one way or another, the result is immediately apparent in the bottom line because of their huge user count. It may be possible that somehow, by cosmic coincidence, wealthy white males would also be the ones making most purchases, moving the most money, and thus the algorithm may appear biased. But it's not. The algorithm performs as it was supposed to. If a face recognition algorithm classifies black people as gorillas, Asian people as blinking, etc, it's not because the algorithm is racist, but because the data it was provided pointed to that result. If looking for a movie title you get torrent links rather than the official web page of the movie it's because that is what people want more. It's not a glitch, it's the way a machine understands reality. An algorithm is no more racist than the Nazi ovens or the Hiroshima bomb.

What I am trying to say is that code, especially now when it is becoming more and more embedded with machine learning (which is a much better term than the terrible misleading "artificial intelligence"), represents an intersection point between specifications, people biases and data biases, to which you add horrible bugs. Algorithms, just like the way pieces of your brain work, are but elements in a puzzle.

"Well, of course, and to make the entire puzzle more socially responsible, we need to make all pieces socially responsible!" That's stupid. It's like working on the paint of the car to make it go faster. Sure, you can use some over engineered paint to reduce drag, but the engine and the wheels are still going to be more important. Male developers don't decide to tweak an algorithm to make it disregard women any more than a human resources female employee doesn't decide to hire developers based on how much they value women. Owners, managers, money ultimately are what lead to decisions.

Stop trying to appear politically correct when you don't know what you are talking about. If a complex computer algorithm that uses math as its underlying mechanism shows a bias, it's not because statistics are racist, but because the data it was fed was biased. The algorithm in question doesn't reveal the small mindedness of the white developer or of the male mathematician, but a characteristic of the world it sees. Even with people feeding them the wrong data, algorithms are more objective than humans - that is a fact - because often you start developing them before you know what you are looking for; a person always works the other way around. Why not use code to show us where we are wrong, or biased, or angry at how the world is, or plain stupid? We have such a wonderful tool to make judgements from formal principles that we can actually tweak and, instead of scrutinizing the principles, you go nitpicking against the developers and the algorithms. I find it especially humorous to see random data introduced into a generic algorithm producing results that are considered biased because you don't like what you see.

Bottom line: want to change the world and make it better? Here is an algorithm for you: take the world and make it better.

And BTW, I find that constantly accusing developers of being white and male is a form of sexist racism. What do you want me to do? Turn black? If you would truly be unbiased you wouldn't care what is the social structure of your IT department. It's only now when computers matter so much that you are bothered of how much the geeks are getting paid.

Wednesday, June 29, 2016

Bookmark Explorer v2.7 - new features

extension options page Just when I thought I don't have anything else to add, I found new stuff for my Chrome browser extension.

Bookmark Explorer now features:
  • configurable interval for keeping a page open before bookmarking it for Read Later (so that all redirects and icons are loaded correctly)
  • configurable interval after which deleted bookmarks are no longer remembered
  • remembering deleted bookmarks no matter what deletes them
  • more Read Later folders: configure their number and names
  • redesigned options page
  • more notifications on what is going on

The extension most resembles OneTab, in the sense that it is also designed to save you from opening a zillion tabs at the same time, but differs a lot by its ease of use, configurability and the absolute lack of any connection to outside servers: everything is stored in Chrome bookmarks and local storage.


Sunday, June 26, 2016

Comparing dates in Javascript

The Date object in Javascript is not a primitive, it is a full fledged object, with a constructor and various instances, with methods that mutate their values. That means that the meaning of equality between two dates is ambiguous: what does it mean that date1 equals date2? That they are the same object or that they point to the same instance in time? In Javascript, it means they are the same object. Let me give you some code:
var date1=new Date();
var date2=new Date(date1.getTime()); // now date2 points to the same moment in time as date1
console.log(date1==date2) // outputs "false"
console.log(date1==date2) // outputs "true", date1 and date2 are pointing to the same object

So, how can we compare two dates? First thought it to turn them into numeric values (how many milliseconds from the beginning of 1970) and compare them. Which works, but looks ugly. Instead of using date1.getTime() == date2.getTime() one might use the fact that the valueOf function of the Date object also returns the same numeric value as getTime and turn the comparison into a substraction instead. To compare the two dates, just check if date2 - date1 == 0.

Friday, June 24, 2016

Facebook page for this blog and chess updates

Clipart of a hand holding a tablet with a facebook page on it I have created a Facebook page for the blog, so if you are tired by my Facebook ramblings and only need the updates for this blog, you can subscribe to it. You may find it here.

Also, I've discovered a bad bug with the chess viewer: it didn't allow manual promotions. If you tried to promote a pawn it would call a component that was not on the page (an ugly component) and then it wouldn't promote anyway because of a bug in the viewer. Hopefully I've solved them both. It mainly affected puzzles like the one I posted today.

Cool chess puzzle from Frédéric Lazard that will wrack your brain!

White to move. Can you draw? Can you win? What would you do? Try - I know it's fucking hard, but do it anyway - to think it through.
[FEN "5kB1/3p1P2/7K/2Pp1P1P/p6p/4P3/7P/8 w - - 0 1"]
1. Kg6 a3 2. h6 a2 3. h7 a1=Q 4. h8=Q Qxh8 (4. .. Qg1+ 5. Kh5 Qxe3 (5. ..
Qg7 6. Qxg7+ Kxg7 7. Kxh4 d4 8. f6+ Kf8 9. c6) 6. Qf6 Qf3+ 7. Kh6 Qf4+ 8.
Kh7) 5. f6 h3 6. Kg5 d4 7. c6 dxc6 8. exd4 c5 (8. .. Qxg8+ 9. fxg8=Q+ Kxg8
10. Kg6 Kf8 11. f7 Ke7 12. Kg7) (8. .. Qh7 9. Bxh7 Kxf7 10. Bg8+ Kxg8 11.
Kg6 Kf8) 9. d5 c4 10. d6 c3 11. d7 c2 12. d8=Q# 1-0

Here is the video for it, from very good channel ChessNetwork:


Thursday, June 23, 2016

Clippy is baaack! ... on my blog

Clippy: it looks like you are bashing furiously on your keyboard. Do you want me to enable Caps Lock? Clippy is back, thanks to this nice project. So what else could I have done than add it to my blog? Just go to Menu and choose your "Assistant".

If the assistant is set, the messages from the blog come from the assistant. It also follows the mouse as it moves around and does various gestures depending on what one does or reads. Have fun!

Tuesday, June 21, 2016

Oh wow, what a beautiful chess combination.

I will give you this as a puzzle, so please try to figure out that White's move is going to be. This and a lot of cool other puzzles are presented by IM Andrew Martin in the following video.

[Event "Ch URS"]
[Site "Moscow"]
[Date "1956.??.??"]
[Result "1-0"]
[White "Tigran Vartanovich Petrosian"]
[Black "Vladimir Simagin"]
[ECO "A53"]
[PlyCount "95"]

1. Nf3 Nf6 2. c4 c6 3. Nc3 d6 4. d4 g6 5. e4 Bg7 6. Be2 O-O
7. O-O Bg4 8. Be3 Nbd7 9. Nd2 Bxe2 10. Qxe2 e5 11. d5 c5
12. Rab1 Ne8 13. f3 f5 14. b4 cxb4 15. Rxb4 b6 16. a4 Bf6
17. Kh1 Bg5 18. Bg1 Nc7 19. Rbb1 Na6 20. Nb3 Ndc5 21. Nxc5
bxc5 22. exf5 gxf5 23. g4 fxg4 24. Ne4 Bf4 25. Rb7 Nc7
26. fxg4 Ne8 27. g5 Qc8 28. Re7 Qh3 29. Rf3 Qg4 30. Qd3 Bxh2
31. Rxf8+ Kxf8 32. Rxe8+ Rxe8 33. Bxh2 Re7 34. Nxd6 Qxg5
35. Qf1+ Kg8 36. Ne4 Qh4 37. Qe2 Rg7 38. d6 Qh6 39. Qd1 Qh4
40. Qe2 Qh6 41. Qf1 Rf7 42. Qg2+ Kf8 43. Ng5 Qxd6 44. Qa8+ Kg7
45. Bxe5+ Qxe5 46. Qh8+ Kxh8 47. Nxf7+ Kg7 48. Nxe5 1-0

Did you find it? I have to admit I did not. The game is Tigran Vartanovich Petrosian vs Vladimir Simagin, played in 1956.

Thursday, June 16, 2016

A jQuery custom selector for 'not hidden' elements

I was working on a project of mine that also has some unit tests. In one of them, the HTML structure is abstracted and sent as a jQuery created element to a page script. However, the script uses the custom jQuery selector :visible, which completely fails in this case. You see, none of the elements are visible unless added to the DOM of a page. The original jQuery selector goes directly to existing browser methods to check for visibility:
jQuery.expr.filters.visible = function( elem ) {

    // Support: Opera <= 12.12
    // Opera reports offsetWidths and offsetHeights less than zero on some elements
    // Use OR instead of AND as the element is not visible if either is true
    // See tickets #10406 and #13132
    return elem.offsetWidth > 0 || elem.offsetHeight > 0 || elem.getClientRects().length > 0;

So I've decided to write my own simple selector which replaces it. Here it is:
$.extend($.expr[':'], {
    nothidden : function (el) {
        while (el.length) {
            if (el[0].ownerDocument===null) break;
            if (el.css('display')=='none') return false;
        return true;

It goes from the selected element to its parent, recursively, until it doesn't find anything or finds some parent which is with display none. I was only interested in the CSS display property, so if you want extra stuff like visibility or opacity, change it yourself. What I wanted to talk about was that strange ownerDocument property check. It all stems from a quirk in jQuery which causes $(document).css(...) to fail. The team decided to ignore the bug report regarding it. But, the question is, what happens when I create an element with jQuery and don't attach it to the DOM? Well, behind the scene, all elements are being created with document.createElement or document.createDocumentFragment which, it makes sense, fill the ownerDocument property with the document object that created the element. The only link in the chain that doesn't have an ownerDocument is the document itself. You might want to remember this in case you want to go up the .parent() ladder yourself.

Now, warning: I just wrote this and it might fail in some weird document in document cases, like IFRAMEs and stuff like that. I have not tested it except my use case, which luckily involves only one type of browser.

Tuesday, June 14, 2016

Every Heart a Doorway, by Seanan McGuire

book cover Every Heart a Doorway started well. Here is this girl that arrives at a specialized institution for "wayward children" - runaways, boys and girls that somehow don't fit into the slot their parents have prepared for them. Like many young adult stories, the main protagonists are young people into a place that accepts them as they are, but is still formal, with strict boundaries. In this case the idea was that the youngsters each have found the door to another world, a world that not only is completely different from ours, but is perfect for them. They have spent some time in it, only to accidentally leave or to be thrown out, with no way to return. After some times years in that place, changed to their deepest core, it is difficult to readapt to the real world, which makes their parents send them to this kind of institution.

From here, though, Seanan McGuire just piles up the tropes, while the careful writing style and setup from the beginning of this short 173 page story decays into a rushed and inconsistent ending. Just like Hogwarts, the house is managed with ancient British style rules, fixed meals, absolute authority, etc. There are children and there are adult teachers. The headmistress is someone who went through the same thing and decided to help others, but outside of that she's just as certain of her point of view and as self righteous as any of the parents that abandoned their offspring there.

And there is this... style, this way of describing the interaction of characters, which annoyed the hell out of me, without being bad as a writing style. You see, the young girl that arrives at the institution is time after time met by people who finish her sentences for her, show her that they think they know better than her, and she accepts it, just because she's the new girl. With that level of meek submission, I wonder why her parents ever wanted her gone. Her perfect world - a place of the dead where she was a servant of royalty and the skill she had learned best was to stay completely still for hours lest she upsets the lord of the dead - was also about total submission, and she loved it there. Most of the people that explored other worlds were similarly bonded to dominant characters that have absolute control over them.

In the end, children start to get killed and the response of "the authorities" is to hide the bodies and instruct youngsters to stay in groups, while the main characters suddenly can use their skills in the real world, as it was completely normal, but fail to use them properly to find the obvious killer. The scene where a skeleton tries to tell them who the murderer is - even if that should not have been possible in the real world - but can only point a finger, so they give up after one attempt of communication is especially sour in my mind.

So yeah, I didn't like the book. I felt it was a cheap mashup of Harry Potter and 50 Shades of Grey, polluted by the author's fantasies of submission and not much in the way of plot or characters. And it's too bad, since I liked the premise immediately.

Monday, June 13, 2016

Metro 2034, by Dmitry Glukhovsky

book cover I've quickly finished the second volume, Metro 2034, by Dmitry Glukhovsky, in the Metro series of books, after reading and being captivated by Metro 2033. To me it felt more geared towards the sci-fi and the writing lore than towards the social satire from the first book. It felt less. There are fewer main characters, fewer stations, less character development, less monsters. The few people that do populate the book are so archetypal that even the author acknowledges it in the guise of a character nicknamed Homer, an old guy that searches for stories and sees his entire adventure an odyssey to be written in a book and his companions filling up the roles of Warrior and Princess and Bard.

Don't get me wrong, I liked it a lot, but I felt that the first book acted as a caricature of current society, with its many stations that each adhered to some philosophy or another, while the second veered quite a large distance from that and went purely towards the catacomb sci-fi thriller. There is still enough philosophical discourse in Homer's musings and it is interesting to see the post apocalyptic world seen through the eyes of someone that lived before as well as with fresh eyes: a girl that only knew one station her whole life. But the book was tamer and I am not the only one to think that.

Now, I scoured the net for some Metro 2035 love, but to no avail. I found a Polish audio book, but nothing else. It is ridiculous how much one has to wait to get a translation of a book written in Russian or how difficult it is to get even the original Russian text.

Monday, June 06, 2016

Metro 2033, by Dmitry Glukhovsky

book cover I've heard of Metro 2033 from a movie link that said Hollywood wants to adapt the book as a feature film, which in fact is really ridiculous: not only is the book famous, it has several sequels, it spawned a video game franchise and many authors have join to write inside a shared Metro universe. So how didn't I know about it? The reason, of course, is that it is written by a Russian: Дмитрий Глуховский. The book was published in 2005 in Russia, but only in 2010 was it published in the US, similar to how Japanese movies or other culturally different art trickles to the predominantly English culture. Meanwhile, the concept has grown so much that there are more than thirty books written in the universe. It's like falling down a rabbit hole. I used to love Russian sci-fi when I was a child and I have not realized how much I missed it until I started reading this book: simple people yet complex characters, with deep philosophical concerns, problems that are rarely solved through sheer force, depressing settings where everything falls apart yet makes people strong and interesting and puts them in the foreground.

Metro 2033 describes a parallel universe where World War III has happened and the few Russian survivors have hidden in the large network of the Moscow subway system. Radiation, biological weapons and other factors have turned the surface into a toxic place, filled with monstrous mutants and terrible creatures, while underground each metro station has developed its own unique culture and mythology. The beauty of the book is that it reads more like a satire of the history of the world and less than a post apocalyptic story. There are religious fanatics, fascists, communists, people who have rejected technology and others that value knowledge and books more than anything else, traders and mystics and people with strange powers. I felt that the author himself didn't really mean to create a credible after war world, as he didn't linger on where the power comes from or how the food is grown or other such technical details, instead focusing on the human spirit, the many myths created to explain the state of the world and radiographed the world in this pathetic microcosm made of barely surviving people.

Somewhere in the middle of the book I got a little bored. I have to admit that the long paragraphs and the many details of some scenes make for difficult reading if you are not in the mood. I loved the book while reading it at night, but had trouble focusing when trying to read on the street or when walking the dog. Yet by the end I am really glad I read the book. I can't imagine reading next anything other than the sequels and I lament the very real possibility that I might delve into the other dozens of books and short stories written by other authors in the same world.

In order to explore the world of Metro 2033, you may start at the Metro2033 web site, of course, where there are beautiful 360 photos of the current Moscow subway stations. Also, you may try the game, which feels a bit dated from the promotional videos, but apparently has a good plot. Of course, exploring the book universe sounds like a better idea, yet most of the spinoffs have not yet been translated into English. Perhaps this is a good opportunity to start reading in Russian...