// ????? qaq
// The Unattended
// #pragma GCC optimize(3, "Ofast", "inline")
#include <random>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <time.h>
#include <string.h>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <math.h>
#include <set>
#include <stack>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
using lnt = long long;
using ull = unsigned long long;
using std::cin;
using std::cout;
#define DG() printf("DEBUG on %3d ", __LINE__)
#define log(...) printf(__VA_ARGS__)
static int __BG;
#define ED() log("TIME used : %3d\n", clock() - __BG)
#define BG() __BG = clock()
#define FR() freopen("dt.in", "r", stdin)
static int _rp_read() {
static int x, ch, f; x = f = 0;
while (!isdigit(ch)) { if (ch == '-') { f = 1; } ch = getchar(); }
while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); }
return f ? -x : x;
}
#define input() _rp_read()
/************************ head ******************************/
const int max_n = 13, max_ly = 3, max_T = 60;
const double max_v = 1, rate_v = 0.9; // 神经元最高电位, 神经元自然电位衰减。
const double rate_et = 0.91; // ET 自然衰减
const int rate_et_dt = 5; // et 随 dt 的指数系数
const double A_up = 0.1, A_down = 0.105;
const int min_dt = 5; // 不应期长度
int Time; // 当前时间
namespace useful_function {
double exp_val[(max_T + 10) * 2];
double et_exp(int t) { return abs(t) < max_T ? exp_val[t + max_T + 10] : 0; }
void init_et_exp() {
for (int i = 0; i < max_T * 2 + 20; ++i) {
exp_val[i] = std::exp(double(i - max_T - 10) / rate_et_dt);
}
}
std::mt19937 rd(713);
std::uniform_real_distribution<double> _rd(0, 1);
inline int rand() { return int(rd()); }
inline int rand_int(int l, int r) { return l + rand() % (r - l + 1); }
inline double rand_double() { return double(_rd(rd)); }
inline int rand_bool(double k) { return std::bernoulli_distribution(k)(rd); }
}
using namespace useful_function;
struct neuron;
struct dendrite {
int to;
double w;
double et; // 资格迹, Eligibility Trace
dendrite(int _to, double _w) : to(_to), w(_w), et(0.0) {}
};
struct neuron {
std::vector<dendrite> to;
int tm; // 最近一次神经元施放时间。
int tm_old;
double v; // 电位
};
neuron base[max_n]; // 神经
struct layer {
int L, R; // 这一层的神经元编号为 [L, R]
layer(int _L, int _R) : L(_L), R(_R) {}
} ly[max_n];
namespace {
void link_rand(int a, int b, double k) { // 链接 a, b 两层, a 层每个神经元与 b 层神经元概率 k 连边
for (int i = ly[a].L; i <= ly[a].R; ++i) {
for (int e = ly[b].L; e <= ly[b].R; ++e) {
if (!rand_bool(k)) continue;
base[i].to.push_back(dendrite(e, rand_double()));
}
}
}
}
void run() {
for (int i = 0; i < max_n; ++i) {
base[i].tm_old = base[i].tm;
}
for (int i = 0; i < max_n; ++i) { // 神经元自然电位衰减.
base[i].v *= rate_v;
for (dendrite &d : base[i].to) { // 资格迹自然衰减.
d.et *= rate_et;
}
}
std::vector<int> st_neu; // 暂存放电神经元
for (int i = 0; i < max_n; ++i) {
if (base[i].v >= max_v && Time - base[i].tm_old >= min_dt) { // 查看条件是否满足: 电位与不应期
st_neu.push_back(i);
}
}
for (int i : st_neu) {
base[i].v -= max_v, base[i].tm = Time;
for (dendrite &d : base[i].to) {
base[d.to].v += d.w;
}
}
for (int i = 0; i < max_n; ++i) { // 枚举前神经元
for (dendrite &d : base[i].to) {
if (base[d.to].tm == Time) { // 后神经元本轮放电.
d.et += A_up * et_exp(base[i].tm_old - Time);
}
if (base[i].tm == Time) { // 前神经元本轮放电.
d.et -= A_down * et_exp(base[d.to].tm_old - Time);
}
}
}
}
void release_DA(double w) { // 巴胺强度 [-1, 1]
for (int i = 0; i < max_n; ++i) {
for (dendrite &d : base[i].to) {
d.w += d.et * w;
d.w = std::max(0.0, std::min(2.0, d.w));
d.et = 0;
}
}
}
double check() {
// ...
}
void solve() {
init_et_exp();
for (int i = 0; i < max_n; ++i) {
base[i].tm = -max_T;
}
for ( ; Time < 100; ++Time) {
run();
double w = check();
if (w != 0) release_DA(w);
}
}
// ************* XOR 测试 ************* //
void build() { // 共 13 个神经元: 2, 10, 1
ly[0] = layer(0, 1);
ly[1] = layer(2, 11);
ly[2] = layer(12, 12);
link_rand(0, 1, 0.999);
link_rand(1, 2, 0.999);
}
int main() {
return 0;
}
/*
3 0 1
1 2 3
1 2 3
*/
/*
1
3
2 1 3
1 2
1 3
*/神经神经神经 1.7
这是 2026年2月10日 存档的第 1 版,不是当前版本。查看当前版本