Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::MultiInstanceNNet Class Reference

#include <MultiInstanceNNet.h>

Inheritance diagram for PLearn::MultiInstanceNNet:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MultiInstanceNNet ()
virtual ~MultiInstanceNNet ()
 PLEARN_DECLARE_OBJECT (MultiInstanceNNet)
virtual void setTrainingSet (VMat training_set, bool call_forget=true)
 Declares the train_set Then calls build() and forget() if necessary Note: You shouldn't have to overload this in subclasses, except in maybe to forward the call to an underlying learner.

virtual void build ()
 **** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()

virtual void forget ()
 (Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)

virtual int outputsize () const
 SUBCLASS WRITING: overload this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options.

virtual TVec< stringgetTrainCostNames () const
 *** SUBCLASS WRITING: *** This should return the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats

virtual TVec< stringgetTestCostNames () const
 *** SUBCLASS WRITING: *** This should return the names of the costs computed by computeCostsFromOutpus

virtual void train ()
 The role of the train method is to bring the learner up to stage==nstages, updating the stats with training costs measured on-line in the process.

virtual void computeOutput (const Vec &input, Vec &output) const
 *** SUBCLASS WRITING: *** This should be defined in subclasses to compute the output from the input

virtual void computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const
 Default calls computeOutput and computeCostsFromOutputs You may overload this if you have a more efficient way to compute both output and weighted costs at the same time.

virtual void computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const
 *** SUBCLASS WRITING: *** This should be defined in subclasses to compute the weighted costs from already computed output.

virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)

Public Attributes

Func f
Func test_costf
Func output_and_target_to_cost
int max_n_instances
int nhidden
int nhidden2
real weight_decay
real bias_decay
real layer1_weight_decay
real layer1_bias_decay
real layer2_weight_decay
real layer2_bias_decay
real output_layer_weight_decay
real output_layer_bias_decay
real direct_in_to_out_weight_decay
real classification_regularizer
bool L1_penalty
bool direct_in_to_out
real interval_minval
real interval_maxval
int test_bag_size
PP< Optimizeroptimizer
int batch_size

Protected Member Functions

void initializeParams ()

Static Protected Member Functions

void declareOptions (OptionList &ol)
 redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down)


Protected Attributes

Var input
Var target
Var sampleweight
Var w1
Var w2
Var wout
Var wdirect
Var output
Var bag_size
Var bag_inputs
Var bag_output
Func inputs_and_targets_to_test_costs
Func inputs_and_targets_to_training_costs
Func input_to_logP0
Var nll
VarArray costs
VarArray penalties
Var training_cost
Var test_costs
VarArray invars
VarArray params
Vec paramsvalues
int optstage_per_lstage
bool training_set_has_changed

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()

Private Attributes

Vec instance_logP0
 Used to store data between calls to computeCostsFromOutput.


Member Typedef Documentation

typedef PLearner PLearn::MultiInstanceNNet::inherited [private]
 

Reimplemented from PLearn::PLearner.

Definition at line 57 of file MultiInstanceNNet.h.


Constructor & Destructor Documentation

PLearn::MultiInstanceNNet::MultiInstanceNNet  ) 
 

Definition at line 103 of file MultiInstanceNNet.cc.

PLearn::MultiInstanceNNet::~MultiInstanceNNet  )  [virtual]
 

Definition at line 124 of file MultiInstanceNNet.cc.


Member Function Documentation

void PLearn::MultiInstanceNNet::build  )  [virtual]
 

**** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()

Reimplemented from PLearn::PLearner.

Definition at line 185 of file MultiInstanceNNet.cc.

References build_().

Referenced by setTrainingSet(), and train().

void PLearn::MultiInstanceNNet::build_  )  [private]
 

**** SUBCLASS WRITING: **** This method should finalize 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 (such as hyper-parameters) have been modified.

You can assume that the parent class' build_() has already been called.

