Skip to main content
Posts by:

Tim Booher

Review: Boys Should Be Boys: 7 Secrets to Raising Healthy Sons

From a one-star review on Amazon:

The content was obvious and the tone was judgmental. The complete lack of nuance is painful. Apparently receiving an MD over 25 years ago makes this Dr. Laura-style author an expert in child psychology? Let’s leave the psychology topics to those professionally trained in that discipline.

I’ve always enjoyed Meg Meeker’s books and her latest is no exception. She’s very practical and conversational, but she brings together a refreshing mix of social conservatism with practical medical know-how. Every chapter is focused towards concrete advice for parents to become more effective in crafting the virtue (and therefore well-being) of our sons. As the quote above shows, she presents a perspective that is out of sync with aspects of modern culture, and in particular with modern medicine’s trend of hyper-specialization and the unwritten rule to leave moral judgments out of medical advice. We all know this trend has risks: a specialist is going to miss the whole person concept that is critical to understand as we tackle a problem as complex as parenting. By forcing those who give us medical and parenting advice to be materialists is to force life’s great questions out of the discussion. A materialist view misses the most important dynamics in developing character and sons who become men of virtue.

Meg Meeker explains that boys need the freedom to explore and test their limits, even if this means some scrapes, bruises and difficult moments. She tries to strike the balance between helicopter and laissez-faire parenting. She slices through these two extremes with a simple call to engage: to double the time we spend with our boys all the while loving them enough to force them to grow in difficult and engaging situations.

It is out of the tension of caring too little and not caring enough that she weaves her plan for an ideal father. In many ways, I find her book more interesting for what it says not to do than what it says to do. She reminds us of the danger in letting our boys be cast adrift into a toxic mix of video games, ersatz online relationships, and a hyper-sexualized culture that emphasizes in individual’s emotion over an external, and fixed, framework of morality.

She makes it clear that there’s no substitute for personal time and attention. She paints the ideal parent as always engaged and aware of what their children are doing in a manner that doesn’t dictate the details of their life but does pour compassion and love into their schedule while allowing them to grow and develop in natural situations. In reading her book, she makes it clear that to avoid the harmful influences of society, we as fathers have to be committed and focused to protecting them in fostering the right environment which allows them to develop in healthy ways.

In 12 chapters she starts with a review of the problem and then goes over seven areas of focus. Here, in brief they are:

  • Know how to encourage your son. One fault is babying and spoiling him. But another is being so harsh that you lose communication with your son and destroy his sense of self worth. We’ll look at how to strike the right balance.
  • Understand what your boys need. Guess what? It’s not another computer game; it’s you. We’ll look at how to get the most of your time with your son.
  • Recognize that boys were made for the outdoors. Boys love being outside. A healthy boy needs that sense of adventure— and the reality check that the outdoors gives him.
  • Remember that boys need rules. Boys instinctively have a boy code. If you don’t set rules, however, they feel lost.
  • Acknowledge that virtue is not just for girls. Boys should, indeed, be boys—but boys who drink, take drugs, and have sex outside of marriage aren’t “normal” teenagers, they have been abnormally socialized by our unfortunately toxic culture. Today, my practice as a pediatrician has to deal with an epidemic of serious, even life-threatening, problems—physical and psychological—that were of comparatively minor concern only forty years ago. A healthy boy strives after virtues like integrity and self-control. In fact, it is virtues like these that make a boy’s transition to manhood possible.
  • Learn how to teach your son about the big questions in life. Many parents shy away from this, either because they are uncomfortable with these questions themselves, or want to dismiss them as unimportant or even pernicious, or because they don’t want to “impose” their views on their children. But whatever one’s personal view, your son wants to know— and needs to know—why he’s here, what his purpose in life is, why he is important. Boys who don’t have a well-grounded understanding on these big questions are the most vulnerable to being led astray into self-destructive behaviors.
  • Remember, always, that the most important person in your son’s life is you.

In the second chapter, she addresses how to deal with peer pressure with a particular emphasis on how toxic are culture is for boys and their identities. She goes on from this to discuss boy’s natural tendencies and how helpful rough and dangerous activities can be. This is exactly the natural state of boys development. She points out that neighborhood games practiced by boys with different ages force them to learn important life lessons which they can’t learn anywhere else.

In the fourth chapter, she explores the role between electronics, virtual worlds and the influence they have on the development of young boys. I’d recommend to all parents of young children read Parmy Olson’s book “We are Anonymous” to better understand how amazingly toxic (and captivating) the underbelly of the internet is for children. (Something we all know, but she brings it forward in vivid detail.)

