28 : charset_map_(nullptr),
29 shape_table_(nullptr),
32 owned_shape_table_(nullptr) {
42 delete owned_shape_table_;
43 owned_shape_table_ =
nullptr;
55 randomize_ = randomize;
56 if (shape_table_ ==
nullptr && charset_map_ !=
nullptr) {
59 int num_fonts = sample_set_->
NumFonts();
62 for (
int c = 0; c < charsetsize; ++c) {
65 int shape_id = owned_shape_table_->
AddShape(c, 0);
66 for (
int f = 1; f < num_fonts; ++f) {
68 owned_shape_table_->
AddToShape(shape_id, c, f);
72 shape_table_ = owned_shape_table_;
74 if (shape_table_ !=
nullptr) {
77 num_shapes_ = randomize ? sample_set_->
num_samples()
89 shape_char_index_ = 0;
91 shape_font_index_ = 0;
100 return shape_index_ >= num_shapes_;
104 if (shape_table_ !=
nullptr) {
107 int font_id = shape_entry->
font_ids[shape_font_index_];
108 return *sample_set_->
GetSample(font_id, char_id, sample_index_);
110 return *sample_set_->
GetSample(shape_index_);
115 if (shape_table_ !=
nullptr) {
118 int font_id = shape_entry->
font_ids[shape_font_index_];
119 return sample_set_->
MutableSample(font_id, char_id, sample_index_);
128 if (shape_table_ !=
nullptr) {
131 int font_id = shape_entry->
font_ids[shape_font_index_];
143 return charset_map_ !=
nullptr ? charset_map_->
SparseToCompact(shape_index_)
157 if (shape_table_ !=
nullptr) {
160 if (sample_index_ < num_samples_)
166 if (shape_font_index_ >= num_shape_fonts_) {
168 shape_font_index_ = 0;
170 if (shape_char_index_ >= num_shape_chars_) {
172 shape_char_index_ = 0;
175 }
while (shape_index_ < num_shapes_ &&
176 charset_map_ !=
nullptr &&
178 if (shape_index_ >= num_shapes_)
180 num_shape_chars_ = shape_table_->
GetShape(shape_index_).
size();
186 int font_id = shape_entry->
font_ids[shape_font_index_];
187 num_samples_ = sample_set_->
NumClassSamples(font_id, char_id, randomize_);
188 }
while (num_samples_ == 0);
197 return charset_map_ !=
nullptr ? charset_map_->
CompactSize()
203 return charset_map_ !=
nullptr 205 : (shape_table_ !=
nullptr ? shape_table_->
NumShapes()
214 sample->MapFeatures(feature_map);
221 int num_good_samples = 0;
228 return num_good_samples;
234 double total_weight = 0.0;
235 int sample_count = 0;
238 total_weight +=
sample.weight();
242 double min_assigned_sample_weight = 1.0;
243 if (total_weight > 0.0) {
246 double weight =
sample->weight() / total_weight;
247 if (weight < min_assigned_sample_weight)
248 min_assigned_sample_weight = weight;
249 sample->set_weight(weight);
252 return min_assigned_sample_weight;
258 return &shape[shape_char_index_];
int CompactCharsetSize() const
int GlobalSampleIndex() const
double NormalizeSamples()
TrainingSample * MutableSample() const
int SparseCharsetSize() const
virtual int SparseSize() const
const TrainingSampleSet * sample_set() const
void MapSampleFeatures(const IntFeatureMap &feature_map)
TrainingSample * MutableSample(int font_id, int class_id, int index)
void Init(const IndexMapBiDi *charset_map, const ShapeTable *shape_table, bool randomize, TrainingSampleSet *sample_set)
int num_raw_samples() const
int GlobalSampleIndex(int font_id, int class_id, int index) const
int NumClassSamples(int font_id, int class_id, bool randomize) const
void AddToShape(int shape_id, int unichar_id, int font_id)
const Shape & GetShape(int shape_id) const
const TrainingSample * GetSample(int index) const
const UNICHARSET & unicharset() const
const ShapeTable * shape_table() const
int GetSparseClassID() const
int AddShape(int unichar_id, int font_id)
virtual int SparseToCompact(int sparse_index) const
const TrainingSample & GetSample() const
TrainingSample * mutable_sample(int index)
GenericVector< int32_t > font_ids
UNICHAR_ID class_id() const
const IndexMapBiDi & charset_map() const
int GetCompactClassID() const