Archis's Blog

April 30, 2011

PendantEEG drivers

Progress on the Brain Computer Interface project. To recap: I picked the Pendant EEG as my device-of-choice. I did not however, purchase the BioEra or BioExplorer packages. Partially because I hate frameworks (more on that later), and mainly because I didn’t want to spend the money. Part of this is just pain ego. I just wanted a raw library from where I could read two-channel data and then pump it into any pipeline I wanted, without an expensive software to do the same thing. (Don’t get me wrong – BioEra is an awesome architecture and especially for home-training sessions, it’s very powerful).

I spend the last three weeks going over options, and couldn’t find the spec (sort of) for capturing raw EEG data. I noticed that, until about 2009, BioEra had an open-source fork called BioEra Light on SourceForge. Turns out this tool claims to read the PendantEEG data. A quick look at their sources and you’ll find the code (best spec), to read this data. It’s a pity this isn’t part of a native library, but now I intend to make it one.

This weekend will be spend in this coding effort. I’m going to try and stick to C as language of choice, since the lib can then be consumed from Java or .Net or whatever (doing the reverse is possible, but breaks my philosophical rant below.) Since such a raw library is asked for many times, it would make sense for me to publish it, but that’s probably going to take a while before I figure out all the agreements and legalities. If it helps, I’ve pointed you to where you can read the code, at a  glance it seems extremely simple, elegant and well-written. If others have followed a better approach, I’m always willing to improve.

EDIT:

I did some more hunting around. Turns out, I was wrong in my assumption. Someone else published some BSD-licenced C++ code on Google Code here: http://code.google.com/p/pyofeedback

For completeness, here’s the link to BioEra: http://sourceforge.net/projects/bioera/

Both projects were last updated in 2009, and I’ve made contact with their owners to get any help I can. I don’t want another fork going around the web for the next person to find. I’m considering contributing to/using one of the above.

Philosophical rant about frameworks: 

Recently, I’ve acquire an absolute and complete hatred of frameworks. Two Three things in particular I want to avoid follow in my weekend projects at least.

1. Code must compile exclusively out of the same directory. If it’s outside of that directory, especially one-level up, it’s got to be a transparent binary that I care nothing about. I come across way too much code which has “frameworks” to help write executables. Command-line parsing logic, some kind of usage-printing-helper, etc. They’re not exactly classes you can reference in a library, but the code files aren’t in the folder you’re reading your logic from. Massive waste of time if you just want to add another param and move on.

2 .Must conform to the platform. NO syntax overloads. I love language-features and libraries. All code I read, I want to give you a spec: .Net 2.0 or .Net 3.5 or whatever, and if you read a code-line, it must correspond to something directly interpretable by and semantically accurate to an anthropomorphic being named .Net 3.5. If a sentence begins with “See this looks just like an event in Java, but internally…” it’s booted ruthlessly.

3. Unix-philosophy of specific tools for a focussed purpose. Like the Terminator, if the purpose vanishes, the tool must question its own reason to exist. I don’t want an ls command that has a data-driven manifest, that tells it to load listing-provider-factories, that instantiate listing-providers, which have their own configurations providing the parameters for their initialization, thereby allowing you to list, not only files and directories, but all the galaxies and stars, and streets in NY or the known prime numbers, using just one command. I’ll put in the effort to learn, as ridiculous as it may sound, a brand new command for the oft-necessary purpose of listing all galaxies when I’m browsing a folder tree.

April 12, 2011

BCI 2

Filed under: Brain-Computer Interface — Tags: , , , — archisgore @ 9:20 am

A continuation to the original BCI post with very minor updates. The first time, they didn’t ship my electrodes, and in the meantime, I’m in India till 4/20, so have no way of performing any tests until I get back. However, I did get a chance to think of the experimental setup and what my initial sanity tests will be. I won’t be starting a dual-feedback loop for another few months due to the potential dangers involved.

The very first thing when I plug it into a human will be to simply look for correlation of motor activity with the spectrum. In order to prevent the subject from performing repeated actions, I’ll record the data along with markers for various motor activity. In order to synchronize the marker with the activity, I intend to have my program provide a visual cue of what the subject is intended to do now, and provide a 10-second window in which they must do it. Appropriate 3-second windows will be added regularly for eye-blinks (yes, they can’t blink an eye unless I tell them to.) The eye-blinks is tricky because I’m not sure right now what kind of artifacts I am going to find in the signal. Separate out 20% marker data as my “test” data.

The next step is to go over these recordings at high-frequency or high-time resolutions (sort of like wavelets but not quite – still multiple FFTs and Sin/Cos being my constituent functions.) Maybe train a classifier to test for identification of markers and use the test-data to protect against memorization. I love linear classifiers unless the data justifies it.

The purpose here is to:

1. Test my software and know that data pipeline is functional and properly written and I have enough disk space for the recordings.

2. Test the device itself and experimentally verify its claimed accuracy/sensitivity.

3. Warm up to all those things I might have forgotten in 3 years.

To reiterate before concluding – for the near future, my interest is in labelling Motor Activity, not Motor Imagery.

April 1, 2011

Making a Brain-Computer Interface

After five years of consistently blogging, and consistently failing to do something about it, the BCI-building has begun. The academician in me needed an outlet and I’ve been craving for something hardcore technical for a while now. So begins the first formal attempt at building a cheap home-made BCI. I’m going to label all entries so that it will be easy to follow progress on this.

