PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Private Types | Private Member Functions | Private Attributes
PLearn::CorrelationProfiler Class Reference

Used to profile the correlation between the elements of a vector. More...

#include <CorrelationProfiler.h>

Inheritance diagram for PLearn::CorrelationProfiler:
Inheritance graph
[legend]
Collaboration diagram for PLearn::CorrelationProfiler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CorrelationProfiler ()
 Default constructor.
 CorrelationProfiler (int dim, string name)
void reset ()
void operator() (Vec &v)
void printAndReset ()
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual CorrelationProfilerdeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Public Attributes

int its_dim
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
string its_name

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

int n
Mat A
Vec sum_v

Detailed Description

Used to profile the correlation between the elements of a vector.

Todo:
Deprecated:

Definition at line 53 of file CorrelationProfiler.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Definition at line 55 of file CorrelationProfiler.h.


Constructor & Destructor Documentation

PLearn::CorrelationProfiler::CorrelationProfiler ( )

Default constructor.

Definition at line 52 of file CorrelationProfiler.cc.

                                              :   its_dim(0), 
                                                    its_name("noname")
    /* ### Initialize all fields to their default value */
{
    // ...

    // ### 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)
}
PLearn::CorrelationProfiler::CorrelationProfiler ( int  dim,
string  name 
)

Definition at line 64 of file CorrelationProfiler.cc.

                                                                :  its_dim(dim),
                                                its_name(name)
{
}

Member Function Documentation

string PLearn::CorrelationProfiler::_classname_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

OptionList & PLearn::CorrelationProfiler::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

RemoteMethodMap & PLearn::CorrelationProfiler::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

bool PLearn::CorrelationProfiler::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

Object * PLearn::CorrelationProfiler::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

StaticInitializer CorrelationProfiler::_static_initializer_ & PLearn::CorrelationProfiler::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

void PLearn::CorrelationProfiler::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::Object.

Definition at line 136 of file CorrelationProfiler.cc.

References PLearn::Object::build(), and build_().

Here is the call graph for this function:

void PLearn::CorrelationProfiler::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 180 of file CorrelationProfiler.cc.

References A, its_dim, PLASSERT, reset(), PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), and sum_v.

Referenced by build().

{
    // ### 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.
    PLASSERT( its_dim > 0 );
    A.resize(its_dim, its_dim);
    sum_v.resize(its_dim);
    reset();
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::CorrelationProfiler::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

void PLearn::CorrelationProfiler::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::Object.

Definition at line 157 of file CorrelationProfiler.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), its_dim, and its_name.

{
    // ### 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)

    declareOption(ol, "dimension", &CorrelationProfiler::its_dim,
                   OptionBase::buildoption,
                   "Dimension of the vector whose correlantion we want (integer).");
    declareOption(ol, "name", &CorrelationProfiler::its_name,
                   OptionBase::buildoption,
                   "Name of the vector whose correlantion we want (string)."
                    "Used in determining the output file's name in"
                    "printAndReset().");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::CorrelationProfiler::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 84 of file CorrelationProfiler.h.

:
    //#####  Protected Options  ###############################################
CorrelationProfiler * PLearn::CorrelationProfiler::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

OptionList & PLearn::CorrelationProfiler::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

OptionMap & PLearn::CorrelationProfiler::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

RemoteMethodMap & PLearn::CorrelationProfiler::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 50 of file CorrelationProfiler.cc.

void PLearn::CorrelationProfiler::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

Definition at line 142 of file CorrelationProfiler.cc.

References A, PLearn::deepCopyField(), PLearn::Object::makeDeepCopyFromShallowCopy(), and sum_v.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    deepCopyField(A, copies);
    deepCopyField(sum_v, copies);

    // ### Remove this line when you have fully implemented this method.
    //PLERROR("CorrelationProfiler::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

void PLearn::CorrelationProfiler::operator() ( Vec v)

Definition at line 78 of file CorrelationProfiler.cc.

References A, PLearn::externalProductAcc(), PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), n, PLASSERT, and sum_v.

{
    PLASSERT( A.length() == v.length() );
    externalProductAcc(A, v, v);
    sum_v += v;
    n++;
}

Here is the call graph for this function:

void PLearn::CorrelationProfiler::printAndReset ( )

Definition at line 87 of file CorrelationProfiler.cc.

References A, PLearn::endl(), PLearn::externalProductScaleAcc(), its_name, n, PLearn::TMat< T >::print(), reset(), and sum_v.

{

    cout << its_name << " - stats based on " << n << " samples." << endl;

    // *** Get mean
    sum_v /= n;

    // *** Divide by n-1 to get non-centered covariance
    A /= (real)(n-1);

    // *** Get the centered covariance
    externalProductScaleAcc(A, sum_v, sum_v, -1.0);

    // TODO check opening
    string file_name;
    file_name = its_name + "_covariance.txt";
    ofstream fd;
    fd.open( file_name.c_str() );
    A.print(fd);
    fd.close();

/*    // *** Get correlation by dividing by the product of the standard deviations
    Vec diagA = diag( A );
    // TODO Not very efficient. Isn't there a lapack function for this. 
    for(int i=0; i<A.length(); i++)   {
        for(int j=0; j<i; j++)   {
            A(i,j) /= sqrt( diagA[i]*diagA[j] );
            A(j,i) = A(i,j);
        }
        // the diagonal
        A(i,i) = 1.0;
    }

    // *** Open file, print correlation and close.
    // TODO check opening
    string file_name;
    file_name = its_name + ".txt";
    ofstream fd;
    fd.open( file_name.c_str() );
    A.print(fd);
    fd.close();*/

    // *** Reset
    reset();
}

Here is the call graph for this function:

void PLearn::CorrelationProfiler::reset ( )

Definition at line 70 of file CorrelationProfiler.cc.

References A, PLearn::TMat< T >::clear(), PLearn::TVec< T >::clear(), n, and sum_v.

Referenced by build_(), and printAndReset().

{
    A.clear();
    sum_v.clear();
    n = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 84 of file CorrelationProfiler.h.

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Definition at line 62 of file CorrelationProfiler.h.

Referenced by build_(), and declareOptions().

Definition at line 63 of file CorrelationProfiler.h.

Referenced by declareOptions(), and printAndReset().

Definition at line 116 of file CorrelationProfiler.h.

Referenced by operator()(), printAndReset(), and reset().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines