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

#include <CartesianProductOracle.h>

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

List of all members.

Public Member Functions

 CartesianProductOracle ()
virtual TVec< string > getOptionNames () const
 returns the set of names of options this generator generates
virtual TVec< string > generateNextTrial (const TVec< string > &older_trial, real obtained_objective)
virtual void forget ()
 SUBCLASS WRITING: Should reset the generator's internal state (as having no info about previous trials).
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual CartesianProductOracledeepCopy (CopiesMap &copies) const

Static Public Member Functions

static string _classname_ ()
 Declares name and deepCopy methods.
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

TVec< string > option_names
 name of options
TVec< TVec< string > > option_values
 A list of option values for each option name.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

TVec< intoption_values_indices
bool last_combination

Private Types

typedef OptionsOracle inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 48 of file CartesianProductOracle.h.


Member Typedef Documentation

Reimplemented from PLearn::OptionsOracle.

Definition at line 50 of file CartesianProductOracle.h.


Constructor & Destructor Documentation

PLearn::CartesianProductOracle::CartesianProductOracle ( )

Definition at line 45 of file CartesianProductOracle.cc.

    :OptionsOracle(), last_combination(false)
/* ### Initialise all fields to their default value */
{
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

void PLearn::CartesianProductOracle::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::OptionsOracle.

Definition at line 137 of file CartesianProductOracle.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::OptionsOracle.

Definition at line 115 of file CartesianProductOracle.cc.

References forget(), i, PLearn::TVec< T >::length(), n, option_names, option_values, option_values_indices, PLERROR, PLWARNING, PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().

Referenced by build().

{
    // Ensure consistency between option_names and option_values
    if (option_names.size() != option_values.size())
        PLERROR("CartesianProductOracle::build_: the 'option_names' and 'option_values'\n"
                "fields don't have the same length; len(option_names)=%d / len(option_values)=%d",
                option_names.size(), option_values.size());
    if (option_names.size() == 0 || option_values.size() == 0)
        PLWARNING("CartesianProductOracle::build_: either 'option_names' or 'option_values'\n"
                  "has size zero; is this what you want?");

    // Try to detect zero-length subarrays of options
    for (int i=0, n=option_values.size() ; i<n ; ++i)
        if (option_values[i].size() == 0)
            PLWARNING("CartesianProductOracle::build_: zero option values were specified\n"
                      "for option '%s'", option_names[i].c_str());

    option_values_indices.resize(option_names.length());
    forget();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file CartesianProductOracle.cc.

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

Declares this class' options.

Reimplemented from PLearn::OptionsOracle.

Definition at line 61 of file CartesianProductOracle.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::OptionsOracle::declareOptions(), PLearn::OptionBase::learntoption, option_names, option_values, and option_values_indices.

{
    declareOption(ol, "option_names", &CartesianProductOracle::option_names, OptionBase::buildoption,
                  "name of each of the options to optimize");

    declareOption(ol, "option_values", &CartesianProductOracle::option_values, OptionBase::buildoption,
                  "A list of lists of options: the top list must have as many elements as there are"
                  "options in the option_names field. Each sub-list contains the values to be tried"
                  "for the corresponding option."
        );
    declareOption(ol, "option_values_indices",
                  &CartesianProductOracle::option_values_indices,
                  OptionBase::learntoption,
                  "The indices of each option value.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::OptionsOracle.

Definition at line 107 of file CartesianProductOracle.h.

CartesianProductOracle * PLearn::CartesianProductOracle::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::OptionsOracle.

Definition at line 59 of file CartesianProductOracle.cc.

void PLearn::CartesianProductOracle::forget ( ) [virtual]

SUBCLASS WRITING: Should reset the generator's internal state (as having no info about previous trials).

Implements PLearn::OptionsOracle.

Definition at line 109 of file CartesianProductOracle.cc.

References PLearn::TVec< T >::clear(), last_combination, and option_values_indices.

Referenced by build_().

Here is the call graph for this function:

Here is the caller graph for this function:

TVec< string > PLearn::CartesianProductOracle::generateNextTrial ( const TVec< string > &  older_trial,
real  obtained_objective 
) [virtual]

SUBCLASS WRITING: This notifies the oracle, of the result obtained for a previous trial it suggested. The oracle is expected to return the next suggestion, or an empty vector if stopping conditions were met, or it run out of suggestions. An empty vector may be passed for older_trial if there is no result to report.

Implements PLearn::OptionsOracle.

Definition at line 85 of file CartesianProductOracle.cc.

References i, last_combination, PLearn::TVec< T >::length(), n, option_names, option_values, and option_values_indices.

{
    if (last_combination)
        return TVec<string>();
    else
    {
        int n=option_names.length();
        TVec<string> values(n);
        // copy current combination
        for (int i=0;i<n;i++)
            values[i]=option_values[i][option_values_indices[i]];
        // increment indices to next combination, in lexicographical order
        last_combination=true;
        for (int i=0;i<n;i++)
        {
            option_values_indices[i]++;
            if (option_values_indices[i]<option_values[i].length()) { last_combination=false; break; }
            else option_values_indices[i]=0;
        }
        return values;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file CartesianProductOracle.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file CartesianProductOracle.cc.

TVec< string > PLearn::CartesianProductOracle::getOptionNames ( ) const [virtual]

returns the set of names of options this generator generates

Implements PLearn::OptionsOracle.

Definition at line 80 of file CartesianProductOracle.cc.

References option_names.

{
    return option_names;
}
RemoteMethodMap & PLearn::CartesianProductOracle::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file CartesianProductOracle.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::OptionsOracle.

Definition at line 144 of file CartesianProductOracle.cc.

References PLearn::deepCopyField(), PLearn::OptionsOracle::makeDeepCopyFromShallowCopy(), option_names, option_values, and option_values_indices.

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::OptionsOracle.

Definition at line 107 of file CartesianProductOracle.h.

Definition at line 59 of file CartesianProductOracle.h.

Referenced by forget(), and generateNextTrial().

A list of option values for each option name.

Definition at line 68 of file CartesianProductOracle.h.

Referenced by build_(), declareOptions(), generateNextTrial(), and makeDeepCopyFromShallowCopy().


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