A typical build method will want to know the inputsize(), targetsize() and outputsize(), and may also want to check whether train_set->hasWeights(). All these methods require a train_set to be set, so the first thing you may want to do, is check if(train_set), before doing any heavy building...

Note: build() is always called by setTrainingSet.

Reimplemented from PLearn::PLearner.

Definition at line 214 of file MultiInstanceNNet.cc.

References PLearn::affine_transform(), PLearn::affine_transform_weight_penalty(), PLearn::TVec< Var >::append(), bag_inputs, bag_output, bag_size, bias_decay, PLearn::binary_classification_loss(), costs, PLearn::cross_entropy(), direct_in_to_out, direct_in_to_out_weight_decay, PLearn::exp(), f, PLearn::hconcat(), initializeParams(), input, input_to_logP0, inputs_and_targets_to_test_costs, inputs_and_targets_to_training_costs, PLearn::PLearner::inputsize(), invars, L1_penalty, layer1_bias_decay, layer1_weight_decay, layer2_bias_decay, layer2_weight_decay, PLearn::lift_output(), PLearn::log(), PLearn::VarArray::makeSharedValue(), max_n_instances, PLearn::VarArray::nelems(), nhidden, nhidden2, output, output_layer_bias_decay, output_layer_weight_decay, outputsize(), params, paramsvalues, penalties, PLERROR, PLearn::TVec< T >::resize(), PLearn::TVec< Var >::resize(), sampleweight, PLearn::sigmoid(), PLearn::TVec< Var >::size(), PLearn::TVec< T >::size(), PLearn::sum(), PLearn::sumabs(), PLearn::sumsquare(), PLearn::tanh(), target, PLearn::PLearner::targetsize(), test_costs, training_cost, PLearn::transposeProduct(), PLearn::unfoldedSumOf(), w1, w2, wdirect, weight_decay, and wout.

Referenced by build().

void PLearn::MultiInstanceNNet::computeCostsFromOutputs const Vec input,
const Vec output,
const Vec target,
Vec costs
const [virtual]
 

*** SUBCLASS WRITING: *** This should be defined in subclasses to compute the weighted costs from already computed output.

The costs should correspond to the cost names returned by getTestCostNames() NOTE: In exotic cases, the cost may also depend on some info in the input, that's why the method also gets so see it.

Implements PLearn::PLearner.

Definition at line 518 of file MultiInstanceNNet.cc.

References PLearn::TVec< T >::fill(), instance_logP0, max_n_instances, MISSING_VALUE, nll, PLearn::TVec< T >::resize(), PLearn::safeexp(), PLearn::safeflog(), PLearn::sum(), and test_bag_size.

void PLearn::MultiInstanceNNet::computeOutput const Vec input,
Vec output
const [virtual]
 

*** SUBCLASS WRITING: *** This should be defined in subclasses to compute the output from the input

Implements PLearn::PLearner.

Definition at line 484 of file MultiInstanceNNet.cc.

References f.

void PLearn::MultiInstanceNNet::computeOutputAndCosts const Vec input,
const Vec target,
Vec output,
Vec costs
const [virtual]
 

Default calls computeOutput and computeCostsFromOutputs You may overload this if you have a more efficient way to compute both output and weighted costs at the same time.

Reimplemented from PLearn::PLearner.

Definition at line 492 of file MultiInstanceNNet.cc.

References bag_inputs, bag_size, f, PLearn::TVec< T >::fill(), inputs_and_targets_to_test_costs, MISSING_VALUE, sampleweight, target, and test_bag_size.

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

redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down)

ex: static void declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "the size of the input\n it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "the learnt model weights"); inherited::declareOptions(ol); }

Reimplemented from PLearn::PLearner.

Definition at line 128 of file MultiInstanceNNet.cc.

References PLearn::declareOption(), and PLearn::OptionList.

void PLearn::MultiInstanceNNet::forget  )  [virtual]
 

(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)

