Today I want to talk about Pickling. This approach allows you to save off a variable/data for re-use later.
Why would you want to do this? Well suppose you're like me and you're working on an AI agent, and you have a LOT of problems you need to run through, and all these problems take a little bit of time, and say 50 of them are already solved by your agent, but that 51st isn't, instead of running all 50 over and over (unless your agent is learning things, in which case, you're good). You can pickle the passed in variable, and then make a simple "test" function that will call only the one you want to call so that it's way easier to test out individual parts.
For more general information about pickling take a look here: https://wiki.python.org/moin/UsingPickle
Lets get started.
Import Pickle in your file with the following line added to the top of your Agent.py file:
import pickle
(I"m going to be using some verbiage from my AI course, however the basic idea is this, the agent we have starts with normal class name, __init__ and must implement a Solve function).
Make the start of your Solve function look like this:
def Solve(self,problem):
pickle.dump( problem, open( './pickles/' + problem.name + ".p", "wb" ) )
Finally Make a new directory called pickles so pickle can save it.
Finally run your agent like you normally would.
If you notice there should be a bunch of .p files in your pickles directory.
Next lets setup a "test" agent that allows you to run a SINGLE test (I know folks on our forums have asked about this, and well... here it is!
Create a new file called test.py
Inside it you would add the following
import pickle
from Agent import Agent
A = Agent()
problem = pickle.load( open( "./pickles/Basic Problem E-09.p", "rb" ) )
A.Solve(problem)
Replacing the .p filename with whatever you choose.
You can make this more "generic" if you'd like by accepting command line input and then you run it like this .
test.py Basic Problem E-09 and it would run the one you command it to. Pretty Slick right?
That would look like this:
import pickle
from Agent import Agent
from sys import argv
A = Agent()
script, name = argv
problem = pickle.load( open( "./pickles/" + name + ".p", "rb" ) )
A.Solve(problem)
and be ran by this command.
python test.py "Basic Problem E-09"
The final test.py can be found here:
https://gist.github.com/onaclov2000/d1d7fc01b22b98e0098e
Saturday, March 12, 2016
Wednesday, March 2, 2016
Thinking outside the box
I'm currently enrolled in the degree program Georgia Tech offers through Udacity. It's called OMSCS. I'm taking Knowledge Based Artificial Intelligence:Cognitive Systems.
The primary project we are working on is Ravens Progressive Matrices.
I have tons of ideas, and approaches. I'll talk about one that I'm experimenting with (and have no idea if it'll work).
One thought that crossed my mind was what if i could think of these problems as a time relationship. Could I apply a Fast Fourier Transform (FFT)? Well I am giving it a shot.
First I took a line by line reading of the image, then layed it end to end. So in a way you have a all kinds of crazy waveform.
Next I used numpy to convert to the Power Domain using numpy.fft.fft(array).
I'm not much further than this, but I did try dividing A by B and A by C and graphing these ratios along with inverse FFT'ing.
I thought the graphs looked really neat. So I am going to leave a few here for your enjoyment.
Which by the way I should note, I have no idea what I'm doing here, it's experimentation and who knows if these graphs are even logical, but they're cool looking.
Original Images
Have a good one, I'll probably post more about this in the future.
The primary project we are working on is Ravens Progressive Matrices.
I have tons of ideas, and approaches. I'll talk about one that I'm experimenting with (and have no idea if it'll work).
One thought that crossed my mind was what if i could think of these problems as a time relationship. Could I apply a Fast Fourier Transform (FFT)? Well I am giving it a shot.
First I took a line by line reading of the image, then layed it end to end. So in a way you have a all kinds of crazy waveform.
Next I used numpy to convert to the Power Domain using numpy.fft.fft(array).
I'm not much further than this, but I did try dividing A by B and A by C and graphing these ratios along with inverse FFT'ing.
I thought the graphs looked really neat. So I am going to leave a few here for your enjoyment.
Which by the way I should note, I have no idea what I'm doing here, it's experimentation and who knows if these graphs are even logical, but they're cool looking.
A/C |
A/B |
Original Images
C |
A |
B |
Subscribe to:
Posts (Atom)