Project: Auto-Soylent

A creamy food flavored beverage. I’m taking a break from the usual lessons to discuss a side project of mine: Auto-Soylent.  The idea of Soylent is to create a single shake that contains all nutrients a person needs.   Auto-Soylent is an application that works with diy.soylent.me to generate recipes automatically from any given ingredients.  Once the math was done, I decided to put my mouth where my money is and mix up a few batches of the computer generated recipe.
For those who don’t know Soylent is a meal replacement shake. Actually that’s a bit of an under-sell. It’s a shake that (supposedly) contains everything you need to be healthy consuming nothing but Soylent and water, which its creator Rob Rhinehart actually did for several months leading up to the crowd funding campaign. It’s a reductionist silicon valley start-up approach to food, and as of this writing shipments of the official product are just beginning  to go out.

I’m not here to talk about the official product though. What I’m here to talk about is the do it yourself community that has sprung up around the idea, and the Auto-Soylent app which is my contribution. In particular there is a DIY Soylent website which is designed to help DIYers build, share, and critique meal replacement recipes.  I spoke briefly with its creator Nick Poulden on the Soylent forums, and he created a code skeleton making it easy for others to attempt to build automatic recipe generators. As far as I know I’m the only one who has done so with much success.

The skeleton was named auto-soylent, and since what I wrote was a relatively simple solver I didn’t feel the need to do any rebranding. I believe the basic version of my code has been merged into the skeleton itself, but my latest version can be found here.  It’ a node.js app so you’ll need that but nothing else to run it.  All of the variables (like the base recipe and target nutrition profile) are at the top of the file and labeled. It shouldn’t be too hard to figure out but feel free to contact me if you need help with it.

The Software

The problem of optimizing a Soylent recipe at its simplest is a linear programming problem. You have minimum and maximum values for each nutrient, there’s a linear relationship between ingredient amounts and nutrients meaning those bounds are linear inequalities you have to satisfy. Within that feasible nutrition region you also want to minimize cost, which is also a linear function on the ingredient amounts. Thus, a linear programming problem. That being said, I didn’t do it that way at all.

It can be rather tricky to get a perfect 100% in every nutrient, and there are other practical concerns like recipe complexity.  At the same time if it is possible to get those 100%’s , particularly in the macro nutrients like protein, fat, and carbohydrates, you’ll want to do so. The approach I took was to use quadratic penalties for every nutrient out of range, and then weight that against cost to get a single fitness function that could be optimized over. Two nice things about this approach are A) it’s convex so a local optimum is a global optimum and B) the combination of a linear cost, non-negative amounts, and quadratic penalties is akin to lasso regularization which induces sparseness in the solution. Sparseness means if you put a long list of potential ingredients into the optimization most of them won’t be used, and you’ll get a simpler, easier to make recipe.

For the optimization I just used gradient descent with a rather simple (and kind of hacky)  parabolic interpolation line search. If I were doing this professionally I’d probably use L-BFGS with a line-search that provably guarantees convergence, but I’m not getting paid so I went with what I could write quickly off the top of my head. The function being optimized is well behaved as I mentioned, so speed and convergence don’t really seem to be significant problems. It usually completes within a couple of seconds.

The Recipe

Ok, so I had this piece of software for optimizing single recipes. I figured, why not try optimizing several recipes together and see if I can combine some of the best ideas into a single better, by which I mean cheaper, recipe.  So I took all of the ingredients from the 5 most favorited recipes on the DIY site, and crunched out a recipe that was supposedly close to one dollar per day.  It seemed like a good idea in theory, but when I began looking at the specifics it became clear that it was impossible to get all of those ingredients at those prices  in one place.  Shipping costs were rarely taken into account in the listed prices.

I decided to add some restrictions to generate a recipe that was actually meaningful. Since many of the ingredients I was able to get were on Amazon, I made a recipe where all of the ingredients could be ordered from Amazon. Not only that, but the prices I used would include the cost of shipping if the item wasn’t eligible for free shipping . This knocked the price up to about 4.50$/day, but you save big on labor. Also, I guess the listed price not being a lie is important.

AutoSoylentAmazonOnlyRecipe

 

 The Mix

I designed a recipe that could be ordered from Amazon. Then I ordered it from Amazon. Well, except for the salt and canola oil. I got those at a local grocery store. I didn’t buy things in as much bulk as the recipe suggests, so I ended up paying more per gram for a few things.

Ingredients for initial batch.

My battle station and tools for Soylent mixing are minimal. A covered table, plates, spoons, bowls, bags. I used a jewelry scale (8$) and a pill-cutter (5$) to measure out the ingredients.

My Soylent mixing battle station.

