<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Data Reflexions</title>
    <description>Data Reflexions.</description>
    <link>https://dbunker.io/</link>
    <atom:link href="https://dbunker.io/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Mon, 18 Dec 2017 04:05:51 -0500</pubDate>
    <lastBuildDate>Mon, 18 Dec 2017 04:05:51 -0500</lastBuildDate>
    <generator>Jekyll v3.0.1</generator>
    
      <item>
        <title>Language Learning Data and Dubbing</title>
        <description>&lt;p&gt;&lt;img class=&quot;alignleft&quot; width=&quot;350px&quot; src=&quot;/img/gan-samples.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1710.07035&quot;&gt;Generative adversarial networks&lt;/a&gt; are ideal for producing deceptively convincing invented media when given only a set of training media. GANs do this by utilizing a pair of dueling neural networks, one &lt;script type=&quot;math/tex&quot;&gt;D&lt;/script&gt;, the detective network, being trained to detect counterfeit media generated by the other network &lt;script type=&quot;math/tex&quot;&gt;G&lt;/script&gt;, and the other network &lt;script type=&quot;math/tex&quot;&gt;G&lt;/script&gt;, the counterfeiter network, being trained to trick &lt;script type=&quot;math/tex&quot;&gt;D&lt;/script&gt; into thinking its generated media is from the training set. This process can is essentially a game, like tic-tac-toe, and can be solved similarly using &lt;a href=&quot;https://en.wikipedia.org/wiki/Minimax&quot;&gt;minimax&lt;/a&gt;, optimizing for each player each turn. The example on the left shows &lt;a href=&quot;https://arxiv.org/abs/1511.06434v2&quot;&gt;generated living spaces&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We can apply this same GAN technique to the problem of matching mouth movement to an audio dub, resulting in a more realistic dubbing. This is done by first creating &lt;script type=&quot;math/tex&quot;&gt;G&lt;/script&gt; and &lt;script type=&quot;math/tex&quot;&gt;D&lt;/script&gt; from the genuine video and audio, where all that is generated is the expected face shape given the audio and background. Then feeding the foreign audio dub through the generator to get the new generated video file to match the foreign audio dub.&lt;/p&gt;

&lt;p&gt;Preprocessing techniques such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Spectrogram&quot;&gt;audio spectrograms&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/3D_modeling&quot;&gt;3D facial modeling&lt;/a&gt; can also be applied.&lt;/p&gt;

&lt;p&gt;The diagram below shows the creation of &lt;script type=&quot;math/tex&quot;&gt;G&lt;/script&gt; and &lt;script type=&quot;math/tex&quot;&gt;D&lt;/script&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;500&quot; class=&quot;aligncenter&quot; src=&quot;/img/DiagramGD.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The following diagram shows utilizing &lt;script type=&quot;math/tex&quot;&gt;G&lt;/script&gt;, the original media, and the foreign audio dub to generate the new dubbed media.&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;500&quot; class=&quot;aligncenter&quot; src=&quot;/img/DiagramOutput.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;These processes are further formalized in this  &lt;a href=&quot;/docs/2017_Bunker_Speech2FaceProposal.pdf&quot;&gt;paper&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A large amount of correctly subtitled media is required for this method to be effective. In this arena, &lt;a href=&quot;https://language.fluency.rodeo&quot;&gt;Fluency Rodeo&lt;/a&gt; can greatly help.&lt;/p&gt;
</description>
        <pubDate>Wed, 13 Dec 2017 00:00:00 -0500</pubDate>
        <link>https://dbunker.io/2017/12/13/language-learning-data/</link>
        <guid isPermaLink="true">https://dbunker.io/2017/12/13/language-learning-data/</guid>
        
        
      </item>
    
      <item>
        <title>Fluency Rodeo</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://language.fluency.rodeo&quot; target=&quot;x&quot;&gt;&lt;img class=&quot;alignleft&quot; width=&quot;200px&quot; src=&quot;/img/rodeo.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the biggest problems in speech recognition and natural language processing is a lack of labeled data. As such, most recent techniques such as generative adversarial networks aim to be useful without much labeled data, but even then potential is limited by the lack of labeled data. One such lack is the matching of audio data to text data, i.e. subtitles.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://language.fluency.rodeo&quot;&gt;Fluency Rodeo&lt;/a&gt; is a language learning tool that allows creating subtitles on audio and video media and turning these into flash cards that can be learned from using spaced repetition. The best way to learn a language is through immersion and media is an excellent way to get there. Allowing these data to be volunteered to improve speech recognition and natural language processing techniques could also be a great boon for researchers in these fields.&lt;/p&gt;
</description>
        <pubDate>Tue, 12 Dec 2017 00:00:00 -0500</pubDate>
        <link>https://dbunker.io/2017/12/12/fluency-rodeo/</link>
        <guid isPermaLink="true">https://dbunker.io/2017/12/12/fluency-rodeo/</guid>
        
        
      </item>
    
      <item>
        <title>Spark Word2Vec on Reddit Comments</title>
        <description>&lt;p&gt;&lt;img class=&quot;alignleft&quot; src=&quot;/img/spark.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This post is a continuation of &lt;a href=&quot;/2016/01/04/spark-and-nlp-on-reddit/&quot;&gt;NLP on Reddit&lt;/a&gt; in which &lt;a href=&quot;http://spark.apache.org/&quot;&gt;Spark&lt;/a&gt; is used with &lt;a href=&quot;http://stanfordnlp.github.io/CoreNLP/&quot;&gt;CoreNLP&lt;/a&gt; to gather sentiment on organizations from the &lt;a href=&quot;https://archive.org/details/2015_reddit_comments_corpus&quot;&gt;Reddit comment corpus&lt;/a&gt;. Although traditional natural language processing is a natural way to derive meaning from sentences, when using an algorithm such as &lt;a href=&quot;https://code.google.com/p/word2vec/&quot;&gt;Word2Vec&lt;/a&gt; it is not necessary to provide tagging, parsing or deeper information about English because the algorithm only considers the word contexts.&lt;/p&gt;

&lt;p&gt;As the name sugests, Word2Vec is designed to convert words to a vector of numbers representing that word’s semantic meaning. This is to say, if the vectors of two words have a high &lt;a href=&quot;https://en.wikipedia.org/wiki/Cosine_similarity&quot;&gt;cosine similarity&lt;/a&gt; those two words would be expected to be &lt;a href=&quot;https://en.wikipedia.org/wiki/Semantic_similarity&quot;&gt;semantically similar&lt;/a&gt;. Semantically similar here means that one word has a high probability of being a possible drop in replacement of the other word within the corpus text. For example, in most texts run through Word2Vec, the vector for “boy” would have highest cosine similarity to the vector for “girl” because one could be a replacement for the other.&lt;/p&gt;

&lt;p&gt;Another similar word to both might be “teenager”, whereas “boy” would also have high similarity to “man”, but not to “woman” and “girl” would have high similarity to “woman” but not to “man”. From this it is possible to form a manner of semantic arithmetic. The phrase “man” is to “king” as “woman” is to “queen” can be written as below.&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;V_{queen} - V_{woman} + V_{man} \approx V_{king}&lt;/script&gt;