Unlike my regular posts which are composed with at least some thought, this series of entries will be more like a journal. I’ll post entries with what I do, what methods I follow, everything I try. With any luck, there should be enough detail that anyone could replicate what I am doing with full fidelity. The attempt at any original research is not even a long-term goal. The goal here is to, and I say this as directly as possible, with no misconceptions whatsoever, and no subtext, “to have fun.”

If you have any interesting theories, experiments, I would love to hear your thoughts. If you’d like to participate, you’re welcome to join. Most followups will be brain-dumps of my thoughts – unedited, raw, and naive. A side-effect of this blog is to also demonstrate any points of failure, or stuff that doesn’t work. At this point, I have nothing working. I don’t want to claim that I knew everything, in case I succeed.  I won’t use the excuse that I never wanted to succeed in case I fail. I want to make this work, and even if it doesn’t, it won’t change the fact that I still wanted it to work. If I make a mistake it’s going to be published, since I will try and publish what I intend to do before I do it as a validation.

At the moment, I picked the PocketEEG from PocketNeurobics (apparently an Australian company) to get started. I’ve been out of this world for a while (four years), and it takes a long time to catch up on the IEEE Journal of Biomedical Engineering where most BCI work is (used to be?) published. The WaveRider system is a clinical device but it costs too much for me at the moment, but if this device fails, I’ll save up for the WaveRider and go with it. It’s a two-channel device.

I haven’t got the electrodes yet, so haven’t taken any readings, but plenty of work has to happen before the electrodes become relevant. The recommended software to be used with it is BioExplorer which I think costs too much. I instead tried to connect the open-source BioEra software. The UI takes me back to the good old colleges days before the polished world of  iPhones and iPads. It has a way to define the processing pipeline but I rather hate doing it graphically. The dongle does provide a fake serial port on your PC that you can read from, but I didn’t want to go through that much trouble. I intend to use BioEra to capture the signal and send it across a local TCP channel into a server I’ll write that does what I want it to. BioEra seems to support plugins, but I love the flexibility of having my own executable as opposed to being “hosted in” another exe.

This pipeline investigation should take until the weekend, and hopefully I’ll have it coded over the weekend. If I’m lucky, and the electrodes to arrive, I’ll be sure to post some recordings of motor activity of right and left hands, captured from the C3 and C4 points at the beta band.

The reason I don’t want to use the provided FFT block is because I much rather enjoy playing with parameters initially. Do I want it sliding window at every point or will I perform it on intervals? If I intend to do something like auto-regression, I’d much rather use my own buffers and optimize the pipeline to operate on. I’ll post what happens.

December 26, 2010

Mythbusters’ method of derivation by first-principles

Filed under: Entertainment, Personal, Preaching, Science — Tags: , , , — archisgore @ 1:20 pm

I’m the type of person who loves deriving from first-principles and one who admires people who like to do the same. This post goes in honour (British English, people – I come from an ex-colony) of the Mythbusters.

To figure things out, to derive things when no knowledge exists is a concept that seems rare today, and yet I’m sure it was rare as far as humanity existed. It is simply observation bias that made me believe the Renaissance period was any better than today. I didn’t read about all the billion people over the world who didn’t do anything while Da Vinci was doing something. Science and Technology ‘exist’ just as a lot of other things.

Most people know things – they don’t find out things, or learn things; they just know things. I came back from a road trip an hour ago on a route that everyone knew had no places to stay or eat, and yet I stayed in warm lodgings, clean beds, and ate some of the best American food in 20 years. We know toast is made by heating bread. We know we’re supposed to go ‘ahhh’ when we eat French or Italian food, and we know bread can’t be made any other way because – well wouldn’t we know about it already? Red wine is better than White wine. Gas pumps have gas, because… they just do, don’t they? Two drinks are never dangerous for driving because I always have control.

Unfortunately, a lot of science education programs also follow this pattern. There exists the earth. It is round. We live on it. It revolves around the sun. I literally don’t know a single person (including myself) around me who can devise a simple experiment right now on the spot to test whether or not the earth is round. I went through five years of college being told Knowledge (no, not a grammatical error there, I was literally told Knowledge – as in a proper noun).

The one thing that really defines the Renaissance was the spirit of individuality and discovery. Leonardo didn’t make ‘great’ paintings, as if God had said, “Let there be a definition of great paintings that humans can aim for. There was hence a definition for what maketh paintings great.” Leonardo made paintings – they were appreciated. Others couldn’t make much better than his, and his paintings obtained value. The renaissance evolved and nurtured the process of independent thought and opinionated thinking (two things I value most.)

I wrote once before about how a process (also called a model) is what defines everything about science, and perhaps what defines science itself versus… well, lack-of-science. I can’t be more precise than that because process is all-encompassing. String theories don’t define one outcome, but define a process by which outcomes for all situations can be predicted. ‘Solutions of equations of the n’th degree’ in mathematics are really the processes used to solve any system of any number of equations with any number of variables of the n’th degree. As a child I had the opportunity to read some interesting books by 20th century scientists, and one difference I noted from modern populist writing is their emphasis on their line of reasoning, their attempts at scientific enquiry, the setbacks, the necessity for designing creative experiments to test hypothesis.

