Archive for the ‘random’ Category

What I want from an online store

Sunday, October 28th, 2012

Amazon's great - I buy all sorts of stuff from there. But their searching interface still seems to be optimized for the books, CDs and DVDs that they started out with. It works fine if you know what you're looking for and just need the search results to decide if you want the hardback or paperback edition. But if you need a waste paper basket that fits into a particular space, a digital alarm clock with a red LED display or a shaver light/socket with an 8" spacing between the mounting holes (all things I've tried to find there) - you're limited to sorting a single department's search results by price or score and then going to each of the thousands of results one by one to see if any have sufficiently detailed information on the product page (most don't).

What I really want is an interface like Mouser's - also known as a parametric search, whereby you can narrow down by (multiple values of) all kinds of different parameters and then sort the results by various parameters as well (Mouser's great by the way - I've bought lots of bits from there and it's got the best combination of prices, interface and selection of all the places I've tried). I suspect that the reasons that this isn't done by Amazon already are:

  1. Electronic component manufacturers often make ranges of components with many parameters that you can choose independently (for example, these resistors have 7 independent parameters mentioned in the datasheet).
  2. Electronic component manufacturers (by necessity) provide much more detailed information about their product than manufacturers of consumer goods (which hitherto have mostly just had to look nice on a store shelf).
  3. Amazon sells a lot more different products than Mouser (I make it 3,489,158 for Mouser and 166,367,811 for Amazon at the time of writing).

This seems like it ought to be surmountable, if enough people cared. It would be great to see an open, crowdsourced, wiki-like worldwide database of SKUs with as much technical information as possible about each product that Amazon, eBay and anyone else who wanted to could plug in to. It wouldn't need to be perfect to be useful (Mouser's isn't) - in fact it's usefulness probably increases roughly linearly with the number of products in it.

LED strobe and spinning disc

Thursday, October 4th, 2012

My son's Elenco Snap Circuits Jr. SC-100 toy came with a spinning disc that demonstrates stroboscopic behavior when accelerating or decelerating under a fluorescent light. I built my own LED strobe with adjustable frequency and duty cycle to make the effect a bit more visible. In the following video you can see what happens as the duty cycle is adjusted:

The circuit is too simple to show a schematic for - just a LED with current limiting resistor and three potentiometers connected to an Arduino. The clever bit is the Arduino program. Also, because I needed to be able to tune the frequency quite precisely, I used two potentiometers for the frequency - one for coarse adjustments and one for fine. Only the top 6 bits of the coarse potentiometer's measured value are used (otherwise the fine potentiometer would be useless due to the jitter). The remaining 10 bits come from the fine potentiometer, yielding a theoretical 16 bits of frequency resolution, giving a range of about 3.8Hz to 250KHz.

The video would probably come out better if I connected multiple LEDs to the output, but I only had one white LED to hand.

British TV is so civilized

Tuesday, October 2nd, 2012

I tried out the iPlayer for the first time last night (at the time of writing) to watch the first episode of the new series of Doctor Who, which I had missed the beginning of due to having to put the children to bed. On going to the BBC website it was just three clicks - one to start "watch live", one to restart the current program and one to maximize the window. And there was negligible buffering time, and it was higher definition than standard definition TV! I was very impressed. It was a great episode too - most of the Dalek episodes suffer from massive unexplained plot holes, but this one was quite well thought out.

Some of the US networks have streaming sites, but they all have adverts, the quality is worse than standard definition TV and new shows usually aren't available for a day to a week after they air. Plus a year's basic cable subscription costs more than a year's UK TV license.

Wireless mice

Saturday, October 31st, 2009

This is fascinating. I wonder how long it will be before people are implanting tiny devices into mouse brains that receive commands from the internet via the cellular networks and transmit video and audio back, so that the mice can be driven around by remote control and used to spy on people and things.

Identity and birth

Friday, October 23rd, 2009

