Tuesday, September 24

Return to school

By Ed Yakovich [Public domain], via Wikimedia Commons
I haven't posted in a while as I haven't been working on anything that can be considered project-driven or really worthy of a post. In the late summer, I was signed up for three additional Coursera courses: Computer Networks, Startup Engineering, and Discrete Optimization. I didn't post on any of them because I wasn't able to finish them. I was interrupted for a very good reason. This fall, I'm jumping back into the academic life. I had a decent time working as a mechanical engineer in industry but never felt satisfied with my level of knowledge. I would spend a lot of free time researching some advanced topics that interested me and now I am ready to start devoting myself to that purpose full time. It is very exciting.

Earlier this month, I moved to Philadelphia to start working at the Scalable Autonomous Systems lab under Dr. Ani Hsieh. I'll be taking over a project that was started by two students over the summer. They have been developing a new generation of the SAS lab's ground robots to be used as a platform for future research. The primary motivation for the new robots is to utilize the multi-core processors recently available on ODroid single-board computers for processing data from RGB-D sensors. I spent most of my time during the first week trying to digest their design documentation and code as I'll need to understand all of the work that they have done in order to continue development.

By Conspiritech (Own work) [Public domain], via Wikimedia Commons
In reality, a lot has been done already, there was a functioning (moving) robot when I walked in the door on the first day. However, as with all projects of this nature, there are plenty of places where improvements can be made. Concessions are often made on the road to functionality and it is important to identify which ones are worth shoring up. I spent a majority of last week rewriting the Arduino code to eliminate the use of floating point data types, implement interrupt-driven encoder reads, eliminate redundant variables, and generally streamline things as much as my naive C-coding skills will accommodate.


Tomorrow I start my first class as a Mechanical Engineering PhD student at Drexel University. I'll be studying Advanced Dynamics and Applied Engineering Analytical Methods. Advanced Dynamics kind of looks like it will cover the same topics that I was drawn to last year when I was playing around with writing an inverted pendulum simulator in GNU Octave. The Analytical Methods course will hopefully be relevant to the work that I do in the future. I don't often like application-driven classes as they tend to skimp out on the theory but this one seems worth while. Overall, I am excited to get started, we'll see how energetic I am next month.

Friday, June 21

Coursera: An Introduction to Interactive Programming in Python

I recently finished taking a class called Interactive Programming in Python. The focus was to introduce students to the process of developing games or other applications that a user may interact with in real time. Much of the course focused on standard Python operators, methods and some "best practices" for using them and organizing intuitive, readable code. The class content was generated through the shared effort of a team of professors at Rice University: Joe Warren, John Greiner, Stephen Wong, and Scott Rixner.

As far as exercises go, the class consisted of relatively challenging weekly review quizzes and a coding project (usually in the form of some game such as Pong, or Memory). I can really appreciate the work that was put into developing the quizzes. They make an effort to compel the student to explore all of the characteristics of the various data structures and ask questions that aren't deliberately answered in the lectures but may be determined via deductive reasoning or plain old trial and error.

The video lectures were very engaging. Professors Warren and Rixner did a great job of keeping the videos interesting and getting the students excited for the weekly project. At the end of each lecture series, there would be a short introduction to the latest assignment. This would usually be capped off with a competition between Professors Warren and Rixner using the game that we would be developing. Through their banter, it was amusing to preview their sort of friendly adversarial relationship off camera. While it can't be expected that a class will be entertaining, as long as it is also informative - it certainly can't hurt.

One unique characteristic of the course was that it was entirely self contained. This is sort of a philosophical objective of coursera courses in general but this course could be completed entirely within the confines of a web browser. The student does not need to download any documents, install Python, or even submit files. This is made possible by Professor Rixner's  browser-based Python emulator CodeSkulptor. This approach to development can be good and bad. While CodeSkulptor makes the coding assignments easier on the student, it limits exposure to some of the contextual learning that is necessary for anyone trying to utilize Python. CodeSkulptor only supports a tightly packaged set of  operations; this narrows the focus of the assignments so that the student isn't as overwhelmed by a gigantic API. At the same time, while it is great for the primary focus of the course, the reliance on CodeSkulptor does not prepare the student to jump into developing Python code right out of the gate. They must learn a little more before they can start initializing their scripts and modules on their own machine.

