Wednesday, November 23, 2011

Papers available and project directions

So, under the suggestion of a database admin for the Green Mountain Coffee Roasters, I made myself a website. It's not the greatest thing and definitely still needs work. But within the projects page there are links to read the papers that I've written on a couple of the projects that I've talked about here.

I'm also thinking about redoing my Python Obstacle Avoidance program, either in python with cleaner code and a nice paper alongside of it to walk through the reasoning in the code itself, or to redo it in Matlab because I feel that Matlab's plotting functions could be of great use. Especially because I could make demo code that would show the algorithm working in real time and could animate a graph on screen to show what it is doing. I really like this idea, and despite moving away from Python, I feel like it will be really good. I'll either have to look up how to do lambda expressions in Matlab, or just throw away their use all together. (If you recall, I used lambda expressions to create functions that would return the value of y given an x, using an equation of a line that was the instance of the class itself.) They weren't necessary in the implementation and were mainly just me trying out something new.

The Smartboard is still coming along, and a paper is in the works for that one. I'm also going to probably be doing some small program in MIPS assembly pretty soon and will have to present it to a class I'm enrolled in, so that may make itself onto my website as well, and quite possibly this blog.
I'm also contemplating redoing the Budget Buddy in C# due to it's Visual Studio capabilities and how easy file IO is in C#, not to mention packaging into an exe. These are all things for the future, and hopefully I'll have time to do them!

Heres the URL to my website:
http://www.uvm.edu/~ejeldrid

Hope you all enjoy.

Tuesday, November 22, 2011

Lambda Expressions in Python


Below is just a sample piece of code that I was playing with the other day, it was fun to mess with and interesting to see how the scope of the variables declared for the lambda expressions behaved. Mainly, that sometimes it seemed that variables declared within lambda expressions were accessible outside of what I thought their scope should be. This happened with the lambda expressions containing lambda expressions both expressions taking variables. It was a fun case study that got me away from all this serious project stuff I'm working on. And I figured I would share, so without further ado, here is the code: throw it into your favorite python IDE (command line, IDLE, eclipse) and run the show function and then play with it yourself. :)


#LAMBDA EXPRESSION TESTING
#Can you horribly abuse lambda expressions such that
#you dont have to actually create functions in a class?


class LamClass1:
    def __init__(self,x,y,z):
        self.x = x
        self.y = y
        self.z = z
        self.getX = lambda: self.x
        self.getY = lambda: self.y
        self.getZ = lambda: self.z
        self.norm = lambda a: a/(self.x+self.y+self.z)
        self.xyLine = lambda m: (lambda n: n*m*self.x+self.y)
        self.xzLine = lambda m: m*self.x+self.z
        #nesting functions to return functions
        self.makeLine = lambda m: lambda b:  lambda x: (m*x+b)
        #nesting arguments!
        self.nesting = lambda m,b,x: (((self.makeLine(m))(b))(x))
        #tupling it up
        self.listF = lambda a,b,n: a+b,a*b,a-b,b-a,n
        #This is a tuple you access to access a function how cool!
        self.listT = lambda a,b: lambda n: (a+b)**n,lambda a,b: lambda n: (a-b)**n
        self.shallowCopy = lambda: self
        self.deepCopy = lambda: LamClass1(self.x,self.y,self.z)
        self.tupleReturn = lambda a,b: (a,b)
        self.funcList = lambda: (self.getX,self.getY,self.getZ,self.xyLine)
        #you cant do multiple statements inside a lambda
        #but you could nest everyline of code as a lambda being called and such


def show():
    l = LamClass1(2,3,4)
    #Standard gets but with lambda
    l.getX()
    l.getY()
    l.getZ()
    #An example of argument passing
    f=l.xyLine(2)(3)
    #Multi Function Computation:
    f=l.listF[0](2,2,3)
    #Example of how Scope Changes
    f=l.listF[1]
    print 'Global Scope of lambda variables'
    print a,b,n
    #you could write a =1 and then another print and watch it be strange
    #Lambda Expression Variables are global, this could be bad
    #Example of tupled functions
    f=l.listT[0](1,2)(2) #(a+b)^n
    f=l.listT[1](2,3)(3) #(a-b)^n
    print a,b,n
    #Notice how I have never declared a,b,n
    #an example of shallowCopying and mutability
    print 'Shallow Copy'
    L2 = l.shallowCopy()
    print 'l.x=',l.getX()
    print 'L2.x=',L2.getX()
    l.x = 3
    print 'l.x = 3'
    print 'L2.x=',L2.getX()
    #an example of deep copy
    L3 = l.deepCopy()
    print 'Deep Copy'
    print 'l.x=',l.getX()
    print 'L3.x=',L3.getX()
    l.x = 5
    print 'l.x =',l.x
    print 'L3.x=',L3.getX()
    print 'Function List'
    print 'l.funcList()[0]() -> getX()'
    print l.funcList()[0]()
    print 'l.funcList()[1]() -> getY()'
    print l.funcList()[1]()
    print 'l.funcList()[2]() -> getZ()'
    print l.funcList()[2]()
    print 'l.funcList()[3](2)(3) -> xyLine(2)(3)'
    print l.funcList()[3](2)(3)
    

Monday, November 21, 2011

Wii Smartboard

The WiiSmartBoard that I'm working on with CS Crew is really coming along, we started working on it 2 days a week every week since early September. We're writing it in C# and using an open source library for interfacing with the Wiimote through bluetooth. When we first started working on it I went and looked through all the documentation for the WiiMote and found out which bits and bytes were returned from the wiimote and was ready to write my own assembly level parsing code. But then we were lucky enough to find the library that we did and I could focus on the actual concepts instead of the nitty gritty detail.
The cool thing is that we're going to attempt to implement a 2 and a half D flicking system to switch between "slides". I suppose I should talk a little bit more about the details.

We're using the Wiimote as a receiver for an infrared pen we built. We're drawing onto bitmaps on our GUI, but we also have buttons that will be able to be clicked. Each bitmap is a slide, stored inside of a lecture class my friend Scott and I created, when we save, we save a .lecture file that holds the information of the order of the slides to load, and saves the images into a subdirectory. It works really well because we're using two stacks to contain the bitmaps, so saving is as easy as popping and pushing them from one slide to the next and saving each one. And then when we load, we just load them in reverse order which is really the right way to do it because of the FILO structure of the stack.

I'm also writing up documentation on it and I'll definitely publish that onto my website.