How Genetic Algorithms work using Hamlet as an Example

Hi!

I’ve officially run out of blog topics, so I’m going to expand upon Aarav’s (hi Aarav) blog about Genetic algorithms (we are on the same software engineering team, so I think this is alright!)

It’s also been awhile since his blog, and we’ve had to rework a lot of how our code works. 

Let’s start from the very beginning!

We have this really great spreadsheet that helps us to read data in. You can see it below:

We pretty much process all of this data into our code, and save it for later. 

After that’s done we need to make a bunch of really bad schedules (the initial generation, think Mendel’s original green and white pea plants), this is where we start with. Basically, we just have to put together 8 lists of room/teacher/class assignments (that makes one schedule, since each list represents a class period, multiplied by 8 makes a full day). Let’s say we have 100 of these to start out. 

Something we’ve improved from last time was the schedules we generate are actually possible schedules! That doesn’t sound super good, but our old code used to stick random teachers with random classes (think of Ms. Hitzeman teaching Software Engineering  – sorry Ms. Hitzeman :)). Now, we start all of our schedules off on the right foot. 

Any time we’re making a new schedule, we have a lot of “Teacher” objects: think various versions of Hamlet. We know each version of Hamlet has a super dramatic “To be or not to be” speech, weird dynamics between Hamlet and Gertrude, along with many other similarities. 

Like each version of Hamlet, where each is different but all have constant ideas/people/scenes, each “Teacher” object has a designated “Class” they teach, as well as a designated “Room” they teach that class in. Since we’d rather not store these values for every teacher for every period manually, we have two lists that hold these values. 

We have a class_list variable, think of it like Hamlet’s revenge checklist. He must talk to Horatio, out Claudius as a killer with the players, kill Polonius, and fence with Laertes. Similarly, each teacher object contains a list like this: [AP Lit, 2, Ap Lit, Lunch, 5, 6, 7, 8]. These hold class data for us. 

Next, we have to make changes to make better schedules. For example, while Ms. Hitzeman could teach 8 classes every single day, that probably isn’t good or healthy for her – so by randomly replacing teachers/classes/rooms between schedules, we can slightly alter how each schedule works (theoretically if we do this enough, combined with the next two steps, we’ll get a good schedule).

Now we have a bunch of mutated schedules, we need to get rid of the bad ones and add new ones! 

Think of making schedules like a AP Lit Hamlet Academic discussion: while we can have 20 people talk for the entire period, what they contribute to the conversation will probably decrease over time. So if we swap out the old people (delete a bad schedule) and sub in a fresh perspective (generating another schedule) then we can keep the very insightful Hamlet discussion going. 

After we do this, we’ve successfully progressed a single generation! If we go back to the AP lit discussion, let’s say that’s one period of discussion. (For the example to work let’s pretend people get carried over from period to period). 

I’m in second period, so let’s say we bring in the 3rd period kids. They’re all new and have great things to add to our conversation! So by progressing to another generation, where we repeat the previous 5-10 steps, we continue talking about how random Hamlet sometimes is and definitely how heroic Horatio is – all while a function is checking to see if we’ve reached a good schedule (think Ms. Hitzeman writing notes until someone finally arrives to the most insightful thing to discuss about Hamlet ever). 

We rinse and repeat for maybe 1000 generations (that would be a lot of AP discussions!), and once we’ve finally reached a good schedule, we save it and output it! 

Some other cool parts about our genetic algorithm: 

This is our super technologically advanced and modernly designed home page!!! Made by the illustrious Jonathan Qunell. Very cool I know. This site is just set up so the teacher who would want to generate schedules simply inputs the values into the spreadsheet I showed above, uploads it through upload data, then can create a schedule using that data, and finally can view any old schedules generated. 

Thanks for reading! I hope this provides some much-needed insight into Hamlet quantified programming.

-Max

Cruise! 

This spring break I went on a cruise with my family! I’m going to talk about my adventures. 

It was a 7-day cruise leaving from Galveston, TX. We were going to 3 ports, two in Mexico and one in Honduras. We had to get up at 3 AM to make the one-day drive! 

Luckily I had a ton of work that night, so I just worked through the night and slept in the car. 

I don’t know about you, but I’m really not a fan of road trips. The constant bumpy movements, music that’s either too loud or just loud enough to be annoying, and the heat from the sun creates a pretty bad travel environment, especially in a super limited space like the car backseat. 

My agenda items for the road trip: Survive without getting super headachey, read a couple of books, and recover my sleep. 

We arrived in Houston at 9:48 pm, 12 minutes before the restaurant where our dinner was waiting for us. We got a couple of pounds of seafood boil, which was super tasty after the extremely long road trip. Unfortunately, I have no pictures! 