Having had a second second child recently got me thinking about the concept of identity. It's a concept we use every day, mostly without thinking about it, but it's not built on a completely solid foundation. The discussion below relates to the US, but I'm sure the story is similar in other jurisdictions.

To get a passport, a driver's license or a social security number, one needs a valid birth certificate. Suppose, for one reason or another you want a second identity. This is illegal and I'm not recommending anyone try it, I'm just interested in thinking about vulnerabilities in systems. Since the government can cross-check with official databases, just forging the piece of paper probably isn't going to work. A method that often seems to be used is obtaining the birth certificate of someone who was born around the same time as you but who died young (and, if possible, in a different state). This "paper chase" method has its disadvantages.

What you really need is an identity that has already been created and maintained, but not used by anyone else - a farmed identity. I'm sure there is a black market for farmed identities, but the question is - how do those identities get created in the first place? That's where the babies come in. If you are a mother with a brand new baby, what's to stop you from going to a doctor and saying "I gave birth to a baby in my house, without even knowing I was pregnant"? (Such things do occasionally happen). The doctor will issue a birth certificate (in addition to the one you already have) and then you have a second identity you can farm for your child (or sell on the black market, if you are so inclined). While most mothers of newborn children probably wouldn't think to do this, I'm sure there are some who do.

Even biometric identity databases can't completely solve this problem unless, whenever a new birth certificate is applied for, the child's biometric information is compared to all the other entries in the database. I'm not sure if that is likely to be practical (given the imperfect nature of biometric data).

One problem with this method is that the mother is now on record as having two different children within a very short space of time, neither of which are recorded as being a twin. This could raise red flags. The answer is for the mother to use a false identity when applying for the second birth certificate. I don't think it would be practical to only give a child a birth certificate after a strong identity check on the mother.

Strongly identifying everyone is a really difficult problem. Should it even be attempted at all? If you don't even try verify everyone's identity, there are certain things you can't do. You can't ban someone from driving, since they could just get a new driver's license under a different name. So if someone is a danger to others on the road, you have to punish them the same way as other crimes - by putting them in prison.

You can't prevent someone from voting more than once by using electoral rolls, so you have to use electoral staining (though I'm not sure if that's perfectly reliable, given the availability of solvents).

You can't give someone large amounts of credit without collateral, since they might just disappear and assume a new identity. I don't think that's likely to be a big problem in practice, since good credit takes time and effort to obtain.

You also can't keep people in (or out) of your country, since they can always obtain a new identity with a clean passport. But national borders tend to be rather porous anyway.

XKCD standard creepiness rule

Sunday, October 18th, 2009

I think the XKCD standard creepiness rule is a good idea - it makes much more sense than the usual age of consent rules (especially when one or more of the people involved is under the age of majority). I built a quick web calculator to allow you to figure out if your relationship is (or would be) creepy, and when it stops (or would have stopped) being so.

Half-size Lego

Wednesday, September 30th, 2009

I've been playing with Lego again recently, since Alexander enjoys it and wants me to help. He has three sorts - the normal Lego bricks, the double-size Duplo bricks and the quadruple-size Quattro bricks. The Lego bricks are not directly compatible with the Quattro bricks but the Duplo bricks are compatible with both and can be used as an interface. This allows one to create models that are very large (using the Quattro bricks) but also detailed (with the Duplo and Lego bricks).

This leads one to wonder whether a fourth size of brick would be possible, with a size half that of normal Lego bricks. It would not be directly compatible with Duplo or Quattro, but would be compatible with Lego bricks in just the same way that Lego bricks are compatible with Duplo bricks.

This is not always possible, since the "bumps" in Duplo and Quattro bricks have indentations in them which are necessary for compatibility. Most Lego bricks don't have these. But some (particularly Technic Lego) do. This leads me to wonder if the Lego company at one point planned to make such half-size bricks. I'm guessing the reason they didn't was that the pieces would be too fiddly for most fingers, too easily lost/swallowed and too difficult to manufacture with the required accuracy (the edges might also have to be dangerously sharp in order to join properly).

