Monday, 30 December 2019

Markov Chains Part 2: Poetic Boogaloo

Markov chains are useful for a lot of things. Economics, biology, predictive text, et cetera. But I thought, "Most people don't like writing poetry. Why not automate it?" I mean, loads of things are being automated nowadays, so why not poetry too?
Well, that really didn't work out well. Sure, there are results, and sure, they are hilarious, but that wasn't exactly what I was intending. But that's okay, and I'll explain why later. But first, let's hear some of these Markov-chain-generated poems!
Grapes gathering leaves no way by Maromas Kierkartar 
burned eyes can no worldliness,
by the slings and only my dreams set free.
On the spackle protrudes.
A sound of beaten trees,
the skinny moonlight.
Maid or athlete proud.
undemanding yellowness; what I done that clicking make amends.
It.
Now, it should be noted that I actually modified the Christmas card program to make this work, mostly because I really didn't want to recreate the original code. Also, I actually hand-selected many pieces of poetry (and other literature) to feed into the program, from many different authors. These include; J. Bennett, J. Berryman, R. Bradbury, C. Bukowski, Lord Byron, T. S. Eliot, R. Frost, A. Ginsberg, B. Jonson, J. Milton, A. F. Moritz, A. Munro, G. Orwell (E. A. Blair), E. A. Poe, D. Salvato, W. Shakespeare, E. Spenser, Lord Tennyson, W. Wordsworth, W. B. Yeats, J. M. Yen (me), and a few anonymous poets. Yes, I kept track of every single author. Yes, I included some of my own poetry. No, I am not a narcissist, in fact, I'm really more of a satisficer. Anyway, here's another poem!
Too much with us ode by Friomotle Maraoter 
best of blood.
Classic Pavlovian conditioning.
I died,
love,
when I could not your care.
Incarnate in a breathing ribcage.
With a sycamore I trust you had the eyeless road in de whites in some sturdy lead,
Just to think.
The fact that there is actual symbolism and one could actually derive meaning from this scares me. The way that I interpret it, this is a poem about betrayal and suicide. A formerly trusted individual had a blind lead in a project, and maybe something went awry. Maybe, some spiritual accident happened, or maybe there was a terrible divorce; let's say, lying and lack of empathy, lack of care. And this drives the narrator to develop a fascination in blood, gore, and, possibly, taking their own life. That's really dark, if I say so myself. I'm not saying that's what it means, I mean, given that it's basically just spouting out words it thinks goes together, I'm almost sure this has no meaning! But it's fun to analyze this kind of thing, even if it's pointless.
 She walks in beauty if by Ursulat Wittanov 
 shocks that is a sleep to me.
 Once upon a black void.
 No sound.
 Nothing to make a quaint and curious volume of the words await another voice.
 And to be wish'd.
 I desire to master,
 though it when I say.
 Falling,
 freely falling,
 I digress.
 It’s a worse mistake.
 Recoil in fear,
 ‘cause this,
 it when I understand now.
I don't know about this one. It just sounds like the narrator is having an existential crisis or something. It could be an out-of-body experience, judging by, "Once upon a black void" (Wittanov, 2), and, "Falling, / freely falling" (Wittanov, 8 - 9). Imagine this:

The narrator drops into a deep sleep. All of a sudden, they feel a shock, and they are sent down into a gaping hole. Spiralling down into a sea of depression and anxiety, with no hope of escaping. They're lost in a black void, no sound can be heard, and they're falling into the empty abyss miles below. They wait for another voice, another person to speak, but to no avail. They wish to see another person, to the light at the end of the tunnel, but once again, it is to no avail. Trapped in an ocean of emotion and regret, they strongly wish to master their emotions, to take control of the tide. They want to be able to use their emotions for the greater good, rather than being enveloped by them. In a moment of epiphany, they realize their mistake, and how it is much worse now. They are taken aback by this realization, which soon turns into an epiphany, for now, they finally understand.

Or maybe I'm looking too far into it. That's probably it.
 Blessed be the windows revelation by Rices Asthman 
Drift forward,
and curious volume of another world.
On the neural ka’bah.
My light will forever shine.
Forever mock.
Forever say sorry to just click,
And the songs escape,
an end the trees look up,
And the hammock wraps me.
I'll leave this one up to you. After all, there are no wrong answers, only improvements.

Wednesday, 11 December 2019

Markov Chains

According to Wikipedia, a Markov chain is
a stochastic model describing a sequence of possible events in which the probability of each event depends only on the state attained in the previous event. In continuous-time, it is known as a Markov process. It is named after the Russian mathematician Andrey Markov
 or something. In short, this guy named Andrei Andreyevich Markov (or Markoff depending who you ask) created this probability model thing. The probability of any given event is only based on whatever directly happened before. For example:

Whiteboard example of Markov chain

From the diagram, here's what we know:
  • Event A has a 50% chance of going to B, but also a 50% chance of going to C
  • Event B has a 70% chance of going back to A, but also a 30% chance of going to D
  • Event C must go to D (100% chance)
  • Event D terminates the sequence (0% chance of going to anything)
Therefore, it is safe to say that event B can never lead to event C, and thus any sequence with B -> C is impossible.

Why do I bring this up? Well, back in August, I had an idea. What if, I could make randomly generated, but somewhat realistic sounding Christmas cards? Well, Markov chains are the solution. They are commonly used to auto-complete sentences or predict your next text, provided enough data. So, I went ahead and created a data set, a Python program, and some complicated thing called a transition matrix, and guess what? It didn't work. Not one bit.
Now, I'm not one to just accept defeat. But I could ask for help. And so I did; I called a colleague of mine proposing the idea. The plan was that she'd do the Markov chain stuff, and I'd do the formatting and creative design stuff. She, to my surprise, actually accepted the idea. So now, there are some Christmas cards, ready to send! I'll provide a link to a .zip file of all the cards, and (if I get permission) a link to a .zip file of all the source code.

Python (my attempts, and the snowflake program I made): https://1drv.ms/u/s!AuPAO--hhotYgjcCYZ8SAm3tD070?e=IPp4di
Java (courtesy of L. Nadlia): TBA