Archive | fun

Using Genetic Algorithms to Generate Negative Training Data

What is a Genetic Algorithm (GA)?

GAs simulate evolution by having genotypes (like DNA in humans) generate phenotypes (like human beings). The genotypes are usually random at the start. The phenotypes are put through some kind of testing function, and the best ones get recombined with the other best ones to make children. Some noise is added, since in the real world DNA isn’t copied exactly correctly and cosmic rays break things occasionally. The phenotypes that don’t do well are discarded. Then the whole process is repeated. For more, see wikipedia.

The Wolfram Language makes it remarkably easy to generate random images, combine them, add noise, and test them against neural networks as a fitness function.

We can thus evolve images to fool neural networks fairly easily.

For example, the default image identification network model is 99.9977% sure that this is an image of Yoda:

That image took about 30 min of compute time to generate, and could be sped up in a variety of ways. It would be interesting to experiment with this to:

  • Select fitness for compression-ability to try and remove the randomness
  • Restrict the colors
  • Use geometry features instead of pixels (lines, rectangles and so on)
  • Use the generated negative images to improve the models

I’m assuming all of this isn’t novel, but after some quick googling around I couldn’t find anything particularly similar.

You can find the notebook here and play with it yourself, and it’s also embedded below:

Relax the Constraints

Space and Time

Problems become much easier to solve if you can relax their constraints.

For example, if you want to buy something and can relax when you buy it then you can find it much cheaper. Candy is vastly cheaper the day after halloween than the day before.

Along with time, the other major constraint is space. If you can relax where you do something then many opportunities open up. For example if you have to buy water at an airport it’s going to be more expensive than elsewhere. If it doesn’t matter where you live then there are far more job opportunities.

If you watch a movie on a Tuesday it’s not only cheaper but there are far less people, so it’s a higher quality experience as well as saving dollars.

So, try to avoid the “right here, right now” and relax all the constraints you can.

Airbus anti-collision lights part 2

Back in December I wrote about making a portable anti-collision light systems for, say, cyclists using the Airbus scheme.

That first version used a generic full-size Arduino unit. I’ve been miniaturizing it and changing hardware platforms over the last month or so as parts arrive from China. Here’s version 2 below. It adds the tail light, switches to a LiPo battery and uses a trinket instead of an Arduino:

Version 3 moves to an ATTiny85 programmer board:

Version 4 uses just the the ATTiny84 IC and switches to rechargeable AAA batteries. By rearranging components I removed 8 wires and added an on/off switch:

The next step is to put the thing on some strip board and/or design a PCB and case for it. There are a bunch of mixed considerations as the case and PCB layout interact with each other, and I’d like it to be waterproof for helmet mounting for cyclists. The battery type introduces a lot of complexity – a rechargeable lithium cell is probably best but that means integrating the charging cicuitry and having a USB socket on the thing. I have more parts ordered from China to test all of this.

Explore OpenStreetMap Statistics

OSM Stats for Namibia

Ever wanted to explore OSM statistics over time and in depth? OSM Stats is for you. Notice the site asks for your location – this is just to show you your country automagically by default.

The site lets you explore by country, over time, major types of OSM data. The left-hand graph shows you the aggregate count over time, the right-hand graph shows the difference (delta) over the same time period. You can click different data types on the left, change country at the top, and change the time range just above the graphs.

You can find some interesting things. Here’s the default view for the United Kingdom:

What it shows is data growing over time. We like graphs that go up-and-to-the-right. The right-hand graph shows, as expected, the amount of data being added declining over time. This is because there’s less and less to map in the UK as I started the project there.

Compare that to Haiti:

Can you guess what the spikes in data addition are?

Now look at residential roads only in the United States:

Things are declining over time! Where are all those residential roads going? Well a small part of the answer (notice the vertical axis is 2 orders of magnitude less than above) is the growth of living streets in the US:

That’s a small taste of the things you can learn – have fun exploring the site and email me any comments.

Continental Drift Part 2

Phone superglued to foundation

(see part 1)

The phone’s been running for nearly a week collecting data despite rebooting servers and wifi failing so I superglued it to the foundation of the house, which is concrete and in the ground. The data collected so far has all been deleted since it was just a test, but from here on out it’s real. In a week or two I’ll write some scripts to analyze the data and figure out what the error bars are.

Measuring Continental Drift with a Phone

Worldwide Continental Drift Velocities

Worldwide Continental Drift Velocities

Here in Colorado if you believe the above map (more detail), we’re moving a few centimeters a year west or south-west. Queue music, and a weekend project.

How is continental drift measured? It turns out there’s not a lot to it, you just superglue a GPS to a rock and take location measurements for a year or two. If you average out the noise of the GPS you should see it move over time.

I have an old Lumia phone that is worth about $5 on eBay yet will run Windows 10 so I grabbed Visual Studio 2015 and wrote a little app to grab the GPS location every second. The app also keeps the screen alive, displays the location and then sends the data off to a server. The “server” here is a Mac running a tiny little ruby daemon which listens for the GPS data and logs it to some files. There’s also a little plist file you put in your launchd directory to keep it running as a background service. A great excuse to learn how Windows 10 apps and ruby sockets work.

Now the “real” geologists, probably their GPS is bright orange, has solar power, a big drive to log data and special clamps to mount the whole thing to the bedrock that’s being measured. It probably has a wonderful view of the sky, and cost $20k or something. The concrete foundation of the house and superglue will have to suffice for mounting. We have interference from the (wooden) roof of the garage. The server might go down. The wifi will too, occasionally, and there is no buffering on the phone at this point so we’ll lose data here and there. The code is all available here.

I’m currently running the setup for a few days and will then superglue the phone to the foundation and forget about it for a few months while it collects data. Though there is one piece left to write for logging, we need to compress the files after they’ve been stagnant a while.

Analysis will come much later, and we’ll need a decent numerical library to make sure the averages are computed correctly. There are various other thing that can break like thermal expansion or some other effect may throw the whole thing off. Stay tuned!

Arduino Airbus Anti-Collision Lights

Airbus aircraft, like the model A380 above have a specific anti-collision lighting setup that I like. The white LEDs on the wing tips blink twice, then the red light on the top and bottom blink. I’m ignoring the tail light since I’m not sure I care about it for what I want to do.

Here’s the timing diagram:

The middle row shows the wingtip lights blinking for 50 milliseconds, wait for 350 milliseconds then blink the red (top row) for 100 milliseconds. The bottom is the tail I’m ignoring for now.

I implemented this on an Arduino:

Here’s the code (and yes, I know the loop is unrolled):

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(LED_BUILTIN, LOW);

So the question of course is, why?

I think it would make a neat set of lights for a bicycle helmet or something lighter (e.g. a headband) for runners. If it’s good enough to protect a half-billion dollar aircraft then why not try it on the mean streets?

I need to miniaturize and package it, and make it work in the rain as next steps.

Here’s the Arduino clone kit I used, and the ultra-bright LEDs. The kit came with some fogged white LEDs which are OK, but not great. Overall it was a fun first project, and if you already know how to write software and some electronics you can get going extremely quickly. My problem was I never had a real reason to use an Arduino until now…

Powered by WordPress. Designed by WooThemes