Initially I only made 2 days worth as I wasn’t sure if it’d be remotely palatable. I tried to get someone to record my spiel and first sample of the concoction, but alas it’s so hard to find good free help on a Monday afternoon these days. Here’s what I did get of my initial reaction:

After I consumed the first two batches over three days, I decided it was pretty good (it tastes rather bland and oaty and the texture is a bit gritty but not terrible) and went ahead and mixed up as much as I could with my remaining stores. I had enough for 13 batches total.  I gave up eating it plain almost immediately in favor of adding various kinds of chocolate.  It throws off the perfectly balanced nutrients a bit with extra sugar, but hey, it’s a nutritionally complete chocolate shake, so that’s pretty cool.

DSCI0030thumb

 

The Results

As of this writing I’ve consumed about 6 days worth. I’ve been getting somewhere between 50 and 75 percent of my daily calories from the soylent.  I haven’t had any grand revelations, but I have noticed a few things. For one, it’s surprisingly filling, but it takes a few minutes to kick in. I felt a bit bloated one day after consuming too much at once.  It’s not really much food by volume, but once my stomach started digesting my body could tell I’d eaten a lot.  I’d also note that while it does suppress my hunger it doesn’t suppress appetite.  I still found myself craving pizza and meat even though I wasn’t hungry. It makes for a very simple diet, but that doesn’t necessarily mean it will be an easy one for someone trying to lose weight.

I do think I have more energy while drinking soylent, but it’s not super pronounced. However, I shared a glass for lunch with one of my friends and he said it made him feel better than he had in a long time. It might be partially psychological, and it probably depends a lot on how good your diet was before. What I can say is that I’ve been drinking soylent for most of my meals for several days, and I haven’t gotten sick or suffered any significant problems. I did have one minor issue. Suffice to say I’m not used to consuming 100% of my daily value of fiber, but that went away after the first day.

I’ve only been eating it for a few days and not at the exclusion of other food. My batches are 2000 calories. My diet is quite obviously more than that. So I really can’t say anything about the long term effects, but in the short term it’s been pleasant. I have high hopes for the official Soylent. I’m not convinced it’ll change the world, but I do think it’ll change my breakfast.

 

P.S. I’m now operating as an independent consultant and accepting contracts under Inductive Bias LLC. I’m trained as a software engineer and an expert in optimization and artificial intelligence. I don’t so much write software as solve problems that need to be solved  with science.

6 thoughts on “Project: Auto-Soylent

  1. Hey, looks great. Solid methods. Have you considered using differing out of range penalties based on whether the item has a top range, including forcing a infinite penalty if it ever breaches top range? (The latter doesn’t seem to be necessary given your results.)

    1. If you put in reasonable ingredients then quadratic penalties for out of range values should be sufficient. I actually had a bit of a problem initially with the recipe always coming out with a serving size which was a few percent too low as it would reduce cost until the quadratic penalty for nutrients overtook the linear penalty for cost. I added in a post processing step that just scales the entire recipe up until the lowest percent is 100%. That of course made some numbers go over the max, but I was able to fix that by penalizing overdoses starting at 75-90% of the max instead of actually at the max. Those two steps together do a pretty good job of guaranteeing you’ll get all your nutrients in range, but it always depends on the ingredients you put in.

      All of the control variables and the various weights for things are at the top of the app.js in the Github repository, so you can see/fiddle with those if you’re interested in the effect they have. https://github.com/Alrecenk/auto-soylent/blob/master/app.js

  2. I was going to attempt to code basically the exact same thing, but you seem to have beat me to the punch…… my plan was to run it against the USDA National Nutrient Database for Standard Reference (SR26) to find a *100% optimal* formula…. have you attempted to do so already?

    1. I haven’t tried running it on anything besides recipes from the DIY site, but I would love to see the results if you do. SR26 doesn’t have prices though, so either you’ll have to get them from somewhere else or use some other criteria (straight up sparsity maybe?). 100% optimal is a pretty fuzzy concept, but with more data we could do better for sure.

      I’m actually rather surprised that nobody beat me to this since the thread that inspired me to write it was 6 months old when I found it http://discourse.soylent.me/t/genetic-algorithms-automatic-diy-soylent/5212

      I get the impression that very few software engineers know anything about mathematical optimization. I’m working on it though. My next article is a tutorial on gradient descent, Newton’s method, and Wolfe conditions as applied to fitting a simple logistic regression model. Should be up in a week or two.

  3. Very nice work. Do you still consume this, today? Any long-term impacts on your overall well-being? I’m considering purchasing this mixture, and would like any advice you have.

Leave a Reply

Your email address will not be published. Required fields are marked *