In an interesting turn, she then explores the societal animosity towards teenage boys. I just finished Sheryl Sandberg’s Lean In in which she makes an excellent case for societal biases against women leaders in business. By contrast, Meeker makes an excellent point that society presents a self reinforcing feedback loop that cast teenage boys as moody, depressed and angry. She makes some excellent points that have particular poignancy coming from a medical professional who is used to dealing with teenage boys: it is okay to be depressed and moody and not the cause of alarm or overreaction from parents. The solution is more old-fashioned that our modern and hyper specialized world wants: more time and attention — in the context of a strategic perspective.

However, the focus of our increased time and attention is the subject of the next chapter. Chapter 6 talks about practical ways to build self-confidence and mental health in our boys. She talks about the critical importance of the fathers blessing, something that always proved far too elusive for me. She describes the feeling of true accomplishment as a powerful emotional resource builder. (I think it’s helpful to contrast true accomplishment with the common empty fawning praise and declarations of how special my children are that they find in school.)

Particular convicting is her clarion call to live my life in an exemplary way that sets the right standards for my son. I want to model the virtues that he should have and she challenges us to picture our son at the age of 25 and to foster those virtues we desire in him — much in the same way Dan Allender’s Bold Love tells us to carefully and tirelessly pursue love with the cunning of a fox.

She moves on in the next chapter to discuss why so many men are merely aged adolescents: They never got through the transition from being a boy to becoming a man. She diagnoses this, in her clinical way, as the result of the absence of a father’s guidance.

She matches this with the next chapter that talks about the importance of faith and of the knowledge of an external God to whom boys feel accountability. She describes how a faith in God helps children to have a well of hope to draw from as life gets tough and develop an understanding of love that is more than a pleasurable act between bodies, to understand the importance of truth and accountability as well as the critical importance of repentance forgiveness and grace to young child. Here as in the rest of the book she makes it clear that this doesn’t mean simply dropping off your son at church and hoping he finds God — she calls fathers to again being the best that they can be for themselves but also for their sons — and model the ideal behavior.

My biggest criticism of her books is the way she remains generic towards faith. While a Judeo-Christian concept of God has been foundational to a historical US worldview, I think she should be more honest in explaining the particular faith she holds and its critical nature to our sons of eternal destiny. A general “faith” without conviction is not what we want our sons to have. Is she really advocating to teach our sons about Islam? She remains neutral on how God is defined — without question — to reach a broader audience. But her own faith of Christianity claims exclusivity, and I found it disappointing that she avoided this.

Her book culminates in the 11th Chapter where she calls us to ideate the core virtues we want our sons to have that will ensure they make the transition from boy to man. She emphasizes virtues we all want in our children such as integrity, courage, humility, meekness, and kindness. She doesn’t just introduce these as words but fully fleshes them out into concepts and practical steps to build them in our sons.

She ends the book with 10 tips to remember and a call to double whatever time we currently are investing in our sons. Here are the 10 tips:

1) Know that you change his world 2) Raise him from the inside out (worry about his inner life and the outer life will follow) 3) Help his masculinity to explode 4) Help him find purpose and passion (other than being a video game master) 5) Teach him to serve (this is where Church can come in handy) 6) Insist on self-respect 7) Persevere 8) Be his hero 9) Watch, then watch again (pay close attention to what is going on in his life) 10) Give him the best of yourself (not just the leftovers)

By 0 Comments

GE GXULQR Twist and Lock Kitchen or Bath Filtration System Replacement Filter Won’t Fit

If you ever have to replace your under the sink GE filter (specifically the GE GXULQR), be ready for a frustrating ride.

It looks like this:

filter

You can find the manual here and the ge product page here.

It is billed as the “Twist and Lock” Replacement Filter, the inside female hex socket sometimes rotates out of alignment when you remove the old filter. If this happens, there is no easy fix. Moreover, since the receiving head is generally under a sink or in some place you can’t easily access, it is very frustrating when you are pushing into the plastic receiver and the new filter doesn’t fit. (It is extra frustrating if you have a cast on a broken right hand, carpal tunnel in the your left hand and can’t bend your back due to a herniated L5/S1.)

head

The instructions only say to “Push filter into the filter head/bracket. Turn filter 1/4 turn to the right until it stops. The top surface of the filter will be flush with the bottom of the filter head/bracket when fully installed.” This only works if everything is properly lined up. The solution is to re-align the receiver by making a new tool from the old filter. By cutting off the head of the old filter (I used an angle grinder), and hammering in a flathead screwdriver, you have a custom alignment tool that looks like this:

custom tool

How far should you rotate it? Enough to get the socket to line up so the flanges align. For me, this meant the top of hex was flat. The biggest challenge is knowing how hard to turn. I still don’t know the internal mechanism, and the casing is all plastic and I didn’t want to break it. For me, I had to rotate it pretty hard before it turned. This was a little scary because water started to leak out from inside. However, after my wife rotated in the cartridge (two hands were necessary, and a cast doesn’t help), everything seems to be working fine.

Hopefully, this spares you some frustration.

