PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <NetflixVMatrix.h>
Public Member Functions | |
NetflixVMatrix () | |
Default constructor. | |
virtual real | get (int i, int j) const |
Get element at i-th row, j-th column. | |
virtual void | getExample (int i, Vec &input, Vec &target, real &weight) |
Default version calls getSubRow based on inputsize_ targetsize_ weightsize_ But exotic subclasses may construct, input, target and weight however they please. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NetflixVMatrix * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
Get part or all of the i-th, starting at the j-th column, with v.length() elements; these elements are put in v. | |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
string | sourceFileName |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
TVec< TVec< int > > | data |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef VMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 65 of file NetflixVMatrix.h.
typedef VMatrix PLearn::NetflixVMatrix::inherited [private] |
Reimplemented from PLearn::VMatrix.
Definition at line 67 of file NetflixVMatrix.h.
PLearn::NetflixVMatrix::NetflixVMatrix | ( | ) |
Default constructor.
Definition at line 55 of file NetflixVMatrix.cc.
{ // ... // ### You may (or not) want to call build_() to finish building the object // ### (doing so assumes the parent classes' build_() have been called too // ### in the parent classes' constructors, something that you must ensure) }
string PLearn::NetflixVMatrix::_classname_ | ( | ) | [static] |
Get part or all of the i-th, starting at the j-th column, with v.length() elements; these elements are put in v.
in case the dimensions of an underlying vmat has changed, recompute it Set element (i,j) to given value (default version repeatedly calls put(i,j,value) which may have a significant overhead) copies matrix m at position i,j of this VMat This method must be implemented for matrices that are allowed to grow fill with given value For matrices stored on disk, this should flush all pending buffered write operations will call putRow if i<length() and appendRow if i==length() will call putRow if i<length() if i>= length(), it will call appendRow with 0 filled rows as many times as necessary before it can append row i default version returns a SubVMatrix referencing the current VMatrix however this can be overridden to provide more efficient shortcuts (see MemoryVMatrix::subMat and SubVMatrix::subMat for examples) copies the submatrix starting at i,j into m (which must have appropriate length and width) copies column i into v (which must have appropriate length equal to the VMat's length) Returns a Mat with the same data as this VMat. The default version of this method copies the data in a fresh Mat created in memory However this method will typically be overrided by subclasses (such as MemoryVMatrix) whose internal representation is already a Mat in order to return this Mat directly to avoid a new memory allocation and copy of elements. In this case, and in this case only, modifying the elements of the returned Mat will logically result in modified elements in the original VMatrix view of it. The default implementation of this method does nothing But subclasses may overload it to reallocate memory to exactly what is needed and no more. Returns the dot product between row i1 and row i2 (considering only the inputsize first elements). The default version in VMatrix is somewhat inefficient, as it repeatedly calls get(i,j) The default version in RowBufferedVMatrix is a little better as it buffers the 2 Vecs between calls in case one of them is needed again. But the real strength of this method is for specialised and efficient versions in subbclasses. This method is typically used by SmartKernels so that they can compute kernel values between input samples efficiently. Returns the result of the dot product between row i and the given vec (only v.length() first elements of row i are considered).
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
OptionList & PLearn::NetflixVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
RemoteMethodMap & PLearn::NetflixVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
Object * PLearn::NetflixVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 50 of file NetflixVMatrix.cc.
StaticInitializer NetflixVMatrix::_static_initializer_ & PLearn::NetflixVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
void PLearn::NetflixVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 90 of file NetflixVMatrix.cc.
{ inherited::build(); build_(); }
void PLearn::NetflixVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 99 of file NetflixVMatrix.cc.
References PLearn::endl(), i, and PLERROR.
{ cout << "NetflixVMatrix::build_()" << endl; // ### This method should do the real building of the object, // ### according to set 'options', in *any* situation. // ### Typical situations include: // ### - Initial building of an object from a few user-specified options // ### - Building of a "reloaded" object: i.e. from the complete set of // ### all serialised options. // ### - Updating or "re-building" of an object after a few "tuning" // ### options have been modified. // ### You should assume that the parent class' build_() has already been // ### called. // Open source file ifstream input( sourceFileName.c_str() ); if( ! input.is_open() ) { PLERROR("Could not open source file %s.", sourceFileName.c_str()); } string str_line; int userIndex = 0; stringstream ss_tokens; int dummy; list< int > l_userProfile; // Determine number of users and resize data while( getline(input, str_line) ) { userIndex++; } cout << userIndex << " users" << endl; length_ = userIndex; data.resize(userIndex); input.clear(); input.seekg(0, ios::beg); userIndex = 0; // Actual loading while( getline(input, str_line) ) { ss_tokens.str(str_line); ss_tokens.clear(); while(ss_tokens >> dummy) { l_userProfile.push_back(dummy); } data[userIndex].resize( l_userProfile.size() ); list< int >::iterator itr_userProfile = l_userProfile.begin(); for(int i=0; itr_userProfile != l_userProfile.end(); itr_userProfile++, i++) { data[userIndex][i] = (*itr_userProfile); } l_userProfile.clear(); userIndex++; } cout << "NetflixVMatrix::build_() - DONE!" << endl; }
string PLearn::NetflixVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file NetflixVMatrix.cc.
void PLearn::NetflixVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::VMatrix.
Definition at line 68 of file NetflixVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), and sourceFileName.
{ // ### Declare all of this object's options here. // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. If you don't provide one of these three, // ### this option will be ignored when loading values from a script. // ### You can also combine flags, for example with OptionBase::nosave: // ### (OptionBase::buildoption | OptionBase::nosave) // ### ex: declareOption(ol, "sourceFileName", &NetflixVMatrix::sourceFileName, OptionBase::buildoption, "Name of the source file - a netflix user profiles file."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::NetflixVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::VMatrix.
Definition at line 202 of file NetflixVMatrix.h.
:
//##### Protected Options ###############################################
NetflixVMatrix * PLearn::NetflixVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::VMatrix.
Definition at line 50 of file NetflixVMatrix.cc.
Get element at i-th row, j-th column.
Implements PLearn::VMatrix.
Definition at line 170 of file NetflixVMatrix.cc.
References PLERROR.
{ // get element at i-th row, j-th column PLERROR("Not implemented!"); return 0.0; }
void PLearn::NetflixVMatrix::getExample | ( | int | i, |
Vec & | input, | ||
Vec & | target, | ||
real & | weight | ||
) | [virtual] |
Default version calls getSubRow based on inputsize_ targetsize_ weightsize_ But exotic subclasses may construct, input, target and weight however they please.
If not a weighted matrix, weight should be set to default value 1.
Reimplemented from PLearn::VMatrix.
Definition at line 180 of file NetflixVMatrix.cc.
References i, and PLearn::TVec< T >::resize().
OptionList & PLearn::NetflixVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file NetflixVMatrix.cc.
OptionMap & PLearn::NetflixVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file NetflixVMatrix.cc.
RemoteMethodMap & PLearn::NetflixVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file NetflixVMatrix.cc.
void PLearn::NetflixVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::VMatrix.
Definition at line 209 of file NetflixVMatrix.cc.
References PLearn::deepCopyField(), and PLERROR.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: deepCopyField(sourceFileName, copies); deepCopyField(data, copies); // ### Remove this line when you have fully implemented this method. PLERROR("NetflixVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
Reimplemented from PLearn::VMatrix.
Definition at line 202 of file NetflixVMatrix.h.
Definition at line 76 of file NetflixVMatrix.h.
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 75 of file NetflixVMatrix.h.
Referenced by declareOptions().