Choosing data structures

I decided earlier in the week that I wanted to write an implementation of a general Markov chain in C; this is not particularly hard, but it does raise some interesting questions along the way—in particular, about data structures. A Markov chain really consists of two nested data structures: the set of the nodes in the list, and the set of outbound edges from each node; these structures serve vastly different purposes, as the order in which the nodes in the Markov chain are accessed depends on how edges are selected, but edges need to be sorted in a standard order so as to match how a Markov process functions. Accordingly, I found myself basing my decision on a few criteria:

Markov nodes:

  • Order of access not absolutely required to be stable
  • Key most likely in a totally ordered set
  • Minimizing access time a handy thought

Edge nodes:

  • Order of access paramount. Needs to remain stable.
  • Edges absolutely in a totally ordered set
  • Access time less important than order.

Based on these criteria, I arrived at two vastly different structures. For the Markov nodes, that “minimizing access time” led directly to thinking about trees, and thinking about how motion through a Markov chain happens led to considering a splay tree. A splay tree, if you’re unaware, is a binary search tree which has only one operation: splay. When you splay the tree, you modify its structure, bringing the node you are looking for (or the closest match) to the root of the tree. This has the handy property of keeping all the most frequently used nodes right in the top few levels of the tree, and still maintains an amortized O(log(n))—even with the slight probability that repeated splay operations will lead to it becoming a linked list.

To the contrary, the data structure I selected for the edges is a linked list, sorted from largest key to smallest key; in this case, I required that the structure remain stable, and furthermore that it have a particular order, with every node in a known position with regards to its value. Although search is an O(n) operation, it is doubtful a graph will have so many connections as to make that prohibitive, while at the same time maintaining a safe, regular, easy to traverse structure when running find_next_state().

By the by, the current code can be found in my Bitbucket repository, in markov.c and markov.h, respectively. They’re currently under rapid development and are nowhere near release-ready; I’m expecting the API to change significantly over the next few days.

A roundup of some cool things

Okay. We just landed a machine on MARS using a SKYCRANE. How awesome is that?

Also, Bjarne Stroustroup (you may not know who he is, which is a damn shame. You fuckers didn’t know who Dennis Ritchie was, either, did you? Ritchie did more for the modern world than Steve Jobs, Bill Gates, and Steve Wozniak together—and hardly anyone knows his name. He created C. Stroustroup created C++.) has on his website the coding standards for the Joint Strike Fighter project. This is wildly cool, even if you’re not big on the military. It’s cool because C++ has been lambasted so many times for being absurd, and yet these standards lay out how to write minimal, powerful, safe, and real-time code. Here’s the link.

I have a ghost story to tell.

It’s a small one, but it’s mine. (Clearly under my copyright, 2012.)

Read more

Music you don’t approve of.

I was reading the Montréal Gazette the other day, when I came across an article about the Sûreté du Québec investigating a Montréal police shooting. Now, the police claimed the man was suicidal, and attacked them with a weapon. As for those details, we’ll read more about them when the SQ are done with their investigation.

That is not the point of this post.

This post is about a fascinating paragraph from the article: Read more

Of quality and image

Or, Why the HELL did I look at the Burberry website?

See, I’m a guy with an understanding of how raw materials become fabrics become garments. Anyone who pays a little attention can know how things work, and for someone who uses yarn a lot, this knowledge becomes integral lore. If I needed to, I could construct a drop spindle and spin and ply my own yarn; probably, most knitters, crocheters, and weavers could.

This is where today’s little diatribe starts: at the cost of producing a fabric product. For something hand-made, these costs can skyrocket if the effort is exceeding a certain level; there’s no real way to produce things like socks in an economical amount of time, unless you’re selling them for hundreds of dollars a pair; say, 8$/hour with 10$ for materials; most pairs of socks take at least 30 hours to complete, if you’re lucky. Suddenly that’s 250$/pair; (friends of mine, take note: that’s why I don’t sell socks. You can’t afford them, and if I give them to you as a gift, I damn well expect them to be worn.)

What is shocking, though, is going to the Burberry website and seeing a scarf cost 400$ or more; that’s just absurd. That’s fucking absurd, for a machined product. Especially one which uses yarn that I can acquire from an online retailer who is marking up that yarn, having acquired mill ends of it, for about 20-30$ a cone; each cone, if I purchased the four colours necessary to weave one of those scarves, would cover the production of probably four or five scarves, all for around a hundred dollars. Somehow, you expect me to believe that your machine-produced scarves are worth 400$? Bullshit.

On the other hand, I’ll sell people scarves for 350$, with better workmanship than the Burberry product. You can take orders in the comments.

QM isn’t deliberately trying to piss me off.

At least, I hope they’re not. But they are anyways.

I get it. We’re queer, so we need to support other minorities. At some point, though, you’re just ignoring the politics and actual circumstances of certain « oppressed minorities » in order to support them. There’s a strong a recent case of QM’s selective blindness which I’ll deal with here.

QM decided recently that they should support a group that is protesting the efforts by « Pink Money » to clean up the Village, to the detriment of the homeless living there. They pay some lip service to the fact that members of the transient community are drug addicts, and yes, they’re queer. However, the group goes off the deep end when they suggest that really, public sanitation isn’t so big a deal that urinating in an alley is a big problem, so why is it a misdemeanour? This was about the moment when I put palm to forehead and wondered why QM thought this was deserving of support, given the fact that this particular group seems to be focused mostly on continuing to support urban decay. That was when I realised what was seriously underlying the discussion here, a core misunderstanding of why things were happening the way they were. QM — and the group they were supporting — were ignoring the underlying malaise to suggest that no treatment was necessary in the first place, because these people are here. Incidentally, and entirely separately of this e-mail from QM, I’ve come to develop a new personal theory about endemic homelessness in Montréal, and notably the strange characteristics of the community here.

One of the defining aspects of a large section of the homeless community is that they’re tattooed, professionally pierced, and have post-punk haircuts, often with heavily dyed hair. To me, although the first two could easily have been acquired before becoming homeless, that last signifies a vast separation between interests and situation, what I’m coming to deem the Horse and Water problem. The adage goes, « You can lead a horse to water, but you can’t make him drink. » I see this as an accurate depiction of the problem in Montréal, that there are support services available — most likely not quite sufficient, as they always are — but the people for whom they are provided do not care to use them, because their current situation fulfils their needs. Unfortunately, their current situation involves urban decay as a core feature; QM seems to ignore this reality and instead deem the homeless an oppressed minority with whom they must show solidarity. They really didn’t learn after the Queeriot debacle?

Getting back to knitting …

And blogging, apparently. Hey blog! I owe you more material, and a candy. I’ll get around to that when I can get a candy thermometer.

On-topic, then. Knitting is one of the things I love to do, but often ignore for long periods of time. Like playing music. Once I have (more) time, I’ll return to playing the violin. Honest.

Now, really on-topic. Every year, it seems, I return to knitting just as exams and assignments start piling one atop each other; whenever I’m studying and just reading, I start knitting to avoid boredom and stress. Plus, it produces materials that I can give other people. Really, the only problem I see is in acquiring the proper materials here. In Canada, I see a fascinating conundrum of fashionable, modern stores — and low consumerism. Online shopping? Yeah, that doesn’t happen. Stores regularly have no internet presence here, or the least possible presence, which makes acquiring yarn quite difficult, since there’s only a few yarn shops around here.

As for what I’m working on, well, I’m finishing up some socks, and I’m about to work on another pair of socks based on a similar pattern; other things, well … those are secret.

Follow

Get every new post delivered to your Inbox.

Join 103 other followers