By 9 Comments

Gradient Descent

[mathjax]

It has been awhile since I’ve studied optimization, but gradient descent is always good to brush up on. Most optimization involves derivatives. Often known as the method of steepest descent, gradient descent works by taking steps proportional to the negative of the gradient of the function at the current point.

Mathematically, gradient descent is defined by an algorithm for two variables, say \theta_0, \theta_1 as repeated updates of:

$$ \theta_j := \theta_j – \alpha \frac{\partial J (\theta_0 , \theta_1) }{\partial \theta_j } $$

from the hypothesis:

$$ \begin{aligned}
h_\theta(x) = \sum_{i=1}^n \theta_i x_i = \theta^{T}x.
\end{aligned} $$

The \alpha is the learning rate. If \alpha is very large, we will take some huge steps downhill, small \alpha would mean baby steps downhill. If \alpha is too small, it might take too long to get our answer. If alpha is too large, we might step past our solution and never converge. Besides the pitfall of picking an  \alpha , you have to have a cost function with existing derivatives (continuous) and a convex function.

Often for linear regression, we use batch gradient descent. In machine learning terminology, batch gradient descent uses all training examples. This means that for every step of gradient descent, we compare all residuals in the final least squares calculation.

Why is this relevant to machine learning? Of course there is always an analytical solution to any model, but this might involve a very large matrix inversion and be computationally infeasible.

$$ \theta = (X^T X)^{-1} X^T y $$

Gradient descent gets used because it is a numerical method that generally works and is easy to implement and a is very generic optimization technique. Also, analytical solutions are strongly connected to the model, so implementing them can be inefficient if you plan to generalize/change your models in the future. They are sometimes less efficient then their numerical approximations, and sometimes there are simply harder to implement.

To sum up, gradient descent is preferable over an analytical solution if:

  • you are considering changes in the model, generalizations, adding some more complex terms/regularization/modifications
  • you need a generic method because you do not know much about the future of the code and the model
  • analytical solution is more expensive computationaly, and you need efficiency
  • analytical solution requires more memory or processing power/time than you have or want to use
  • analytical solution is hard to implement and you need easy simple code
By 0 Comments

FlexEvents: WOD 3 Simulation

During a recent CrossFit competition, flex on the mall, we had to accomplish a team chipper in which we were able to pick the order of team members in order to minimize our workout time. The workout was simple: 50 burpees, 40 over the box jumps, and 30 kettle-bell snatches. Each exercise had to be accomplished in serial: no one could start an exercise until their previous team member had finished. This meant everyone waited while the first person started. As simple as this was, I got confused when figuring the optimal order for team members: should the slowest go first or last?

At the time, I thought the best strategy would be to have the fastest go first, to prevent the scenario where the fast folks were waiting and unable to help the team. I was focused on the idea that you didn’t want anyone to be waiting — so clear out the fast people first. My partners wanted the slowest to go first because the slower participants could rest, go super slow and not affect the final score.

While I was wrong, and they were correct, this didn’t make sense at the time, because I was viewing the whole thing as a linear operation where order didn’t matter, but waiting on someone would definitely slow down the overall time. It turns out that if you put the slowest last, no one is waiting, but the clock is rising totally based upon the slowest time, when you otherwise could have obscured their slow time. The workout came down to the following critical path: the time it took to do everyone’s burpees plus the last participant’s time.

However, this is only true if the time it took to do burpees was significantly more than the other events and there was not a significant difference in fitness between team members. After the competition, I wanted to understand the dynamics of this workout and build a quick model to understand where these assumptions held true and hone my intuition for stuff like this.

It turns out the worst thing to do is have the slowest person go last. The reason why is really simple: you are putting them in the critical path. In fact, an optimal strategy is to have the slowest always go first. If I assume all four members have different speeds, and made an assumption like this based on expected values of their workout times. Let’s assume four members have the following expected completion times (in notional units), where person 1 was the fastest and each successive participant was slower in all events.

Note: These are totally made up numbers and have nothing to do with our team . . . says the man whose wife now routinely kicks his scores to the curb.

person 1 2 3 4
burpees 9 10 15 17
box jumps 7 8 13 15
KB snatch 5 7 11 13

_

In this case, I wrote some Matlab to look through all (4! = 24) permutations. (Remember: 1 = fastest, 4 is slowest.)

CrossFit Order

This is such a simple event that you can see the basic building blocks without much introspection: 21 is the fastest time to complete the sequence and 45 is the slowest. If the team were all comprised of person 1 they could complete the whole thing in 48. As this fictional team is, burpees alone will account for 51 regardless of order, but if the fastest goes at the end, you can get away with only adding 15 on to the total time, versus adding 28 if the slowest person goes last.

Several things here. It is so simple to work the math of this with variables instead it probably should be done. A better analysis could show you how much variation you could tolerate between athletes before the problem dynamics above don’t apply. Maybe another lunch break for that.