For the last three years, I’d been trying to figure out just what makes me such a mad fan of the Mythbusters, and the answer is that they are more old-school scientists than many I have met in my life in a university. Of course one does chance upon those rare inquisitive individuals who want to know, but they are few and far apart. I must say that the Mythbusters remind me of some of the influential people from my past who made me who I am today – people who genuinely wanted to find out. I will put this out there – Adam and Jamie are two of the very best science teachers that exist on earth today, and the reason is precisely because they are not scientists (while that’s clearly not true, we’ll go by their claim for now.)

They love to discover. They love to figure out. Sure, you’d say, why figure out what’s already known? If you really just said that, then you don’t know squat! :-) To design an experiment to test a hypothesis is a complex task, heck there’s a whole specialization one can study in design of experimentation. Designing an experiment for a theory that cannot be easily tested rarely happens through dreams, no matter how much we want to believe that that’s how we’ll get rich some day. It comes through practice. Let’s be honest, half the things Adam and Jamie test are not known – sure we can make an educated guess at them, but we don’t know them do we? Chickens are not spheres with point mass.

The Mythbusters teach true, pure science, while selflessly claiming they’re not scientists. They derive from first-principles. Instead of assuming chickens are spheres of point-mass, they start with chickens as chickens, and spherical-masses as spherical-masses. If the two being shot out of a cannon demonstrate the same result, Adam goes, “Hmm… Jamie, what if we replaced our chickens with small spherical balls?” (such a thing has not really happened on the show, I made that up.) This casual remark teaches tons more science than all of high-school physics put together. It demonstrates how generalizations come to be in the first place. What the phrase, ‘without loss of generality’ means. What substitutions are allowed. How experiments must be broken down. How do you discover theory in the first place?

Deriving from basics is one of the key overlooked abilities of this decade. Yes, we know the earth is round. We know we can go in space and figure it out. We also know that some ancients figured it out long ago. Most readers of this blog, I’m sure, are at least self-styled techies who are ‘in the know’ about all things technology. I doubt there’s anyone who can come up with an experiment to test the veracity of that hypothesis right now without leaving this page. That’s the kind of stuff the Mythbusters do daily. Some of the tests they are asked to conduct are impossible to imagine being tested. It is like a classic Sherlock Holmes mystery – when you know the answer, it’s obvious, it couldn’t have been anyone else! I’ve been racking my own brains for the last hour trying to figure out how, given that I don’t even know what “The earth” is, I would attempt to figure out its shape. I’ve had formal education in high-school physics.

They also follow a pre-declared results-based experimentation process. A lot of experiments in my high-school physics were dead-on in conclusions, but they never defined what a set of outcomes would have implied before the results were described. The Mythbusters approach is truly scientific. They would first ask: Why do you decide that you want to put an Apple in liquid nitrogen? Then they would define what each outcome would imply: Suppose it were to come out soft, what would that tell us? Suppose it were to come out hard, what would that tell us?

Objectivity is very hard to learn – and is a constant struggle. We all hope our very first outcome is favourable, and it rarely is. Data is manipulated, conclusions are creatively worded, because the results don’t quite imply what we expect them do. The Mythbusters are not afraid to fail, but heck, they love to fail! Almost every other episode they are proven wrong. They love it! It doesn’t get any purer science than that!

If today’s kids are going to break new barriers, then they must have the ability to derive from first-principles – from the very basic axioms. This however, must be done without compromising clear and hard science. Plenty of out-of-the-box thinkers who promote unlearning what universities teach, get too carried away in philosophy, spirituality or just plain stupidity. Deriving from first-principles never causes you to unlearn what you have learnt, but rather causes you to conform what you have learnt. If you were to put an apple in liquid nitrogen, no matter how out-of-the-box you are, it must have the same results as anyone else doing it. If not, you’ve hit upon something and must find out why.

I’m glad the President Obama recognized such brilliant men who love to discover and figure out. It is heartening to see them teaching principles of science (and I know secretly that they too know they are following the scientific method) without making it ‘science’. Under the casual tone of ‘obvious necessary steps’, they are secretly teaching some very fundamental methods of scientific enquiry that took me years to learn.

EDIT: Some people just asked me, why this is important. We come across people treating simple problems as if they were obstacles created by God, or treating solutions as if they just came into existence of their own accord, without appreciating that there was some human being who developed that solution. If one cannot appreciate that, then one can never look at current problems as solvable, since they inevitably ‘exist’. Brings to me frightful visions of the Eloi.

November 28, 2010

Whatever happened to “The Renaissance Man”?

Filed under: Personal, philosophy, Preaching — archisgore @ 9:43 pm

Most who know me, know my obession with the Renaissance period – when people like Leonardo Da Vinci defined the ideal man. A man who strived to improve himself, to better himself. (Ladies, forgive me for not using the more politically-correct “person” here, because I speak in the context of the age.) These men were certainly different. They were different from their peers. They strived to excel in multiple human endeavours, ideally simultaneously. Math, literature, painting, sculpting, music, poetry, to name just a very few. It therefore goes that to strive to improve oneself, if followed through better than others, certainly elevates you to a position of distinction. I’ll shortly get to the judgementalism of this statement.

My obsession with Star Trek represented the same ideal. It showed characters who worked to “improve themselves”. Characters who strived to explore the unknown, to excel in diplomacy, warfare (should the need arise), but the biggest objective of all – to gain understanding. Whether it be planets, or civilizations, or warp technology. Understanding is more than just knowledge – it reflects acceptance and peace.

