Monthly Archives: October 2010

NaNoWriMo Preparations

EDIT 11.30.2010 1938 EST | I’ve won! Expect a reflection post within the next handful of days.

For those of you who don’t know about National Novel Writing Month (NaNoWriMo), just imagine that what I’m doing isn’t part of an international “contest.”

With October coming to an end, I have quite a few things to look forward two: the end of my second exam season, the end of the semester, Thanksgiving, Halloween, a weekend. November also brings with it a new challenge, especially around my already challenging life, this year: NaNoWriMo. I’ve been writing long fiction on-and-off for five or six years, but I’ve never really finished anything meaningful (aside from No Exit [PDF]). I’ve always wanted to, but I would get sidetracked by homework, editing what I’ve written, life.

Not this year. This year, I’m officially signed up for NaNoWriMo (check out my profile HERE), a month-long sprint to write a 50,000-word novel in thirty days. Crazy? You bet, but if life was always boring then it isn’t really doing much for you anyway. I’ve known about the “contest” (I quote that, since it really is just a contest against yourself and the calendar) for a few years, but never signed up since other obligations always got in the way, or I felt that they would during November. This time, I don’t care, since I’ve basically finished my grad school applications, I only have fourteen credits, and I have a ton of free time that I just waste. Why not put those lost hours per day to use doing something productive?

I’m taking a slightly different approach than my previous failed novel attempts (and the same approach I took with No Exit) in that I’m not planning anything out beforehand. Well, almost anything, since I have two main characters more-or-less fleshed out and a general idea of how the novel will start (and end, in some regards), so I’m not going into it completely blind. I also have a few ideas for some encounters, just because I think it be cool to write those events. Other than that, I’m letting my frantic typing carry the story through the 2,592,000 available seconds.

For those of you also planning on pecking out 50k words this November and want a writing buddy though the interwebs, add ME as a buddy. You can also find some basic info about my planned novel there as well and track my progress. Also, since I plan on having my only writing be for the novel (and homework…), I won’t be posting here until December. I do plan on having a daily word-count posted on my Twitter account every day of November, plus whatever else I decide to include, so follow me there if you’re interested.

See you in December!

Advertisements

netJina and Grad School Applications

This past Monday, I had my most recent meeting with Doc Brown about my Astrophysics senior thesis, which went well for a handful of reasons. From now on, what I’m doing for the research will actually be relevant for the final project. No more will I simply be just reading and learning things to get up to speed; I’ve actually started programming for the final project! But, before I get ahead of myself, let’s go over what happened:

gfortran was fixed…
After e-mailing my advisor to set up the meeting, he told me to grab the most recently updated files through the svn, read through them quickly, then compile them to make sure things worked right (just a ./clean and ./make_all to do everything). So, that’s what I did, but I got an error return during the make. I e-mailed him back soon after, and he said that I just needed to update my compiler (I think I was using gfortran 4.2 or 4.3), which I then set out to do. Note that this is all happening on Saturday, which I was thankful that he sent responses so quickly. For the next four hours, I scoured the interblags trying to download and install gfortran 4.6, the most recently released version. Nothing worked, and I got so frustrated that I decided to re-use my startup disk and clear out the bad files that had invariably started to litter my laptop. Come Sunday afternoon, I bit the bullet and stuck with gfortran 4.5 and hoped it would be fine. Thankfully, I could compile files again (something I had lost during the fiasco the day before), but I was getting a different error message back.

So, come the meeting on Monday, Doc Brown checked the error return and figured it out (he was actually using gfortran 4.4, so I didn’t necessarily need to waste all of that time on Saturday). The was actually an “error” in the ./clean command, since one of the directories wasn’t getting cleaned properly. I put that in quotes since it wasn’t an error, really; the command just didn’t clean that directory since the programmer didn’t want to have that directory cleaned. With that, frustration number one was gone, and I felt grateful that it both worked and that it wasn’t my fault it wasn’t working before.

…I’m actually writing the driver program now…
Once the world was in order, and the test (right) was successful, we started talking about the meat of the project: programming the driver program to run through the r-process! We went through the test_burn.f file just so he could explain a few weird points, I asked questions and understood what was going on, then we discussed a bunch of things related to the project. I’ll be writing two/three tester programs first, just to include the weaklib routines and try out a few different starting values, but my final project will be largely similar to the programs I’m writing now. He also pointed me toward a paper from a few years back to read during my programming to determine some start values and get an overview of an actual application of what I’m doing.

…and I have one reference letter lined up!
Finally, once things were said and done, and I was well-informed on my next steps in my senior thesis, I asked the question that was in the back of my mind for the last month or two: would you be able to write a reference letter for my grad school applications for me? Almost immediately he responded yes, which was a great confidence boost and an amazing way to start the week off. I just had to send him some files (statement of purpose, c.v., etc.) to help him write it, which I compiled and sent out earlier today. I’m just glad that I have one letter set, so I just need two more (I’ve e-mailed one prospect, and I’m going to try to catch one of the others tomorrow or Monday, but if not he’ll get an e-mail as well).

The meeting couldn’t have gone better, at least for the point I am right now. I’m just glad that one stressor has been removed from my life, so things should go much more smoothly now…

Prime Python Philanthropy