The timeline was a little more rigid than other coursera courses that I have experienced. Unfortunately, the second and third weeks coincided with a trip that I took to Turkey which caused me to miss one or two deadlines and really hurt my overall score. I can understand the motivation for the deadlines - the class implemented a unique scoring method that came with some logistic trade-offs. For instance, All coding assignments were peer-reviewed. After submitting an assignment, the student is then expected to grade five additional assignments before doing  a self-evaluation. The tradeoff here is that, although this allows for flexible implementation of the assignment because it is being interpreted by a proficiently heuristic machine (another human being), the grading takes more than a few days and the deadlines are absolute. If a submission is late, no one may grade it and the student does not get any credit. This is a challenging characteristic for a Massive Open Online Course - usually assignments in online courses of this nature have a healthy buffer to accommodate students with demanding schedules.

I think this process worked out fairly well. All of my graders seemed to put a good deal of thought into their feedback (and I did the same for those who I graded). This indicated to me that they took the role seriously and the process worked pretty well. I believe there are ways of improving the logistics such that students who need to submit past the deadline may be paired with others who need to do the same for partial credit. Additionally, in anticipation of abuse, I would suggest implementing a method for the student to provide feedback to the graders such that consistently poor graders (graders whose assessments consistently represent outliers) may be identified and isolated from impacting other student's grades.

In summary, I'm pleased with the class. I decided to try this one out because I wanted to learn a little more about generating user interfaces and graphics objects in Python. This is sort of a weak point for me - most of the code that I have generated so far is for personal use, terminal based, and sort of clunky. I was also interested in learning some better practices for organizing interactive programs and implementing robust GUIs. Unfortunately, the class did not get a whole lot deeper than timers, simple drawing, and interactive objects. Still, I learned a good deal in the course and I look forward to additional opportunities to learn about interactive programming in this type of setting.

Saturday, June 15

Coursera: Machine Learning

I started the latest track of Andrew Ng's Machine Learning Coursera Course a month ago. There are about two more weeks in the class and my experience so far has been positive. We've covered Linear classifiers, Logistic regression by gradient descent, multi-layer neural networks, and SVMs. This week's topic is unsupervised learning via K-means clustering.

Part of the material has been review for me as I studied Ng's OpenClassroom materials in the past.  I posted on that experience a little bit in My Introduction to Machine Learning. Although my primary goal when working through those materials was to understand how to implement backpropagation of artificial neural networks for supervised learning, this iteration of the class on Coursera has greatly increased my intuition for how to improve and by what metrics to judge the performance of a learning algorithm.

One large contrast between this course and the OpenClassroom materials is the in-video questions and review quizzes. Distributed practice is a great method for learning concepts and keeping the viewer engaged; Coursera courses in general seem to do a great job of keeping the learning experience interactive. Ng's Machine Learning, being sort of the "flagship" Coursera course, is no exception.

Good Lectures

Ng's lectures are very good at explaining the motivations and the nuances of employing machine learning algorithms. Every algorithm as presented has some prototypical application upon which analogies and concepts are based. He provides a lot of insights based on his own experiences with the profession of machine learning as to common pitfalls that people tend to run into when implementing a classification algorithm. For instance, it is common for someone, when their algorithm does not perform well, to conclude that the solution is to find more training data examples or features. In real-world applications, 'finding more training data' can be a significant project on its own. Furthermore, in the case of over-fitting, it would actually be detrimental to increase the number of features in the training set.

This type of meta-knowledge for the application of learning algorithms is incredibly useful to me as an aspiring data scientist. Some of the techniques such as cross-validation or generating learning curves were entirely unknown to me when I was playing around with that Kaggle assignment. If I had been aware of and made use of those techniques, I would have generated much better classification accuracy in that project and done so in a much shorter amount of time by correctly tailoring my algorithm to the data.

