/*-------------------------------------------------------------------------*/ void resetParam(AzParam &azp) { const char *eyec = "AzPrepText2_gen_regions_parsup_Param::resetParam"; azp.vInt(kw_top_num_each, &top_num_each); azp.vInt(kw_top_num_total, &top_num_total); azp.vStr(kw_feat_fn, &s_feat_fn); azp.vStr(kw_xtyp, &s_xtyp); azp.vStr(kw_xdic_fn, &s_xdic_fn); azp.vStr(kw_inp_fn, &s_inp_fn); azp.vStr(kw_rnm, &s_rnm); azp.vStr(kw_txt_ext, &s_txt_ext); azp.vInt(kw_pch_sz, &pch_sz); azp.vInt(kw_pch_step, &pch_step); azp.vInt(kw_padding, &padding); f_pch_sz = pch_sz; f_pch_step = 1; f_padding = f_pch_sz - 1; azp.vInt(kw_f_pch_sz, &f_pch_sz); azp.vInt(kw_f_pch_step, &f_pch_step); azp.vInt(kw_f_padding, &f_padding); azp.vInt(kw_min_x, &min_x); azp.vInt(kw_min_y, &min_y); azp.vInt(kw_dist, &dist); azp.swOn(&do_lower, kw_do_lower); azp.swOn(&do_utf8dashes, kw_do_utf8dashes); azp.swOn(&do_nolr, kw_do_nolr); azp.vStr(kw_batch_id, &s_batch_id); azp.vStr(kw_x_ext, &s_x_ext); azp.vStr(kw_y_ext, &s_y_ext); azp.swOn(&do_binarize, kw_do_binarize); if (!do_binarize) { azp.vFloat(kw_scale_y, &scale_y); } azp.vFloat(kw_min_yval, &min_yval); AzXi::throw_if_empty(s_feat_fn, eyec, kw_feat_fn); AzXi::throw_if_empty(s_xtyp, eyec, kw_xtyp); AzXi::throw_if_empty(s_xdic_fn, eyec, kw_xdic_fn); AzXi::throw_if_empty(s_inp_fn, eyec, kw_inp_fn); AzXi::throw_if_empty(s_rnm, eyec, kw_rnm); AzXi::throw_if_nonpositive(pch_sz, eyec, kw_pch_sz); AzXi::throw_if_nonpositive(pch_step, eyec, kw_pch_step); AzXi::throw_if_negative(padding, eyec, kw_padding); AzXi::throw_if_nonpositive(f_pch_sz, eyec, kw_f_pch_sz); AzXi::throw_if_nonpositive(f_pch_step, eyec, kw_f_pch_step); AzXi::throw_if_negative(f_padding, eyec, kw_f_padding); AzXi::throw_if_nonpositive(dist, eyec, kw_dist); if (f_pch_sz > dist) { AzBytArr s(kw_f_pch_sz); s << " must be no greater than " << kw_dist << "."; AzX::throw_if(true, AzInputError, eyec, s.c_str()); } }
void resetParam(AzParam &azp, const char *pfx, bool is_warmstart=false) { azp.reset_prefix(pfx); azp.vFloat(kw_rho, &rho); azp.vFloat(kw_eps, &eps); coeff = 1; azp.reset_prefix(); }
virtual void resetParam(AzParam &azp, const char *pfx, bool is_warmstart) { azp.reset_prefix(pfx); if (!is_warmstart) { azp.vStr(kw_activ_typ, &s_activ_typ); if (s_activ_typ.length() > 0) typ = *s_activ_typ.point(); azp.vFloat(kw_trunc, &trunc); } azp.swOn(&do_stat, kw_do_stat); azp.reset_prefix(); }
/*------------------------------------------------------------------*/ void AzOptOnTree::resetParam(AzParam &p) { p.vFloat(kw_lambda, &lambda); p.vFloat(kw_sigma, &sigma); p.vInt(kw_max_ite_num, &max_ite_num); p.vFloat(kw_eta, &eta); p.vFloat(kw_exit_delta, &exit_delta); p.vFloat(kw_max_delta, &max_delta); p.swOn(&doUseAvg, kw_doUseAvg); p.swOff(&doIntercept, kw_not_doIntercept); /* useless but keep this for compatibility */ p.swOn(&doIntercept, kw_doIntercept); if (max_ite_num <= 0) { max_ite_num = max_ite_num_dflt_oth; if (AzLoss::isExpoFamily(loss_type)) { max_ite_num = max_ite_num_dflt_expo; } } }
/*--------------------------------------------------------*/ void AzsSvrg::resetParam(AzParam &azp) { AzBytArr s_loss; azp.vStr(kw_loss, &s_loss); if (s_loss.length() > 0) loss_type = lossType(s_loss.c_str()); azp.vInt(kw_svrg_interval, &svrg_interval); azp.vInt(kw_sgd_ite, &sgd_ite); azp.vInt(kw_test_interval, &test_interval); azp.vInt(kw_ite_num, &ite_num); azp.vInt(kw_rseed, &rseed); azp.vFloat(kw_eta, &eta); azp.vFloat(kw_momentum, &momentum); azp.vFloat(kw_lam, &lam); azp.swOn(&do_compact, kw_do_compact); azp.swOn(&do_show_loss, kw_do_show_loss); azp.swOn(&do_show_timing, kw_do_show_timing); azp.swOn(&with_replacement, kw_with_replacement); azp.vStr(kw_pred_fn, &s_pred_fn); }
/*------------------------------------------------*/ virtual void resetParam_data(AzParam &azp, bool is_training) { const char *eyec = "AzpData_img::resetParam_data"; azp.vInt(kw_channels, &channels); azp.vInt(kw_sz1, &sz1); azp.vInt(kw_sz2, &sz2); azp.vFloat(kw_data_scale, &data_scale); AzXi::throw_if_nonpositive(channels, eyec, kw_channels); AzXi::throw_if_nonpositive(sz1, eyec, kw_sz1); AzXi::throw_if_nonpositive(sz2, eyec, kw_sz2); AzXi::check_input(s_x_ext, &sp_x_ext, eyec, kw_x_ext); if (s_y_ext.length() > 0) AzXi::check_input(s_y_ext, &sp_y_ext, eyec, kw_y_ext); }
/*--------------------------------------------------------*/ int AzRgforest::resetParam(AzParam &p) { const char *eyec = "AzRgforest::resetParam"; /*--- for storing data indexes in the trees to disk ---*/ /*--- this must be called before adjustTestInterval. ---*/ p.vStr(kw_temp_for_trees, &s_temp_for_trees); /*--- loss function ---*/ p.vLoss(kw_loss, &loss_type); /*--- weight optimization interval ---*/ int lnum_inc_opt = lnum_inc_opt_dflt; p.vInt(kw_lnum_inc_opt, &lnum_inc_opt); if (lnum_inc_opt <= 0) { throw new AzException(AzInputNotValid, eyec, kw_lnum_inc_opt, "must be positive"); } opt_timer.reset(lnum_inc_opt); /*--- # of trees to search ---*/ p.vInt(kw_s_tree_num, &s_tree_num); if (s_tree_num <= 0) { throw new AzException(AzInputNotValid, eyec, kw_s_tree_num, "must be positive"); } /*--- when to stop: max #leaf, max #tree ---*/ int max_tree_num = -1, max_lnum = max_lnum_dflt; p.vInt(kw_max_tree_num, &max_tree_num); p.vInt(kw_max_lnum, &max_lnum); if (max_tree_num <= 0) { if (max_lnum > 0) max_tree_num = MAX(1, max_lnum / 2); else { AzBytArr s("Specify "); s.c(kw_max_lnum); s.c(" and/or "); s.c(kw_max_tree_num); throw new AzException(AzInputMissing, eyec, s.c_str()); } } lmax_timer.reset(max_lnum); /*--- when to test: test interval ---*/ int lnum_inc_test = lnum_inc_test_dflt; p.vInt(kw_lnum_inc_test, &lnum_inc_test); if (lnum_inc_test <= 0) { throw new AzException(AzInputNotValid, eyec, kw_lnum_inc_test, "must be positive"); } lnum_inc_test = adjustTestInterval(lnum_inc_test, lnum_inc_opt); test_timer.reset(lnum_inc_test); /*--- memory handling ---*/ p.vStr(kw_mem_policy, &s_mem_policy); if (s_mem_policy.length() <= 0) beTight = false; else if (s_mem_policy.compare(mp_beTight) == 0) beTight = true; else if (s_mem_policy.compare(mp_not_beTight) == 0) beTight = false; else { AzBytArr s(kw_mem_policy); s.c(" should be either "); s.c(mp_beTight); s.c(" or "); s.c(mp_not_beTight); throw new AzException(AzInputNotValid, eyec, s.c_str()); } p.vFloat(kw_f_ratio, &f_ratio); if (f_ratio > 1) { throw new AzException(AzInputNotValid, kw_f_ratio, "must be between 0 and 1."); } int random_seed = -1; if (f_ratio > 0 && f_ratio < 1) { p.vInt(kw_random_seed, &random_seed); if (srand > 0) { srand(random_seed); } } p.swOn(&doPassiveRoot, kw_doPassiveRoot); /*--- for maintenance purposes ---*/ p.swOn(&doForceToRefreshAll, kw_doForceToRefreshAll); p.swOn(&beVerbose, kw_forest_beVerbose); /* for compatibility */ p.swOn(&beVerbose, kw_beVerbose); p.swOn(&doTime, kw_doTime); /*--- display parameters ---*/ if (!out.isNull()) { AzPrint o(out); o.ppBegin("AzRgforest", "Forest-level"); o.printLoss(kw_loss, loss_type); o.printV(kw_max_lnum, max_lnum); o.printV(kw_max_tree_num, max_tree_num); o.printV(kw_lnum_inc_opt, lnum_inc_opt); o.printV(kw_lnum_inc_test, lnum_inc_test); o.printV(kw_s_tree_num, s_tree_num); o.printSw(kw_doForceToRefreshAll, doForceToRefreshAll); o.printSw(kw_beVerbose, beVerbose); o.printSw(kw_doTime, doTime); o.printV_if_not_empty(kw_mem_policy, s_mem_policy); o.printV_if_not_empty(kw_temp_for_trees, &s_temp_for_trees); o.printV(kw_f_ratio, f_ratio); o.printV(kw_random_seed, random_seed); o.printSw(kw_doPassiveRoot, doPassiveRoot); o.ppEnd(); } if (loss_type == AzLoss_None) { throw new AzException(AzInputNotValid, eyec, kw_loss); } return max_tree_num; }