OK, on some more thought, I thought I would look at several scenarios and show optimal strategies.

A team member is much slower on burpees, but faster on the other events.

In this case, it still makes sense for her to go last. The burpees are linear, but speed in the bottom two events determines the order. It helps me to assign a color to each team member and see all 24 strategies on one plot. The lightest shade is member one who has a burpee time of 40 compared to 4 for the others, but is faster in the other two events than the others. In the plot below, the fastest combinations are at the top where you can see that all the fastest outcomes have member one going last.

burpees slower on 1

Burpee times equal KB snatch times

So if their event times look like this where everyone’s KB snatch times equal their burpee times.

burpee times:    1   2   3   4
box jump times:  2   2   2   2
KB snatch times: 1   2   3   4

Then all outcomes are equal and you get a truly random pattern where all outcomes are equal regardless of order. So in this case it doesn’t matter what order you do the workout in, even though 4 is much slower than 1. Interesting and counter-intuitive.

colors

My code is below for any of those interested.

By One Comment

CY2014 Quarter 1 Financial Review

Chrissy and I review our spending on a quarterly basis. Updating every 90 days isn’t too long to correct mistakes and remember purchases, but it also allows for the busy multi-week sprints that life presents us. While we have used every financial management program available, I’ve found the most straightforward and flexible solution is to download historical transactions into Excel where I can assign categories and do the type of analysis you can see below. This works for me because I have complete control. All the other solutions I used (MS Money, Quicken, Mint, GNU Wallet) introduce errors that have required lots of time to fix (or that can’t be fixed), but more importantly they constrain me to their interface and I got used to exporting information into tools that could flexibly answer my questions.

My basic workflow is to download statements from all our bank accounts and credit cards in put them all into one spreadsheet, where I ensure a consistent list of categories. I can do this quickly by filtering and sorting as most of our expenses are cyclical. Once everything is in the right format, I use lots of Excel SUMIF and SUMIFS functions to produce reports.

My purpose of doing a financial review is intended to accomplish the following:

  • Quality check (Are we getting paid the right amounts? Any incorrect expenses?)
  • Spending feedback (Are we overpaying in any categories? Anything we need to reign in?)
  • Tax Production

While my tax production and quality check was very helpful to me, I wanted to share the results of the spend analysis in case my reports might be useful to others.

Spending feedback

In summary, we had a small rise in our overall Grocery and Dining out categories, but the major cost drivers were:

  • Ellie’s 12 cavities were very expensive (no dental insurance)
  • We bought a new espresso machine (major purchase for us)
  • We bought a new car
  • We went crazy on clothes
  • Committed (again) to Army Navy Country Club

spending-by-category

Where are we spending?

This doesn’t have a real effect on our spending, but I thought this was interesting. We don’t have saving/investments in here, this is just “spending”. I treated stuff like insurance, taxes, medical, fees, haircuts, etc as “cost of life” — things I feel we can’t avoid and don’t really have discretion in spending. Some other stuff that might fit this category (power bill) gets lumped into household (as does home maintenance and mortgage). I would love to do some more analysis and compare our spending to this article.

pie

Daily Feedback

The plot below has categories on the Y-axis and days on the bottom. Intensity of color is the spend amount. I used matlab to produce this plot. I like it because the colormap used filters everything in way that comes out like a log scale — and that tells me what is a big deal and what is noise. The interesting dynamic is the frequency/magnitude trade that happens with spending dynamics: medical is in seldom/big chunks while grocery expenses are a constant but smaller expense.

imagesc_daily_spending

You can see that our daily spending has a huge variance: The spending had a standard deviation that was twice our average spending — big purchases had a pronounced effect. I explore four levels of spending: discretionary (dining out), some and limited discretion (haircuts, medical) and non-discretionary (mortgage, tax) at the bottom.

DailySpendingBar

Weekly Feedback

Click on the below to see full size

WeeklySpending

So how much can we control this?

If I break down spending into four categories:

  • Committed — We have to pay it (i.e. Mortgage)
  • Limited Discretion — We can commit extra time to reduce it (i.e. Home and Car Maintenance)
  • Some Discretion — We can make choices to decrease our quality of purchase (i.e. Groceries)
  • Total Discretion — We can do without this if we have to (i.e. Dining Out/New Clothes)

It turns out that a third of our expenses are committed where about a quarter each apply to limited and some discretion. Roughly 20{aaa01f1184b23bc5204459599a780c2efd1a71f819cd2b338cab4b7a2f8e97d4} of our expenses are totally discretionary and 70{aaa01f1184b23bc5204459599a780c2efd1a71f819cd2b338cab4b7a2f8e97d4} of our expenses could be changed if we had to. The takeaway for me is to focus on eliminating the stuff we pay for but don’t enjoy (fees) and the things that don’t bring joy/reward for their cost.