Some of you will argue, I’m sure, that my definition of what “elevates” a person isn’t necessarily the one they must live by. While I will give a rational and tangible answer below, you know my standard response in case you do not care to present a rational argument: “This is my blog. If you disagree, go write your own blog and see who’d read it.”

Let me explain what I mean by “elevation”, when I say that the Renaissance Man was ever-attempting to elevate himself from his peers. From childhood, my dad always reminded me that the normal curve has two narrow points, and it can be very simple to not realize that you are on the wrong tapering end. A person must remain ever-vigilant to this possibility.

We all have intrinsic objective functions we use to evaluate and judge things – situations, people, objects, value, worth, etc. I’m not defining the objective function in any way, I must remind you. Regular readers know that I never insist upon defining the rules of the game myself, but do insist that when someone does define the rules of a game, that they not break those rules themselves.

Based on these objective functions, it is not difficult to measure the quality of a person. Sure you’d say, “But what’s important to you, may not be important to me.”, and boy am I sick and tired of repeating myself but must refer you to the paragraph above. I’m not speaking of what’s important to me, I am indeed speaking of what you claim to be important to yourself and whether you are being truthful, if not to me, at least to yourself. So yes, given what you claim is important to you, it is not difficult ot measure the quality of any process, person, object, whatever. I’m not saying an objective function has to be necessarily simple, but I do insist that it exists (if it didn’t exist, then you are not acting with a purpose, and by definition are not intent on improvement.)

If I find enough squealing pigs repeating the same hashed out point about what I define as improvement is not what they define, I’ll add an edit to this post later. For now, what I am saying is that if you were on a number line, and if you stepped to your left, and the number decreased, then it must increase if you step to the right. This change is called learning (almost all AI, statistical, modelling, game-theoretic, and optimization problems work off this definition.) So a change with a direction as determined to be that which brings you closer to your objective function is what we know as improvement or learning.

Getting back to what this has to do with the Renaissance Man. So the Renaissance Man, was above all, a functional man. Someone who contributed to his objective and struggled to improve upon it. If Leonardo were a great painter, then any painter who might make paintings of equal quality as that of Leonardo, but who could possibly make more of the paintings would be known as a “better” painter. And for the third time, if you were about to say, “who are you to say making more paintings makes for a better painter?”, I must send you back a few paragraphs. See we’re already talking about Leonardo. That means he’s a big deal of some sort. If he’s not, you shouldn’t be arguing against me, so go home. Having accepted that he’s a big deal, we might agree that he’s a big deal because he made some pretty damn popular (be careful now, I didn’t comment on the quality) paintings (I’m not saying only paintings, but paintings being one of the things that made him a big deal – yes I must be excruciatingly precise because some people get on my nerves with idiotic responses.) Now intrinsictly we are stating that paintings that were made of his quality are desirable. If they’re not, he’s no longer a big deal, so go home and leave me alone. If you can agree that paintings are desirable, then logically, we are left with no other conclusion than that anyone who made more paintings of equal quality would be an improvement.

In short, “If Leonardo is a big deal”, then, “Anyone who made paintings of his quality, but more than he made, would be better than him.” If you refuse statement two, you reject statement one.

So that, not by my definition, but your own definition, is what “improvement” means. With improvement comes difference. Change. Deviation. Departure. A man who makes paintings of equal quality of those of Leonardo, but can make more of them must be different in some way (basic math). A few (but not exhaustive) possibilities are, he may be a faster painter, have some kind of tools not known to Leonardo, have magical abilities, more dedication to painting, less interest in any activities other than painting, to name a few. We may not agree on what that difference is, but we must agree that there is a difference.

So far I would expect most people to follow and agree with me. We can agree that somewhere the above logic is intrinsic in our brains and perhaps instincts. Whether it is a modern feature of a man is debatable, and irrelevant. Being more functional is to be better. Being better is to be different.

Now we come to the kicker. How many people do you know who do things just to be different? When did this tendency arise? Is it a sign of too much prosperity and having nothing better to do? I’ll bet you’ve had the following version of a conversation with someone in the last… say… week?

Bob: Hey, I need a phone with features a, b, and c.

Alice: Yup. Those are pretty much the needs of every person I know. Phone X is what you want.

Bob: Yeah… no…. everyone has phone X, so what’s the use?

And there we have it. The decline of a set of philosophies that were in vogue a hundred years ago. Bob doesn’t say, “I wish I had a phone that did 2a, 4b and 6c.” Instead Bob’s objective function is to be different. Yet somehow, it is a tendency for which Bob feels, if not is in actuality, rewarded socially. Once more, if he weren’t rewarded, he wouldn’t do it, and the tendency should die out. Instead I see it growing day by day. Whether its televisions or phones or gaming consoles. I know classic Linux fanatics who have a custom-tweaked Kernel, for what purpose, I don’t know. (Nope, not that I don’t understand their reason, but I’m never told the reason – under the cowardly blanket of telling me I wouldn’t understand.)

At what point did we forget functionality? When did we stop looking at what we need out of an object, process, method or entity, that the entity in question fulfills? At what point did we stop caring for a good piece of music, but more for the adamantium alloy that forms the strings of the guitar on which it was played badly? At what point did we stop caring about whether a phone could do what we need out of it, and instead decided to survive with a few lacking features just so we would be different? At what point did we lose sight of the fact that to be different does not necessarily constitute an improvement by even a long shot?

