bool getTrainSamplesFeaturesAndGt(const MatrixType &features_matrix,const VectorType >_vector,MatrixType &sampled_features_matrix, VectorType &sampled_gt_vector,unsigned int n_pos_samples,unsigned int n_neg_samples,float pos_thresh = 100.0){ unsigned int n_features_tot = features_matrix.cols(); sampled_features_matrix = MatrixType::Zero(n_neg_samples+n_pos_samples,n_features_tot); sampled_gt_vector = VectorType::Zero(n_neg_samples+n_pos_samples); // std::cout << "finding samples " << std::endl; MatrixTypeUint pos_indeces;// = getIndecesGreater<VectorType>(gt_vector,pos_thresh); //find(gt_vector>=pos_thresh) MatrixTypeUint neg_indeces;// = getIndecesSmaller<VectorType>(gt_vector,pos_thresh); //find(gt_vector<pos_thresh) getIndecesSmallerGreater<VectorType>(gt_vector,pos_thresh,neg_indeces,pos_indeces); //find(gt_vector>=pos_thresh) and find(gt_vector<pos_thresh) if(pos_indeces.rows() < ((float)n_pos_samples)/100.0){ std::cout << "No enough Positive samples found for image "<< std::endl; return false; } if(neg_indeces.rows() < ((float)n_neg_samples)/100.0){ std::cout << "No enough Negative samples found for image " << std::endl; return false; } boost::random::mt19937 generator_pos; generator_pos.seed(static_cast<unsigned int>(std::time(0))); boost::random::uniform_int_distribution<unsigned int> distribution_pos(0,pos_indeces.rows()-1); boost::random::mt19937 generator_neg; generator_neg.seed(static_cast<unsigned int>(std::time(0))); boost::random::uniform_int_distribution<unsigned int> distribution_neg(0,neg_indeces.rows()-1); //get pos samples for(unsigned int i_pos =0; i_pos<n_pos_samples;i_pos++ ){ unsigned int rand_pos_index = distribution_pos(generator_pos); sampled_features_matrix.row(i_pos) = features_matrix.row(pos_indeces(rand_pos_index)); sampled_gt_vector(i_pos) = gt_vector(pos_indeces(rand_pos_index)); } // get neg samples for(unsigned int i_neg =0; i_neg<n_neg_samples;i_neg++ ){ unsigned int rand_neg_index = distribution_neg(generator_neg); sampled_features_matrix.row(i_neg+n_pos_samples) = features_matrix.row(neg_indeces(rand_neg_index)); sampled_gt_vector(i_neg+n_pos_samples) = gt_vector(neg_indeces(rand_neg_index)); } return true; }
int main(int argc, char *argv[]) { QApplication qapp(argc, argv); eng::Engine engine; bool do_solarsystem = true; //do_solarsystem = false; if(do_solarsystem) { // init solar system example // mass, X, Y, speedX, speedY, name, color engine.add_astre( 2e30, 1, 1, 0, 0, "sun", Qt::yellow); engine.add_astre( 3.3e23, 1.38, 1, 0, 47.15, "mercure", Qt::darkGray); engine.add_astre(4.87e24, 1.72, 1, 0, 35.15, "venus", Qt::darkYellow); engine.add_astre(5.98e24, 2, 1, 0, 29.82, "earth", Qt::blue); engine.add_astre(7.34e22,2.00257, 1, 0, 30.82, "moon", Qt::white); engine.add_astre(5.98e24, 2.5, 1, 0, 24.35, "mars", Qt::red); std::cout << "KILOMETER_PER_PIXEL = " << KILOMETER_PER_PIXEL << std::endl; std::cout << "PIXEL_PER_KILOMETER = " << PIXEL_PER_KILOMETER << std::endl; std::cout << " KILOMETER_PER_AU = " << KILOMETER_PER_AU << std::endl; std::cout << " METER_PER_PIXEL = " << METER_PER_PIXEL << std::endl; std::cout << " PIXEL_PER_METER = " << PIXEL_PER_METER << std::endl; } else { std::uniform_int_distribution<int> distribution_pos(0,200); std::uniform_int_distribution<int> distribution_spd(-3,3); std::uniform_int_distribution<int> distribution_mass(10,18); for(int i = 0; i < 1500; i++) { double pos_x = distribution_pos(random_gen) / 100.; double pos_y = distribution_pos(random_gen) / 100.; int spd_x = distribution_spd(random_gen); int spd_y = distribution_spd(random_gen); engine.add_astre(pow(10, distribution_mass(random_gen)), pos_x, pos_y, spd_x, spd_y, "unamed"); } } view::Universe universe_view(engine); universe_view.show(); return qapp.exec(); }