Categories
Math Software

A Probability Surprise

For quite a while now I’ve been exercising on a regular basis. My favourite physiotherapist recently told me there was a fair bit of overlap in the exercises I was doing. I had multiple exercises that were working the same muscles. In these cases he suggested I could either just pick one of the two, or alternate between them.

I’m slightly embarrassed to admit that I get a bit excited when I stumble across a real life situation that gives me the (contrived?) opportunity to tell myself “I can build an app for that!”

Specifically, I started out wanting to build an app that would:

  1. have the details of all the exercises I use
  2. know which ones could be alternated
  3. generate a ‘random’ program that would select among the pairs of exercises that were interchangeable.

But then I thought of a couple of things that caused me to increase the scope of the project.

  1. I wanted to be able to specify the relative probabilities in a pair of exercises (for example pick one 65% of the time and pick the other 35% of the time)
  2. I wanted to be able to choose 2 exercises out of a group of 4 and have it randomly pick different pairs.

For example, I have 4 calf exercises, and I wanted to randomly pick 2 each time I was working out. So if I weighted all 4 equally and picked 2 each one would be included 50% of the time. But if I weight one at 50% and the other 3 at 16.67%, when I choose 2, how frequently would the 50% exercise be selected?

SideNote: Why does it matter what fraction of the time an exercise gets picked? In terms of building the app, it doesn’t really matter. My main motivation for figuring out how to calculate this was to make sure that the random selection code was working correctly.

In the case where the app picks 2 items from a set of four individually weighted choices, how could I determine how frequently each item would get picked.

  1. list all the possible combinations [(1,2), (1,3), (1,4), (2,1), (2,3), (2 ,4), (3,1), (3,2), (3 ,4), (4,1), (4,2), (4,3)]
  2. determine the probability of each combination. Note that the probability calculations for the second selection need to exclude the item that was picked first. For example, using the previous values (50%, 16.67%, 16.67%, 16.67%) when 1 is picked first, the probabilities for 2,3,4 will all be 33%. When 2 is picked first, the probabilities for 1,3,4 will be 60%, 20%, 20%
  3. for each combination in step 1, multiply the probabilities for the first pick and the second pick, to determine the probability of each combination. Note in the current example
    (1,2) => (50% x 33.33%) => 16.67% but
    (2,1) => (16.67% x 60%) => 10%
  4. make sure the sum of all the probabilities is 100%
  5. sum the probabilities for all the combinations that include the item in question. For example, item 2’s list of combinations would be [(1,2), (2,1), (2,3), (2 ,4), (3,2), (4,2)]