Programming Exercises

The class involves mandatory weekly programming exercises that center around some particular algorithm from the week's lectures. The tasks can range from anywhere between classifying spam emails to teaching a neural network to recognize hand-written digits. The exercises are well developed and, in the interest of time, are provided with a lot more content than what the student generates. For instance, all of the data is imported and pre-processed in the provided script files and functions. All that the student is usually tasked with is implementing one or more cogs in the system - some particular cost function or kernel for the task at hand. The submission process is also completely automated by the supplied "submit" script - all that the user has to do is update the indicated code and run it.

This is all very impressive but it can be rather limiting. I understand that the motivation is to make the coding task as clean and standardized as possible to allow for reasonable evaluation of the student's work and for the student to focus on the particular concepts that they are trying to practice. However, the whole experience is so convenient and constrained that it feels too easy. I remember the satisfaction that I felt after implementing an ANN from scratch for the tutorial Kaggle Digit Recognition Challenge and these exercises, although they involve some incredibly exciting algorithms, don't invoke that sensation in me. I could be a complete outlier in that view - I haven't had a chance yet to learn what other students' opinions are on the forums.

Moving Forward

Nevertheless, I'm very excited by the knowledge and experience that I have obtained throughout this course and greatly appreciate the efforts of Andrew Ng and his TAs in providing this learning experience. There is a great deal to explore about just the application of machine learning algorithms - not to mention their potential adaptations. My next goal is to read up on the subject of neural networks and built a better context for understanding these machine learning algorithms. I recognize that the ANN implementation that Ng presents is just a special case called a 'feed forward' neural networks. It would be interesting to learn how neural networks behave in real time so I've found an old book called Introduction to the Theory of Neural Computation that looks promising and I've recently begun reading Sebastian Seung's Connectome.

Thursday, June 13

Calculus of Variations, 2/2