With each passing day, I realize that I love programming more an more. Part of it comes from the fact that every line of code is a little puzzle: how it interacts with other lines, itself, variables, functions elsewhere in the code, etc. Getting everything to work together is such an accomplishment, something akin to (at least for me) finishing a race, winning a game, or doing well on an exam. I take almost any opportunity to program, even if it’s just a few short lines to decide what to eat for dinner.

Recently, I’ve been helping a few of my friends with their Python homework for CSE 231. I never took the course, my roommate took it last semester, but we both just like flexing our programming muscles every now and again. We are both in a programming course right now (him in CSE 232, me in MTH 451), but just going back and writing little Python programs is always fun. Today, I wrote a short bit of code that added two binary numbers via string manipulation: completely unnecessary in the real world, but fun to program in its own right.

Of course, my own programming homework is always more difficult than what the CSE 231 homework is. This week, for instance, we needed to write three functions to solve a system of linear equations using three different Gaussian elimination schemes (no pivoting, partial pivoting, and scaled partial pivoting). My first stab at it did not go well, since I started with the actual numerical solving schemes than tackling the machinery underneath. After fusing around for a while, I scrapped it and started fresh, first writing basic matrix manipulation functions (switch rows, multiply row by a constant, etc.), then gradually moved up to actually solving the equations.

# Matrix manipulation functions
def exchange_rows(A, i, j):
  A[i], A[j] = A[j], A[i]
  return A

def multiply_row(A, i, mult):
  for q in xrange(len(A[i])):
    A[i][q] = A[i][q]*mult
  return A

def add_rows(A, i, j):
  for q in xrange(len(A[i])):
    A[j][q] = A[j][q] + A[i][q]
  return A

# Pivot Checking
def check_pivot(A, i):
  if A[i][i] == 0:
    A = exchange_rows(A, i, i+1)
  else:
    pass
  return A

# Generic entry elimination functions
def forward_substitution(A, i):
  A = multiply_row(A, i, 1/float(A[i][i]))
  for q in xrange(i+1, len(A)):
    if A[q][i] != 0:
      mult = -1.0*float(A[q][i])
      A = multiply_row(A, i, mult)
      A = add_rows(A, i, q)
      A = multiply_row(A, i, 1.0/mult)
    else:
      pass
  return A

def backward_substitution(A, i):
  for q in xrange(i, 0, -1):
    if A[q-1][i] != 0:
      mult = -1.0*float(A[q-1][i])
      A = multiply_row(A, i, mult)
      A = add_rows(A, i, q-1)
      A = multiply_row(A, i, 1.0/mult)
    else:
      pass
  return A

# Three solver methods
def gauss_np(A):
  for index in xrange(len(A)):
    A = check_pivot(A, index)
    A = forward_substitution(A, index)
  for index in xrange(len(A)-1, -1, -1):
    A = backward_substitution(A, index)
  return A

def gauss_pp(A):
  startrow = 0
  for index in xrange(startrow, len(A)):
    maxindex = 0
    maxvalue = 1
    for i in xrange(index, len(A)):
      if A[i][index] > maxvalue:
        maxindex = i
        maxvalue = A[i][index]
    A = exchange_rows(A, index, maxindex)
    A = forward_substitution(A, index)
    startrow += 1
  for index in xrange(len(A)-1, -1, -1):
    A = backward_substitution(A, index)
  return A

def gauss_spp(A):
  list = []
  for j in xrange(len(A)):
    maxvalue = -1000
    for i in xrange(len(A[0])-1):
      if A[j][i] > maxvalue:
        maxvalue = A[j][i]
    list.append(maxvalue)
  for index in xrange(len(A)):
    temp = list
    for i in xrange(len(temp)):
      temp[i] = abs(A[i][index]) / float(temp[i])
    max = 0
    ind = i
    for i in xrange(index, len(temp)):
      if temp[i] > max:
        max = temp[i]
        ind = i
    temp[index], temp[i] = temp[i], temp[index]
    A = exchange_rows(A, index, i)
    A = forward_substitution(A, index)
  for index in xrange(len(A)-1, -1, -1):
    A = backward_substitution(A, index)
  return A

# Main function commands
def grab_input():
  A = input("Input Matrix A: ")
  b = input("Input Vector b: ")
  option = raw_input("(1-Gaussian, no pivot : 2-Gaussian, partial pivot : Gaussian, scaled partial pivot)\nSelect Solving Method: ")
  if len(b) != len(A[0]):
    print "Matrix/Vector dimensions mismatched."
    A = "1"
  return A, b, option

def prep_matrix(A, b):
  for q in xrange(len(A)):
    A[q].append(b[q])
  return A

def solve_function(A, option):
  if option == "1":
    A = gauss_np(A)
  elif option == "2":
    A = gauss_pp(A)
  elif option == "3":
    A = gauss_spp(A)
  return A

def grab_solution(A):
  x = []
  for q in xrange(len(A)):
    x.append(A[q][-1])
  return x

def main():
  A, b, option = grab_input()
  A = prep_matrix(A, b)
  A = solve_function(A, option)
  x = grab_solution(A)
  print x

if __name__ == "__main__":
  main()

For the solver functions, I wrote gauss_np(), then gauss_pp(), then gauss_spp(). You can kind of tell that order since the latter ones are way less elegant than the rest of the code. I guess that happens after fusing with the program for a few hours straight, but at the same time I enjoyed trying to track down those little bugs and index errors and what-not that crept in while typing the commands.

It’s a scavenger hunt, academic contest, tabletop puzzle, and basketball game all rolled into one!