&lt;p&gt;It is also possible to then cluster words by meaning by clustering their vectors using a method such as &lt;a href=&quot;https://en.wikipedia.org/wiki/K-means_clustering&quot;&gt;K-means&lt;/a&gt;. So given the words, “cat” “dog” “hamster” and “documents”, “documents” would be marked least similar. This method is applied to the movie reviews sentiment analysis &lt;a href=&quot;https://www.kaggle.com/c/sentiment-analysis-on-movie-reviews&quot;&gt;Kaggle dataset&lt;/a&gt; in their &lt;a href=&quot;https://www.kaggle.com/c/word2vec-nlp-tutorial&quot;&gt;Word2Vec NLP tutorial&lt;/a&gt;, which ultimately uses &lt;a href=&quot;https://radimrehurek.com/gensim/&quot;&gt;Gensim&lt;/a&gt; and K-means to cluster words and derive sentiment. This &lt;a href=&quot;http://rare-technologies.com/word2vec-tutorial/&quot;&gt;tutorial&lt;/a&gt; also explores Gensim further and provides some examples.&lt;/p&gt;

&lt;p&gt;Spark offers its own implementation of &lt;a href=&quot;http://spark.apache.org/docs/latest/mllib-feature-extraction.html#word2vec&quot;&gt;Word2Vec&lt;/a&gt; which can be used with the &lt;a href=&quot;http://spark.apache.org/docs/latest/ml-features.html#word2vec&quot;&gt;ML pipeline&lt;/a&gt;, which will be a good match in applying to the &lt;a href=&quot;https://archive.org/details/2015_reddit_comments_corpus&quot;&gt;Reddit comment corpus&lt;/a&gt; for January 2015. The source for this is available on &lt;a href=&quot;https://github.com/dbunker/bluejay#word2vec&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In order to produce these word vectors, Spark uses the Skip-Gram model. The variables &lt;script type=&quot;math/tex&quot;&gt;w_1, w_2, \dots, w_T&lt;/script&gt; represent the words in the corpus used and &lt;script type=&quot;math/tex&quot;&gt;k&lt;/script&gt; is the size of the training window, i.e. the context words to either side of the target word. The negative cost function is written below. The goal is to maximize the average log-probabilities of a word being used in its proper context of words.&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\frac{1}{T} \sum_{t = 1}^{T}\sum_{j=-k}^{j=k} \log p(w_{t+j} | w_t)&lt;/script&gt;

&lt;p&gt;The probability of predicting the word &lt;script type=&quot;math/tex&quot;&gt;w_i&lt;/script&gt; given the word &lt;script type=&quot;math/tex&quot;&gt;w_j&lt;/script&gt; is the &lt;a href=&quot;http://ufldl.stanford.edu/tutorial/supervised/SoftmaxRegression/&quot;&gt;softmax model&lt;/a&gt; as stated below. In this equation &lt;script type=&quot;math/tex&quot;&gt;u_w&lt;/script&gt; is the vector for word &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; and &lt;script type=&quot;math/tex&quot;&gt;v_w&lt;/script&gt; is the vector for the context of word &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt;. &lt;script type=&quot;math/tex&quot;&gt;V&lt;/script&gt; is the total vocabulary size.&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;p(w_i | w_j) = \frac{\exp(u_{w_i}^{\top}v_{w_j})}{\sum_{l=1}^{V} \exp(u_l^{\top}v_{w_j})}&lt;/script&gt;

&lt;p&gt;The diagram below from &lt;a href=&quot;https://www.tensorflow.org/versions/master/tutorials/word2vec/index.html&quot;&gt;Tensorflow&lt;/a&gt; Word2Vec shows how the context words are used to deduce the target word. The context is used to produce softmax classifier results, the highest probable word of the vocabulary is then selected.&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;500&quot; class=&quot;aligncenter&quot; src=&quot;/img/softmax-nplm.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This can be sped up by using hierarchical softmax which avoids calculating the full probabilistic model, instead focussing on the most probable target words, and not including noise words.&lt;/p&gt;

&lt;p&gt;There are a number of parameters that need to be specified before running Word2Vec. The vector size of each word chosen for the Reddit model was 300 and minimum number of word occurrences required before being included was set to 10. Below are the Word2Vec results shown with a &lt;a href=&quot;https://github.com/dbunker/react-tabulator&quot;&gt;react table&lt;/a&gt; built for this purpose. The table can filter via the inputs or order rows by clicking the sortable column headers.&lt;/p&gt;

&lt;div id=&quot;root-word-to-vec&quot; style=&quot;font-size: .7em;&quot;&gt;&lt;/div&gt;

&lt;p&gt;Many interesting features can be derived from this including how competitors or related entities so often line up, “Nintendo” to “Sega”, “NFL” to “NBA”, “Disney” to “Pixar” etc.&lt;/p&gt;

&lt;p&gt;Other options available for performing Word2Vec include &lt;a href=&quot;http://torch.ch/&quot;&gt;Torch&lt;/a&gt;, &lt;a href=&quot;https://www.tensorflow.org/versions/master/tutorials/word2vec/index.html&quot;&gt;Tensorflow&lt;/a&gt; and &lt;a href=&quot;http://deeplearning4j.org/word2vec.html&quot;&gt;Deeplearning4j&lt;/a&gt;. Another common algorithm for word vector representation is &lt;a href=&quot;http://nlp.stanford.edu/projects/glove/&quot;&gt;GloVe&lt;/a&gt;. Overall, vector representation of words is a burgeoning tool for semantic analysis.&lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;p&gt;1) T. Mikolov, et al. &lt;a href=&quot;http://arxiv.org/pdf/1301.3781.pdf&quot;&gt;Efficient Estimation of Word Representations in
Vector Space&lt;/a&gt;, 2013&lt;/p&gt;

&lt;p&gt;2) T. Mikolov, et al. &lt;a href=&quot;http://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf&quot;&gt;Distributed Representations of Words and Phrases
and their Compositionality&lt;/a&gt;, 2013&lt;/p&gt;

&lt;p&gt;3) Y. Goldberg, et al. &lt;a href=&quot;http://arxiv.org/pdf/1402.3722v1.pdf&quot;&gt;word2vec
Explained: Deriving Mikolov et al.’s
Negative-Sampling Word-Embedding Method&lt;/a&gt;, 2014&lt;/p&gt;

&lt;script src=&quot;/script/bundle-word-to-vec.js&quot;&gt;&lt;/script&gt;