By 2 Comments

Fun with Bessel Functions

[mathjax]

Well, I certainly forget things faster than I learn them. Today is a quick review of Bessel functions and their applications to signal processing.

The Bessel functions appear in lots of situations (think wave propagation and static potentials), particularly those that involve cylindrical symmetry. While special types of what would later be known as Bessel functions were studied by Euler, Lagrange, and the Bernoullis, the Bessel functions were first used by F. W. Bessel to describe three body motion, with the Bessel functions appearing in the series expansion on planetary perturbation

First, I think they should be called Bernoulli-Bessel functions both because that sounds more pompous and because they were discovered by Daniel Bernoulli and generalized by Friedrich Bessel. While they sound (and can be) complicated, they are the canonical solutions y(x) of Bessel’s differential equation:

$$ x^2 \frac{d^2 y}{dx^2} + x \frac{dy}{dx} + (x^2 – \alpha^2)y = 0 $$

for an arbitrary complex number \alpha (where \alpha denotes the order of the Bessel function). The most important cases are for \alpha as an integer or half-integer. Since all math ties together, I find it pretty cool that Bessel functions appear in the solution to Laplace’s equation in cylindrical coordinates.

Although \alpha and −\alpha produce the same differential equation that a real \alpha does, it is conventional to define different Bessel functions for these two values in such a way that the Bessel functions are mostly smooth functions of \alpha.

Bessel functions of the first kind: J_\alpha

Bessel functions of the first kind, known as J_\alpha (x), are solutions of Bessel’s differential equation that are finite at the origin (x = 0) for integer or positive \alpha, and diverge as x approaches zero for negative non-integer \alpha. It is possible to define the function by its Taylor series expansion around x = 0.

$$ J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m+\alpha+1)} {\left(\frac{x}{2}\right)}^{2m+\alpha} $$

where \Gamma(z) is the gamma function, a shifted generalization of the factorial function to non-integer values.

Bessel functions of the second kind : Y_\alpha

The Bessel functions of the second kind, denoted by  Y_\alpha (x) are solutions of the Bessel differential equation that have a singularity at the origin.

For non-integer \alpha, Y_\alpha is related to J_\alpha by:

$$ Y_\alpha(x) = \frac{J_\alpha(x) \cos(\alpha\pi) – J_{-\alpha}(x)}{\sin(\alpha\pi)} $$

In the case of integer order n, the function is defined by taking the limit as a non-integer \alpha tends to n:

$$ Y_n(x) = \lim_{\alpha \to n} Y_\alpha(x). $$

There is also a corresponding integral formula (for Re(x) > 0),

$$ Y_n(x) =\frac{1}{\pi} \int_0^\pi \sin(x \sin\theta – n\theta) \, d\theta – \frac{1}{\pi} \int_0^\infty \left[ e^{n t} + (-1)^n e^{-n t} \right] e^{-x \sinh t} \, dt.$$

Y_\alpha(x) is necessary as the second linearly independent solution of the Bessel’s equation when \alpha is an integer. But Y_\alpha (x) can be considered as a ‘natural’ partner of J_\alpha (x).

When \alpha is an integer, moreover, as was similarly the case for the functions of the first kind, the following relationship is valid:

$$ Y_{-n}(x) = (-1)^n Y_n(x).\,$$

Both J_\alpha (x) and Y_\alpha (x) are holomorphic functions of x on the complex plane cut along the negative real axis. When \alpha is an integer, the Bessel functions J are entire functions of x. If x is held fixed, then the Bessel functions are entire functions of \alpha.

Bessel Filters

In electronics and signal processing, a Bessel filter is a type of linear filter with a maximally flat group delay. The Bessel filter is used because a low pass filter is characterized by transfer function. The denominator of the Bessel filter is a reverse Bessel polynomial. Bessel filters are often used in audio crossover systems. Analog Bessel filters are characterized by almost constant group delay across the entire passband, thus preserving the wave shape of filtered signals in the passband.

A low pass active filter with a Bessel response is used when the filter needs to exhibit minimum differential delay between the various frequency components of interest contained within the input signal being filtered. In essence this means that the fundamental frequency of say an applied squarewave experiences the same input-to-output delay as the other harmonics within the filter’s pass-band. This results in a high degree of fidelity of the output signal relative to the input signal.

By 0 Comments

Excel Sorting and Grouping

I had two tables downloaded from Amazon:

Items

Order Date  Order ID    Title   Category
1/26/14 102-4214073-2201835     Everyday Paleo Family Cookbook
1/13/14 115-8766132-0234619     Awesome Book A
1/13/14 115-8766132-0234619     Awesome Book B

and

Orders

Order Date  Order ID    Subtotal
1/6/14  102-6956821-1091413 $43.20
1/13/14 115-8766130-0234619 $19.42
1/16/14 109-8688911-2954602 $25.86

