{"id":4803,"date":"2017-11-03T17:26:52","date_gmt":"2017-11-03T21:26:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=4803"},"modified":"2017-11-03T17:26:52","modified_gmt":"2017-11-03T21:26:52","slug":"generating-insight-with-cody-function-clouds","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2017\/11\/03\/generating-insight-with-cody-function-clouds\/","title":{"rendered":"Generating Insight With Cody Function Clouds"},"content":{"rendered":"<p>One of the things I like about Cody is that it not only encourages you to solve a particular problem, but it encourages you to solve it\u00a0<em>many different ways<\/em>. Even better, after you&#8217;ve done your best, you can look at how other people solve the same problem. This is often the most enlightening part of the Cody process. I am always surprised and often delighted\u00a0when I look at other people&#8217;s solutions. As I do so, you&#8217;re likely to hear me mumbling things like &#8220;I didn&#8217;t know you could do that&#8221; or &#8220;That never would have occurred to me&#8221; or even &#8220;I&#8217;ve never heard of that function before!&#8221;<\/p>\n<p>Let me give you an example of learning from Cody. Specifically from\u00a0<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/661\">Problem 661: Spot the outlier.<\/a>\u00a0Which of these points is not located on a single line?<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"290\" class=\"alignnone size-full wp-image-4811\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier00.png\" alt=\"\" \/><\/p>\n<p>If I show you the points as numbers, it&#8217;s a little tricky to work it out. But once you see it on a plot, it&#8217;s quite easy. Easy for you, but how would you teach MATLAB to solve this problem?<\/p>\n<p>Let&#8217;s look at how people solved this one. First of all here is the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/661-spot-the-outlier\/solutions\/map\">Solution Map<\/a> for all the solutions so far.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"630\" height=\"353\" class=\"alignnone size-full wp-image-4805\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier01.png\" alt=\"\" \/><\/p>\n<p>We can see that the size ranges from 12 to around 200 with a handful of answers even bigger than that. And there are more than twice as many wrong answers as correct answers. But beyond that, there&#8217;s not a lot of insight to be gained here.<\/p>\n<p>Here&#8217;s a histogram of the size of all the correct answers.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"494\" height=\"418\" class=\"alignnone size-full wp-image-4806\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier02.png\" alt=\"\" \/><\/p>\n<p>Now we can see that most of the correct answers come in at around size=70. That shows how many people are solving the problem. But <em>how<\/em> are they solving it? We can\u00a0sift through individual solutions, but it would be nice if there were some way we could get some insight into lots of solutions at once. One way to do this is with a function cloud.\u00a0First we boil\u00a0each solution down until it&#8217;s just list of functions. Then we can build up a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/wordcloud.html\">word cloud<\/a> with these functions. Thus: function cloud. Here&#8217;s a function cloud for all 323 correct solutions received so far.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"570\" height=\"406\" class=\"alignnone size-full wp-image-4808\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier03.png\" alt=\"\" \/><\/p>\n<p>It&#8217;s kind of a mess, but you can get some ideas from what you see there: <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/polyarea.html\">polyarea<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/corrcoef.html\">corrcoef<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/detrend.html\">detrend<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/nchoosek.html\">nchoosek<\/a>. Each one of these is a clue worth puzzling over. But let&#8217;s try another tactic. Let&#8217;s make a function cloud of the smallest correct solutions.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"566\" height=\"425\" class=\"alignnone size-full wp-image-4809\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier04.png\" alt=\"\" \/><\/p>\n<p>Hmmm. Clearly\u00a0<a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/delaunay.html\">delaunay<\/a>\u00a0is the key here. But how? The Delaunay triangulation returns a list of triangles based on the points you give it. By virtue of being the one point that&#8217;s off the line, point 2 shows up in all the triangles returned by delaunay. That means that its index, 2, appears in the matrix tri more than any other number. So the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/mode.html\">mode<\/a> of the numbers in the matrix is our answer: 2.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"394\" class=\"alignnone size-full wp-image-4813\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier05.png\" alt=\"\" \/><\/p>\n<p>It never would have occurred to me to do it that way, but I&#8217;m sure glad Cody reminded of this useful function.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/outlier00.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>One of the things I like about Cody is that it not only encourages you to solve a particular problem, but it encourages you to solve it\u00a0many different ways. Even better, after you&#8217;ve done your&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2017\/11\/03\/generating-insight-with-cody-function-clouds\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[250],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4803"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=4803"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4803\/revisions"}],"predecessor-version":[{"id":4817,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4803\/revisions\/4817"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=4803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=4803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=4803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}