</description>
        <pubDate>Tue, 05 Jan 2016 00:00:00 -0500</pubDate>
        <link>https://dbunker.io/2016/01/05/spark-word2vec-on-reddit/</link>
        <guid isPermaLink="true">https://dbunker.io/2016/01/05/spark-word2vec-on-reddit/</guid>
        
        
      </item>
    
      <item>
        <title>Natural Language Processing with Spark on Reddit Comments</title>
        <description>&lt;p&gt;Ever since the beginnings of &lt;a href=&quot;https://en.wikipedia.org/wiki/Natural_language_processing&quot;&gt;natural language processing&lt;/a&gt; starting with the &lt;a href=&quot;https://en.wikipedia.org/wiki/Turing_test&quot;&gt;Turing test&lt;/a&gt;, understanding human language has remained one of the most sought after achievements in artificial intelligence. Human languages are varied and complex and have &lt;a href=&quot;https://www.youtube.com/watch?v=iWDKsHm6gTA&quot;&gt;evolved&lt;/a&gt; over thousands of years resulting in thousands of languages and dialects. Linguists can group and trace languages back to fundamental root languages, forming language trees such as the Indo-European and Uralic language families illustrated below.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.sssscomic.com/comic.php?page=196&quot;&gt; &lt;img class=&quot;aligncenter&quot; width=&quot;800&quot; src=&quot;/img/language.jpeg&quot; /&gt; &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Though just because a language is closer to the root, such as Latin to European Romance languages or Sanskrit to many Indian languages, doesn’t necessarily mean it is more fundamental such that it would be easier to process by a NLP system. Many attempts have been made to create simpler and more expressive languages, though none have all the properties of the mythic &lt;a href=&quot;https://en.wikipedia.org/wiki/Universal_language&quot;&gt;Universal Language&lt;/a&gt;. Some such invented languages include &lt;a href=&quot;http://www.omniglot.com/writing/esperanto.htm&quot;&gt;Esperanto&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Lojban&quot;&gt;Lojban&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Blissymbols&quot;&gt;Blissymbols&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Basic_English&quot;&gt;Basic English&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Basic English was designed to have only 850 words and a simplified grammer such that it could be easily learned and spoken globally. This appears at first to be a noble proposition, however it later inspired
&lt;a href=&quot;https://en.wikipedia.org/wiki/Newspeak&quot;&gt;Newspeak&lt;/a&gt; which was introduced to the people of Oceania in the book &lt;a href=&quot;https://en.wikipedia.org/wiki/Nineteen_Eighty-Four&quot;&gt;1984&lt;/a&gt; as an attempt to control the population by limiting the ideas possible to express.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Linguistic_relativity&quot;&gt;Sapir–Whorf hypothesis&lt;/a&gt; proposes that the way people think is profoundly affected by the language they use. These language features include what is easy to express, what is difficult to express, and what must be expressed as a consequence of using the language. For example, English requires personal pronouns to have gender: he, she and it. In contrast, spoken Chinese makes no distinction as these are all pronounced “ta”. In the science fiction novel &lt;a href=&quot;https://en.wikipedia.org/wiki/Babel-17&quot;&gt;Babel-17&lt;/a&gt; a language itself was weaponized as learning it acted as an intellectual contagion.&lt;/p&gt;

&lt;p&gt;All of this complexity poses difficulties for natural language processing. In order to truly understand language it is first necessary to have the context of the world in which it exists. However, providing a computer with this context is quite difficult. Most modern &lt;a href=&quot;https://en.wikipedia.org/wiki/Machine_translation&quot;&gt;machine translation&lt;/a&gt; systems take advantage of &lt;a href=&quot;https://en.wikipedia.org/wiki/Stochastic_grammar&quot;&gt;statistical models&lt;/a&gt; or more recently &lt;a href=&quot;https://en.wikipedia.org/wiki/Deep_learning&quot;&gt;deep learning&lt;/a&gt;, however back when computers were less powerful and there was less data available, a linguistic approach was taken involving &lt;a href=&quot;https://en.wikipedia.org/wiki/Rule-based_machine_translation&quot;&gt;linguistic rules&lt;/a&gt;. A famous early example of this approach was used in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Georgetown-IBM_experiment&quot;&gt;Georgetown experiment&lt;/a&gt; in 1954.&lt;/p&gt;

&lt;p&gt;In this approach the text is first represented according to &lt;a href=&quot;https://en.wikipedia.org/wiki/Syntax&quot;&gt;syntactic rules&lt;/a&gt;, the structure of the sentence, such as the sentence “the cat sat on the mat” shown below. This is then used to derive the &lt;a href=&quot;https://en.wikipedia.org/wiki/Semantics&quot;&gt;semantics&lt;/a&gt;, the meaning of the sentence.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;500&quot; src=&quot;/img/sentence.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This approach seemed the best place to start in deriving sentiment from the 2015 Reddit comments corpus for named entities, such as organizations, if only to compare to more modern approaches. The source for this is available on &lt;a href=&quot;https://github.com/dbunker/bluejay#nlp&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, all comments for the month January 2015 was downloaded from the &lt;a href=&quot;https://archive.org/details/2015_reddit_comments_corpus&quot;&gt;2015 Reddit comments corpus&lt;/a&gt;, which was extracted on “Sat, 28 Feb 2015 11:50:07 GMT”. Next, to build the pipeline. The data was loaded into S3 where it could be easily processed and aggregated by &lt;a href=&quot;http://spark.apache.org/&quot;&gt;Spark&lt;/a&gt;. Once this is complete Spark can be run using &lt;a href=&quot;https://aws.amazon.com/elasticmapreduce/&quot;&gt;AWS EMR&lt;/a&gt;. Next, to parse the sentences. &lt;a href=&quot;http://stanfordnlp.github.io/CoreNLP/simple.html&quot;&gt;CoreNLP&lt;/a&gt; is a great choice for performing the initial NLP steps of tokenization, part of speech tagging, stemming, and named entity recognition.&lt;/p&gt;

&lt;p&gt;These steps will first separate the sentences into &lt;a href=&quot;http://nlp.stanford.edu/software/tokenizer.shtml&quot;&gt;tokens&lt;/a&gt; and &lt;a href=&quot;http://nlp.stanford.edu/software/tagger.shtml&quot;&gt;tag&lt;/a&gt; them according to their type, “orange” is tagged adjective (JJ), “cat” is tagged noun (NN) etc. &lt;a href=&quot;http://nlp.stanford.edu/IR-book/html/htmledition/stemming-and-lemmatization-1.html&quot;&gt;Stemming&lt;/a&gt; converts all words to word stems, “am”, “are”, and “is” becomes “be”, “walk”, “walked”, “walks”, and “walking” becomes “walk”. Named entity recognition (&lt;a href=&quot;http://nlp.stanford.edu/software/CRF-NER.shtml&quot;&gt;NER&lt;/a&gt;) marks if a noun is a special type, such as an organization.&lt;/p&gt;

&lt;p&gt;CoreNLP has more advanced features, including sentence parsing and it’s own &lt;a href=&quot;http://nlp.stanford.edu/sentiment/code.html&quot;&gt;sentiment analysis&lt;/a&gt;. However, since only single entities, not whole comments are being considered, and this is a hefty task given every comment must be parsed, these were not included in the pipeline.&lt;/p&gt;