I’m building our Q1 2014 taxes and needed rows in the following format:

1/13/14 115-8766132-0234619 $22.43 Awesome Book A, Awesome Book B

In order to do this without using SQL, I did the following. If columns B corresponds to Order Id and C corresponds to the item Title, then I put the following formula in column N3

=+IF(B3=B2,N2 & " | " &C2,C3)

and in column O3 a column which might be named: “last before change?”:

=+IF(B3=B4,"", TRUE)

Then I could easily sort out the unwanted values. Done. Still, I would like to better automate this. Any thoughts appreciated.

By 0 Comments

Sampling Exploration

[mathjax] I needed to review the Nyquist–Shannon sampling theorem. The coolest thing about Nyquist is that it expresses the sample-rate in terms of the function’s bandwidth and leads to a formula for the mathematically ideal interpolation algorithm.

What is sampling?

Sampling is nothing more than converting a signal into a numeric sequence. Shannon states:

If a function x(t) contains no frequencies higher than B hertz, it is completely determined by giving its ordinates at a series of points spaced 1/(2B) seconds apart.

This is really simple: A sufficient sample-rate is therefore  \scriptstyle 2B samples/second, or anything larger. The two thresholds, \scriptstyle 2B and \scriptstyle f_s/2 , are respectively called the Nyquist rate and Nyquist frequency.

I can’t understand something unless I explore with it. So, I defined the following code.

First we have to make the following definitions for a given sample-rate of  f_s :

  • $$ \scriptstyle T \stackrel{\mathrm{def}}{=}\ 1/f_s $$ represents the interval between samples.

Say we have a simple sign wave modulated at a frequency of 1/8.

Simple Sin Wave

If we explore, we can get:

Exploration

Aliasing

When the bandlimit is too high (or there is no bandlimit), the reconstruction exhibits imperfections known as aliasing.

Let X(f) be the Fourier transform of bandlimited function x(t):

$$ X(f) \stackrel{\mathrm{def}}{=}\ \int_{-\infty}^{\infty} x(t) \ e^{- i 2 \pi f t} \ {\rm d}t $$

and

$$ X(f) = 0 \quad \text{for all} |f| > B $$

The Poisson summation formula shows that the samples, x(nT), of function x(t) are sufficient to create a periodic summation of function X(f). The result is:

$$ X_s(f)\ \stackrel{\mathrm{def}}{=} \sum_{k=-\infty}^{\infty} X\left(f – k f_s\right) = \sum_{n=-\infty}^{\infty} \underbrace{T\cdot x(nT)}_{x[n]}\ e^{-i 2\pi n T f}, $$

This function is also known as the discrete-time Fourier transform.

Questions I’m after:

  • How is it that the samples of several different sine waves can be identical, when at least one of them is at a frequency above half the sample rate?

You can see my source code here:

By One Comment

Practical Cutting Stock Problem

Warning. This post is for an audience of close to zero. My technical friends will find this pretty basic, and my non-technical friends will find this too technical. Welcome to the middle space that I occupy between these two worlds.

I wanted to build this series of retaining walls to replace the overgrown ivy and eroding slope next to my stairs in my front yard.

Retaining Walls

One of the challenges of my current job is to keep my skills sharp as a program manager. I decided to find an automated solution, even when the practical solution was pretty obvious. My problem was basic, I had to make the following cuts:

  • 43 1/8
  • 4′ 7/8
  • 44.5″ x 3

[mathjax]

As these were landscape timbers, I knew that I could get them at Home Depot in 8, 10 or 12 foot lengths at $20.57, $29.97, or $37.27. The longer lengths cost more at 2.57, 3, and 3.11 a foot. To minimize my cost, I wanted to buy the least number of pieces and at the shortest lengths possible.

I solved this in 2 minutes in excel, by just guessing and found that I could do one 8 and one 12 or three eights. Three eights would be $62 and and 8,12 would be $58. I’m going to pay the $4 and get pieces I can more easily move, and get 4 more feet to play with.

However, isn’t this a nice knapsack problem for the excel solver? I thought I would give it a try. Google showed me this quick refresher and Wikipedia provides a nice start and the integer program can be formulated as:

$$\min\sum_{i=1}^n c_i x_i$$ $$\text{s.t.}\sum_{i=1}^n a_{ij} x_i \ge q_j, \quad \quad \forall j=1,\dots,m$$ $$x_i \ge 0, \text{integer} $$

where a_{ij} is the number of times order j appears in pattern i and c_i is the cost (often the waste) of pattern i.

However, I wanted to be quick. I didn’t want to have to find all patterns ahead of time. After playing around for a couple minutes, I got this working in excel using a genetic algorithm by forcing each cut to only happen once and minimizing the amount spent.

Excel Solver Example