The next morning we drove 2 hours to Galveston and boarded our cruise. I expected the security process to be long and tedious, but it took about an hour and then we were on the ship! Since we dropped off our luggage we made our way to one of the three dining rooms available at the time and had some really good shrimp and beef tenderloin (picture below). 

After lunch, we went to check out the ship! Somehow instead of exploring the main exciting areas of the boat, like the buffet or the pools, we went to the very top and got locked out (since staff didn’t think people would go right to deck 19), and had to get let back in by a staff member. 

For the first few days of the cruise, when we were at sea, my days looked a lot like this:

I totally didn’t finish my voices novel in 2 days……

While I’m super carsick, boats are surprisingly not bad at all, 90% of the time it felt like we were on land. Which I guess is lucky for me – most of my family was hit pretty hard with seasickness. 

These days at sea I also told myself I would do the onboard activities – so between ping pong tournaments, culinary demonstrations, and origami classes, I got to meet a lot of shipmates. 

Do you know how most cruise ships have stores you can shop at? I never thought I’d spend my time in any of these – but low and behold I spent almost as much time in the jewelry store as I did the buffet. 

There’s a good reason, however! They were giving out these charms – most were related to our actual cruise (a ship wheel with our cruise line’s logo, the ports we visited). 

As a joke, I told my family that we should collect all 6-7 charms that were spaced out over the cruise… everyone picked up on it and it became our daily tradition for a week to go collect our charm things. 

Once we got to the ports the cruise was super fun! Not only did we have the same great cruise amenities, but there was also an entire port to explore (not to mention the ship was completely still – for some reason the restaurants would be super rocky even though the rest of the ship was good. 

POV my dad in Cozumel (or was it Costa Maya? One of the two).

Since my sister was taking this week off from school (even though she still had classes) we only visited each port for a couple of hours, especially since there really wasn’t that much to do besides buy super touristy stuff or lie on the beach. 

After the 3 sea days, we had three port days, each in a new destination. Our schedule every day would pretty much be waking up at 7, getting breakfast then start exploring the port at 8. At about 10 we’d either 1) Exhaust what each destination had or 2) Get really hot with the sun beating down. We’d return to the ship at about 11 and have a good 4 hours with all the cruise amenities to ourselves. That was super nice! 

Overall I really enjoyed my cruise! Was a great way to refresh after January, Feb, and March. I would definitely make it a spring break tradition – it’s like a normal vacation except you don’t have to worry about transportation, food, hotels, entertainment,   and a bunch of other great things. 

-Max 

 

From Film to Photos the Old Fashioned Way

This semester I’m taking Photography 1, initially for the Fine Arts credit, but a few weeks in the class has been super rewarding and fun! While at first, I cursed my choice to pick Traditional Photography over Digital, (as one is much more tedious than the other), I’ve found the experience of developing film into photographs super fascinating. (I’ve also been doing it for a month straight so I think I can provide a valid description!). 

The Process:

First, we need light-sensitive film, as well as a camera. I’ll have to talk about taking pictures with film some other time, that process also takes a bit of time to understand! 

Yet once we have our film, we can take it out of our camera in a little metal canister and place it into our changing bag (picture below). Since the film is light sensitive, we can’t just open our film canister in a bright room, because it’ll overexpose our images and we’ll end up with completely white pictures. Thus, the dark bag allows us to load our film for development. 

Ever try to walk around a hotel room at night with the lights off? That’s pretty much how it feels to use a changing bag. You have to 1) open up the film canister with a can opener, 2) pull out the film roll and trim it to size with scissors, 3) load it onto the white rolls (depicted above) 4) place all of that into the gray colored film developer tank, and 5) lock in the funnel and lid on the tank. And you have to do all of that without being able to look at what you’re doing. 