In the first post of this series, the Barchistochrone problem was introduced and we looked at how the performance of a particular curve could be evaluated. Recall that the total transit may be expressed in this way:

 [;T = \int^{x_B}_{x_A}\frac{\sqrt{1+f'(x)^2}}{v}\,dx;]

Also, because the bead is traveling through a constant gravitational field, the velocity may be expressed as a function of the change in height by conservation of energy.

[; v = \sqrt{2g(y_A-y)};]

[; v = \sqrt{2g(f(x_A)-f(x))};]

Therefore, a functional that evaluates the transit time for some curve f(x) in the brachistochrone problem is given by:

[; T(f(x),f'(x),x) = \int^{x_B}_{x_A} \frac{\sqrt{1+f'(x)^2}}{\sqrt{2g(f(x_A)-f(x))}}\,dx ;]

which may be generalized with a function L:

[; T(f(x),f'(x),x) = \int^{x_B}_{x_A} L(f(x),f'(x),x)\,dx ;]

where

[; L(f(x),f'(x),x) = \frac{\sqrt{1+f'(x)^2}}{\sqrt{2g(f(x_A)-f(x))}} ;]

Now that we have an expression for the total transit time of the bead for any continuous differentiable function between points A and B, imagine how changing that function might change the transit time of the bead. For the optimal curve, any perturbation in the curve will increase the transit time. If we can come up with a relationship between perturbations of a function and changes in the functional T, we can look at how infinitesimal perturbations of the function change the transit time. The motivation here is to use that relationship in order to find a function for which infinitesimal perturbations produce no change in the transit time - at which point the function can be said to minimize T.

Thursday, May 16

Calculus of Variations, 1/2

I've decided to post on this topic for two reasons. First, I want to solidify my own comprehension; I was introduced to variational calculus as a supplemental portion of a Finite Element Analysis course that I took during the third year of my BME. When my FEA professor lectured on it, I wasn't particularly comfortable with the method; I got the gist of what was being done but I wasn't able to reconstruct it on my own when I sat down to a piece of paper. Second, since that lecture, I have recognized it in a handful of applications in the realm of optimization, mechanics, control theory, and FEA; Those topics are pretty damned important for someone interested in robotics. For those reasons, although plenty of people have produced better summaries and  course materials on the topic, I feel compelled to make a modest attempt for my own sense of completion.

To start, it is sometimes useful to learn about the history of a subject in order to understand the context in which it was developed. As far as mathematical methods go, there is usually some famous problem for which it was developed. In the case of variational calculus, that problem was finding the Brachistochrone Curve. The problem was posed by Johann Bernoulli as part of a correspondence between friends and contemporary mathematicians of his time. He asked his colleagues to determine the optimal curve that a bead would follow through a uniform gravitational field between two points in the shortest amount of time. As one might expect, the name is derived from the latin brachis meaning "shortest" and chron meaning "time".

The Brachistochrone Problem

Monday, May 6

My Introduction to Machine Learning

Open classroom exercises


A couple of months ago, I worked through some of the exercises for Andrew Ng's OpenClassroom Machine Learning Class. I think the site is now defunct (or maybe morphed into coursera) but the assignments were still available at the time of this post. The experience left me with a pretty good basis for starting to learn about using artificial neural networks (in addition to other ML algorithms) to solve optimization and classification problems. This is a very exciting field for me to peer into as it involves some promising prospects for the creation of intelligent machines. Deep learning, one ML research area that seems to be prevalent, is essentially just the clever utilization of very large neural network models to learn complex relationships. One of my current goals is to comprehend some of the strengths, weaknesses, and challenges involved with deep learning networks and their implementation.


Childhood dream


My first exposure to neural networks was Jeff Hawkins' book, On Intelligence, where he proposed ways that neural networks might be organized to mimic the neocortex of the human brain and achieve a powerful self-teaching mechanism. At the time, this book had me very excited - the idea seemed simple enough to implement (a 13 year old kid could loosely comprehend it) and the notion of building an actual learning machine is very appealing. Mary Shelley's Frankenstein had people excited when it was written and all Dr. Frankenstein did was assemble limbs - he had an intact brain and didn't have to put one together from scratch! However, I wasn't scrutinizing enough to consider questioning the claims in the book and I didn't know enough about neural networks to evaluate them. Since then, I've heard some critical things from people in the machine learning and artificial intelligence communities but I still haven't been exposed to the topic sufficiently to make a judgement on the value of that book nor the validity of the claims therein. It looks like Mr. Hawkins' company, Numenta, has been pretty closed about their work but recently announced that they would be open sourcing their Cortical Learning Algorithm. I'm interested in learning more about the progress he has made -  in any case, his book made a lasting impression on me what with inspiration and so forth.


My current conception


While neural networks may provide powerful and flexible algorithms, there is still a great deal to be discovered about their behavior and, historically, a kind of stigma surrounding their use. It seems that there was a little bit of hype followed by disenchantment in their history. Machines weren't powerful enough to implement them at the scale required for useful or impressive results and they were seen as flexible but inefficient toys for solving problems that weren't necessarily novel. Another limitation was the lack of an appropriate back-propagation algorithm that could allow for many-layer ANNs. Today, neural networks can be seen in a variety of useful applications, and the niche seems to be growing.

One strong application of ANNs is the classification of datasets. Classification problems involve training a network with samples of a known class such that a decision boundary is defined between two regions in the feature space. Instances that lie on one side of that boundary will be classified in one way while instances that lie on the other will be classified in the opposite way. The process of 'learning' in this case can be reduced to manipulating the boundary between those two classifications. If the data used to 'train' a neural network is representative of the task as a whole, then one can expect relatively accurate classifications of new data.


Tuesday, April 30

Coursera: Control of Mobile Robotics

I completed a Coursera course last month on the subject of the Control of Mobile Robotics. The class was sort of a bite-sized introduction to control theory in the flavor of autonomous navigation at the hardware level. This means that no consideration was given to mechanical system design or AI approaches. Magnus Egerstedt of Georgia Tech was the primary instructor and his research and teaching assistants provided supplemental lectures, responded to questions on the forum, and presented programming exercises using their Simiam robotic simulation software (a package of Matlab files). This course was useful for me as my formal experience with a Dynamics Systems and Controls was kind of abstract and didn't possess a strong focus on real-world application.

The first lesson was an introduction to dynamic systems which was embodied by the investigation and design of an automotive cruise controller. The lesson explored some of the primary objectives in control system design for autonomous systems:

  • Stability
  • Tracking
  • Robustness
  • Disturbance Rejection
  • Optimality 

Friday, March 29

Nand2Tetris

 ==>


A while back, I had a conversation with an old roommate on the topic of computer science. He mentioned that one of the better ways to become familiar with the application of computer science was to actually build one from scratch. At the time, I thought that sounded like a fun, but daunting and time-consuming task; time that might be better spent on some specialization. I realized that there was a hierarchy of unique and challenging topics between hardware and software in a modern personal computer and that a lifetime could be spent mastering any particular aspect of those. At the same time, if some resource existed that could help an individual navigate through that hierarchy, the practical knowledge could be acquired without the expensive and painstaking mastery necessary for the corporeal implementation of a computer.

Last December, I was lucky enough to come across Nand2Tetris - the very resource that I idly dreamt of. The Nand2Tetris coursework does exactly as the name describes: the student is given materials that allow them to build and simulate logic circuits and, starting with a simple NAND gate, the student implements all of the components necessary to perform the operations involved in a game of Tetris. The organization of the class is impressively clean. There are multiple simulators spanning a variety of stages in the process which represent checkpoints in the course: Hardware Simulator, CPU Emulator, VM Emulator, Assembler, Compiler, Operating system; each of these are first implemented by the student and then utilized (for the sake of speed) as the succeeding topic is breached. In that way, the student never utilizes components that weren't  (in spirit) originally constructed by them - everything ties back to the original NAND gate. What follows is a user-friendly, intuitive, and educational series of tasks that simulate the main points of implementing a computer achitecture from scratch while retaining the continuity of the experience and filtering out any potential headaches due to inefficiency of the hardware simulation (at the scale necessary for building a working computer).


Whats more, the materials are open to the public: the simulation software, assignments, and half of the book. I was able to work through the first 6 chapters without paying a cent and learned a great deal about the practical and necessary constraints on machine language, assembly code, and virtual machine. Working through these exercises has given me a more detailed perspective of the landscape of computer science and its application. For a mechanical engineer who is interested in mechatronics systems or computer architectures, this course is an absolute blessing. I've purchased the book and plan on finishing the last 6 chapters in the coming weeks.



Even if a person was constrained by time and unable to perform the exercises, the book itself is worth reading. Topics are presented with little assumptions of prerequisite knowledge. In fact, this material could be (and I believe is) taught in highschools and middle schools to great effect. Overall, I am very pleased with this course and greatly appreciate the work of Noam Nisan, Shimon Schocken, and the rest of the Nand2Tetris team for preparing it.

Underactuated Robotics

I recently came across materials from a class on MIT's Open Courseware (OCW) that has me pretty excited: Underactuated Robotics. I ran into one of the lecture notes during my investigation into inverted pendulum control schemes (a project which sort of branched out of my review of the calculus of variations). I was originally interested in modeling the dynamics of a pendulum in a variety of force fields and decided it would be more interesting to investigate controlling that system in ordinary conditions. I'm planning on implementing this system physically once I have a sense of what I would like to accomplish with it.

 The first lecture opened my ears to a fundamental bifurcation in the application of mechanical and control system design. Primarily, fully actuated systems which possess the same number of actuators as they do degrees of freedom and underactuated systems which have no direct influence over the unactuated degrees of freedom. More succinctly, fully actuated systems are capable of producing accelerations along arbitrary directions in the state space. For systems where the dynamics may have a linear relationship with the actuation vector:

$\ddot{q} = f_1(q,\dot{q},t) + f_2(q,\dot{q},t)u $

Where $q$ is a vector in the state space, $u$ is a vector of all actuators, and $f_2$ maps the actuators to some dimension in the state space. A fully actuated system will possess the following property:

$rank[f_2(q,\dot{q},t)] = dim[q]$

Whereas underactuated systems will not map the actuation space to all dimensions of the state space.

$rank[f_2(q,\dot{q},t)] < dim[q]$


In order to reach a particular position in the state space, an underactuated system must make use of the indirect and dynamic characteristics of the system that relate the actuated features of the state vector to the desired unactuated feature. For instance, a cart and pole inverted pendulum is underactuated. It may be modeled as an actuated prismatic joint coupled with an unactuated revolute joint with some mass at the end of the free member. This is apparent because there are two degrees of freedom in the system and only one actuator. It is generally possible to reach any point in the state space, but not necessarily possible to describe any path through the space. The available paths that may be taken through the state space are defined by the dynamics of the system.

Tuesday, January 29

Project Euler

Portrait of Leonhard Euler (1707-1783)

Fun and challenging problems


I've been working my way through these Project Euler exercises since September 2012. From what I gather, these problems originally spawned off of a thread on mathschallenge.net in 2001 and moved to a seperate domain in 2006. The gist of these tasks is that a problem is presented that requires the derivation of some mathematical truth (such as the number of twin primes below some value or the last 10 digits of !1000). All of the tasks are meant to be performed by algorithms implemented on a modern computer in under one minute.

For instance, the latest problem that I have solved is number fifty. It asks for the prime number less than 1,000,000 which is the sum of the largest chain of consecutive primes.




-----------------------------------------------------------------

Problem 50



The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred.
The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes?
----------------------------------------------------------------


Wednesday, January 2

Useful Hotkey Script

This post is only tangentially related to the purpose of this blog but I find it to be pretty useful nonetheless.

I came across this pretty convenient utility a while ago for writing scripts for your desktop. There are innumerable applications where this tool may be used to speed up or automate particularly repetitive tasks on the computer. The highlight of this post is a particular script that enables re-sizing, closing, minimizing, and maximizing windows with the ALT key and mouse. It also includes what I considered to be a pretty creative implementation that the author terms as the "double-alt".

All of these hotkeys involve a combination of the ALT key and some mouse button. The purpose is to enable manipulation of windows in a way that doesn't require precision. Any window may be re-positioned by holding ALT, left clicking anywhere inside the desired window, and dragging to the desired location. Any window may be re-sized by holding ALT, right clicking inside the window, and dragging to the desired size. This is effectively a corner-drag that selects the nearest corner rather than requiring you to surgically select each corner and re-size. One useful characteristic (or annoying, depending on the context) is the fact that these resize operations do not involve selecting the window as active. In other words, an inactive window may be resized or moved without changing it to the active window.

The last three hotkeys involve double-tapping (and holding) the ALT button and using the left, right, and center mouse buttons to minimize, maximize/restore, and close windows respectively. The double-alt takes a little bit of getting used to, but once you incorporate it into your habits, it becomes a lot easier than clicking on a window's minimize, close, and restore icons.

One might argue that WINDOW+D or ALT+F4 are good enough for the purposes of minimization and closing. One thing to note about the double-alt method in this script is that it will modify any visible window on the screen. If you want to close or eliminate a window that has popped up but isn't active, you will have to select it before using ALT+F4 whereas, if you want to be done with it immediately, double-alt click can be enormously convenient.

Alt+Left Mouse Click (Hold)

Drag Window

Alt+Right Mouse Click (Hold)

Resize Window

Double-Alt Left Mouse Click

Minimize Window

Double-Alt Right Mouse Click

Maximize/Restore Window

Double-Alt Middle Mouse Click

Close Window