*** SUBCLASS WRITING: *** A typical forget() method should do the following:

  • initialize a random number generator with the seed option
  • initialize the learner's parameters, using this random generator
  • stage = 0; This method is typically called by the build_() method, after it has finished setting up the parameters, and if it deemed useful to set or reset the learner in its fresh state. (remember build may be called after modifying options that do not necessarily require the learner to restart from a fresh state...) forget is also called by the setTrainingSet method, after calling build(), so it will generally be called TWICE during setTrainingSet!

Implements PLearn::PLearner.

Definition at line 598 of file MultiInstanceNNet.cc.

References initializeParams().

Referenced by setTrainingSet().

TVec< string > PLearn::MultiInstanceNNet::getTestCostNames  )  const [virtual]
 

*** SUBCLASS WRITING: *** This should return the names of the costs computed by computeCostsFromOutpus

Implements PLearn::PLearner.

Definition at line 381 of file MultiInstanceNNet.cc.

TVec< string > PLearn::MultiInstanceNNet::getTrainCostNames  )  const [virtual]
 

*** SUBCLASS WRITING: *** This should return the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats

Implements PLearn::PLearner.

Definition at line 371 of file MultiInstanceNNet.cc.

void PLearn::MultiInstanceNNet::initializeParams  )  [protected]
 

Definition at line 550 of file MultiInstanceNNet.cc.

References direct_in_to_out, PLearn::fill_random_normal(), PLearn::PLearner::inputsize(), PLearn::manual_seed(), nhidden, nhidden2, optimizer, PLearn::seed(), w1, w2, wdirect, and wout.

Referenced by build_(), and forget().

void PLearn::MultiInstanceNNet::makeDeepCopyFromShallowCopy CopiesMap copies  )  [virtual]
 

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. Typical implementation:

void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { SUPERCLASS_OF_THIS::makeDeepCopyFromShallowCopy(copies); member_ptr = member_ptr->deepCopy(copies); member_smartptr = member_smartptr->deepCopy(copies); member_mat.makeDeepCopyFromShallowCopy(copies); member_vec.makeDeepCopyFromShallowCopy(copies); ... }

Reimplemented from PLearn::PLearner.

Definition at line 607 of file MultiInstanceNNet.cc.

References bag_inputs, bag_output, bag_size, PLearn::CopiesMap, costs, PLearn::deepCopyField(), f, input, input_to_logP0, inputs_and_targets_to_test_costs, inputs_and_targets_to_training_costs, instance_logP0, invars, nll, optimizer, output, output_and_target_to_cost, params, paramsvalues, penalties, sampleweight, target, test_costf, test_costs, training_cost, PLearn::varDeepCopyField(), w1, w2, wdirect, and wout.

int PLearn::MultiInstanceNNet::outputsize  )  const [virtual]
 

SUBCLASS WRITING: overload this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options.

Implements PLearn::PLearner.

Definition at line 368 of file MultiInstanceNNet.cc.

Referenced by build_().

PLearn::MultiInstanceNNet::PLEARN_DECLARE_OBJECT MultiInstanceNNet   ) 
 

void PLearn::MultiInstanceNNet::setTrainingSet VMat  training_set,
bool  call_forget = true
[virtual]
 

Declares the train_set Then calls build() and forget() if necessary Note: You shouldn't have to overload this in subclasses, except in maybe to forward the call to an underlying learner.

Reimplemented from PLearn::PLearner.

Definition at line 191 of file MultiInstanceNNet.cc.

References build(), forget(), PLearn::VMat::length(), training_set_has_changed, and PLearn::VMat::width().

void PLearn::MultiInstanceNNet::train  )  [virtual]
 

The role of the train method is to bring the learner up to stage==nstages, updating the stats with training costs measured on-line in the process.

*** SUBCLASS WRITING: ***

TYPICAL CODE:

static Vec input; // static so we don't reallocate/deallocate memory each time... static Vec target; // (but be careful that static means shared!) input.resize(inputsize()); // the train_set's inputsize() target.resize(targetsize()); // the train_set's targetsize() real weight;