What surprises me most is that at least ten years ago, people would take the trouble to fake improvement. At least they’d display the sour-grapes syndrome. If they wanted a “different” phone that didn’t have feature ‘c’, they’d take the trouble of claiming they didn’t want or need the feature anyway. Today they’re so blunt as to tell me they can’t perform so-and-so task because they don’t have feature ‘c’, and if they had it, what’s the difference left between them and others? Yes, seriously, I’m not kidding. I’ve been in situations with people where they actually boast about being sub-optimal, because, if they did what everyone else did, how’d they be “cool”? Da Vinci was different because he had an extra feature “d” that nobody had, not because he lacked something everyone in the world had.

It’s like saying, “Whats the big deal? Everyone eats food. I need to be different. I don’t have the faintest idea what makes gourmet food, but I’ll bet not many people eat out of a trash can. Wow, I’m so hip – I eat out of a trash can, that’s so different from what anyone in the world does!”

Where did the Renaissance Man go? What happened to being different by being better, by striving, by struggling, by achieving? Not by someone else’s objective function, but at least by your own? What happened to the guy who bought the phone with all the features they need, and then adding some more of their own, making them different from all others?

This trend is all the more common in a supposedly highly-educated class of engineers today. Most often I find myself dragged into unnecessary discussions about my choices of furniture, or televisions or phones, or anything I do. A lot of times some of the most highly educated people would advise me to act in a sub-human manner. Now I don’t claim I wouldn’t want something functionally superior. If there were Sofa A, but then there were Sofa B which was a superset of functionality of Sofa A, I’d certainly take advice to choose B. Such an argument is painfully difficult to find these days. People tell me, “Sure, Sofa B doesn’t have all the comfort of Sofa A, but it comes with this other thing that others don’t have.” We see this with bad drivers on the roads too. These guys would suck if they were to go on a race course. A man attempting to improve fast driving would go on a race track and improve upon their speeds there, instead of one-upping gentle old ladies who just want to get to the grocery store. Leonardo didn’t compete with kids throwing finger paint on the walls.

The conjunction for indicating improvement is “and”, not “or”. Improvement does not mean degradation of something more fundamental and basic. Improvement, elitism and pretentiousness have their place in this world. They come after basic necessities have been satisfied, not in their stead. The I-have-something-you-don’t-have thing does work, and does command respect or envy, but only when you truly have everything else I don’t have. Otherwise, it only goes to show why techies are ridiculed and laughed at.

I grew up in a village in India where most homes had a refrigerator long before my family had one. From the front, you could see a lot of fancy decorated openings into those houses too. If you ever showed up you’d probably not know why that place was a village, until you found out that none of the houses had toilets. People did their “business” so-to-speak on a large open ground. Sure, they apparently had all the comforts of someone living in the city, but did they? If I’d have started with this story, I’m sure many elitists would have laughed at the “obvious” deficiency of the villagers’ reasoning, and yet, are we any better with our fancy degrees from big universities?

September 14, 2010

Review of “Salt”

Filed under: Entertainment — Tags: , — archisgore @ 10:20 pm

I very rarely post reviews of movies, unless they really give me something different. Salt was one such movie. The thing that stands out throughout the movie? The villians.

In every conventional movie, the villian is given a lot of importance and story-building time. This is good, no doubt, but the humanizing factor is present mainly to explain to us the irrational objectives, and sometimes stretch-goals of villians. The only bond villian I really saw coming close to the Salt villians, was Drax, from Moonraker – “kill everyone on earth”, and even with that, I’m not sure what happens to those surviving in bunkers and air-filtered installations.

Salt is so obsessed with Salt herself, that thankfully the writers were perhaps ignorant of the villians and this is totally the way future movies should be written. There were no elaborate complicated plots for the goals they had. It was pretty damn simple, and in one case the villian even voices it, “Step two: Kill a million people. Piss off a billion Muslims.” I love it – precise, objective, measurable! What more could you want? We just see them doing stuff that is most certainly damaging, and pretty damn straight forward – kill presidents, launch nukes, kill an objective and measurable number of people (unlike a vague goal such as ‘bombing new york’ or whatever) – what’s not badass about that? The steps really seemed like a good way of pacing themselves, but whatever order they pulled it off, it really seemed like it’d cause world-wide chaos nevertheless.

Also loved how Salt’s actions were carefully detailed – who didn’t see the venom bullet being shot into the Russian president? This aspect goes exactly into the very thing I love about Perry Mason books - give the audience all the information that your star character has, and allow them the same previledges. There was no attempt to get stupid camera angles just so the audience is deliberately kept in the dark.

I must admit though, I was prepared to be amazed by a truly rule-breaking movie if Salt really were the villian. A couple of times, I actually wanted Salt to turn out to be the agent just to make a movie that was even more straight-forward and direct!

All in all, if you’re the types who loves dissecting characters, and following their thought-processes and trying to understand their allegiences and motivations, you’re going to love this one!

(I still maintain that The Expendibles has a legitimate place in this world.)

August 27, 2010

The Electronic Voting Machine issue in India

Filed under: Politics, Technology — Tags: , , , , , — archisgore @ 5:53 pm

I never looked at my blog as anything more than selfish gratification, until quite recently when a person named Hari Prasad got arrested last week for allegedly having “stolen” an electronic voting machine.