&lt;p&gt;Now to apply our simple linguistic rules, these are &lt;em&gt;direct adjectives&lt;/em&gt; of the form “adjective noun” and &lt;em&gt;connected adjectives&lt;/em&gt; of the form “noun is adjective” to start. This can be illustrated with some examples generated using the &lt;a href=&quot;http://nlp.stanford.edu:8080/parser/index.jsp&quot;&gt;CoreNLP demo&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;direct-adjectives&quot;&gt;Direct Adjectives&lt;/h3&gt;

&lt;blockquote&gt;
&quot;The &lt;strong&gt;blue dog&lt;/strong&gt; ate lasagna&quot;
&lt;/blockquote&gt;

&lt;pre&gt;&lt;code&gt;The/DT blue/JJ dog/NN ate/VBD lasagna/NN
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;(ROOT
  (S
    (NP (DT The) (JJ blue) (NN dog))
    (VP (VBD ate)
      (NP (NN lasagna)))))
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;connected-adjectives&quot;&gt;Connected Adjectives&lt;/h3&gt;

&lt;blockquote&gt;
&quot;The &lt;strong&gt;dog is &lt;a href=&quot;https://www.youtube.com/watch?v=FlMHdhf0nvE&quot;&gt;blue&lt;/a&gt;&lt;/strong&gt;&quot;
&lt;/blockquote&gt;

&lt;pre&gt;&lt;code&gt;The/DT dog/NN is/VBZ blue/JJ
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;(ROOT
  (S
    (NP (DT The) (NN dog))
    (VP (VBZ is)
      (ADJP (JJ blue)))))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Also word articles like “a” and “the” are ignored, the conjunction “and” is used for combination, and sequences of adjective modifiers and adjectives are applied to full nouns which may consist of multiple words. These results can be seen below in a &lt;a href=&quot;https://github.com/dbunker/react-tabulator&quot;&gt;table&lt;/a&gt; built for this purpose using &lt;a href=&quot;https://facebook.github.io/react/&quot;&gt;React&lt;/a&gt;, &lt;a href=&quot;http://redux.js.org/&quot;&gt;Redux&lt;/a&gt;, &lt;a href=&quot;https://facebook.github.io/immutable-js/&quot;&gt;Immutable&lt;/a&gt;, and &lt;a href=&quot;https://webpack.github.io/&quot;&gt;Webpack&lt;/a&gt;. The table can be filtered by entering in the input and sorted by clicking the column title.&lt;/p&gt;

&lt;div id=&quot;root-word-count&quot; style=&quot;font-size: .7em;&quot;&gt;&lt;/div&gt;

&lt;p&gt;From here it is possible to filter to desired organizations, Subreddits and adjectives. For example filtering by “AMD” organization, the “pcmasterrace” Subreddit considers them “cheaper”, whereas “buildapc” Subreddit also says “just as good”. According to the “DotA2” Subreddit the “valve” organization is “lazy” but also “smart”.&lt;/p&gt;

&lt;p&gt;Though of course these linguistic rules are simplistic and would certainly not be able to properly parse a sentence like the &lt;a href=&quot;https://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo&quot;&gt;buffalo sentence&lt;/a&gt;. Though humans have difficulty with this sentence as well.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;500&quot; src=&quot;/img/buffalo.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And even when the parsing is correct according to the syntax, that doesn’t necessarily lead to meaningful semantics, as is the case for the sentence &lt;a href=&quot;https://en.wikipedia.org/wiki/Colorless_green_ideas_sleep_furiously&quot;&gt;“Colorless green ideas sleep furiously”&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;400&quot; src=&quot;/img/syntax.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;However, for the simple case, simple parsing is sufficient. Though this can be greatly improved using neural network algorithms such as &lt;a href=&quot;https://code.google.com/p/word2vec/&quot;&gt;Word2Vec&lt;/a&gt; which is explored in the next &lt;a href=&quot;/2016/01/05/spark-word2vec-on-reddit/&quot;&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Links:&lt;br /&gt;
1) &lt;a href=&quot;https://github.com/dbunker/bluejay&quot;&gt;Spark analysis&lt;/a&gt;&lt;br /&gt;
2) &lt;a href=&quot;https://github.com/dbunker/react-tabulator&quot;&gt;Customizable table&lt;/a&gt;&lt;/p&gt;

&lt;script src=&quot;/script/bundle-word-count.js&quot;&gt;&lt;/script&gt;

</description>
        <pubDate>Mon, 04 Jan 2016 00:00:00 -0500</pubDate>
        <link>https://dbunker.io/2016/01/04/spark-and-nlp-on-reddit/</link>
        <guid isPermaLink="true">https://dbunker.io/2016/01/04/spark-and-nlp-on-reddit/</guid>
        
        
      </item>
    
      <item>
        <title>The Nature of Data</title>
        <description>&lt;p&gt;&lt;img class=&quot;alignleft&quot; src=&quot;/img/data.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;New advances are continually being made in machine learning algorithms, improvements in recurrent and convolutional deep neural networks being some of the most notable recent examples. However, it’s often not the quality of the algorithm or even the quality of the data that leads to the best results, but the sheer amount of data that can be brought to bear against a problem.&lt;/p&gt;

&lt;blockquote&gt;
&quot;It&#39;s not who has the best algorithm that wins, it&#39;s who has the most data.&quot;&lt;br /&gt;
- Andrew Ng
&lt;/blockquote&gt;

&lt;p&gt;As presented near the end of the excellent &lt;a href=&quot;https://www.coursera.org/learn/machine-learning&quot;&gt;Machine Learning Coursera course&lt;/a&gt;, the graph below shows a small example of the data quantity vs. result accuracy phenomena in action as applied to the subject of &lt;a href=&quot;http://research.microsoft.com/pubs/66840/acl2001.pdf&quot;&gt;Natural Language Disambiguation&lt;/a&gt;. Although there are diminishing returns, often in ML research getting a 75% prediction accuracy is easy whereas getting to 90% is near impossible, we can still see that the algorithms used don’t impact the results effectiveness nearly as much as the amount of data does.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;alignleft&quot; src=&quot;/img/ml-data.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Another way of phrasing this is that when the amount of data is small, most techniques used will inevitably overfit the provided examples unless pressure is explicitly applied, such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Regularization_(mathematics)&quot;&gt;regularization&lt;/a&gt;, to prevent this. For example, A polynomial exists that can &lt;a href=&quot;https://en.wikipedia.org/wiki/Curve_fitting&quot;&gt;exactly match&lt;/a&gt; any n-dimensional set of values, however it almost certainly will not generalize to new values even if they follow the same general pattern as the original values because the model would be so hyper focussed on matching the training examples.&lt;/p&gt;

&lt;p&gt;One could make an analogy here to the notion of perspective. Anyone brought up in a certain context, though well suited for its particular nuances, will be woefully unprepared, &lt;a href=&quot;https://en.wikipedia.org/wiki/The_Prince_and_the_Pauper&quot;&gt;Prince and the Pauper&lt;/a&gt; style, for dealing with a new context.&lt;/p&gt;

