Wednesday, January 9, 2013

Python Script for Transposing a Table in LaTeX

Sometimes you gotta try transposing a table in LaTeX, just to see if it looks better. It probably doesn't, but you gotta try. And it's a nasty job to be doing that by hand.

Try this:
(Download the .py file to keep that indentation right!)


#LaTeX table transpose
#Peter Raffensperger
#9 Jan 2012

import numpy

x = r"""
\hline
a & b & c & d & e\\
\hline
f & g & h & i & j \\
k & l & m & n & o \\
"""

x = x.replace(r'\hline', '')
tableRows = x.split(r'\\')
table = None
for i, t in enumerate(tableRows):
if t != '\n':
if table is None:
table = numpy.array(t.split('&'))
else:
table = numpy.vstack((table, numpy.array(t.split('&'))))

tableTrans = table.T.tolist()

tNew = ''
for row in tableTrans:
for col in row:
tNew += col.strip() + ' & '
tNew = tNew[:-2] + r' \\' + '\n'
print tNew

Saturday, January 5, 2013

Archimedes' War Machine


Archimedes entered the darkened room where the sibyl of the Oracle at Delphi sat on her tripod seat. He heard the woman raving as the priests translated the words of the prophetic god Apollo:
...
To wit, every single one.

If you count successive
Letters in Russian prose
Observe the likelihood
Of this one after that
Now then you find indeed
That the law of large sums
Generalises to
Those sequences that are
History dependent
...

"Which great future thinker sayeth these fell things?" Archimedes asked the chief priest.

"One Andrey Andreyevich Markov of Ryazan. But seek you now occulted things, things other than the deep knowledge of statistics, probability and history-dependent sequences?"

"Forsooth, I do seek! I must devise a war machine to defend Syracuse. Summon me one yet born, who knows things of strategy, of intrigue and complexity, and of those black things yet to be named that teach a nave the ways of bloodshed, revenge and violence."

The chief priest's eyes darkened. The smoke rising from the crack in the floor thinned. The sibyl of oracle abruptly stopped her babbling. The translating priests stopped on syllable four of the hexameter, interrupting their poetic description of the foundation of 20th century statistics.
This implies that ...

The smoke, raving, and translations then began anew:
Here you are, a spirit
Of trouble and deceit
Wars are fought on his guile
And nobles fall without
His counsel; So now heed:

I am John Forbes Nash two
The son of John Nash one
A mathematician,
And a man of great vice
But I have what you seek!

Calculate you must, the
Von Neumann-Morgenstern
Utility functions
For each of the players
To know his value for
Each possible outcome!

Then, we define a point
In the space of player
Strategies and vices:
The equilibrium!
At this magical point
No player can ever
Improve his lonely lot
By changing his vile plan
Without another's grace!

Find ye this fabled point
Of assured destruction
And act, fight, now defend!
You can do nothing more
If your enemy knows
What truly is in store

But evil, evil woe!
Beware exam marking!
Bad undergraduates
Always make undue haste
When writing their answers,
Filling reams upon reams
With poorly reasoned crap
And demonic scribbles
... 

Another brave man came to the oracle to make an inquiry about x-ray computed tomography, so the chief priest shuffled Archimedes off on his way. "But how?" inquired Archimedes, "How can I calculate your equilibrium point?" But the sibyl of the oracle silenced the soul of John F. Nash Jr and started the processing of summoning the soul of Professor R. H. T. Bates.

Thursday, December 20, 2012

Beatshifting remix stems


Earlier today, I explained how I created a remix. In the tradition of open source music, I'm giving away the remix stems for Beatshifting, so that you can try remixing it yourself!

Download the Beatshifting remix stems! 

They're free -- licensed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license.

Just for reference, here's the original song:



And my remix:




The Creation of Beatshifting (re-shifted)



To give you a little insight into the underlying creative process I'll highlight some of the coolest things I did on this remix of my own song.

  • Use Ableton Live to deconstruct the original song into its component sections. Merge similar tracks from the original into a smaller set of remix stems. 
  • Study The Glitch Mob's music and become entranced by their use of selective silences to create spooky rhythmic effects. Take this idea totally overboard to create rhythms that as awkward as Napoleon Dynamite by routing some of your tracks into the "Gator" track which has a clips to automate muting of your submix in a rhythmic way.
  • Record your own percussion instrument samples and apply the stochastic music principles pioneered by Iannis Xenakis to create a custom music digital instrument in Kontakt to add randomized chaotic musical noise to your remix.
  • Use Ableton Live's Beat Repeat to sound like every other kid sitting in his bedroom making a remix with Ableton Live in the 2010's. Also automate a low pass filter to get that sweet 'whole-mix filtered' sound.
  • Use the built-in OSX voice to create custom robot lady voice samples, from the terminal.
  • Map a variety of strange percussion sounds to your Launchpad and add mad finger-drumming to your remix.
  • Use Processing to create song art by algorithmically kit-bashing fonts together, blending sections of letters to create a smooth transition between two words.

  • Write a blog post about the process so that your audience can enjoy a full multi-media experience. And so that you can be a pretentious stuck-up geek.

Tuesday, December 18, 2012

Why Looking for a Job is Fundamentally Demoralising


Looking for a job begets misery because job hunters face brutal free-market competition, the expected time until employment is constant even if a hunter has been unemployed for a long time, and getting a good job means turning down adequate jobs. Ultimately, I aim to encourage my fellow job seekers by helping them to understand their predicament more clearly so they take the bad aspects less personally.

Many people find that looking for a job is a long, frustrating process. No, duh. I'm not here to talk about the beaten-path reasons for why job hunting sucks, I want to convince you that job hunting is fundamentally demoralising. Why?

1) You are un-jacked from The Matrix. Welcome to the real world of free-market competition. At school, or in your last job, someone was telling you what to do so that you could add value to yourself. Now you have to show someone else how you can add value to them. You are truly master of your own destiny. You feel the full weight of your freedom, but also the opposing force of everyone else's freedom.

2) Finding a job can take forever. Think about it like this: you either have a job or you don't. Each day you actively look for a job, there's a chance you might get a ready-to-sign offer. That chance is the same, regardless of how long you've been looking. So the length of your periods unemployment are drawn from Poisson distribution. (A better model would be that they're fractally distributed; read about Black Swan theory.) This has horrible psychological implications because you seem to be making no progress while facing a constant flow of rejection. But, while we're breaking illusions, the rejection is not personal. Employers aren't looking to objectively evaluate prospective employees, they're just trying to find ones that they like without doing much work themselves. Read Paul Graham's essay on judgement.

3) Getting a good job requires reckless bravery. Different job offers have different values to you. You're probably looking for more value than a job at McDonalds, so you might reject some jobs. Some of those jobs would be good enough. But you're trying to do what you love
not just survive. Read Paul Graham's essay on doing what you love. So you have to voluntarily stay unemployed until you get that amazing job offer that you can't refuse. It takes guts to do that.

Misery is in the very essence of the job hunt process. Once you realise that, hopefully you will view your search in a different light. You're not a loser, you're just facing self-interested employers in the free market. Don't give up, you get out of the unemployment rut not by searching for a fixed time but by getting just one lucky break. Be brave, you might just have to turn down an offer. To get practical help on finding a job, read the excellent book by Richard Bolles, "What Colour is Your Parachute?"