This video (https://www.youtube.com/watch?v=H3h8WT9GjbM) explains it much better than I can!

Basically, it’s a lot of physical fumbling that you have to do without being able to see anything. 

It’s also super stressful to do! Since the developing process takes 30 or so minutes, and you have to do it all in one class period, you have to figure out the previous 5 steps in about 10 minutes. 

Once we have our film loaded into the gray tank, we can start developing! The process is quite a lengthy one, I’ll detail it below. 

  1. We need to rinse our film to prepare it for all of the chemicals and help to remove some of the silver crystals that make the film light-sensitive. We soak the film for 30 seconds in water, then pour it out. 
  2. We now need to develop our film! After taking a picture there is a latent image on the film that we need to expose. There are a bunch of chemicals that we don’t really cover, but basically, we take 10 ounces of magical mysterious Developer chemical and alternate between soaking the film in the chemical or agitating it by shaking the container. 
  3. Now we pour the chemicals out, rinse for 30 seconds again, and pour the “Fixer” chemical into the tank. Basically, our image is developed and visible, yet the image is still light-sensitive. Since we want to see the image in light, we have to “fix” the image, basically freeze it onto the film. 
  4. After much agitation, and then pouring the chemicals out, we have to stop the fixer chemicals from eating away at the film by washing it in water for 10 minutes. 
  5. Last step! Our film is wet, so we have to let it dry. Yet drying it right now would leave a bunch of watermarks on our film. So we have to submerge our newly developed film into a photography flo chemical that helps with the water drying. 

After you wait for a day, your film looks like this! (below)

This is pretty fun because this is the first time you can see what your photos look like after originally taking the pictures! Usually, my pictures look pretty blurry, but I’m always surprised.

Now we just have to cut the film into 5 picture strips (as the original film is a 25-picture strip). Then we place it into one of those clear plastic sleeves so we can safely store our negatives for future use. 

Next week, I’ll describe the process to take our newly developed film into creating an actual photograph (that’s 8.5 x 11 instead of a tiny rectangle of the film). 

Included below is my recent photography lab! We had to photograph an object, and I chose this origami cube puzzle because I thought it would look good with shadows. I’ll explain how we mounted the image to a black background later on. 


Thanks so much!

-Max

 

 

Poetry Difficulty Essay Blog

I’ve always wanted to do an in-depth read of an Edgar Allan Poe poem after watching videos like TedEd’s piece on Poe: https://youtu.be/8lgg-pVjOok, as well as Buzzfeed Unsolved’s video on analyzing his death: https://youtu.be/y4DTW4B3Sjs

I settled on his piece “The Haunted Palace” due to it’s more convoluted tone, alongside the fairly complex yet descriptive diction, as it would make a challenging read. When reading through, I found my best approach to understanding the poem was to go line by line, stanza by stanza, then finally piecing it all together, so I’ll structure my blog in a similar way! You can find the poem here: https://www.poetryfoundation.org/poems/52370/the-haunted-palace, and I’ll be showing the particular parts of the poem as I discuss them. 

The poem opens with this image of luscious green valleys stretching for miles, and immediately starts with words like “tenanted” “seraph” and “pinion”. Through admittedly a lot of dictionary searches, my interpretation of this first stanza is setting the scene for the rest of the work: on top of this picturesque, angel-owned landscape (due to tenanted meaning to own property or land like modern day tenants) there is a bright palace that even angels haven’t flew/been to (as seraphs refer to angels, and a pinion is a special feather used for flight). This puts us, the reader, into this almost dreamlike world with a palace that even angels don’t visit to disrupt the landscape. 

One especially tricky part about this passage is the line “In the monarch Thought’s dominion”, where we learn that this palace is controlled by a monarch. Yet the wording at first is unclear here: is “Thought” the monarch? Or is it the concept of “Thought” that allows this palace to exist, inside of one’s mind? Mulling it over, I found that the name of “Thought” would be pretty arbitrary out of all the possible names Poe could’ve chose, leading me to believe in the second interpretation, that this palace is not truly a location somewhere, but an idea in one’s mind. Technically, we could say that the monarch named “Thought” does control this palace, as the castle is at the whims of one’s imagination. As the poem progresses, we can piece together what this means for Poe’s intentions of the work. 

Continuing on, this next paragraph describes the “palace” itself, ironic since we just discerned that this palace is controlled by one’s imagination, so it is fluid in nature and not fixed to one particular look.  While a lot of descriptions, Poe continues with flight metaphors, where he states “Along the ramparts plumed and pallid” (Poe 15). While initially it sounds like the entire palace is decorated, pallid has a meaning closer to pale – where we can understand that Poe sees this palace as heavily decorated, yet pale and almost fake looking. Digging deeper, this palace isn’t the magnificent place we initially thought, the edges of this mental picture are less refined (like the pale ramparts), much like our own thoughts. 

This next stanza is definitely my favorite in the entire piece! While the line about luminous windows seems like a simple description of the palace architecture, I found the logic to not make sense. Mainly due to the fact that “wanders” wouldn’t see the palace inside from the outside (we know the “windows” separate the wanders and palace interior due to the descriptions of the monarch’s throne). 

Instead, using our earlier approach that this palace only exists in imagination, it makes more sense for these “windows” to not be windows at all, but rather 2 eyes. When we imagine, we close our eyes, and open “windows” into imaginary thoughts. 

While the imagination approach makes more sense than the literal representation, I did want to point out a confusing part of this stanza I had to work through: the word “Porphyrogene”. Apparently this word literally means “to be born in purple”, calling back to roman royalty wear colored purple due to the cost of purple silk at the time. Using the literal interpretation, Poe hints at how this palace isn’t as pristine as we initially think. 

This stanza contains one point I want to note further that helps us understand this poem, in the first line. We hear about all of this pearl and ruby that glows, either due to 1) manual shining/polishing or 2) some sort of ethereal glowing quality. While either interpretation leads to a plausible conclusion, I believe the latter conclusion makes more sense with what we’ve been discussing. 

