PLearn 0.1
|
Generate samples from a mixture of two gaussians. More...
#include <AnalyzeDond2DiscreteVariables.h>
Public Member Functions | |
AnalyzeDond2DiscreteVariables () | |
Default constructor. | |
int | outputsize () const |
SUBCLASS WRITING: override this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options. | |
void | train () |
*** SUBCLASS WRITING: *** | |
void | computeOutput (const Vec &, Vec &) const |
*** SUBCLASS WRITING: *** | |
void | computeCostsFromOutputs (const Vec &, const Vec &, const Vec &, Vec &) const |
*** SUBCLASS WRITING: *** | |
TVec< string > | getTestCostNames () const |
*** SUBCLASS WRITING: *** | |
TVec< string > | getTrainCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual AnalyzeDond2DiscreteVariables * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Finish building the object; just call inherited::build followed by build_() | |
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 PPath & | declaringFile () |
Public Attributes | |
string | variable_name |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
string | target_name |
The field name of the target. | |
TVec< pair< real, real > > | values_to_analyze |
The vector of values to check the correlation with the target. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
void | analyzeDiscreteVariable () |
Generate samples from a mixture of two gaussians.
Definition at line 52 of file AnalyzeDond2DiscreteVariables.h.
typedef PLearner PLearn::AnalyzeDond2DiscreteVariables::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 54 of file AnalyzeDond2DiscreteVariables.h.
PLearn::AnalyzeDond2DiscreteVariables::AnalyzeDond2DiscreteVariables | ( | ) |
string PLearn::AnalyzeDond2DiscreteVariables::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
OptionList & PLearn::AnalyzeDond2DiscreteVariables::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
RemoteMethodMap & PLearn::AnalyzeDond2DiscreteVariables::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
Object * PLearn::AnalyzeDond2DiscreteVariables::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
StaticInitializer AnalyzeDond2DiscreteVariables::_static_initializer_ & PLearn::AnalyzeDond2DiscreteVariables::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
void PLearn::AnalyzeDond2DiscreteVariables::analyzeDiscreteVariable | ( | ) | [private] |
Definition at line 114 of file AnalyzeDond2DiscreteVariables.cc.
References PLearn::TVec< T >::clear(), PLearn::endl(), PLearn::is_missing(), PLERROR, PLearn::TVec< T >::size(), and PLearn::ProgressBar::update().
{ // initialize primary dataset int main_length = train_set->length(); int main_width = train_set->width(); Vec main_input(main_width); TVec<string> main_names(main_width); main_names << train_set->fieldNames(); // check for valid options int number_of_values = values_to_analyze.size(); int variable_col = -1; int target_col = -1; for (int main_col = 0; main_col < main_width; main_col++) { if (variable_name == main_names[main_col]) variable_col = main_col; if (target_name == main_names[main_col]) target_col = main_col; } if (variable_col < 0) PLERROR("In AnalyzeDond2DiscreteVariables: variable name not found: %s", variable_name.c_str()); if (target_col < 0) PLERROR("In AnalyzeDond2DiscreteVariables: target name not found: %s", target_name.c_str()); if (number_of_values <= 0) PLERROR("In AnalyzeDond2DiscreteVariables: invalid values_to_analyze"); // initialize working variables Vec value_target_sum(number_of_values); Vec value_present_count(number_of_values); value_target_sum.clear(); value_present_count.clear(); real target_sum = 0.0; real target_squared_sum = 0.0; real variable_present_count = 0.0; //Now, we can process the discrete variable. ProgressBar* pb = 0; pb = new ProgressBar( "Analyzing discrete variable " + variable_name, main_length); for (int main_row = 0; main_row < main_length; main_row++) { train_set->getRow(main_row, main_input); real variable_value = main_input[variable_col]; if (is_missing(variable_value)) continue; real target_value = main_input[target_col]; target_sum += target_value; target_squared_sum += target_value * target_value; variable_present_count += 1.0; for (int value_col = 0; value_col < number_of_values; value_col++) { if (variable_value < values_to_analyze[value_col].first || variable_value > values_to_analyze[value_col].second) continue; value_target_sum[value_col] += target_value; value_present_count[value_col] += 1.0; } pb->update( main_row ); } delete pb; if (variable_present_count <= 0.0) { cout << "In AnalyzeDond2DiscreteVariables: no value present for this variable" << endl; return; } real target_mean = target_sum / variable_present_count; cout << "In AnalyzeDond2DiscreteVariables, for variable: " << variable_name << endl; cout << variable_present_count << " values are present out of " << main_length << " samples." << endl; for (int value_col = 0; value_col < number_of_values; value_col++) { real ssxy = value_target_sum[value_col] - value_present_count[value_col] * target_mean; real ss2xy = ssxy * ssxy; real ssxx = value_present_count[value_col] * (1.0 - value_present_count[value_col] / variable_present_count); real ssyy = target_squared_sum - target_sum * target_mean; real correlation_coefficient = ss2xy / (ssxx * ssyy); cout << "For value from: " << values_to_analyze[value_col].first << " to: " << values_to_analyze[value_col].second << " occurence: " << value_present_count[value_col] << " correlation coefficient: " << correlation_coefficient << endl; } }
void PLearn::AnalyzeDond2DiscreteVariables::build | ( | ) | [virtual] |
Finish building the object; just call inherited::build followed by build_()
Reimplemented from PLearn::PLearner.
Definition at line 95 of file AnalyzeDond2DiscreteVariables.cc.
{ // ### Nothing to add here, simply calls build_(). inherited::build(); build_(); }
void PLearn::AnalyzeDond2DiscreteVariables::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Definition at line 105 of file AnalyzeDond2DiscreteVariables.cc.
References PLERROR.
{ if (train_set) { analyzeDiscreteVariable(); PLERROR("AnalyzeDond2DiscreteVariables: we are done here"); } }
string PLearn::AnalyzeDond2DiscreteVariables::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
void PLearn::AnalyzeDond2DiscreteVariables::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 189 of file AnalyzeDond2DiscreteVariables.cc.
{}
void PLearn::AnalyzeDond2DiscreteVariables::computeOutput | ( | const Vec & | input, |
Vec & | output | ||
) | const [virtual] |
*** SUBCLASS WRITING: ***
This should be defined in subclasses to compute the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 188 of file AnalyzeDond2DiscreteVariables.cc.
{}
void PLearn::AnalyzeDond2DiscreteVariables::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PLearner.
Definition at line 61 of file AnalyzeDond2DiscreteVariables.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), target_name, values_to_analyze, and variable_name.
{ declareOption(ol, "variable_name", &AnalyzeDond2DiscreteVariables::variable_name, OptionBase::buildoption, "The field name of the variable to be analyzed."); declareOption(ol, "target_name", &AnalyzeDond2DiscreteVariables::target_name, OptionBase::buildoption, "The field name of the target."); declareOption(ol, "values_to_analyze", &AnalyzeDond2DiscreteVariables::values_to_analyze, OptionBase::buildoption, "The vector of values to check the correlation with the target.\n" "The algorithm groups the values from, to of each pair specified.\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::AnalyzeDond2DiscreteVariables::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Definition at line 93 of file AnalyzeDond2DiscreteVariables.h.
:
//##### Protected Member Functions ######################################
AnalyzeDond2DiscreteVariables * PLearn::AnalyzeDond2DiscreteVariables::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
OptionList & PLearn::AnalyzeDond2DiscreteVariables::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
OptionMap & PLearn::AnalyzeDond2DiscreteVariables::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
RemoteMethodMap & PLearn::AnalyzeDond2DiscreteVariables::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file AnalyzeDond2DiscreteVariables.cc.
TVec< string > PLearn::AnalyzeDond2DiscreteVariables::getTestCostNames | ( | ) | const [virtual] |
*** SUBCLASS WRITING: ***
This should return the names of the costs computed by computeCostsFromOutputs.
Implements PLearn::PLearner.
Definition at line 190 of file AnalyzeDond2DiscreteVariables.cc.
References PLearn::TVec< T >::append().
{ TVec<string> result; result.append( "MSE" ); return result; }
TVec< string > PLearn::AnalyzeDond2DiscreteVariables::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 196 of file AnalyzeDond2DiscreteVariables.cc.
References PLearn::TVec< T >::append().
{ TVec<string> result; result.append( "MSE" ); return result; }
void PLearn::AnalyzeDond2DiscreteVariables::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 83 of file AnalyzeDond2DiscreteVariables.cc.
References PLearn::deepCopyField().
{ deepCopyField(values_to_analyze, copies); deepCopyField(variable_name, copies); deepCopyField(target_name, copies); inherited::makeDeepCopyFromShallowCopy(copies); }
int PLearn::AnalyzeDond2DiscreteVariables::outputsize | ( | ) | const [virtual] |
SUBCLASS WRITING: override 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 186 of file AnalyzeDond2DiscreteVariables.cc.
{return 0;}
void PLearn::AnalyzeDond2DiscreteVariables::train | ( | ) | [virtual] |
*** SUBCLASS WRITING: ***
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.
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 187 of file AnalyzeDond2DiscreteVariables.cc.
{}
Reimplemented from PLearn::PLearner.
Definition at line 93 of file AnalyzeDond2DiscreteVariables.h.
The field name of the target.
Definition at line 67 of file AnalyzeDond2DiscreteVariables.h.
Referenced by declareOptions().
The vector of values to check the correlation with the target.
The algorithm groups the values from, to of each pair specified.
Definition at line 71 of file AnalyzeDond2DiscreteVariables.h.
Referenced by declareOptions().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
The field name of the variable to be analyzed.
Definition at line 64 of file AnalyzeDond2DiscreteVariables.h.
Referenced by declareOptions().