First some background – ever since the EVMs were used in elections, my mom has been involved with a group of politically-un-allied activists. Naturally I made quite a bit of fun of her (my family always enjoys a bit of a jest at each others’ expense.) She used to visit me in Hyderabad often on account of her meetings with Mr. Hari Prasad who has his offices in Madhapur. She introduced me to him on multiple occasions but I always took the meetings casually, being more involved in my “work or whatever.”

You may imagine my surprise when one morning I wake up and see this same Hari Prasad an internet sensation making the headlines on Digg and Slashdot. Then you would have seen me telling everyone, “I know that guy personally and I know that he knows what he’s talking about.” I just found out my mom is in Mumbai awaiting his release and has been subpoena’d (not sure by which side right now), and decided to at least bring the issue to attention. Let me be honest, an year ago, she was in Hyderabad at least five or six times, and while I did believe what she said about the machines, I would never have imagined that they would be taken seriously, and let me be the first to say, I am sooooooo happy I was wayyyyy wrong! If you met those people, they’re really just electronicians – these guys aren’t politicians, and they don’t know squat about that stuff. They know how chipsets work and serial ports work, and that’s all they are making claims about.

To reach slashdot and get that much international attention, to get arrested is pretty impressive. What’s more, I called a few friends and family members in India right now, and nobody down there has any clue that this is even happening. That was a bit disturbing frankly.

So what really is the deal with the voting machines? Quite a lot really – I’ve heard discussions and arguments right from having found the seals broken on the boxes in which they were being carried, and the fact that the storage chips on which the numbers are stored could be plugged out and replaced with relative ease – and this stuff is what they teach in Electronics 101.

I don’t have all the specs with me right now, but I’ve been talking to these people enough where it warrants at least some looking-into by voters before you make up your minds. Whether you are for the winning party or not, as Perry Mason would say, everyone is entitled to a defense because it protects us from being falsely accused of a crime. In the same way, even if you love the winning party, it is in your best interests to at least give attention to the matter so that you are protected, should the system be compromised against you.

The real issue from a common-sense point of view that every really seems to overlook is this: that the “count” stored on the machines is virtual. You see, everyone makes comparisons to conventional ballot-boxes, and a casual “what’s the difference really?” kind of arguments. What they don’t realise is, in the old system there were physically 10,000 pieces of paper that necessitated tampering. An interested political party just needed to hire a street-side loafer to follow the van that carries the sealed ballot boxes from the voting booths back to the election-commission offices to see that nobody brought in another set of a thousand or so pieces of paper to replace the originals. Then again, when the boxes are sealed/unsealed, there are witnesses who sign the locks. Even the ballot papers used for counting can be verified for authenticity and their authenticity can be questioned (if you notice an inkjet printout, it’s a no-brainer.) In short, the system has multiple checks in place to ensure lack of tampering.

In an EVM though, all these checks and balances go out and what we get is: Party A: 5000, Party B 20,000. These are pure numbers. There is no public-key system that ensures even 25,000 different people walked into the booth. There is no way to “go back”, or trace tampering. There is no log of when entries were made – even a text file that contains time-stamps of actions without any Personally Identifiable Information (PII) would make tampering that much harder since a scammer would have to fabricate a large text-file and make sure it’s consistent. Heck, someone could even look at what sectors/clusters each of the block of the text-file was stored in to provide an indication whether it was generated over a period of 5 hours, or was just copied from one large blob.

Does it make forgeries impossible? Of course not, and those claims existed against the old-school ballots too. But does the current machine make forging ridiculiously simple? Yes. For anyone politically inclined, I would encourage you to at least check out his youtube videos. I’ll provide more edits to this post with more details on where to find information.

August 19, 2010

Polynomial approximations of neural networks

Filed under: Science — archisgore @ 11:23 am

Still in draft-purge mode, so lots of older shit from five years ago is coming out now. This post particularly makes no sense whatsoever anymore, partly because the neural network scene is much more mature today, and AI isn’t the sexy-new-thing grads look forward to. But…. since I had this written, wanted to go ahead and throw it out there. I must say I am very proud of the attempt even today, even though it was an embarrassment in the end.

Back in college I was bigtime into signal processing and brain-computer interfaces. The biggest challenge in such a system is data-filtering. You end up with a ton of data per second, and your system has to find the right data to process at the right time. To give you an idea (and this may be outdated stuff, since today people use ECoGs and fMRIs), an EEG  has about 64 channels, each sampling at about 100 Hz (assume 8-bit accuracy of each sample – in whatever units – usually micro-amperes).

Obviously there are a lot of conventional tools to process this data (Principal Component Analysis, Independent Component Analysis – which wasn’t of much help since it turned out there is very little cross-talk between channels, Support Vector Machines, etc.) But who in college is content with what we have? I secretly hoped the data had non-linear components (which it didn’t – all non-linear methods gave about 10% more accuracy than linear ones, and it seemed a lot like the reason was memorization rather than a better fit.)

So I had this crazy idea for sensitivity analysis. I had a well-trained Neural Network, and which the old method of branch-and-bound on the input vector to check variance in output is well known, I somehow wanted to model it in an equation, reason being, through sampling, you can find out that the answer is very sensitive to dimension X1, but not so sensitive to dimension X2. However, I wanted to know what Xi’s were most important and what weren’t and by how much. It’s the same concept you use in PCA – you want to pick ’r’ channels out of ‘n’ channels so that you get a ’90%’ accuracy. PCA gives you the contribution index of each channel to the final output. The idea is a trivial extension of the sampling method used above, but simply substitutes polynomials in place of the logarithmic/exponential functions used.

