1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 06:27:17 +00:00

improved dhrg::logistic

This commit is contained in:
Zeno Rogue 2023-08-22 20:03:17 +02:00
parent fd1be4beb8
commit bb22d363c8

View File

@ -40,10 +40,13 @@ bool dhrg_animate(int sym, int uni);
/* for logistic regression */
struct logistic {
ld R, T;
ld yes(ld d) { return 1/(1 + exp((d-R) / 2 / T)); }
ld no(ld d) { return 1/(1 + exp(-(d-R) / 2 / T)); }
ld lyes(ld d) { return log(yes(d)); }
ld lno(ld d) { return log(no(d)); }
ld yes1(ld d) { return 1/(1 + exp(d)); }
ld no1(ld d) { return 1/(1 + exp(-d)); }
ld nor(ld d) { return (d-R) / 2 / T; }
ld yes(ld d) { return yes1(nor(d)); }
ld no(ld d) { return no1(nor(d)); }
ld lyes(ld d) { d = nor(d); return d > 200 ? -d : log(yes1(d)); }
ld lno(ld d) { d = nor(d); return d < -200 ? d : log(no1(d)); }
logistic() {}
logistic(ld _R, ld _T) : R(_R), T(_T) {}
void setRT(ld _R, ld _T) { R = _R; T = _T; }