The Lego company did actually make a smaller version of Lego called Modulex but the bricks are 5/8 size rather than half size and are therefore not compatible.

Improved geohashing algorithm

Friday, August 14th, 2009

Geohashing is an awesome idea (though I've never actually gone to any of the hash points). However, it does suffer from some problems - often the chosen location will be too far away, or in an inaccessible area. It is also slightly biased towards the poles (though because few people live in the polar regions this isn't a particularly big deal for most people). It would be nice to have an improved algorithm which solves these problems.

We'll start the same way, by hashing the date and that date's DOW opening to get a set of 128 random bits R.

Given any area A we want to find a function (which we'll call f(A)) mapping a set of bits R onto a point x, (f(A))(R) = x. We would also like to have the property that if B is a subset of A containing x and if (f(A))(R) = x then (f(B))(R) = x. So if the New York State meetup happened to be in New York City, all the people who were just going to the New York City meetup would be there too. Another desirable property would be if the points (f(A))(R) were evenly spread throughout A.

Here is an algorithm that I think fulfills both properties.

First, use R to pick a random point on the globe, taking 64-bit random floating point fractions u and v in [0,1) from R in the usual way and then transforming them into longitude and latitude as:
\displaystyle long = 360frac(u+a(N))-180
\displaystyle lat = \frac{180}{\pi}cos^{-1}(2frac(v+b(N))-1)
Where frac takes the fractional part, leaving a number between 0 and 1 (one could also use XOR instead of add and frac) and N is the smallest integer > 0 that causes the resulting coordinates to end up inside A.

a and b are functions that find points that are furthest away from any tried so far. They have binary expansions as follows:

N  a(N)  b(N)  c(N)     d(N)
0  0.000 0.000 0.000000 0.000000
1  0.100 0.100 0.110000 0.100000
2  0.100 0.000 0.010000 0.010000
3  0.000 0.100 0.100000 0.110000
4  0.010 0.010 0.001100 0.001000
5  0.110 0.110 0.111100 0.101000
6  0.110 0.010 0.011100 0.011000
7  0.010 0.110 0.101100 0.111000
8  0.010 0.000 0.000100 0.000100
9  0.110 0.100 0.110100 0.100100
10 0.110 0.000 0.010100 0.010100
11 0.010 0.100 0.100100 0.110100
12 0.000 0.010 0.001000 0.001100
13 0.100 0.110 0.111000 0.101100
14 0.100 0.010 0.011000 0.011100
15 0.000 0.110 0.101000 0.111100
16 0.001 0.001 0.000011 0.000010

And so on, to as many binary places as you need. If you interleave the bits of a(N) and b(N) you get c(N), which looks like d(N) but with each even bit XORed with the bit to its left. d(N) is the binary expansion of the integers but with the bits in the reverse order (and flipped to the other side of the binary point).

The sequences a and b together are related to the Bayer matrix which describe a 2D ordered dither. If you want 65 shades of grey but only have a grid of 8x8 pixels, each of which can only be black or white, the most regular patterns with n black bits are described by those that have 8a(N) and 8b(N) black if N<n and white otherwise.

Public medicine and medical research

Friday, August 7th, 2009

The US pays twice as much for healthcare per person as the average western country, and supplies a lower quality of care. So where does all that extra money go to?

Some of it goes to administrative overhead (it costs a lot of money to pay the people at your insurance company who are looking for excuses to deny you coverage). But a larger fraction goes towards the profits of the insurance companies. People invest in these companies (often as part of a 401k or other retirement plan) and get back a profit (at the expense of those who pay insurance premiums and consume healthcare).

But not all of a company's profits go immediately back to its investors - any reasonable company will spend some portion of their profits on research into ways to make even more money in the future. In terms of medical insurance companies, this generally means medical research - research into new techniques, medicines and gadgets that improve the state of the art and make us all healthier in the long run.

So if the US switches to public medicine, what happens to the state of medical research? If the massive profits go away, will the research money dry up too? I have heard concerns that socialized medicine will cause medical research to grind to a halt, leaving the entire world with 2009-level medical technology for the forseeable future. I don't think it will be quite that bad - there are other sources of medical research money than US insurance companies (the US government and other governments).

I hope that in the process of transforming the country to socialized medicine, the government continues the investment in medical research and changes its focus a bit. I have the impression that the direction of medical research is set at least somewhat by the treatments that will make the most money rather than the treatments that are medically best. Drug companies pursue research on drugs that they can patent, not new uses for existing drugs on which the patents have expired. Cures are pursued at the expense of prevention and finding causes. With a change in focus we can hopefully get more effective research for less money overall.

Why insurance is the wrong model for healthcare

Thursday, August 6th, 2009

Insurance is a good model for things like car insurance and home insurance because the duration of a claim is very short - one never has to change one's insurance provider for reasons beyond one's control during a car crash or an earthquake. But a medical condition can last for many years or even a lifetime, during which there can be many individual claims.

Once you have a medical condition that is likely to take many years to resolve and be extremely expensive, you're beholden to your insurance provider, since you are a liability for them. Should you be allowed to change insurance providers? Okay, most of us can't change providers anyway without spending a lot more (to avoid paying tax on our health premiums we're stuck with our employer-provided health plans) but suppose that problem was fixed?

Let's suppose the answer is no, you shouldn't be allowed to change (at least not without taking a cripplingly large increase in premiums turning it from insurance into a payment plan) - no business should be required to take on a customer that is guaranteed to lose them money. Then the "free market" aspect of health insurance is denied to those people who need it most - it's not a free market when you can't make a choice.

So let's suppose the answer is that you should - that insurers should not able to deny access to insurance based on pre-existing conditions (which really ought to include genetic predispositions). Then insurers have to factor in the costs of such patients to all their customers' premiums. That doesn't sound so bad at first glance but consider the consequences - suppose that insurance company A had low premiums but covered very little and insurance company B had high premiums and covered everything. Then all the healthy people get insurance from A and switch to B when they get sick. B's prices then rise to cover the cost of their coverage and what you essentially end up with is equivalent to not having insurance at all. This means that government has to regulate what coverage is provided as well as who it is provided to. All insurance companies will then provide that level of coverage but none will provide any more. We've gone from having no choice to having no real choice. Either way we fail to have a free market for healthcare.

Socialized medicine aka single-payer healthcare aka politically controlled medicine has problems too. In the UK, different districts decide which treatments they will offer, resulting in a "postcode lottery" for some treatments. Waiting lists of years are not unheard of for treatments that are not imminently life threatening, and doctors and nurses are overworked and underpaid compared to their counterparts in the US. However, the average Brit pays about half what the average US resident pays in healthcare costs and gets better coverage on average. There is also no worry about medically-induced bankruptcy, and no worries about one's insurance company refusing coverage (due to a "pre-existing condition") once a serious medical condition is found.

I disagree that single-payer healthcare gives patients an incentive to over-consume. It should not be the insurance company that gets to decide that - doctors should be ones to decide which treatments are medically necessary. And if some doctors are over-prescribing compared to other doctors in their geographical area or speciality, that is something that should be investigated.

Another criticism of single-payer healthcare is that providers have no incentive to compete on price - the government will have to pay whatever they ask for critical treatments. But there's nothing special about single-payer healthcare there - there's nothing stopping the government from acting the same way as insurance companies to do to keep a check on prices. In fact the government has more power than an insurance company there - the insurance company only has the power to drop an overcharging provider from their preferred providers list while the government has the ability to take away their medical license.

Yet another criticism is that if the government gets to decide what treatments are on offer, people don't have any choice. Well, most of us don't have any choice anyway under the insurance model but at least with the government you can vote them out if they aren't doing a good job with healthcare. Yes, socialized medicine means a government bureaucrat between the patient and the doctor, but better an elected bureaucrat than an insurance-company bureaucrat that one has no control over.