<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Algorithms on traviscj/blog</title>
    <link>https://traviscj.com/blog/tags/algorithms/</link>
    <description>Recent content in Algorithms on traviscj/blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 09 Jan 2018 08:00:00 +0000</lastBuildDate>
    <atom:link href="https://traviscj.com/blog/tags/algorithms/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>profitably wrong</title>
      <link>https://traviscj.com/blog/post/2018-01-09-profitably_wrong/</link>
      <pubDate>Tue, 09 Jan 2018 08:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2018-01-09-profitably_wrong/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve come to realize that my career so far has been built on being &amp;ldquo;profitably wrong.&amp;rdquo;&#xA;I think this is interesting because the usual approaches are being &amp;ldquo;profitably fast&amp;rdquo; (optimizing)&#xA;or &amp;ldquo;profitably better&amp;rdquo; (improving),&#xA;and most people think of any kind of wrongness as being a terrible thing.&#xA;But sometimes the best way to optimize or improve is &lt;em&gt;approximating&lt;/em&gt;!&lt;/p&gt;&#xA;&lt;p&gt;The definitions of &amp;ldquo;profitably&amp;rdquo; has changed as I&amp;rsquo;ve worked on different things, as has the specific type of &amp;ldquo;wrongness&amp;rdquo;.&#xA;A couple specific ways accepting &amp;ldquo;wrongness&amp;rdquo; have been profitable for me include:&lt;/p&gt;</description>
    </item>
    <item>
      <title>snack buying</title>
      <link>https://traviscj.com/blog/post/2017-11-13-snack-buying/</link>
      <pubDate>Mon, 13 Nov 2017 07:01:25 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2017-11-13-snack-buying/</guid>
      <description>&lt;p&gt;I got this text message from my father-in-law:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Ok. Soda 1.50&#xA;Chocolate bar 1.00&#xA;Gum 0.10&#xA;Jelly Bean .05&lt;/p&gt;&#xA;&lt;p&gt;Have to buy exactly 14 items and spend $10&lt;/p&gt;&#xA;&lt;p&gt;At least one of each.&lt;/p&gt;&#xA;&lt;p&gt;There are 4 diff combos. (Order: soda, chocolate, gum and jelly bean)&lt;/p&gt;&#xA;&lt;p&gt;Got 5-2-3-4&#xA;3-5-4-2&lt;/p&gt;&#xA;&lt;p&gt;Can’t get others. Any ideas?  :)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I whipped up this solution to check in python:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#!/usr/bin/python3&#xA;# created_at: 2017-11-13 13:53:19 -0800&#xA;&#xA;def main():&#xA;    solutions = 0&#xA;    for si in range(1,7):&#xA;        for ci in range(1,11):&#xA;            for gi in range(1,101):&#xA;                for ji in range(1,201):&#xA;                    total = si*150 + ci*100 + gi*10 + ji*5&#xA;                    items = si + ci + gi + ji&#xA;                    if total == 1000 and items == 14:&#xA;                        print(si,ci,gi,ji, total, items)&#xA;                        solutions += 1&#xA;    print(solutions)&#xA;&#xA;if __name__ == &amp;quot;__main__&amp;quot;:&#xA;    main()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The core of this solution is the check&lt;/p&gt;</description>
    </item>
    <item>
      <title>black box machine learning</title>
      <link>https://traviscj.com/blog/post/2014-07-15-black_box_machine_learning/</link>
      <pubDate>Tue, 15 Jul 2014 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2014-07-15-black_box_machine_learning/</guid>
      <description>&lt;p&gt;During my Ph.D. I studied optimization algorithms.&#xA;Optimization algorithms are typically an integral part of machine learning algorithms, and we discussed many machine&#xA;learning algorithms, but somehow I made it through without doing very much actual machine learning training or&#xA;prediction tasks.&lt;/p&gt;&#xA;&lt;p&gt;It turns out that it isn&amp;rsquo;t very hard to do some very basic machine learning:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;pip install -U numpy scipy scikit-learn&#xA;ipython&#xA;from sklearn.ensemble import RandomForestClassifier&#xA;from sklearn import datasets&#xA;iris_data = datasets.load_iris()&#xA;rfc = RandomForestClassifier()&#xA;rfc.fit(iris_data[&#39;data&#39;], iris_data[&#39;target&#39;])&#xA;rfc.predict([6.1,2.6,5.6,1.4])    # yields array([2])&#xA;rfc.predict([5.7,4.4,1.5,0.4])    # yields array([0])&#xA;&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    <item>
      <title>a really simple iterative refinement example</title>
      <link>https://traviscj.com/blog/post/2013-10-17-a_really_simple_iterative_refinement_example/</link>
      <pubDate>Thu, 17 Oct 2013 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2013-10-17-a_really_simple_iterative_refinement_example/</guid>
      <description>&lt;p&gt;I wanted to have a quick example of what iterative refinement is and looks like.&lt;/p&gt;&#xA;&lt;p&gt;Suppose you wanted to solve the (very simple!) problem of solving 5.1x=16, without dividing by decimal numbers. (Yes, this is a bit contrived–I&amp;rsquo;m not sure why you would be able to divide by an integer to get a decimal, but not divide by a decimal to get a decimal. Bear with me.)&lt;/p&gt;&#xA;&lt;p&gt;The standard way would be, of course, to simply evaluate x = (5.1)^{-1}16=3.137254. But this is not available–you can&amp;rsquo;t find an inverse of multiplying by 5.1!&lt;/p&gt;</description>
    </item>
    <item>
      <title>implementation of set operations</title>
      <link>https://traviscj.com/blog/post/2013-03-13-implementation_of_set_operations/</link>
      <pubDate>Wed, 13 Mar 2013 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2013-03-13-implementation_of_set_operations/</guid>
      <description>&lt;p&gt;We got in a bit of a debate yesterday in the office over the implementation of associative containers, which I thought was pretty fun.&#xA;We made up the big chart of complexity results you see below.&lt;/p&gt;&#xA;&lt;h2 id=&#34;nomenclature&#34;&gt;nomenclature:&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$S$, $S_1$, and $S_2$ are subsets of $\Omega$.&lt;/li&gt;&#xA;&lt;li&gt;Denote an element by $e\in\Omega$.&lt;/li&gt;&#xA;&lt;li&gt;$n$,$n_1$,$n_2$,$N$ are the sizes of the set $S$, $S_1$, $S_2$, and $\Omega$, respectively, and $n_1 \geq n_2$.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;complexity&#34;&gt;Complexity&lt;/h2&gt;&#xA;&lt;table&gt;&#xA;  &lt;thead&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;th&gt;Operation\Approach&lt;/th&gt;&#xA;          &lt;th&gt;Hash Table&lt;/th&gt;&#xA;          &lt;th&gt;Hash Tree&lt;/th&gt;&#xA;          &lt;th&gt;Binary List&lt;/th&gt;&#xA;          &lt;th&gt;Entry List (sorted)&lt;/th&gt;&#xA;          &lt;th&gt;Entry List (unsorted)&lt;/th&gt;&#xA;          &lt;th&gt;&lt;/th&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/thead&gt;&#xA;  &lt;tbody&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;$e \in S&#x9;&#x9;  $&lt;/td&gt;&#xA;          &lt;td&gt;$O(1)   &#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(log(n))&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(1)&#x9;&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(log(n))&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n)&#x9;&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;$S_1 \cup S_2    $&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1+n_2)&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1+n_2)&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(N)&#x9;&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1+n_2)&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1n_2)&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;$S_1 \cap S_2    $&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1)&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(log(n_1)n_2)$&lt;/td&gt;&#xA;          &lt;td&gt;$O(N)&#x9;&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_2)&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n_1n_2)&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;space complexity&lt;/td&gt;&#xA;          &lt;td&gt;$O(n)&#x9;&#x9;&#x9;$&lt;/td&gt;&#xA;          &lt;td&gt;$O(n)          $&lt;/td&gt;&#xA;          &lt;td&gt;$O(N)$ bits.&lt;/td&gt;&#xA;          &lt;td&gt;$O(n)          $&lt;/td&gt;&#xA;          &lt;td&gt;$O(n)          $&lt;/td&gt;&#xA;          &lt;td&gt;&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;As I said&amp;ndash;this was just what came out of my memory of an informal discussion, so I make no guarantees that any of it is correct.&#xA;Let me know if you spot something wrong!&#xA;We used the examples  $S_1 = {1,2,3,4,5}$ and $S_2 = {500000}$ to think through some things.&lt;/p&gt;</description>
    </item>
    <item>
      <title>some tips for project euler problems</title>
      <link>https://traviscj.com/blog/post/2013-01-26-some_tips_for_project_euler_problems/</link>
      <pubDate>Sat, 26 Jan 2013 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2013-01-26-some_tips_for_project_euler_problems/</guid>
      <description>&lt;p&gt;I wanted to make a list of a few tips on solving &lt;a href=&#34;http://projecteuler.net&#34;&gt;Project Euler&lt;/a&gt; problems that have been helpful for me while I solve them.&#xA;These are general principles, even though I do most of my Project Euler coding in Python.&lt;/p&gt;&#xA;&lt;p&gt;Without further ado:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If the problem is asking for something concerning the number of digits, typically this indicates that the use of the $\log n$ function is warranted.&lt;/li&gt;&#xA;&lt;li&gt;If the problem is asking for the last few digits, modulo arithmetic might speed it up considerably.&lt;/li&gt;&#xA;&lt;li&gt;Some might consider this cheating, but looking up some small numbers in the &lt;a href=&#34;http://oeis.org/&#34;&gt;Online Encyclopedia of Integer Sequences&lt;/a&gt; is occasionally pretty helpful.&lt;/li&gt;&#xA;&lt;li&gt;Many problems boil down to: Find numbers with property $X$ and property $Y$. Two solutions are:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Brute force: Try all numbers with tests of property $X$ and $Y$.&lt;/li&gt;&#xA;&lt;li&gt;Find numbers with property $X$ and filter by a test of property $Y$.&lt;/li&gt;&#xA;&lt;li&gt;Find numbers with property $Y$ and filter by a test of property $X$.&lt;/li&gt;&#xA;&lt;li&gt;Find the set of numbers with property $X$ and the set of numbers with property $Y$. Compute their intersection.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve found that it&amp;rsquo;s sometimes hard to predict which one will end up being the fastest.&#xA;It depends on the relative speed of the tests and the generators, and the frequency of finding numbers which have that property.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Game of Life</title>
      <link>https://traviscj.com/blog/post/2012-11-20-game_of_life/</link>
      <pubDate>Tue, 20 Nov 2012 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2012-11-20-game_of_life/</guid>
      <description>&lt;p&gt;When I was a sophomore in high school, I was fascinated with&#xA;[ Conway&amp;rsquo;s Game of Life].&#xA;I still am. I did a pretty rudamentary study of the kinds of patterns that could&#xA;form from the simple rules of the game.&lt;/p&gt;&#xA;&lt;p&gt;One thing that wasn&amp;rsquo;t available when I was a sophomore was Youtube.&#xA;Two of my favorite Game of Life videos:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://www.youtube.com/watch?v=xP5-iIeKXE8&#34;&gt;lifeception&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://www.youtube.com/watch?v=C2vgICfQawE&#34;&gt;epic life&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Another direction that Game of Life has gone recently is something that I really should have thought of, honestly.&#xA;Many times I&amp;rsquo;ve thought that there&amp;rsquo;s at least some superficial relationship between Game of Life and diffusion equations.&#xA;Turns out that S. Rafler has extended Game of Life to continuous domains through what he calls &lt;a href=&#34;http://arxiv.org/abs/1111.1567&#34;&gt;SmoothLife&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>a trig problem solved in MATLAB</title>
      <link>https://traviscj.com/blog/post/2012-02-01-a_trig_problem_solved_in_matlab/</link>
      <pubDate>Wed, 01 Feb 2012 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2012-02-01-a_trig_problem_solved_in_matlab/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;http://i.imgur.com/yOswe.jpg&#34; alt=&#34;diagram&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;I came across &lt;a href=&#34;http://www.reddit.com/r/matlab/comments/p4b4s/nothing_feels_as_good_as_getting_a_somewhat/&#34;&gt;this&lt;/a&gt; post. The basic idea is the guy wants to maximize $L_1+L_2$&#xA;constrained to this box, where $L_i$ is the length of beam $i$. It&amp;rsquo;s constrained&#xA;to be a 61 cmx61 cm box, but one beam must start from 10cm up from the bottom&#xA;right corner and the beams must meet at a point along the top of the box.&#xA;I added the further assumption that the other beam must end in the bottom left&#xA;corner.&lt;/p&gt;</description>
    </item>
    <item>
      <title>spamfunc for optimization in matlab</title>
      <link>https://traviscj.com/blog/post/2012-01-30-spamfunc_for_optimization_in_matlab/</link>
      <pubDate>Mon, 30 Jan 2012 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2012-01-30-spamfunc_for_optimization_in_matlab/</guid>
      <description>&lt;h1 id=&#34;what-spamfunc-is&#34;&gt;what spamfunc is&lt;/h1&gt;&#xA;&lt;p&gt;In developing optimization algorithms, one of the most tedious parts is trying different examples, each of which might have its own starting points or upper or lower bounds or other information.&#xA;The tedium really starts when your algorithm requires first or second order information, which might be tricky to calculate correctly.&#xA;These bugs can be pernicious, because it might be difficult to differentiate between a bug in your algorithm and a bug in your objective or constraint evaluation.&#xA;Handily, Northwestern Professor &lt;a href=&#34;http://users.iems.northwestern.edu/~4er/&#34;&gt;Robert Fourer&lt;/a&gt; wrote a language called &lt;a href=&#34;http://www.ampl.com/&#34;&gt;AMPL&lt;/a&gt;, which takes a programming-language specification of objective and constraints and calculates derivatives as needed.&#xA;The official amplfunc/spamfunc reference is contained in &lt;a href=&#34;http://ampl.com/REFS/HOOKING/#UsewithMATLAB&#34;&gt;Hooking Your Solver to AMPL&lt;/a&gt;, but I&amp;rsquo;m shooting for a more low-key introduction.&lt;/p&gt;</description>
    </item>
    <item>
      <title>What could you possibly do with mathematics?</title>
      <link>https://traviscj.com/blog/post/2009-08-24-what_could_you_possibly_do_with_mathematics/</link>
      <pubDate>Mon, 24 Aug 2009 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2009-08-24-what_could_you_possibly_do_with_mathematics/</guid>
      <description>&lt;p&gt;Recently, at a family gathering, I was confronted by the question many a college graduate is faced after telling someone I had majored in mathematics for my now-finished college degree: &amp;ldquo;But how are you going to make any money at that?&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;Now, certainly it&amp;rsquo;s true: Graduate students don&amp;rsquo;t make that much. The average stipend for a grad student is roughly on par with (but still less than) unemployment checks. But that&amp;rsquo;s okay&amp;ndash;in general, mathematicians know that they could make money other places, but they chose it anyways because of their love for the subject. Not that mathematicians make &lt;!-- raw HTML omitted --&gt;too&lt;!-- raw HTML omitted --&gt; bad of money anyway: The average in the US is about 50K, with associate professors making more than that. The particularly salary-inclined could pick up other credentials to become actuaries or work in hedge funds.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Dijkstra&#39;s Algorithm Paper</title>
      <link>https://traviscj.com/blog/post/2008-07-30-dijkstras_algorithm_paper/</link>
      <pubDate>Wed, 30 Jul 2008 00:00:00 +0000</pubDate>
      <guid>https://traviscj.com/blog/post/2008-07-30-dijkstras_algorithm_paper/</guid>
      <description>&lt;p&gt;The week before my sister’s wedding, I was tasked with writing a paper on Dijkstra’s Algorithm for my Discrete Mathematical Modeling class. I think I might have missed the mark a little bit, but I had so much fun writing it that I’m posting it here.&lt;/p&gt;&#xA;&lt;p&gt;I’m almost considering writing some more stuff in this style… anything anyone would like to see written about?&lt;/p&gt;&#xA;&lt;p&gt;Here’s a link: Dijkstra’s Algorithm&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
