Skip to content
Snippets Groups Projects
Commit 4e3cc88f authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Adding a sampling strategy to set a percentage of samples to be used in each class

parent 2fe99578
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,15 @@ private:
AddParameter(ParameterType_Int, "strategy.constant.nb", "Number of samples for all classes");
SetParameterDescription("strategy.constant.nb", "Number of samples for all classes");
AddChoice("strategy.percent","Use a percentage of the samples available for each class");
SetParameterDescription("strategy.percent","Use a percentage of the samples available for each class");
AddParameter(ParameterType_Float,"strategy.percent.p","The percentage to use");
SetParameterDescription("strategy.percent.p","The percentage to use");
SetMinimumParameterFloatValue("strategy.percent.p",0);
SetMaximumParameterFloatValue("strategy.percent.p",1);
SetDefaultParameterFloat("strategy.percent.p",0.5);
AddChoice("strategy.smallest","Set same number of samples for all classes, with the smallest class fully sampled");
SetParameterDescription("strategy.smallest","Set same number of samples for all classes, with the smallest class fully sampled");
......@@ -234,15 +243,22 @@ private:
m_RateCalculator->SetNbOfSamplesAllClasses(GetParameterInt("strategy.constant.nb"));
}
break;
// smallest class
// percent
case 2:
{
otbAppLogINFO("Sampluing strategy: set a percentage of samples for each class.");
m_RateCalculator->SetPercentageOfSamples(this->GetParameterFloat("strategy.percent.p"));
}
break;
// smallest class
case 3:
{
otbAppLogINFO("Sampling strategy : fit the number of samples based on the smallest class");
m_RateCalculator->SetMinimumNbOfSamplesByClass();
}
break;
// all samples
case 3:
case 4:
{
otbAppLogINFO("Sampling strategy : take all samples");
m_RateCalculator->SetAllSamples();
......
......@@ -68,6 +68,9 @@ public:
/** Method to set the same number of required samples in each class */
void SetNbOfSamplesAllClasses(unsigned long);
/** Method to set a percentage of samples for each class */
void SetPercentageOfSamples(double percent);
/** Method to choose a sampling strategy based on the smallest class.
* The number of samples in each class is set to this minimum size*/
void SetMinimumNbOfSamplesByClass(void);
......
......@@ -110,6 +110,19 @@ SamplingRateCalculator
}
}
void SamplingRateCalculator
::SetPercentageOfSamples(double percent)
{
MapRateType::iterator it = m_RatesByClass.begin();
for (; it != m_RatesByClass.end() ; ++it)
{
it->second.Required = static_cast<unsigned long>(vcl_floor(0.5+percent * it->second.Tot));
it->second.Rate = percent;
}
}
void
SamplingRateCalculator
::Write(std::string filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment