30 : charset_map_(nullptr)
31 , shape_table_(nullptr)
32 , sample_set_(nullptr)
34 , owned_shape_table_(nullptr) {
44 delete owned_shape_table_;
45 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) {
88 shape_char_index_ = 0;
90 shape_font_index_ = 0;
99 return shape_index_ >= num_shapes_;
103 if (shape_table_ !=
nullptr) {
106 int font_id = shape_entry->
font_ids[shape_font_index_];
107 return *sample_set_->
GetSample(font_id, char_id, sample_index_);
109 return *sample_set_->
GetSample(shape_index_);
114 if (shape_table_ !=
nullptr) {
117 int font_id = shape_entry->
font_ids[shape_font_index_];
118 return sample_set_->
MutableSample(font_id, char_id, sample_index_);
127 if (shape_table_ !=
nullptr) {
130 int font_id = shape_entry->
font_ids[shape_font_index_];
155 if (shape_table_ !=
nullptr) {
158 if (sample_index_ < num_samples_) {
165 if (shape_font_index_ >= num_shape_fonts_) {
167 shape_font_index_ = 0;
169 if (shape_char_index_ >= num_shape_chars_) {
171 shape_char_index_ = 0;
174 }
while (shape_index_ < num_shapes_ && charset_map_ !=
nullptr &&
176 if (shape_index_ >= num_shapes_) {
179 num_shape_chars_ = shape_table_->
GetShape(shape_index_).
size();
183 num_shape_fonts_ = shape_entry->
font_ids.size();
185 int font_id = shape_entry->
font_ids[shape_font_index_];
186 num_samples_ = sample_set_->
NumClassSamples(font_id, char_id, randomize_);
187 }
while (num_samples_ == 0);
201 return charset_map_ !=
nullptr
209 std::vector<int> indexed_features;
222 MapFeatures(*sample, feature_map);
229 int num_good_samples = 0;
236 return num_good_samples;
242 double total_weight = 0.0;
243 int sample_count = 0;
246 total_weight += sample.
weight();
250 double min_assigned_sample_weight = 1.0;
251 if (total_weight > 0.0) {
254 double weight = sample->
weight() / total_weight;
255 if (weight < min_assigned_sample_weight) {
256 min_assigned_sample_weight = weight;
261 return min_assigned_sample_weight;
267 return &shape[shape_char_index_];
int SparseSize() const override
int SparseToCompact(int sparse_index) const override
void IndexAndSortFeatures(const INT_FEATURE_STRUCT *features, int num_features, std::vector< int > *sorted_features) const
std::vector< int32_t > font_ids
void AddToShape(unsigned shape_id, int unichar_id, int font_id)
unsigned AddShape(int unichar_id, int font_id)
unsigned NumShapes() const
const Shape & GetShape(unsigned shape_id) const
const INT_FEATURE_STRUCT * features() const
UNICHAR_ID class_id() const
uint32_t num_features() const
bool features_are_mapped_
void set_weight(double value)
std::vector< int > mapped_features_
bool features_are_indexed_
int MapIndexedFeatures(const std::vector< int > &index_features, std::vector< int > *map_features) const
const IntFeatureSpace & feature_space() const
const TrainingSample & GetSample() const
void Init(const IndexMapBiDi *charset_map, const ShapeTable *shape_table, bool randomize, TrainingSampleSet *sample_set)
const TrainingSampleSet * sample_set() const
void MapSampleFeatures(const IntFeatureMap &feature_map)
int GlobalSampleIndex() const
const IndexMapBiDi & charset_map() const
int SparseCharsetSize() const
TrainingSample * MutableSample() const
int CompactCharsetSize() const
int GetSparseClassID() const
double NormalizeSamples()
int GetCompactClassID() const
const ShapeTable * shape_table() const
int NumClassSamples(int font_id, int class_id, bool randomize) const
int num_raw_samples() const
const UNICHARSET & unicharset() const
int GlobalSampleIndex(int font_id, int class_id, int index) const
TrainingSample * mutable_sample(int index)
const TrainingSample * GetSample(int index) const
TrainingSample * MutableSample(int font_id, int class_id, int index)