EPGY 2013 Artifical Intelligence Project – Algorithmic Music Composition Demo

Above is a demo of the project I worked on while at Stanford’s EPGY Artifical Intelligence program. My project proposal was in one of my previous blog posts (https://evanjkatz.wordpress.com/2013/07/26/project-abstract/), so if you are interested in learning about how it works check it out. I hope to work on this project in the future so it can be expanded to have a lot more features; right now I’m having to hard-code the key changes in the piece which limits what kind of output i’m getting, so that would be the first thing to work on. Hope you guys like it.

‘Her’ – An upcoming film involving Artificial Intelligence

Her, a movie that is set to revolve around the life of a man and his artifically intelligent smartphone, is sure to be interesting to watch. It seems that the main conflict in the movie is the set of ethical implications brought on by ‘dating’ an AI-based operating system and how the main character, played by Joaquin Phoenix, deals with them. I bring this movie up because it directly relates to one of my past posts discussing the ethics of AI. https://evanjkatz.wordpress.com/2013/07/17/ethical-considerations-of-ai-programming/

Though I’m sure this will be a great movie (Joaquin Phoenix is fantastic and the plot is definitely eye-catching), it’s going to show the world the ethical issues with artifical intelligence; namely, can AI ‘go too far’? Is it socially acceptable for someone to develop a loving relationship with a computer? And does Samantha, the name of the female operating system, actually have deep emotions for the main character? I would like to talk about the last of the previously mentioned issues. When considering these problems it is advantageous to take a look at what we know about artificial intelligence now and how it is increasingly pervading our society. What people know about AI who study AI is that it is very hard to program emotions. What a lot of AI (in terms of programming for emotions) programming is now is trying to make the computer simulate how to react to certain stimuli. One could say that’s how humans act, but is that really the case? Humans are very complex creatures; one’s emotions come from so much more than how the average joe would respond to something. They come from their current mood, their past experiences, their relationships with others, and much more. So it does not seem like a computer would actually be able to develop a complex relationship with someone. And if the user is able to be deceived into thinking the computer actually has human emotions, would they not be the emotions of the programmer as it were his or her thoughts on how to act in certain situations that were going into the code?

Her will likely present viewers with very intriguing insight as to how AI can develop in the future. But it will also show the ethical considerations that exist among user-AI interactions. It will be interesting to see how the director feels about such a controversial issue.

EPGY Artificial Intelligence Recap

The past 3 weeks at Stanford have been some of the best weeks i’ve ever spent during any summer. They’ve been filled with tons of good memories, fun programming (and blogging) sessions, and great lectures from our teacher Sherol Chen. I’m really glad I got the opportunity to come to Stanford for this program and I’ll definitely keep these memories for the years to come.


First day of EPGY. I’m the guy in the white shirt closest to the camera!


Lock/Metaphor/Life-Lesson-Teaching exercise. Trying to figure out a combination written in Chinese is pretty difficult.


Momchil (the Bulgarian Beast)’s induction proof. Probably the best mathematician in our class.


Craig Reynold’s live lecture near the end of the session. We were lucky to have such a smart and nice guy come talk to us. Great presentation.


Brian our RA (guy in the green) talking to us about the realities of college life. Thanks B-Ry.


Group picture in front of the California Academy of Science Museum. Really fun trip and a really great group of people (too bad we couldn’t get our teacher in the picture). Thanks for a great 3 weeks!

Dilemmas of Open Source Software



When I think about open source software, a thought pops into my mind. It’s not economical. Let me explain why.

Reading the famous Bill Gates letter to the open source community (http://upload.wikimedia.org/wikipedia/commons/1/14/Bill_Gates_Letter_to_Hobbyists.jpg) has helped me formulate my opinion on the issue. Take a hypothetical situation: two groups of programmers spends 2 months working on an OS. One group plans to sell theirs and the other does not. Assuming both groups are spending normal work hours (9AM – 5PM) working on their project, a lot of time is bound to be spent over the course of their project. Let’s also assume that each group’s working value is $10 an hour.

When both projects are done, one will go up for sale and the other won’t. What happens? Most likely, people will download the OS that is free, because people don’t want to spend money on something they can get free. (A similar issue arises in piracy.) Consequently, 2 issues arise. For one, a combined 640 hours of work is left unaccounted for. Neither party was paid for their work. So, assuming both parties are composed of adults, that’s a total of 640 hours of work that does not go into the economy, and the party that expected to be paid is left fruitless. For someone that was expecting a monetary compensation for their work, that can be devastating.

Additionally, the group that worked on the to-be-sold OS ends up not getting paid at all. What happens from this? Obviously that party doesn’t receive compensation for their work, but also their chances of working in the future on such projects are slim. Why spend so much time working on something that you won’t receive compensation for? There’s no reason to. And because of that, a whole group of people stops advancing the field they’re working on. In this case, the party that wanted to sell their OS would stop working on OS development and move on to something else. In a world of rapid technological advancement, that’s surely not something we as a society want to happen.

Clearly the issue with open source software is one that should receive more attention; not only with open source software, but with all projects that are vulnerable to exploitation through piracy. If such problems were solved, we would have a more progressive economy and provide more incentive to advance technological research.

Autonomy and Agency


I think autonomy and agency are very closely related. In order to have agency in the world, you have to be able to think for yourself. You have to be able to make your own decisions. Why? Because if you never make your own decisions, you’re not influencing others. You’re letting someone or something else control what you do in this world.

Sure, you can have your own opinions. But they’ll remain lodged in your head if you have no autonomy. You’ll be in a position of inferiority under your peers; a position that forces you to do what others tell you to. It’s just like being a gear in a machine. Do individual gears in a clock don’t get recognition for what they do? No. The watch gets all the fame.

To really have agency in our world you have to have autonomy. Those who think for themselves are the ones that formulate new ides. They’re the ones that create new things, the ones that run businesses, and the ones that follow their dreams because they’re not afraid to make their own decisions and create their own paths in life. The only way to make a difference in our world is to have agency, and without autonomy, you’ll have none.

Generation of Harmonic Patterns through Melody Analysis – Proposal


The purpose of this project is to create a program that will take a melody as an input and create various harmony and bass lines that fit the melody according to music theory principles. Programming will be done in Java and music output will be performed through the java.sound.midi package. The goal is to be able to create a multi-part song from a simple melody.


While algorithmic music composition is not a new field of study in terms of specialized fields of computer science, it is certainly not one of the more popular fields. Algorithmic music composition entails the ability to create music either using solely a computer program or with the assistance of a computer program. For this project, music will be created only from the software, not without any assistance. Various procedures have been used in past projects in terms of ways to randomly generate music, the most notable being Markov chains, deep learning, and analysis/imitation of pieces of music.


Most research into algorithmic music composition has gone into developing techniques to create melodies. However, my project is more centered on using algorithms to create suitable harmonies and bass lines that complement a given melody. Therefore, it will be less about random-note-generating algorithms that create single lines of music and more about using music-theory based principles in my algorithms, though the latter will be involved. The final product will ideally be able to output a fleshed out piece of music with various harmonies, a melody, and bass line. Such software would have many applications, notably as a source of inspiration for composers. Many musicians, including me, struggle with developing harmonies that can coincide with brainstormed melodies. Such a program would attempt to solve this problem, effectively nullifying a difficult part of the creative process.

Previous Work

A fair amount of work has been done in the field of algorithmic music composition, though it still has a long way to go. David Cope, a leader in algorithmic music composition, is notorious for his work in the field. A lot of his work has focused on analysis of greater known classical pieces and imitating their melodic and harmonic patterns. Such practices have led to generation of music that has been so expertly crafted, that it’s been confused with pieces created by Bach; you could say those pieces passed the ‘turing test’ of algorithmic music composition. While such a feat may not be able to be accomplished within a one week period, further development of my program could lead to big results.

Along with more serious programmers, there are some small communities that work on developing techniques to take current states of the computer and put them into notes. It’s a hard concept to describe, but it has proven to work (though it doesn’t generate the most appealing pieces of music).

Current Problems in the Area

From my research it seems that a big problem in the field of algorithmic music composition is the ability to randomly generate music that is truly appealing without using deep learning techniques; that is, analyzing works by well-known composers and imitating their music. So, it seems that truly randomized music has not been able to compare to actual composed pieces in terms of musical appeal.

Proposed Solutions

Because generating appealing music on its own is a big problem, the best place to start is by working with harmonies rather than melodies. Since musical appeal is already established in a melody, it makes more sense to build off of something that sounds good rather than building off of something random that may or may not be something the average listener is going to want to listen to. By studying the outcome of harmony generation, I might gain more insight into what techniques work for creating appealing musical progressions and could apply such techniques to melody generation.


Algorithmic music composition is a field that should catch the attention of both composers and programmers. Using software to craft musical pieces is a whole new way to think about musical composition, and while the field may scare composers who fear a lack of creativity in music, it is a field that should be more thoroughly developed due to its practical applications for musical composition. Hopefully my project will make some grounds in terms advancing algorithmic music composition as a subset of computer programming and music theory.

Future Work

As developing a program as noteworthy as say, David Cope’s Bach imitation program, is a very unlikely task to accomplish in a one week period, future work will be dedicated to improving my program in any way possible. That will probably include accounting for key changes within a melody and generating more dynamic harmonies in terms of rhythmic structure.


Cope, David. Computer Models of Musical Creativity. 2005. Print.

Jacob, Bruce. Algorithmic Music Composition as a Model of Creativity. December 1996. Retrieved 3 January 2013.

Maurer, John. A Brief History of Algorithmic Music Composition. 1999. <https://ccrma.stanford.edu/~blackrse/algorithm.html&gt;.

Langston, Peter. Techniques for Algorithmic Music Composition. Morristown, New Jersey. <http://www.langston.com/Papers/amc.pdf&gt;.

D. E. Knuth. ‘‘The Complexity of Songs’’. SIGACT News vol. 9, no. 2, pp. 17−24. (1977).

Book Proposal


When I say that the next Bach could be a computer program, though I expect some puzzled faces and serious doubt, there is a lot of validity to that claim. As Classical music diminishes in popularity (as it has been in the past few years as newer generations get hooked on newer genres of  music), so will the number of composers that are responsible for new, orchestral music. It is up to us as programmers to fill that gap with software that can do the composing for us.

As with all research projects, there will be a need to reference the big boys in the field. With that in mind, I’m requesting funds to purchase David Cope’s book, Computer Models of Creativity. Such a book would grant me the intellectual tools I require to begin my journey to start my project: creating dynamic compositions by generating harmonies and bass lines according to a given melody utilizing creative algorithms.

Hopefully my project will end up being successful in terms of its creative output, but I think a lot can be gained from reading David’s book on algorithmic music composition. Although I’m not too worried. If one iteration of a song isn’t appealing, i’m sure at least one out of the hundreds that could be produced by such a program will be.

Workshop in Algorithmic Computer Music



The Workshop in Algorithmic Computer Music was held at UC Santa Cruz from June 24th to July 7th, and was led by David Cope. Sadly I came to Stanford a couple of weeks too late to attend but it seems like it would’ve been the perfect conference to go to for some insight on what modern practices for algorithmic music composition look like. It would’ve been very beneficial for me to see such practices as my project will most likely employ some of the same techniques, but luckily I have David’s book that I’m sure has a lot of similar material.

The workshop offered classes that went into detail on topics such as algorithmic composition, musical analysis, Markov-based rules programs, neural networks, and other practices used when programming music-based software. Hopefully I’ll be able to ask David about some of the topics he covered at this conference on Monday when he Skypes in during our class.

kNN and Data Mining Project

ImageToday I created a program that assigns labels to points using a kNN method. The label assigned is the label that appears more than the others among the 3 closest points to the testing point. There wasn’t really anything graphical to show so I just took a picture of the result: 83% of the tested points were assigned the correct label. I’m pretty happy with my results.

Surveillance and Privacy


The popular debate over extensive surveillance in our country draws parallels to the question whether freedom or safety is more important to have in life. I personally believe that the surveillance programs employed by the government have proved themselves way beyond anyone could’ve ever imagined. Who knows how many lives have been saved as a result of programs like NSA or TSA? And who knows how many future crimes will be solved if even more extensive surveillance was put in place?

Frankly I think people’s obsessions over privacy are overstated, and they are very hard to advocate when compared to the benefits we receive from utilizing surveillance programs. I hope to see such programs extended in the near future so we can have a safer society as a whole.