With these constraints:

Solver Parameters Solver Parameters

While I had a quick solution under my belt, I waited until a long plane flight to cook up something better. First, I skimmed through these papers:

For me, it turns out the key to solving this is to come up with a list of potential patterns and to solve for the pattern combinations in order to get the quantities right. First, I used Matlab to come up with feasible combinations by using the and the very handy allcomb function to generate all possible combinations and removing those that were too long.

{aaa01f1184b23bc5204459599a780c2efd1a71f819cd2b338cab4b7a2f8e97d4} here 3 cuts are hard-coded
M = allcomb([0:max_num], [0:max_num], [0:max_num]);

{aaa01f1184b23bc5204459599a780c2efd1a71f819cd2b338cab4b7a2f8e97d4} now reduce to the feasible solutions
F = M(M*cuts' < max_length, :);

{aaa01f1184b23bc5204459599a780c2efd1a71f819cd2b338cab4b7a2f8e97d4} remove the trivial
F = F(2:end,:);

First, I implemented this in Excel using their simplex solver.

Improved Solver

With the following solver constraints:

I also implemented an end-to-end solution in Matlab that should be useful for my next project. This way I understand the math behind it and can use my optimizer for any number of projects.

This produces an output like:

board: 1 | quantity: 1 | 2 cuts of 44.5  waste: 7
board: 2 | quantity: 1 | 1 cuts of 44  waste: 52
board: 3 | quantity: 1 | 1 cuts of 44 1 cuts of 44.5  waste: 7.5
board: 4 | quantity: 2 | 1 cuts of 44 1 cuts of 49  waste: 3
----------------------
Total waste: 72.5 inches

And I added some graphics to be able to guide my cuts.

matlab_results

Please share any comments/insights.

By 5 Comments

Consistency, Focus and Grace

“My commitment must be to truth, not to consistency.” — Ghandi

Then Jesus said to his host, “When you give a luncheon or dinner, do not invite your friends, your brothers or sisters, your relatives, or your rich neighbors; if you do, they may invite you back and so you will be repaid. But when you give a banquet, invite the poor, the crippled, the lame, the blind, and you will be blessed. Although they cannot repay you, you will be repaid at the resurrection of the righteous.” Luke 14:12-14

It was the smell of smoke which alerted me to his presence. I had a long layover in Salt Lake City and I was taking the Trax downtown to sketch, tour the sights, and find a good coffee shop. The sun shone brightly into the impeccably clean and nearly empty car as I did my quick survey of my new fellow traveler. He was an over-weight latin-american with an unshaven and stressed out face. His shoes were worn out and he was talking on a cheap pre-paid cell phone with a friend to figure out how he was going to get $40 to pay for medicine his wife needed. Not excessively loudly, but definitely not softly he explained that his wife recently had a medically-induced accident that resulted in injuries to their infant. He talked about trusting God to provide the money and highlighted that their baby was fine, but that his wife was not.

I was feeling excessively penitent due to a Bishop Bienvenu encounter with a Las Vegas police officer the night before. He gave me a warning despite clocking me at nearly 40 mph over the speed limit in Red Rock Canyon after a run. I had also been upgraded to first class for both flights that day, and this new passenger made me very aware that we were two members of very different worlds whose lives were coming into contact. Additionally, I had just taken out $40 from an ATM in the airport and the money he was stressing over was sitting two feet from him in my pocket.

I reached into my pocket and fingered the bills, thinking of the words to use as I handed them to him. But then my left brain kicked in.

“Doesn’t this story sound too contrived.” “Isn’t this exactly what he would say to get our money.” “By his accent, English is not his native language, but he is speaking english.” “This train is empty, but he sat right next to me with this story.” “I should give this money to a real charity who can better discern the need.” “I don’t want to insult him.”

These thoughts rushed through my head as I felt what I would describe the Holy Spirit tug at my heart to give him the dollars. I thought of the joy that this could bring his day. I prayed to God to make things more clear to me, and was convicted that He had already done that. But then I thought about being used, about the risk of being played. Hadn’t I been working 12 hour days for the last month to take care of my family? I could use this money to buy a great gift for my kids. Or get closer to my church tithe . . .

As I carried on this internal dialogue, I arrived at my stop and quickly fled to the certainty of the doors which opened next to me. In near tears, I thought of how much I love being a recipient of grace, but how hard it is to activate my own ability to practice grace. I tried to catch a sight of him as the train drove on, but was denied the opportunity. I didn’t deserve it.

I walked across the street back into my familiar channel, bathed in sunshine and surrounded by mountains as I walked past the amazingly well groomed grounds of the Mormon temple and Salt Lake’s best shopping and restaurants. As I walked past Nordstrom, I watched an amazing fountain show as well-off kids danced in front of the dancing water. I thought of the fountain shows I had seen the night before at the Aria and the Bellagio. I thought of the discussions I had with my fellow engineers about how to create laminar flow, keep the pumps running and what computer models would be best to simulate the fountains; all stuffed from the Holstein’s burgers and shakes that were just settling in our bellies. I was hit with the pang of remorse a loving father feels when he is 1000s of miles from his wife and kids — who is constantly away because I want to succeed for them, for you, but mostly for me.

As I sat by an artificial creek that ran through the outdoor shopping mall to sketch a bronze pair of statues, I couldn’t shake the interconnectedness of three discussions I had lately that explored the interplay of motivation, focus, and grace.

The first was a Facebook “discussion” (mostly me ranting) regarding the endorsement a friend of mine gave to a disillusioned evangelical who was decrying the evil of those who threatened to withdraw their support from World Vision’s reversal on its employment/ethics policy regarding those in active homosexual relationships. I found the article to be an unfair screed which characterized evangelicals such as myself with being out of touch with science, culture and “on the wrong side of history”. My friend was particularly sympathetic to the article’s claim that conservative Christians were putting politics over children’s lives and made the claim that a dollar withheld of WorldVision was directly (and willfully) depriving a child of food. To me, who has never provided support to World Vision, this complaint definitely hit close to home.

The bigger issue that I couldn’t get out of my mind was the idea that there is constant death around us. Constant suffering, like that of my fellow traveler mentioned earlier. Though I put forward a passionate defense of my fellow evangelicals, I was convicted that are actions are never really defensible. I’m well aware that if we really felt, and knew, the true nature of need in the world, I would cry out like Oskar Schindler:

If I’d made more money… I threw away so much money. You have no idea. If I’d just…This car. Goeth would have bought this car. Why did I keep the car? Ten people right there. Ten people. Ten more people. This pin. Two people. This is gold. Two more people. He would have given me two for it, at least one. One more person.

Every day I make so many selfish decisions. I put my heart in my job, in my abilities and my pleasures. How defendable are any of us before a standard such as this? I remember the time in college when I was seized by the gravity of my selfishness and offered all my possessions to the fellow college students in my house. It was passionate, selfless and valiant — until someone took my chair. Optimizing one’s life is hard and we show our true colors when our values conflict.

This point was driven home as I read about Jim Kim’s efforts at the World Bank to punish african nations (and therefore their populace) who are not supportive of active homosexual lifestyles. Just like my friend, I found myself indignant that someone would withdraw aid where needed, just like cities in the US that withdrew support for Catholic charities to the homeless and children in need of adoption because of dissonance between their doctrinal stance on abortion and progressive politics.

The Economist states the importance of focus well:

The uncomfortable truth is that an economic institution like the bank has to pick its battles. There is a limit to how many conditions outsiders can attach to their aid. Its aim is to encourage economic development. Most of the evidence is that the bank is most effective when client countries see it as an economic partner, rather than a boss imposing a Western agenda.

It seems we are all trying to optimize the world in our own image per our own objectives. Which calls into question my most prized possessions: my motivation and drive. I see my life priorities summarized as (1) Worship, (2) Love and (3) Achieve. As a Christian, I believe I was created to bring God glory, to worship Him. To worship Him is to serve Him, and to serve him is to love others with the love we desire for ourselves: both our family and others. To love others is to love my country and my world, who I want to make a more secure and better place. Hence my desire to achieve — to make a difference.

This third priority was called into question by another discussion when a coworker told me that he worked to support his family. Period. He didn’t work for national security. He didn’t work to find fulfillment. He didn’t work to prove to the world that he was somebody and that his life has value. While I know this friend to do excellent work, he made it clear where his vocational heart was.

To me, this is an irreconcilable position. I take great pride in my long hours. I want to teach my children the value of hard work. I want to teach them to make a difference and love the feeling of getting something done. I want to be a net giver professionally — to be a contributor, not organizational dead weight. Yes, I want to support my family, but in line with Jim Collins’ Good to Great, that is only of the three necessary conditions for meaningful work. I also love what I do and believe that I have the desire, motivation and capability to be the best in the world in my field. Isn’t that how everyone should approach their job? Aren’t those good things to want and doesn’t wanting them make me a better citizen, father and man?

What concerns me is the false dichotomy that I know we can all fall prey to. These days, I’m well aware that the good is the enemy of the better and there are so many seemingly good choices which are inconsistent with my goals. I’m convinced that maturing professionally is making the hard choices and deciding not to do many good things. It is all about focus and focus is all about priorities.

I hope to figure all this out, but I’m not there yet. What I do know is that I’m commanded to love, be humble and have an open heart that is ready to serve — despite my own desire to always get in the way. As for me, I’m thankful that the Christian conception is of a prodigal, not efficient Father. After all, isn’t His message of grace the most inefficient message in history? In any case, it certainly didn’t lack focus.

By One Comment