&lt;p&gt;Overfitting is a common problem in statistics where practitioners know if data is worked on long enough, it is possible to force it to say almost anything. One of the primary impediments to forming meaningful predictions based on historical data is the &lt;a href=&quot;http://xkcd.com/552/&quot;&gt;correlation vs. causation&lt;/a&gt; problem. Based only on a narrow set of information it is difficult to determine cause and effect.&lt;/p&gt;

&lt;p&gt;There is a study targeted towards MBA finance students that shows an excellent &lt;a href=&quot;http://nerdsonwallstreet.com/stupid-data-miner-tricks-quantitative-finance-85&quot;&gt;correlation&lt;/a&gt; between butter production in Bangladesh and the S&amp;amp;P 500 Index between the 80s and 90s, but for any other years there is no correlation. This exemplifies the fact that  there can exist strong correlations that don’t have any deeper meaning or explanation. This study also demonstrates that even reasonable theories that are propped up by supporting data may in reality be no more meaningful than butter to stock prices when viewed with greater context.&lt;/p&gt;

&lt;p&gt;Correlation vs. causation problems appear all over the modern world. For example, in the case of finance it is of paramount importance to properly understand causation. Connections like: bad whether leads to low wheat production which implicates higher wheat prices which provokes unrest in the Middle East leading to low oil production and high oil prices. However, as complex as these connections can be, in the case of the stock market it’s also important to consider what the other traders, human and machine, think, and what &lt;a href=&quot;https://www.youtube.com/watch?v=k53NGe64RBU&quot;&gt;they&lt;/a&gt; think other traders think and so on. This is one reason why oil prices continue to rise even when there is plenty of oil.&lt;/p&gt;

&lt;p&gt;This meta-consideration is part of what makes the question of &lt;a href=&quot;http://www.wired.com/wiredscience/2010/10/twitter-crystal-ball/&quot;&gt;twitter funds&lt;/a&gt; interesting. Supposedly it is possible to track the mood of the general public using twitter and use it to predict stocks. Even if the study is flawed, it remains valid if traders believe in it and thus make it true. For instance when there was a lot of buzz around Anne Hathaway, the stock for Berkshire Hathaway shot up because trading machines saw a lot of positive talk about Hathaway and assumed the Berkshire Hathaway stock would rise. It made no difference whether in actuality it was Anne or Berkshire, the stock still went up in the short term.&lt;/p&gt;

&lt;p&gt;This is part of what makes short term and high frequency trading unpredictable, it doesn’t matter if value is real or not. This isn’t all that surprising given that markets in general run almost entirely on faith. This is also why there are flash crashes involving trigger happy machines and fear filled traders. When asked about this, George Soros admitted the irony of hedge funds protecting investors from market volatility that hedge funds themselves create.&lt;/p&gt;

&lt;p&gt;It’s hard to know whether the correlations being looked at are really predictive, or just random. Ultimately, the world is complicated and is often impossible to boil down to easily digestible ideas and sometimes it can’t be boiled down to anything at all. Though having more data and greater context certainly helps.&lt;/p&gt;
</description>
        <pubDate>Fri, 10 Jul 2015 00:00:00 -0400</pubDate>
        <link>https://dbunker.io/2015/07/10/the-nature-of-data/</link>
        <guid isPermaLink="true">https://dbunker.io/2015/07/10/the-nature-of-data/</guid>
        
        
      </item>
    
      <item>
        <title>NMF and Crystallography</title>
        <description>&lt;p&gt;&lt;img class=&quot;alignleft&quot; width=&quot;150&quot; src=&quot;/img/crystal.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/X-ray_crystallography&quot;&gt;X-ray crystallography&lt;/a&gt; is the use of x-rays to determine the molecular structure of crystals. This underlying atomic structure can then be used to determine physical properties such as elasticity, tensile strength, conductivity, or &lt;a href=&quot;http://www.pdai.phys.rice.edu/pdffiles/pc243_201.pdf&quot;&gt;superconductivity&lt;/a&gt;, making it an important tool for &lt;a href=&quot;https://en.wikipedia.org/wiki/Materials_science&quot;&gt;materials science&lt;/a&gt;. X-ray crystallography involves mounting a crystalline material on a platform, blasting it with x-rays at various angles and measuring the intensity of the reflected rays.&lt;/p&gt;

&lt;p&gt;The graph of intensity against x-ray angle is referred to as the diffraction pattern, the peaks of which are used to determine atomic structure. Below is the diffraction pattern of &lt;a href=&quot;https://en.wikipedia.org/wiki/Silicon_carbide&quot;&gt;silicon carbide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;450&quot; src=&quot;/img/diffraction.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;However, considering there are an infinite number of possible &lt;a href=&quot;https://en.wikipedia.org/wiki/Alloy&quot;&gt;alloy&lt;/a&gt; combinations, looking through all of them to find the ideal crystalline structure for a given use case is infeasible. This makes it an excellent place to employ a machine learning algorithm.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Non-negative_matrix_factorization&quot;&gt;Non-negative Matrix Factorization&lt;/a&gt; is frequently used in &lt;a href=&quot;https://en.wikipedia.org/wiki/Recommender_system&quot;&gt;recommendation systems&lt;/a&gt;, but is also uniquely well suited for deriving patterns from signal data. The basic principle is to represent all the signals as a matrix of values V, each row of numbers representing a single signal. The matrix factorization process then produces matrices W and H where W multiplied by H is an approximation of the original matrix V.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;600&quot; src=&quot;/img/nmf-1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Another way of imagining this is as H, a series of base signals, and W the percentages of each of those base signals combined to produce B, the approximation of V.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;600&quot; src=&quot;/img/nmf-2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In NMF, the goal is to minimize the error between the actual and derived signal matrix. Put another way, to minimize the &lt;a href=&quot;http://mathworld.wolfram.com/FrobeniusNorm.html&quot;&gt;Frobenius norm&lt;/a&gt; of the error matrix.&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;f = { \frac{1}{2} \|V - WH\|^2 }&lt;/script&gt;

&lt;p&gt;One way of achieving this is using &lt;a href=&quot;https://en.wikiversity.org/wiki/Least-Squares_Method&quot;&gt;alternating least squares&lt;/a&gt;. In alternating least squares only one of the two matrices, W or H is updated to minimize the Frobenius norm each iteration. This is in contrast to gradient descent in which both are updated each iteration to approach a minima of the Frobenius norm. Via differential calculus, the following update equations can be derived.&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\frac{\partial f}{\partial H} = -W^TV + W^TWH
\quad\quad\quad
\frac{\partial f}{\partial W} = -VH^T + WHH^T&lt;/script&gt;

&lt;p&gt;Regularization can also be added for desired properties such as &lt;a href=&quot;http://www.jmlr.org/papers/volume5/hoyer04a/hoyer04a.pdf&quot;&gt;matrix sparcity&lt;/a&gt;. Since the most important aspects of the diffraction patterns are the peaks, most values in the base signals should be geared towards 0.&lt;/p&gt;

