ivoflipse / Pawlabeling

Tool for processing and analyzing pressure measurements
Other
18 stars 1 forks source link

Add a gait diagram to the entire plate panel #23

Closed ivoflipse closed 10 years ago

ivoflipse commented 11 years ago

Gait diagrams can be very useful for determining which paw should come next and/or which paws are concurrently making contact.

ivoflipse commented 11 years ago

I fear I don't have the space to add this to the Processing widget as it currently stand.

A possible solution would be to create a tab widget and put either the entire plate widget or the paws widget in it so you can switch between either view. Given the way it looks, I think the entire plate widget would be the most natural fit.

lynforster commented 10 years ago

Gait diagrams are also very useful for making sure you've set the contacts correctly. e.g. if a paw at either end of the plate appears in isolation it can be hard to tell if it's a front or hindpaw. On a gait diagram it is obvious if a paw is mis-assigned as its appearance in the gait diagram will be too soon or too late.

ivoflipse commented 10 years ago

I'm experimenting with how to create the gait diagram. Creating one from labeled contacts isn't an issue: image

This is what you get when you simply assume the order is consistent and there are no missing contacts: image

They line up nicely but as soon as one paw would go missing, things fall apart. Because the next contact would be put on the wrong line and from there every other contact will have that error too.

I've also been thinking about instead of displaying the x, y plain (basically looking down onto the plate), using the y, z plain. Here the horizontal aspect is still the length of the plate, but the height/width is replaced by the time. So you can see when contacts were in contact together by the overlap they have. To accentuate this I've added vertical lines to mark the overlap. image

I can do something similar for the width of the plate and the time axis. But I should note that the nearly matching lengths of the images are a coincidence. Had the plate been shorter, this image would have looked completely different: image

I just thought I'd try Joe's code to see what it would produce, but like I expected, the first contact is 'labeled' incorrectly, because the actual contact that should be in that spot (temporally) is just off the plate: image

I'm not sure how to work around this problem just yet. Perhaps it would be an idea to use temporal/spatial information and try and find a pattern. Then put contacts in rows in such a way that the distances in time and space are most consistent.

ivoflipse commented 10 years ago

I'm trying to figure out if I can spot a pattern, so I'm trying to plot the distances between the paws. Here's a rather cryptic graph, where green = LF, dark green = LH, red = RF and dark red = RH. Then the marker of the point tells us compared to which contact it was: square = left and circle = right, the larger markers are the front paws and the smaller ones the hind paws: image

Perhaps it would be just as informative if you just had a table or something. IF the dog walked in a reasonably straight line, these values seem to be each other's polar opposites. Surely we should be able to use that information somehow.

Though I just made another version of the graph where I drew lines between the contacts we compared with: image image (flipped the x and y axis)

While this is only based on a single measurement, I'm sure we can get something interesting out of it, when you start looking at this info for all measurements in a session. Also note that I only took 3 of the paws I compared with, so I excluded the 'stride' where we compare a paw against itself.

I'm not yet sure though what feature I could get from these 'triangles' though.

I tried adding the stride as well, but its rather lackluster, as they all have similar stride lengths and side-ways motion is minimal. I also tried changing the presentation, by letting the markers be set by the paw compared against, while leaving the arrow between them be set by the contact we're using for the comparison. image

Switching it back to skipping the stride seems like a better idea: image I also marked the 'first' contact with a star, though the calculation is probably off (my z values are the difference between the middle points of each step, so step length differences mess this up).

ivoflipse commented 10 years ago

I decided to try some clustering (the solution to every problem!). Its basically create a heap where the score is the euclidean distance between two paws we compared against. So each contact has been compared against 3-4 contacts, then we compare it against the 3-4 contacts of every other contact and find its best match. The total distance between each best match is then the score. Using a naive clustering method gives the following groups: image

For something unsupervised this works pretty good! The only problem will be if a dog starts mixing its gait pattern between measurements, else I'm sure I could decide which paw is what nearly unsupervised.

Another caveat is that big dogs are too wide for the plate, which causes them to miss certain contacts to compare against. Worst case there are no other paws available, so this wouldn't work at all.

ivoflipse commented 10 years ago

One issue with the method described above is that it only takes future contacts into account. The 9th contact doesn't have any valid contacts to calculate step length/width for and therefore gets excluded from the distance matrix. If it would have included 3 steps backwards and forwards, it would have been included. Though its obvious it would prefer contacts it was compared against.

Another issue is that it wasn't really unsupervised, as the step lengths were calculated using the contact labels. It would be interesting to see what would happen if we simply ignored all that and just took the previous 4 and next 4 contacts and started calculating distances. Perhaps applying a filter to remove values that are higher than a certain threshold or if we could somehow recognize when we're back and the same contact (so we've completed a stride).

ivoflipse commented 10 years ago

I tried taking it up a notch and simply load all measurements, calculate the distances regardless of what the ID of the other paw was. However, this makes it a bit harder to create the visualizations I made yesterday, because I can't guarantee I put them in the right subplot.

After some messing around I thought I'd just take the average of each contact's distances and cluster those using K-Means: image

There are at least 4 reasonably clear clusters, though the two bottom clusters are fairly close in the middle. Also, there is a smaller cluster in the middle, which kind of belongs to nothing. There are also some values at the top that don't belong to a clear group, I suspect some wrapping around kind of issues. For example, a paw that just touches the plate, but which isn't located in its natural 'order', such that its compared against paws of the wrong stride.

It'll be interesting to see how I can translate this somewhat unsupervised clustering into a prediction for the labeling.

Changing the number of clusters from 8 to 6 forces it to keep merging and gives the following result: image

Not 100% whether I think that's an improvement.

ivoflipse commented 10 years ago

I also experimented with only using the next 2 or 4 contacts to calculate the average, but those resulted in much more grouped up points, making it harder to discriminate cluster effectively.

I'm also considering trying to use a different distance measure. For example, calculating the distance of each paw to the plate's COP, which should be fairly unique to each paw and takes all the other paws into account automatically.

ivoflipse commented 10 years ago

I still think this is a useful feature, but I think I'll refrain from adding it until after Iris and Fanny are done labeling. It would be 'easier' to add it as a type of analysis, since then I can assume the contacts have been labeled.

On the other hand, if you spot any errors in the labeling because of the gait diagram, you wouldn't be able to change it...

lynforster commented 10 years ago

One other thing is that if someone has a short plate with big dogs (like I do ;) ) often you get one contact of each paw - four contacts on the plate, no repeats. So no ability to compare contacts.

ivoflipse commented 10 years ago

I just added the gait diagram to the Analysis widget and thought I might as well add it to the Processing widget:

image

While @lynforster is right: if you have a short plate, its not of much use (nothing is really). But if you have repeated patterns like here, you can easily spot errors. I already fixed two errors in some sample measurements I was looking at!