{"id":244,"date":"2014-04-26T00:05:48","date_gmt":"2014-04-26T06:05:48","guid":{"rendered":"http:\/\/inductivebias.com\/Blog\/?p=244"},"modified":"2014-05-20T22:08:58","modified_gmt":"2014-05-21T04:08:58","slug":"project-auto-soylent","status":"publish","type":"post","link":"http:\/\/inductivebias.com\/Blog\/project-auto-soylent\/","title":{"rendered":"Project: Auto-Soylent"},"content":{"rendered":"<div style=\"word-wrap: normal; -webkit-hyphens: none; -moz-hyphens: none; hyphens: none;\"><span style=\"font-size: small;\"><strong><a href=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/pitchericonthumb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-263\" src=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/pitchericonthumb.png\" alt=\"A creamy food flavored beverage.\" width=\"150\" height=\"150\" \/><\/a> I&#8217;m taking a break from the usual lessons to discuss a side project of mine: Auto-Soylent.\u00a0 The idea of Soylent is to create a single shake that contains all nutrients a person needs.\u00a0\u00a0 Auto-Soylent is an application that works with diy.soylent.me to generate recipes automatically from any given ingredients.\u00a0 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.<br \/>\n<\/strong><\/span><!--more-->For those who don&#8217;t know <a href=\"http:\/\/soylent.me\">Soylent<\/a> is a meal replacement shake. Actually that&#8217;s a bit of an under-sell. It&#8217;s a shake that (supposedly) contains everything you need to be healthy consuming nothing but <a href=\"http:\/\/soylent.me\">Soylent<\/a> and water,\u00a0which its creator <a href=\"http:\/\/robrhinehart.com\/\">Rob Rhinehart<\/a> actually did for several months leading up to the crowd funding campaign. It&#8217;s a reductionist silicon valley start-up approach to food, and as of this writing shipments of the official product are just beginning\u00a0 to go out.<\/p>\n<p>I&#8217;m not here to talk about the official product though.<span class=\"text_exposed_show\"> What I&#8217;m here to talk about is the <a href=\"http:\/\/discourse.soylent.me\/category\/diy-soylent\">do it yourself community<\/a> that has sprung up around the idea, and the Auto-Soylent app which is my contribution. In particular there is a <a href=\"http:\/\/diy.soylent.me\">DIY Soylent website<\/a> which is designed to help DIYers build, share, and critique meal replacement recipes.\u00a0 I spoke briefly with its creator <a href=\"https:\/\/github.com\/nick?tab=repositories\">Nick Poulden<\/a> on the Soylent forums, and he created <a href=\"https:\/\/github.com\/nick\/auto-soylent\">a code skeleton<\/a> making it easy for others to attempt to build automatic recipe generators. As far as I know I&#8217;m the only one who has done so with much success.<\/span><\/p>\n<p>The skeleton was named auto-soylent, and since what I wrote was a relatively simple solver I didn&#8217;t feel the need to do any rebranding. I believe the basic version of my code has been merged into the skeleton itself, but <a href=\"https:\/\/github.com\/Alrecenk\/auto-soylent\">my latest version can be found here<\/a>.\u00a0 It&#8217; a node.js app so you&#8217;ll need that but nothing else to run it.\u00a0 All of the variables (like the base recipe and target nutrition profile) are at the top of the file and labeled. It shouldn&#8217;t be too hard to figure out but feel free to contact me if you need help with it.<\/p>\n<h2 style=\"word-wrap: normal; -webkit-hyphens: none; -moz-hyphens: none; hyphens: none;\"><span style=\"color: #000080;\">The Software<\/span><\/h2>\n<p>The problem of optimizing a Soylent recipe at its simplest is a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Linear_programming\">linear programming <\/a>problem. You have minimum and maximum values for each nutrient, there&#8217;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&#8217;t do it that way at all.<\/p>\n<p>It can be rather tricky to get a perfect 100% in every nutrient, and there are other practical concerns like recipe complexity.\u00a0 At the same time if it is possible to get those 100%&#8217;s , particularly in the macro nutrients like protein, fat, and carbohydrates, you&#8217;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&#8217;s <a href=\"http:\/\/en.wikipedia.org\/wiki\/Convex_optimization\">convex<\/a> 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 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Proximal_gradient_methods_for_learning#Lasso_regularization\">lasso regularization<\/a> which induces sparseness in the solution. Sparseness means if you put a long list of potential ingredients into the optimization most of them won&#8217;t be used, and you&#8217;ll get a simpler, easier to make recipe.<\/p>\n<p>For the optimization I just used <a href=\"http:\/\/en.wikipedia.org\/wiki\/Gradient_descent\">gradient descent<\/a> with a rather simple (and kind of hacky)\u00a0 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Successive_parabolic_interpolation\">parabolic interpolation<\/a> line search. If I were doing this professionally I&#8217;d probably use L-BFGS with a line-search that provably guarantees convergence, but I&#8217;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&#8217;t really seem to be significant problems. It usually completes within a couple of seconds.<\/p>\n<h2 style=\"word-wrap: normal; -webkit-hyphens: none; -moz-hyphens: none; hyphens: none;\"><span style=\"color: #000080;\">The Recipe<\/span><\/h2>\n<p>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.\u00a0 So I took all of the ingredients from the 5 most favorited recipes on the DIY site, and crunched out <a href=\"http:\/\/diy.soylent.me\/recipes\/autosoylent-top-five-remix-simplified\">a recipe that was supposedly close to one dollar per day<\/a>.\u00a0 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\u00a0 in one place.\u00a0 Shipping costs were rarely taken into account in the listed prices.<\/p>\n<p>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 href=\"http:\/\/diy.soylent.me\/recipes\/autosoylent-amazononly\">a recipe where all of the ingredients could be ordered from Amazon<\/a>. Not only that, but the prices I used would include the cost of shipping if the item wasn&#8217;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.<\/p>\n<p><a href=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/AutoSoylentAmazonOnlyRecipe.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-267\" src=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/AutoSoylentAmazonOnlyRecipe.png\" alt=\"AutoSoylentAmazonOnlyRecipe\" width=\"1192\" height=\"1163\" srcset=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/AutoSoylentAmazonOnlyRecipe.png 1192w, http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/AutoSoylentAmazonOnlyRecipe-300x292.png 300w, http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/AutoSoylentAmazonOnlyRecipe-1024x999.png 1024w\" sizes=\"auto, (max-width: 1192px) 100vw, 1192px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u00a0<span style=\"color: #000080;\">The Mix<\/span><\/h2>\n<p>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&#8217;t buy things in as much bulk as the recipe suggests, so I ended up paying more per gram for a few things.<\/p>\n<p><a href=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0004thumb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-269 size-full\" src=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0004thumb.png\" alt=\"Ingredients for initial batch.\" width=\"700\" height=\"525\" srcset=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0004thumb.png 700w, http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0004thumb-300x225.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p><a href=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0024thumb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-270 size-full\" src=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0024thumb.png\" alt=\"My Soylent mixing battle station.\" width=\"700\" height=\"525\" srcset=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0024thumb.png 700w, http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0024thumb-300x225.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>Initially I only made 2 days worth as I wasn&#8217;t sure if it&#8217;d be remotely palatable. I tried to get someone to record my spiel and first sample of the concoction, but alas it&#8217;s so hard to find good free help on a Monday afternoon these days. Here&#8217;s what I did get of my initial reaction:<\/p>\n<p><iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/aWIMnKtDOYA\" width=\"700\" height=\"525\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>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.\u00a0 I gave up eating it plain almost immediately in favor of adding various kinds of chocolate.\u00a0 It throws off the perfectly balanced nutrients a bit with extra sugar, but hey, it&#8217;s a nutritionally complete chocolate shake, so that&#8217;s pretty cool.<\/p>\n<p><a href=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0030thumb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-271\" src=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0030thumb.png\" alt=\"DSCI0030thumb\" width=\"700\" height=\"525\" srcset=\"http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0030thumb.png 700w, http:\/\/inductivebias.com\/Blog\/wp-content\/uploads\/2014\/04\/DSCI0030thumb-300x225.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000080;\">The Results<\/span><\/h2>\n<p>As of this writing I&#8217;ve consumed about 6 days worth. I&#8217;ve been getting somewhere between 50 and 75 percent of my daily calories from the soylent.\u00a0 I haven&#8217;t had any grand revelations, but I have noticed a few things. For one, it&#8217;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.\u00a0 It&#8217;s not really much food by volume, but once my stomach started digesting my body could tell I&#8217;d eaten a lot.\u00a0 I&#8217;d also note that while it does suppress my hunger it doesn&#8217;t suppress appetite.\u00a0 I still found myself craving pizza and meat even though I wasn&#8217;t hungry. It makes for a very simple diet, but that doesn&#8217;t necessarily mean it will be an easy one for someone trying to lose weight.<\/p>\n<p>I do think I have more energy while drinking soylent, but it&#8217;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&#8217;ve been drinking soylent for most of my meals for several days, and I haven&#8217;t gotten sick or suffered any significant problems. I did have one minor issue. Suffice to say I&#8217;m not used to consuming 100% of my daily value of fiber, but that went away after the first day.<\/p>\n<p>I&#8217;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&#8217;t say anything about the long term effects, but in the short term it&#8217;s been pleasant. I have high hopes for the official Soylent. I&#8217;m not convinced it&#8217;ll change the world, but I do think it&#8217;ll change my breakfast.<\/p>\n<p>&nbsp;<\/p>\n<p>P.S. I&#8217;m now operating as an independent consultant and accepting contracts under Inductive Bias LLC. I&#8217;m trained as a software engineer and an expert in optimization and artificial intelligence. I don&#8217;t so much write software as solve problems that need to be solved\u00a0 with science.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m taking a break from the usual lessons to discuss a side project of mine: Auto-Soylent.\u00a0 The idea of Soylent is to create a single shake that contains all nutrients a person needs.\u00a0\u00a0 Auto-Soylent is an application that works with diy.soylent.me to generate recipes automatically from any given ingredients.\u00a0 Once the math was done, I &hellip; <a href=\"http:\/\/inductivebias.com\/Blog\/project-auto-soylent\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Project: Auto-Soylent<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-project"],"_links":{"self":[{"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":18,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":349,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/posts\/244\/revisions\/349"}],"wp:attachment":[{"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/inductivebias.com\/Blog\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}