&lt;p&gt;This process was applied to the Iron-Palladium-Galium alloy combinations and written up in a &lt;a href=&quot;http://scitation.aip.org/content/aip/journal/rsi/80/10/10.1063/1.3216809&quot;&gt;paper&lt;/a&gt; coauthored while working at &lt;a href=&quot;http://www.nist.gov/&quot;&gt;NIST&lt;/a&gt;. Below is shown some derived signals from the W and H matrices, next to the experimental data.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;600&quot; src=&quot;/img/nmf-deflation.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is an example of 46% Iron, 26% Palladium and 28% Gallium. The percentage of each structure is shown as a slice of the pie. Each of the known structures are labeled and the de-convoluted signal is at the botom.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; width=&quot;300&quot; src=&quot;/img/nmf-example.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The results can be represented as a triangle of pie charts, the location of the pies showing the alloy composition and the slices of each pie representing percentages of the base signals.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;alignleft&quot; width=&quot;350&quot; src=&quot;/img/nmf-base.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;350&quot; src=&quot;/img/nmf-triangle.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;One of the problems with using NMF for base diffraction pattern derivation is phase shifts. As the composition moves from mostly one type of atom to another, atoms will be swapped, though the crystalline structure may not change. This results in the peaks moving and NMF generating a new base signal when it should reuse one already generated as can be seen in BCC Fe (110). Despite phase shift deviations, NMF is useful in deriving base diffraction patterns and visualizing the results.&lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;p&gt;1) C. J. Long, et al. &lt;a href=&quot;http://scitation.aip.org/content/aip/journal/rsi/80/10/10.1063/1.3216809&quot;&gt;Rapid identification of structural phases in combinatorial thin-film libraries using x-ray diffraction and non-negative matrix factorization&lt;/a&gt;, 2009&lt;/p&gt;

&lt;p&gt;2) P. O. Hoyer, et al. &lt;a href=&quot;http://www.jmlr.org/papers/volume5/hoyer04a/hoyer04a.pdf&quot;&gt;Non-negative Matrix Factorization with
Sparseness Constraints&lt;/a&gt;, 2004&lt;/p&gt;

&lt;p&gt;3) P. Dai, et al. &lt;a href=&quot;http://www.pdai.phys.rice.edu/pdffiles/pc243_201.pdf&quot;&gt;Synthesis and neutron powder diffraction study of the superconductor HgBa2Ca2Cu308 by T1 substitution&lt;/a&gt;, 1994&lt;/p&gt;
</description>
        <pubDate>Sun, 09 Nov 2014 00:00:00 -0500</pubDate>
        <link>https://dbunker.io/2014/11/09/nmf-and-crystallography/</link>
        <guid isPermaLink="true">https://dbunker.io/2014/11/09/nmf-and-crystallography/</guid>
        
        
      </item>
    
      <item>
        <title>Adrift Generator</title>
        <description>&lt;p&gt;Constraint solving remains a niche art, which is in part why it’s so refreshing to find instances were it can be put to good use. Recently came across the &lt;a href=&quot;http://playadrift.com/&quot;&gt;Adrift&lt;/a&gt; puzzle game and thought it would be fun to create a puzzle solver and generator. Although it has been shown that the game is &lt;a href=&quot;http://bosker.wordpress.com/2013/03/13/adrift-is-np-complete/&quot;&gt;NP-complete&lt;/a&gt; that doesn’t necessarily mean we can’t write a speedy solver.&lt;/p&gt;

&lt;p&gt;The goal in the Adrift game is to connect each of the color end point pairs by a string of blocks of the same color. From constraints extrapolated from this goal we can solve and even create new puzzles. A key insight that can be gleaned from this puzzle is that each color must be surrounded by exactly two of its color, unless it is on an end, in which case it is surrounded by exactly one of its color. Using this observation, we can write a simple solver for the first puzzle using &lt;a href=&quot;http://sabrlang.org/&quot;&gt;SABR&lt;/a&gt; and extend this solver to even larger puzzles.&lt;/p&gt;

&lt;p&gt;First we need to state that the allowed symbols are R (red), B (blue) and X (stone).&lt;/p&gt;

&lt;div class=&quot;setcode&quot;&gt;
Sym { R B X }
&lt;/div&gt;

&lt;p&gt;Now we can set the board, this is simply stating all the blocks that exist in the puzzle which we can later constrain.&lt;/p&gt;

&lt;div class=&quot;setcode&quot;&gt;
Board { 				&lt;br /&gt;
&lt;div class=&quot;settab&quot;&gt;
      ..... a0;			&lt;br /&gt;
      .... b0 b1;		&lt;br /&gt;
      ... c0 c1 c2;		&lt;br /&gt;
      .... d0 d1;		&lt;br /&gt;
      ..... e0;			&lt;br /&gt;
&lt;/div&gt;
x0 x1 x2 . y0 y1 y2;	&lt;br /&gt;
x3 x4 x5 . y3 y4 y5;	&lt;br /&gt;
x6 x7 x8 . y6 y7 y8;	&lt;br /&gt;
}
&lt;/div&gt;

&lt;p&gt;Below is our first constraint. We tell the board the starting positions of R, B, and X and what we want to fill in via !X (not X) meaning it must be a color. We will do this with a requirement (Req) on the Board object.&lt;/p&gt;

&lt;div class=&quot;setcode&quot;&gt;
Req Board {														&lt;br /&gt;
&lt;div class=&quot;settab&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;R;					&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;      		!X &amp;nbsp;X;					&lt;br /&gt;
&amp;nbsp;&amp;nbsp;      			&amp;nbsp;B !X &amp;nbsp;X;			&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;			!X !X;						&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;		 !X;						&lt;br /&gt;
&lt;/div&gt;
 &amp;nbsp;X  &amp;nbsp;X !X  		&amp;nbsp;  &amp;nbsp;X !X  &amp;nbsp;X;		&lt;br /&gt;
 &amp;nbsp;X  &amp;nbsp;X !X  		&amp;nbsp;  &amp;nbsp;X !X  &amp;nbsp;X;		&lt;br /&gt;
 &amp;nbsp;B !X !X  			&amp;nbsp;  &amp;nbsp;X !X  &amp;nbsp;R;		&lt;br /&gt;
}
&lt;/div&gt;

&lt;p&gt;Below we have the meat of our solver were we express block links. For a block to be a link it must be surrounded by exactly two of its color. The first represents the link block and the subsequents represent the blocks it is surrounded by.&lt;/p&gt;

&lt;p&gt;This construct uses option (Opt) groups for each of the objects: link2, link3, link4. An option group is like a requirement, only that at least one, but not necessarily all of the requirements in the option group must be met. For example, in link3 we express that for whatever symbol occupies the first place, exactly two of the next three places must match this symbol.&lt;/p&gt;

&lt;div class=&quot;setcode&quot;&gt;
Opt link2 { v v v }			&lt;br /&gt;
							&lt;br /&gt;
Opt link3 { v !v v v }		&lt;br /&gt;
Opt link3 { v v !v v }		&lt;br /&gt;
Opt link3 { v v v !v }		&lt;br /&gt;
							&lt;br /&gt;