Enter the brand new idea of sampling each neuron at ‘n’ intervals in its range, and using a curve-fitting method to generate an ‘n’th order polynomial for each neuron, and then injecting that into the next neuron it feeds. Here’s the idea:

1. Each input’s domain is determined. Whether it’s an Int32, or Int64 or double or quad. You know the exact bounds of the set.  Therefore, whatever function you use, (in my case TanH),and since backpropagation requires the function to be continuous and 2nd-order differentiable, you know that it’s range is finite and well-known. This range feeds into the next neuron, so it applies to all neurons.

2. Since most used networks (most used by me) were 2-layer, it was a tractable problem.

3. What you do is, you sample each neuron in the first layer at ‘n’ evenly-spaced points in it’s domain, and you compute output-values. Then you fit a polynomial (Spline, Bezier, whatever) to mimic that exact shape (you don’t do this earlier, because this is a fixed graph that can’t be “trained” anymore using backpropagation).

4. You feed in the polynomial as a symbolic variable into the next neuron’s polynomial too, and then simpify the result.

5. What you would get is an n^2 (2 being the number of layers) order polynomial for each output in “m” unknowns (‘m’ being the number of input variables).

Based on the constants and exponents for each variable, you can judge what it contributes to the output. It felt like a good way to quantify in relative terms and symbolically, the importance of each variable, and to find which channels/dimensions could be dropped entirely without losing significant accuracy.

Frankly, if I worked with ANNs ever again, I’d still go this route, especially for problems where the nonlinearity is unknown and you find an ANN that gives you a good fit. Of course, if I worked with ANNs again, I’d catch up on where the world is today, but that’s another matter. :-)

August 17, 2010

What does 100% CPU usage mean?

Filed under: Technology — Tags: , , , — archisgore @ 1:32 am

Traditional scientists (mathematicians, physicists, and engineers in traditional disciplines of mechanics, dynamics, etc.) have always known that certain entities are temporal in nature. Temporal means time-dependent (using the term losely here), meaning quantities or values that only make sense “across time”. The larger time period you observe them for, the more sense they make, and the less you know about local details (you lose details of when  happened but you get a greater understanding of what exactly happened.) This is Heisenberg’s principle applied to time-domain metrics. I don’t want to go into all the stuff Fourier gave us, but heck that dude really changed the way we do stuff today.

A quick refresher example (or introductory example for those who didn’t study a lot of signal analysis). Imagine you were sitting in a large theatre at 8:00pm in the evening with the theatre partially filled up (say 30% of the seats were filled when you entered at 8:00pm sharp). At 8:01, you observe one person coming into the room. Given this data, would you be able to describe either, by what time the theatre would be filled up, or how many people would be in the theatre at 8:30pm the same evening? Now you doze off for 3 minutes, and again observe at 8:05, you notice another person entering the room (due to the darkness, you don’t know how many people are in the theatre currently). A better estimate of the answers to the two questions? Suppose the first person who entered at 8:01 clarified that between him entering and the next person entering at 8:05, he can assure you nobody else entered while you were dozing off, would that make your answer more accurate?  If by 8:20, you got details of how many people entered when, would your estimate be even more accurate?

As you see, when making such estimates, specific point-data has very little value. Given, at 8:15, there were 40 people seated, is quite pointless to figure out when your show should start. Without knowing how many people are currently seated, but the rate-of-entry per minute is much more valuable. Knowing both, is even more so. Knowing the rate-of-entry as it differs each minute is even more valuable (whether it is decreasing, increasing or constant.)

This is all fairly introductory textbook stuff for most other disciplines. In computing though, a lot many programmers while aware of temporal quantities, either misinterpret them or overlook their usefullness. This can mean a lot of implications in terms of quality, performance and correctness. I comment based on some observations and interpretations I have seen in this industry over the last few years and how we misinterpret benchmarks and metrics.

The most commonly misinterpreted statistic thrown around out there is “CPU usage”. We see people panic at “100%” CPU usage, while there are also apps out there who could have only 10% CPU usage but bring systems to a crawl. Ask a common coder, “My app uses 100% CPU sometimes, is that good?” and the immediate response is, “What kind of coder would write such a program?” Let’s look at how a CPU works for a minute.

The CPU runs on a wave (a square wave to be precise). It has a certain number of vibrations per second, and it does work every time it vibrates (just like the piston of an engine). What you see as CPU usage for a certain program, is the number of vibrations of the CPU the program used to do its own work (basically if a car engine could divide it’s piston strokes between the axle and the air conditioner’s compressor, the amount of strokes it allocated to the axle). A lot of times, we have a tendency to interpret “100%” CPU usage as bad. While this is generally the right metric to use in very generic terms, when you are developing a controlled system, it could lead to some quirky scenarios.

A CPU, just like the car engine, is running whether or not it is used to get work done. Of course, 100% usage naturally means nobody else gets a bit of that power when they need it, but there’s no reason why it shouldn’t be used whenever possible (when nobody else needs it). At times, you turn off your airconditioner, so that you get a higher boost in acceleration. In the same way, for certain applications, if a program is deliberately NOT using 100% CPU, it is a very very bad thing.

