Here is the original C++ class I converted to Lisp at the very bottom of this post.
class TrainingData
{
public:
TrainingData(const string filename);
bool isEof(void) { return m_trainingDataFile.eof(); }
void getTopology(vector<unsigned> &topology);
// Returns the number of input values read from the file:
unsigned getNextInputs(vector<double> &inputVals);
unsigned getTargetOutputs(vector<double> &targetOutputVals);
private:
ifstream m_trainingDataFile;
};
It is a class from a C++ Neural Network I am converting to Common Lisp. The entire 400 line Neural Net is here.
Below is the conversion I came up with. Based on the Neural Network I linked above, can anyone tell me if I converted the C+ class, above, correctly with the following Lisp code? I'd rather have a little assurance before I start converting the entire 400 lines.
(defclass training-data ()
((training-data-stream :reader training-data-stream
:writer |set training data stream (using a funky name)|
:initarg :training-data-stream))
)
;;; initialize-instance :after -- This is your 'constructor' code.
(defmethod initialize-instance :after ((td training-data)
&key
training-data-stream
&allow-other-keys)
;; Initialize the slot.
;; Note that 'opening' a stream, as it is implied by the C++ class
;; definiton and leaking the open stream handle is very impolite.
(let ((is (etypecase training-data-stream
((string pathname) (open training-data-stream :direction :input))
(stream (if (input-stream-p training-data-stream)
training-data-stream
(error "Not an input stream.")))))
)
(|set training data stream (using a funky name)| is td)
))
(defgeneric is-eof (td)
(:method ((td training-data))
;; Are you sure you want this method?
))
EDIT: As far as tests go, please let me explain:
Due to the fact I'm just a intermediate at Linear Algebra I had a wee bit of a time understanding Neural Networks. This conversion into Lisp is the way I figured out how to figure out what Neural Networks do. I'm best at Lisp, pretty good at C, and sort of good at C++, so I'm trying to learn Neural Networks by converting a C++ nn to Lisp.
I don't have enough info to test any specific piece of the code I posted here or at the link yet. I'm still in the process of learning std::stringstream
and I've just learned what bitwise XOR was. I can post the instructions that tell how to run the C++ nn at the link in its entirety, and the code to create the data file for it, so you can see how it runs or explain how the incomplete snippet I posted ties in with the rest of the code. The incomplete member functions I added in this post have completed counterparts within the rest of the code at the link I just added.