Opt link4 { v v v !v !v }	&lt;br /&gt;
Opt link4 { v v !v v !v }	&lt;br /&gt;
Opt link4 { v v !v !v v }	&lt;br /&gt;
Opt link4 { v !v v v !v }	&lt;br /&gt;
Opt link4 { v !v v !v v }	&lt;br /&gt;
Opt link4 { v !v !v v v }	&lt;br /&gt;
&lt;/div&gt;

&lt;p&gt;Now we simply describe all of the objects that match up to our Opt groups using DesObj. Note that while Req and Opt can only contain symbols and temporary variables representing symbols, DesObj can only contain Board cells.&lt;/p&gt;

&lt;div class=&quot;setcode&quot;&gt;
DesObj link3 { b0 a0 c1 c0 }		&lt;br /&gt;
DesObj link4 { c1 b0 b1 d1 d0 }		&lt;br /&gt;
DesObj link4 { d0 c0 c1 e0 x1 }		&lt;br /&gt;
DesObj link4 { d1 e0 c1 c2 y1 }		&lt;br /&gt;
DesObj link4 { e0 d0 d1 y0 x2 }		&lt;br /&gt;
DesObj link4 { x2 e0 y0 x5 x1 }		&lt;br /&gt;
DesObj link4 { x5 x2 y3 x8 x4 }		&lt;br /&gt;
DesObj link3 { x7 x4 x8 x6 }		&lt;br /&gt;
DesObj link3 { x8 x5 y6 x7 }		&lt;br /&gt;
DesObj link4 { y1 d1 y2 y4 y0 }		&lt;br /&gt;
DesObj link4 { y4 y1 y5 y7 y3 }		&lt;br /&gt;
DesObj link3 { y7 y4 y8 y6 }		&lt;br /&gt;
&lt;/div&gt;

&lt;p&gt;Running our &lt;a href=&quot;https://github.com/dbunker/SABR/blob/master/module/other-test/general/Adrift/adrift.tb&quot;&gt;source&lt;/a&gt; code with “./sabr 1 source” we get the only valid &lt;a href=&quot;https://github.com/dbunker/SABR/blob/master/module/other-test/general/Adrift/adrift-expected.txt&quot;&gt;solution&lt;/a&gt;. This is quite a simple example, but we can easily extend this reasoning to create a more expressive &lt;a href=&quot;https://github.com/dbunker/SABR/blob/master/module/other-test/general/Adrift/compute-adrift-2.tb&quot;&gt;solver&lt;/a&gt; and solve more complex puzzles.&lt;/p&gt;

&lt;p&gt;You can try out the generator posted &lt;a href=&quot;https://github.com/dbunker/SABR/blob/master/module/other-test/general/Adrift/gen_x.py&quot;&gt;here&lt;/a&gt;. It works by picking five random location pairs for the five colors, solving it to make sure it can be solved, then trying to solve it again another way to make sure there is only one valid solution. It is fairly fast, generating a new 5x5 with five color puzzle every couple of minutes on a laptop. Here’s a little visualization that shows some of the puzzles it created. To complete the puzzle, click and drag the colored blocks.&lt;/p&gt;

&lt;script src=&quot;/js/jquery.min.js &quot;&gt;&lt;/script&gt;

&lt;script src=&quot;/script/puzzle.js&quot;&gt;&lt;/script&gt;

&lt;canvas class=&quot;aligncenter&quot; id=&quot;canvas&quot; width=&quot;400&quot; height=&quot;440&quot;&gt;
	Your browser does not support the HTML5 canvas tag.
&lt;/canvas&gt;

&lt;div align=&quot;center&quot;&gt;
    &lt;button type=&quot;button&quot; style=&quot;width:150px&quot; onclick=&quot;resetBoard();&quot;&gt;Reset Puzzle&lt;/button&gt;
    &lt;button type=&quot;button&quot; style=&quot;width:150px&quot; onclick=&quot;showSolution();&quot;&gt;Show Solution&lt;/button&gt;
    &lt;button type=&quot;button&quot; style=&quot;width:150px&quot; onclick=&quot;newBoard();&quot;&gt;Next Puzzle&lt;/button&gt;
&lt;/div&gt;

&lt;p&gt;They are not curated, so the difficulty curve is all over the map. Writing a program to automatically determine puzzle difficulty would be quite a challenge and likely delve into psychology, so it would probably be faster just to take a sample of solving times and use ascending order. As with many computing problems, it’s surprising how far can be reached just by counting.&lt;/p&gt;
</description>
        <pubDate>Sun, 17 Mar 2013 00:00:00 -0400</pubDate>
        <link>https://dbunker.io/2013/03/17/adrift-generator/</link>
        <guid isPermaLink="true">https://dbunker.io/2013/03/17/adrift-generator/</guid>
        
        
      </item>
    
      <item>
        <title>Now.js</title>
        <description>&lt;p&gt;Have given &lt;a href=&quot;https://github.com/Flotype/now&quot;&gt;Now.js&lt;/a&gt; a shot with an &lt;a href=&quot;https://play.google.com/store/apps/details?id=au.com.twosquared&quot;&gt;Invertris&lt;/a&gt; Javascript &lt;a href=&quot;https://github.com/dbunker/Double-Tetris&quot;&gt;implementation&lt;/a&gt; and it turned out fairly well so wanted to provide a post mortem on the Invertris project and consider the Now.js framework and the Node.js ecosystem in general. Now.js certainly made writing socket style Javascript way easier after some time spent developing in it, though feels like there is a lot of magic happening under the hood. This is great for efficiency because naturally folks don’t want to have to worry about functionality that can be built by the framework itself, but it can lead to problems in latency and security.&lt;/p&gt;

&lt;p&gt;It can sometimes be unclear when a variable set in the client would get to the server and although Now.js has disabled the ability to run client code on the server, it still seems possible a Now.js program could deliberately or inadvertently allow remote code execution via a variable transfer with a function prototype. This seems like a cool idea that could have disastrous security implications.&lt;/p&gt;

&lt;p&gt;Then there is the problem with scaling, although this is more an issue with Node.js. The beauty of Node.js is that the system itself is quite simple, which contributes to why so many like it. It is single threaded with epoll/select style network io, exclusively uses network blocking, and runs entirely on event based callbacks. Unfortunately these can all lead to scalability issues including, but not limited to, load balancing and callback spaghetti.&lt;/p&gt;

&lt;p&gt;Fortunately, there are a number of techniques and libraries available to help mitigate these issues. A common technique used is to have Nginx &lt;a href=&quot;http://wiki.nginx.org/HttpUpstreamModule&quot;&gt;Upstream&lt;/a&gt; round robin to multiple identical nodes running on different ports. This can make use of all the CPUs on the machine and mitigate the risk of one client hogging all the IO like one grumpy guy trying to return a piece of fruit at the only cash register. Unfortunately, Nginx struggles with the raw TCP of &lt;a href=&quot;http://socket.io&quot;&gt;Socket.io&lt;/a&gt;, on which Now.js is based, so decided to try to use another TCP load balancer going with the Unix one, Balance, as per the &lt;a href=&quot;http://en.wikipedia.org/wiki/Unix_philosophy&quot;&gt;Unix Philosophy&lt;/a&gt;: Those who don’t understand UNIX are condemned to reinvent it, poorly.&lt;/p&gt;