I’ve been developing server applications for a while now, and this gets brought up a lot. When my webserver is hit with one request, the server goes to 100% CPU usage for about 2-3 milliseconds. This isn’t only not bad, but actually helpful because what else did I expect the server to be doing anyway? What would it mean if I got 20 requests in one second? The server would still use 100% CPU and answer the requests in order and they get answered faily fast too. I’ve seen people going nuts on forums when they see their OS running at 90% CPU – you can imagine how the question is framed, “If with only a one request it used 100% CPU, how will it handle 2 requests at all?”

It’s not all that hard to reproduce on your home desktop too. Ever notice how media players always seem to be using 80% CPU and the system is still responsive (I compile large code-trees while playing a movie on my 2nd screen)? Well, why shouldn’t they, if nobody is using those ‘piston strokes’ for driving the axle? Contrary to that, sometimes a program goes unresponsive, and you open up task manager but you see barely 1-2% of total CPU usage, and wonder why the program is stuck? Happens to me too – even on programs I’ve written, until I realise that the whole “noble coding” era is passed. Back then we used to use more “efficient” workarounds to common functions to do things faster. Modern OSes expect you to be more semantic than syntactic – tell the OS what you need in no indirect terms, and the OS knows best how to provide it to you. Try doing custom memory tricks, and you end up with inefficient code. This doesn’t mean that the “hacker culture” doesn’t exist where super-smart minds exploit new ways to improve speed and efficiency, however it’s just that no longer can you read books on using “a+a” instead of “a*2″ and hope to gain a lot of applause.

May 12, 2010

…therefore God exists

Filed under: philosophy, Preaching — Tags: , , , , , — archisgore @ 6:33 am

As a child I heard this story. Once a prominent mathematician was asked by the King to come to court and prove the existence of God. The mathematician solved some complex problem on the board, and wrote below it, “…therefore, God exists.” I don’t know who the scientist was, but do comment if you know more about this story. I found the story hillarious as a kid, and laughed at how stupid the king was.

As an adult, every day I deal with people using such arguments to make their point or worse, enforce their opinions on us. This is a commentary, and as always will follow with some tips on defending yourself against such people (I personally prefer going on the offensive, because it’s just so awesome to see them try and squirm their way out.) Those who are cursed with a logical mind are unfortunately subject to the constant torture of consciously recognising it all the time. Let’s start with a quick real-life story to illustrate the point.

A couple of years ago, I made a comment about some opinion of a famous personality that I felt was misplaced. As you would have guessed, in less than an hour, my mailbox had the first holier-than-thou super-authoritative mail sitting in it, telling me how great the personality was, and how puny I was in comparison. The mail said nothing of the opinion I commented upon, nor my own comment itself. It said nothing about the issue at hand. The crux of the mail exactly amounted to, “*gibbersh* therefore, you’re wrong.”

Have you ever been at the receiving end of such an argument? Do you feel helpless and frustrated? If it’s any consolation, you’re not alone, and many of us still haven’t figured out a good defense yet. I’ve worked in a “corporate” and “business” environment long enough to know that at least in the top tech companies, this kind of talk isn’t entertained. However, it is too common to be coincidence how much people use this kind of argumentative logic and how often they use it. It feels as if there is some academy where such kind of training is imparted on a mass scale.

The basic premises that lead to such situations are:
1. Existence of a subject in need of attention
2. Lack of sufficient knowledge about the object of the conversation
3. An inherent need for self-gratification by appearing involved in the conversation

As the two premises are fundamentally contradictory, how can they be reconciled? You guessed it! *gibberish* (sub-classed by *tech-gibberish*, *economic-gibberish*, *philosophical-sounding-gibberish*, etc.)

Since actually making a well-thought-out argument is beyond question, and the subject has nothing substantial to say anyway, subject chooses path of lease resistence using the logic ‘afterall, so many people can’t be wrong’ (a blog on this is pending). Stick to the “large corporation”, “famous personality”, or “popular choice’, and you’re relatively safe from being interrogated in depth allowing them to preserve the appearence of caring about bigger picture by rehashing some statements they’d have heard here and there.

Your very first defense against such attacks is identifying the attack. You must be self-aware when a discussion or a debate is moving away from issues relevant to the object. In the case of my story above, the author sent me a 3-page biography of the personality and a lot of info about some program that I did not care about. Knowing that a person is changing the issues of discussion is a vital part of defense. Last evening in another such debate, I faced a new one - a commentator simply pulled out one noun from my sentence and responded with, “Since you said…” and created a sentence of his own using my noun with completely different semantics. It was a new learning for me.

Why should you care? Because they may end up being decision makers that affect your life. Managers, politicians, relatives, etc. When such people become decision makers, it is altogether too difficult to argue or escape from them as their objective is self-gratification only. The best defense is a good offense. They are relatively easy to corner. When cornered, they will go on a last-ditch attack effort by stating more “stuff” which could be things from your past or just general stuff they consider to be your flaws. You see, in their world, everyone is a weasel, and all they need to do is find that one time you screwed up so you will back off. See this as a sign of weakness and exploit it! That is the time to strike back and strike hard. Don’t waste time defending yourself, but quickly bring the conversation back to the topic of focus and you shall win the debate.

The end won’t be as satisfactory as them admitting to being ignorant, but rather with them rephrasing your own point and saying, “That’s what I was saying in the first place.” Leave it at that if you can. That’s the best you can expect.

Any similar experiences you’ve had?

« Newer PostsOlder Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 122 other followers