void player_exp_gain(struct player *p, s32b amount) { p->exp += amount; if (p->exp < p->max_exp) p->max_exp += amount / 10; adjust_level(p, TRUE); }
void player_exp_lose(struct player *p, s32b amount, bool permanent) { if (p->exp < amount) amount = p->exp; p->exp -= amount; if (permanent) p->max_exp -= amount; adjust_level(p, TRUE); }
double estimate_step_size(const mat &Uhat, const mat & gamma_grad,const mat & w, double sG,struct STATUS & status, const struct GRASTA_OPT &options) { const double LEVEL_FACTOR = 2; mat DL_prev_gamma; int newlevel = 0; double t = 0.0; if (fabs(status.step_scale) < 0.0000000000001) { status.step_scale = options.STEP_SCALE*(1+options.MIN_MU)/sG; if (!options.QUIET) PRINTF("Estimated step-scale %.2e, sigmoid :[%.2f, %.2f, %.2f]\n", status.step_scale,options.OMEGA, options.FMAX, options.FMIN); } if (options.ADAPTIVE) { DL_prev_gamma = status.last_gamma - Uhat*(trans(Uhat)*status.last_gamma); //double grad_ip = trace(status.last_w * (trans(DL_prev_gamma) * gamma_grad) * trans(w)); double grad_ip = trace(status.last_w * (trans(status.last_gamma) * gamma_grad) * trans(w)); //double normalization = norm(DL_prev_gamma* trans(status.last_w), "fro") * norm(gamma_grad * trans(w), "fro"); double normalization = norm(status.last_gamma * trans(status.last_w),"fro") * norm(gamma_grad * trans(w),"fro"); double grad_ip_normalization = 0.0; if (fabs(normalization) > 0.00001 ) grad_ip_normalization = grad_ip/normalization; status.last_mu = max(status.last_mu + sigmoid(-grad_ip_normalization, options.OMEGA, options.FMAX, options.FMIN) , options.MIN_MU); t = status.step_scale * pow((double)LEVEL_FACTOR, (double)(-status.level)) * sG; // (1+status.last_mu); } else{ status.last_mu = status.last_mu +1; t = status.step_scale * sG / (status.last_mu); } if (t > options.MAX_STEPSIZE) t= options.MAX_STEPSIZE; if (options.ADAPTIVE) adjust_level(status, options); return t; }