&lt;p&gt;Unfortunately, it had occasional handshake errors so in the end returned to a single node. In the future will likely switch to HAProxy or Nginx’s TCP plugin to provide fair load balancing via speedy worker threads.&lt;/p&gt;

&lt;p&gt;Links:&lt;br /&gt;
1) &lt;a href=&quot;/tetris/&quot;&gt;The Game&lt;/a&gt;&lt;br /&gt;
2) &lt;a href=&quot;https://github.com/dbunker/Double-Tetris&quot;&gt;The Source&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sat, 29 Oct 2011 00:00:00 -0400</pubDate>
        <link>https://dbunker.io/2011/10/29/nowjs/</link>
        <guid isPermaLink="true">https://dbunker.io/2011/10/29/nowjs/</guid>
        
        
      </item>
    
      <item>
        <title>SABR FAQ</title>
        <description>&lt;p&gt;This is a FAQ related to the programming language SABR, which can be found at &lt;a href=&quot;http://sabrlang.org&quot;&gt;sabrlang.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) It seems far removed from the problem, using a language to write out a problem to be solved by a satisfiability solver rather than solved by the compiler itself. Why do it that way?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The satisfiability problem is an ongoing field of research and there are continual advancements in distributed and machine learning based &lt;a href=&quot;http://en.wikipedia.org/wiki/Conjunctive_normal_form&quot;&gt;Conjunctive Normal Form (CNF) solvers&lt;/a&gt;, and there will likely be greater discoveries in the future. Many are already using satisfiability solvers to solve problems in spatial and temporal logic. However, although the problem of restating some problem as a CNF will undergo improvements, these improvements may be less significant than the progress made in CNF solvers. As the solvers improve, it will be possible to just hook in a new CNF solver, and it will suddenly solve the problem faster. If, for example, a neural network algorithm been used to solve the SABR language problem, this type of effortless advancement would not be possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Where does SABR fit in relation to other language?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SABR is a domain specific language that fits in the discrete spatial and temporal representation niche of the constraint programming niche, which is a pretty small piece of the overall programming pie, and can’t even claim to have a monopoly on that. However, SABR does have the potential to cause people to think differently about the problems they face and how they can be solved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Is the language expected to grow much in the future?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The language is stripped down by design because it is expected that the problems fed to it will be complicated enough that bells and whistles would hurt performance too much. One of the design goals was that the language should have at or under an n-squared relationship between the size of the program and the size of the CNF so that users will get a sense of when their programs may be becoming unmanageable for the CNF solver. Although frequently more constraint can speed up CNF solving, CNF size is still a fair heuristic to use for time to solve. As an added bonus, since SABR has this property it can be used to show that a problem class is NP easy.&lt;/p&gt;

&lt;p&gt;The addition of a SABR Python library could in the future have features like integer programming, tiling for bin packing, model checking, Computational Tree Logic (CTL) and Linear Temporal Logic (LTL). Computer languages, like computer software, often suffer from feature creep (i.e. Duke Neukem Forever syndrome). It has been said that all software inevitably evolves up to and beyond the point it includes an email server and it is arguably gratuitous that Prolog can be used to write a webserver. So instead of adding features using the language syntax, greater utility may be gained from adding features to a library which uses SABR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) Any other future use cases?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SABR could be used for program verification and model checking, potentially to analyze assembly or byte code. Could also be used with machine learning, distributed computing, and GPU based CNF solvers. Constraint solving is a multifaceted area, so there are lots of opportunities to explore.&lt;/p&gt;
</description>
        <pubDate>Thu, 28 Jul 2011 00:00:00 -0400</pubDate>
        <link>https://dbunker.io/2011/07/28/sabr-faq/</link>
        <guid isPermaLink="true">https://dbunker.io/2011/07/28/sabr-faq/</guid>
        
        
      </item>
    
      <item>
        <title>Genetic Quine</title>
        <description>&lt;p&gt;&lt;img class=&quot;alignleft&quot; src=&quot;/img/dna.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Have just come across an interesting fact from a &lt;a href=&quot;http://www.pbs.org/wgbh/nova/evolution/intelligent-design-trial.html&quot;&gt;NOVA documentary&lt;/a&gt; on evolution. Bacteria are among the few creatures that use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotating_locomotion_in_living_systems&quot;&gt;rotary motor&lt;/a&gt;, their bacterial flagellum, for propulsion. The comments about it in this documentary also point out one of the fundamental flaws in &lt;a href=&quot;https://en.wikipedia.org/wiki/Genetic_algorithm&quot;&gt;genetic algorithms&lt;/a&gt;. From the perspective of the genetic algorithm there is a point A which is bad and  point B which is substantially better, however in order for the genetic algorithm to venture from point A to point B most of the steps along the way have to show improvement. It may happen that there was an in between stage that was useful, as evidence shows happened in the bacteria’s case, but that relies a lot on luck.&lt;/p&gt;

&lt;p&gt;However, genetic algorithms still have the potential to create unique solutions to problems. For instance, a genetic algorithm could be set up that would, with a little luck, eventually write a &lt;a href=&quot;http://en.wikipedia.org/wiki/Quine_%28computing%29&quot;&gt;quine&lt;/a&gt; in C.  To set up the environment, start by cutting the size to 200 characters (27 letters + 10 numbers + 20 misc = 57 possible chars) which is 57^200 possible programs. Put another way, many times more than the number of atoms in the universe (a mere 10^82), though ideally quickly narrows this number. Breeding is done by sporadic character insertion of two programs.&lt;/p&gt;

&lt;p&gt;Next, to set up the reward structure. If the breeding produces a program that compiles,  points for that offspring, increasing its longevity. If it produces output, more points. And if it starts to produce output identical to the front of its output, many more points. Finally, if it produces the exact same output as itself, it wins and the algorithm completes.&lt;/p&gt;

&lt;p&gt;It does of course matter greatly how the environment is set up, in particular the breeding and rewards system. Using a language which offers fewer characters and is more likely to produce compilable output also increases the chance of success.&lt;/p&gt;

&lt;p&gt;DNA is particularly elegant because so much produces viable candidates (creatures), which is ideal in genetic algorithms. The genetic algorithms batches just do the best they can with the parameters they are given. Living creatures are the same.&lt;/p&gt;
</description>
        <pubDate>Tue, 26 Jul 2011 00:00:00 -0400</pubDate>
        <link>https://dbunker.io/2011/07/26/genetic-quine/</link>
        <guid isPermaLink="true">https://dbunker.io/2011/07/26/genetic-quine/</guid>
        
        
      </item>
    
  </channel>
</rss>