In summary, Poe’s use of describing thoughts through this imaginary palace challenges us to think with vivid imagery.

I put in the rest of the poem below, for your enjoyment. Thanks for reading!

 

-Max

 

How to Name Organic Molecules

First blog of 2023! 

Diverging from technology, I’d like to discuss a bit of chemistry today. Having taken Advanced Chem last semester (and not knowing what I can write 750 words about), I figured describing the very convoluted and backward way organic chemists name molecules would be a great thing to do. 

Before we start, there are a few prefixes that you need to know: 

Here, Meth- means 1, eth- means 2, prop- means 3, so and so forth. 

Let’s start with the most basic molecules, Alkanes. These are single bonded Carbon molecules. Not bad!

Here’s an example below:

C’s denote carbons. Now how do we name this molecule?

We simply count up the amount of carbons (here there are 5), find the corresponding prefix from our handy chart (in this case pent-), and simply add the suffix -ane since this is an Alkane molecule (single bonds connecting the carbons, seen above by the single dashes), this molecule is pentane. 

That wasn’t bad! But a majority of molecules have branches of either carbon chains (like what we see above), or different elements. 

Here is a slightly harder molecule: 

I’ll explain the Iodine (I) and bromine (Br) seen here. There are a few molecules that are often attached to these carbon molecules, which we denote with the prefix Iodo- for iodine, bromo- for bromine, fluoro- for fluorine, etc. Since this molecule is more than just a simple chain, we need to order our branches. 

We start ordering from the end with the closest branch. Since with this molecule, either end has a Iodo- molecule or a bromo-molecule 1 carbon in, this is a tie and results in us using the very backwards approach organic chemists take to order these molecules: going by the alphabet

Which letter comes first, I (like iodo-) or B (like bromo)? Bromo, so we start ordering our molecule from that end. So from right to left, we name each carbon with a number, starting with 1, then 2, then 3, then 4, up to 6. 

Lastly, we have a carbon branch. Referring to our table, this is a single carbon, so it should start with the prefix Meth-. Since it’s a branch, we end it with -yl, so we call this branch methyl. 

Now taking all those parts together, we have our right to left ordered carbon, bromo, iodo, and methyl branches, now it’s time to name! Here’s a picture below, with the carbons ordered and the branches circled. 

Again, going by the alphabet, we name the branches before the base molecule, so bromo, iodo, then methyl. 

Bromine is attached to the second carbon, so we name this branch as 2-bromo. Iodine is attached to the 5th carbon, so we name it as 5-iodo. (Note here, while the methyl is the next molecule we should name, organic chemists chose to do it alphabetically so we have to name the iodine branch first!). Lastly, we have the methyl branch, attached to the 3rd carbon, so we call it 3-methyl. 

Finally, since we have 6 carbons, consulting our handy chart this works out to be hex- as a prefix, so hexane as the base chain of 6 molecules. 

Put it all together, and this molecule is 2-bromo 5-iodo 3-methyl hexane. 

Nice! We can name linear molecules, but what about circular ones? 

Here’s a more complex molecule. Note how the red donut of 5 carbons are connected to each other in a circular fashion. Since they are this way, we add the prefix cyclo- to the ending bit of the molecule. Since this central (red) ring of carbons contains 5 of them, referring to our table this molecule should have pent- in it. Furthermore, we can see the “bonds” or lines around the 4 o’clock region of the molecule are double instead of single, this denotes a double bond, which would mean this molecule is an alkene, slightly different from the Alkanes we named earlier. This means the molecule above would end with the conventions cyclopentene

Onto ordering the carbons! We found with the previous molecule that we need to order the carbon order so that the branches are in the right places. Since this is a alkene, we must start at a double bond (more organic chemistry backwardness). Yet do we name our carbons clockwise or counterclockwise? 

It turns out here that we should follow the red number order, since each way you start naming you name a branch on the 3rd carbon. Since the E in Ethyl comes before the F in fluoro, we name with the red numbers. 

All in all, this makes the molecule 3-ethyl 5-flouro 4-iodo cyclopentene. 

Here’s Mrs. Brucker’s youtube channel for further information: https://www.youtube.com/watch?v=GJVvOixr–c&list=PLQAytuMyLyMVTdfLoCTSCEsGr6Qb46OMs. She is infinitely better than me at teaching this material!

-Max