if(!train_stats) // make a default stats collector, in case there's none train_stats = new VecStatsCollector();

if(nstages<stage) // asking to revert to a previous stage! forget(); // reset the learner to stage=0

while(stage<nstages) { clear statistics of previous epoch train_stats->forget();

... train for 1 stage, and update train_stats, using train_set->getSample(input, target, weight); and train_stats->update(train_costs)

++stage; train_stats->finalize(); // finalize statistics for this epoch }

Implements PLearn::PLearner.

Definition at line 391 of file MultiInstanceNNet.cc.

References batch_size, build(), PLearn::endl(), f, inputs_and_targets_to_training_costs, PLearn::PP< Function >::isNull(), PLearn::VMat::length(), max_n_instances, optimizer, optstage_per_lstage, params, PLERROR, PLearn::sumOverBags(), PLearn::tostring(), training_set_has_changed, PLearn::ProgressBar::update(), and PLearn::VMat::width().


Member Data Documentation

Var PLearn::MultiInstanceNNet::bag_inputs [protected]
 

Definition at line 74 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::bag_output [protected]
 

Definition at line 75 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::bag_size [protected]
 

Definition at line 73 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

int PLearn::MultiInstanceNNet::batch_size
 

Definition at line 129 of file MultiInstanceNNet.h.

Referenced by train().

real PLearn::MultiInstanceNNet::bias_decay
 

Definition at line 111 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::classification_regularizer
 

Definition at line 119 of file MultiInstanceNNet.h.

VarArray PLearn::MultiInstanceNNet::costs [protected]
 

Definition at line 82 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

bool PLearn::MultiInstanceNNet::direct_in_to_out
 

Definition at line 122 of file MultiInstanceNNet.h.

Referenced by build_(), and initializeParams().

real PLearn::MultiInstanceNNet::direct_in_to_out_weight_decay
 

Definition at line 118 of file MultiInstanceNNet.h.

Referenced by build_().

Func PLearn::MultiInstanceNNet::f [mutable]
 

Definition at line 95 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutput(), computeOutputAndCosts(), makeDeepCopyFromShallowCopy(), and train().

Var PLearn::MultiInstanceNNet::input [protected]
 

Definition at line 64 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Func PLearn::MultiInstanceNNet::input_to_logP0 [protected]
 

Definition at line 79 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Func PLearn::MultiInstanceNNet::inputs_and_targets_to_test_costs [protected]
 

Definition at line 77 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Func PLearn::MultiInstanceNNet::inputs_and_targets_to_training_costs [protected]
 

Definition at line 78 of file MultiInstanceNNet.h.

Referenced by build_(), makeDeepCopyFromShallowCopy(), and train().

Vec PLearn::MultiInstanceNNet::instance_logP0 [mutable, private]
 

Used to store data between calls to computeCostsFromOutput.

Definition at line 60 of file MultiInstanceNNet.h.

Referenced by computeCostsFromOutputs(), and makeDeepCopyFromShallowCopy().

real PLearn::MultiInstanceNNet::interval_maxval
 

Definition at line 123 of file MultiInstanceNNet.h.

real PLearn::MultiInstanceNNet::interval_minval
 

Definition at line 123 of file MultiInstanceNNet.h.

VarArray PLearn::MultiInstanceNNet::invars [protected]
 

Definition at line 86 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

bool PLearn::MultiInstanceNNet::L1_penalty
 

Definition at line 121 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::layer1_bias_decay
 

Definition at line 113 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::layer1_weight_decay
 

Definition at line 112 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::layer2_bias_decay
 

Definition at line 115 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::layer2_weight_decay
 

Definition at line 114 of file MultiInstanceNNet.h.

Referenced by build_().

int PLearn::MultiInstanceNNet::max_n_instances
 

Definition at line 105 of file MultiInstanceNNet.h.

Referenced by build_(), computeCostsFromOutputs(), and train().

int PLearn::MultiInstanceNNet::nhidden
 

Definition at line 107 of file MultiInstanceNNet.h.

Referenced by build_(), and initializeParams().

int PLearn::MultiInstanceNNet::nhidden2
 

Definition at line 108 of file MultiInstanceNNet.h.

Referenced by build_(), and initializeParams().

Var PLearn::MultiInstanceNNet::nll [protected]
 

Definition at line 80 of file MultiInstanceNNet.h.

Referenced by computeCostsFromOutputs(), and makeDeepCopyFromShallowCopy().

PP<Optimizer> PLearn::MultiInstanceNNet::optimizer
 

Definition at line 127 of file MultiInstanceNNet.h.

Referenced by initializeParams(), makeDeepCopyFromShallowCopy(), and train().

int PLearn::MultiInstanceNNet::optstage_per_lstage [protected]
 

Definition at line 91 of file MultiInstanceNNet.h.

Referenced by train().

Var PLearn::MultiInstanceNNet::output [protected]
 

Definition at line 72 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Func PLearn::MultiInstanceNNet::output_and_target_to_cost [mutable]
 

Definition at line 97 of file MultiInstanceNNet.h.

Referenced by makeDeepCopyFromShallowCopy().

real PLearn::MultiInstanceNNet::output_layer_bias_decay
 

Definition at line 117 of file MultiInstanceNNet.h.

Referenced by build_().

real PLearn::MultiInstanceNNet::output_layer_weight_decay
 

Definition at line 116 of file MultiInstanceNNet.h.

Referenced by build_().

VarArray PLearn::MultiInstanceNNet::params [protected]
 

Definition at line 87 of file MultiInstanceNNet.h.

Referenced by build_(), makeDeepCopyFromShallowCopy(), and train().

Vec PLearn::MultiInstanceNNet::paramsvalues [protected]
 

Definition at line 89 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

VarArray PLearn::MultiInstanceNNet::penalties [protected]
 

Definition at line 83 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::sampleweight [protected]
 

Definition at line 66 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::target [protected]
 

Definition at line 65 of file MultiInstanceNNet.h.

Referenced by build_(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

int PLearn::MultiInstanceNNet::test_bag_size [mutable]
 

Definition at line 124 of file MultiInstanceNNet.h.

Referenced by computeCostsFromOutputs(), and computeOutputAndCosts().

Func PLearn::MultiInstanceNNet::test_costf [mutable]
 

Definition at line 96 of file MultiInstanceNNet.h.

Referenced by makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::test_costs [protected]
 

Definition at line 85 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::training_cost [protected]
 

Definition at line 84 of file MultiInstanceNNet.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

bool PLearn::MultiInstanceNNet::training_set_has_changed [protected]
 

Definition at line 92 of file MultiInstanceNNet.h.

Referenced by setTrainingSet(), and train().

Var PLearn::MultiInstanceNNet::w1 [protected]
 

Definition at line 67 of file MultiInstanceNNet.h.

Referenced by build_(), initializeParams(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::w2 [protected]
 

Definition at line 68 of file MultiInstanceNNet.h.

Referenced by build_(), initializeParams(), and makeDeepCopyFromShallowCopy().

Var PLearn::MultiInstanceNNet::wdirect [protected]
 

Definition at line 70 of file MultiInstanceNNet.h.

Referenced by build_(), initializeParams(), and makeDeepCopyFromShallowCopy().

real PLearn::MultiInstanceNNet::weight_decay
 

Definition at line 110 of file MultiInstanceNNet.h.

Referenced by build_().

Var PLearn::MultiInstanceNNet::wout [protected]
 

Definition at line 69 of file MultiInstanceNNet.h.

Referenced by build_(), initializeParams(), and makeDeepCopyFromShallowCopy().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:27:08 2004 for PLearn by doxygen 1.3.7