But here’s the part that was counterintuitive (at least to me): When I change the relative weighting of item 1 and item 2, the probailities for item 3 and item 4 will change. (even though their weightings stay exactly the same.

In the 4 choose 2 example, when all 4 items are weighted equally, all items will appear in 50% of the results. But when item 1 is reduced to 5% and item 2 is increased to 45% (items 3 and 4 are both left at 25%) item 3 and item 4 will now appear in 55% of results.

Categories
Hobbies Photography

Focus!

Several months ago, I took my beloved favourite camera to a Hana soccer game, fully intending to take photos. Between the torrential rain, and my parents having come to watch I ended up not taking any photos. My camera stayed in my pack for the entire game. Sadly I hadn’t paid much attention to protecting it from the rain. (spoiler: wrapping a camera in a tattered plastic shopping bag, and putting it in an entry level day pack will lead to heartbreak if you stand in the rain for 2 hours.)

After the game ended I took a few of photos and they were all out of focus. I didn’t think much of it, but the next time I took soccer photos, they were all unsharp. And the time after that, more blurry photos. Time to take my head out of the sand. After trying multiple lenses on both camera bodies, I became reasonably confident both the body and the lens had issues.

I sent the body to Nikon (something I hate doing) but was still unsure what I should do about the lens. I’d bought some time waiting until the body came back, but soon would need to figure out how to ‘fix’ the lens. (My camera body is a Nikon D500 and the lens is an 80-200 AF 2.8)

When my body came back from Nikon, I wanted to figure out how to get my favourite lens back to being useful. My first plan was to setup my fancy test target try different AF-FineTune values. I eventually landed on the following setup:

  1. test target in the bright sun shine
  2. camera mounted on a tripod close enough that the target filled the frame (but far enough away that it could focus)
  3. shutter release timer

I forget the exact AF FineTune value that resulted from this exercise, but sadly when using the lens wide open, it still tended to focus behind the subject. 🙁

I was able to sort of work around this by:

  1. trying to focus in front of my subjects
  2. stopping down the aperture (eg F4)

But still, even with these adaptations I was getting a large portion of photos being blurry. Eventually, I tried a different experiment. I:

  1. took my son’s bike to a grassy field and set up the camera on a tripod 20 feet away
  2. set the zoom to 80mm (widest value)
  3. using typical settings (1/1000s, f2.8) took photos using different AF Fine Tune values (-20, -15, -10, -5, 0, 5, 10, 15, 20)
  4. Moved the camera a few different distances from the bike (35′, 45′, 70′) For the middle distances, I used multiple zoom values (typically 80mm, 125mm, 200mm) The further away I went, the longer the focal lengths I used.
  5. In all distance/focalLength combinations, I’d take photos with the same array of AF Fine Tune values

The results of this experiment were revealing. All photos were focused behind the bike. The -20 photos were generally less back focused, not much too blurry to be usable.

Unfortunately, the cost of repairing this lens most likely exceeds the cost of replacing it.

In happier news I have now acquired a very modern 70-200 F4 lens. Less shallow depth of field, but also less weight, and much less expensive. While I still dream of switching to mirrorless (I’d love to use a Z6iii) I’m enjoying the sharp photos I’m able to create with my 70-200 and D500. I’ve also enjoyed doing the ‘bike on grass’ experiment with different combinations of lens and body.

Categories
Haiku

Haiku for an Old House

Tearing down the house
Big yellow excavator
Eating bite by bite

One house to the west
A new foundation in place
Waiting for the top

Gonna miss the house
Next door. Small quaint and frumpy
Great people in there

Categories
Haiku

Rubiks Cube Haiku

Turn the yellow face
Now white is messed up. Next time
Unpeel the stickers

Categories
Haiku Uncategorized

Random Full Time Employment Haiku

You and me belong
To the Sun. Everyone does,
But you more than most.

Marge thought through laughing
Ivy is more circumspect
Syllables matter

Categories
Books

Ice and Death Haiku

Squishy sidewalk ice
Slippery as hell, very hard
Glued to the concrete

Not near our house
Not my problem, even though we
Would all fall quickly

I get the mattock
To attack it, whack by whack
Big chunks break apart

Kick the chunks and slush
Off to the sides, clear the path
Unslippery again

Admiring my work
Every time I go that way
Walking is easy

What if I am gone?
This clear patch of path could be
My big legacy

Categories
Haiku

Mish Mash Mush Haiku

Hearing Makossa
Smelling sand roasted peanuts
This is Yaoundé

When I skate outside
My eyes smile and my legs sing
A blade glides on ice

But once it warms up
The ice turns to gooey mush
Puddles of warm slush

Categories
Haiku

Winter Haiku

A spruce Christmas tree
Throwing shimmering warm light
Guarding wrapped gifts

Below zero days
Turn the lake to glass, ready
For many skaters

Poinsettia sitting
By the window, watching the
Cold walkers cruise by

Weather report says
Mixed rain and snow. One snowflake
Gives reason to hope

Categories
Haiku

HodgePodge Haiku

Eating pineapple
Listening to gentle waves
Lapping at the shore

It’s below zero
The sun blinds in the blue sky
I must wear my toque

Sometimes I’m afraid
But I seldom know what of
I’m nervous Nellie

Categories
Haiku

In the Moment Haiku

Light rain falling now
So cold, it might turn to snow
Bring on a blizzard

Dislocating shoulder
Painful when out, then tender
Wish it would stay in

Walking recharges
It’s good for your soul and lungs
and also the soles