跳到正文

科技·工程

神经神经神经

dongzhenmao约 17 分钟
原文
文章信息与版本

文章信息

收录
2026年2月1日
更新
2026年5月16日
篇幅
约 17 分钟

版本

  1. v2当前
  2. v1

12.23 开工。

C++
// ????? 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 = 1e4 + 1e1, mod = 998244353, B = 500;

const double mx_v = 2, rate = 0.9; // 神经元最高电位, 神经元自然点位衰减。

int Time;

struct neuron;
std::vector<neuron*> nnow; // 本轮中将要释放的神经元

std::mt19937 rd(713);
std::uniform_real_distribution _rd(0, 1);

#define gen() (_rd(rd()))

struct neuron {
	struct dendrite {
		int to;
		double w;
	};

	std::vector<dentrite> to;
	std::vector<int> tm; // 神经元的释放时间

	double v; // 位

	void check();
	void release(int t);
};

neuron base[max_n]; // 神经

void neuron::release(int t) {
	for (dendirte &d : to) {
		base[d.to].v += d.w;
	}
}

struct layer {

	void link_rand(int k) {
		for (neuron &t : v) for (int i = 0; i < k; ++i) {
			dentrite d;
			d.p = &nx->v[(rd()) % nx->v.size()];
			d.w = gen();
			t.to.push_back(d);
		}
	}

};

void run() {
	for (int i = 0; i < max_n; ++i) { // 神经元自然电位衰减。
		base[i].v *= rate;
	}
}

int main() {



    return 0;
}

/*
3 0 1
1 2 3
1 2 3
*/

/*
1
3
2 1 3
1 2
1 3

*/

我目前在学 SNN,请判断这个架构是否合理

理清架构:

采用 <资格迹-多巴胺确定与否定> 的方式。

抛弃指针,直接采用数组存储,储存信息更方便(处理电位自然衰落)。

for 时间 tt:

  • 感知(首层)神经元特殊处理。
  • 查看哪些神经元达到最大电位,记录她们。将她们的电位设为 00,更新她们的最近放电时间,并查看她的 prev 神经元的最近放电时间,按照特化的最后按照产期增强与削弱效应处理放电时间差生成资格迹(只处理最近一次的)。
  • 放电。
  • 处理电位衰落与资格迹的时间衰减。

在以上循环结束后根据答案的正确性来确定或者削弱。


1.05: 睡觉

C++
// ????? 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 = 1e4 + 1e1, mod = 998244353, B = 500;

const double mx_v = 1, rate = 0.9; // 神经元最高电位, 神经元自然点位衰减。

const double A_up = 0.5, A_down = 0.5;

const int min_dt = 5; // 不应期

int Time; // 当前时间

struct neuron;
std::vector<neuron*> nnow; // 本轮中将要释放的神经元

std::mt19937 rd(713);
std::uniform_real_distribution _rd(0, 1);

#define gen() (_rd(rd()))

struct dendrite {
	int to;
	double w;
	double et; // 资格迹
};

struct neuron {
	std::vector<dentrite> to;
//	std::vector<int> from;
	int tm; // 最近一次神经元施放时间。
	int tm_old;

	double v; // 位

	void check();
	void release(int t);
};

neuron base[max_n]; // 神经
std::vector<int> post[max_n]; // 防电时间

void neuron::release(int t) {
	for (dendirte &d : to) {
		base[d.to].v += d.w;
	}
}

struct layer {
	void link_rand(int k) {
		for (neuron &t : v) for (int i = 0; i < k; ++i) {
			dentrite d;
			d.p = &nx->v[(rd()) % nx->v.size()];
			d.w = gen();
			t.to.push_back(d);
		}
	}

};

double calc() {

}

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;
		for (dentrite &d : base[i].to) { // 资格迹自然衰减.
			d.cw *= rate;
		}
	}

	for (int i = 0; i < max_n; ++i) {
		if (base[i].v >= max_v && Time - base[i].tm_old >= min_tm) { // 查看条件是否满足: 电位与不应期
			base[i].v -= max_v;
			base[i].tm = Time;
			for (dentrite &d : base[i].to) {
				base[d.to].v += d.w;
			}
		}
	}

	for (int i = 0; i < max_n; ++i) {   // 枚举前神经元
		for (dentrite &d : base[i].to) {
			if (base[d.to].tm == Time) { // 后神经元本轮放电.
				d.et += A_up * exp(base[i].tm_old - Time);
			}
			if (base[i].tm == Time) { // 前神经元本轮放电.
				d.et -= A_down * exp(base[d.to].tm_old - Time);
			}
		}
	}

}

void solve() {
	for () {
		run();
	}

	for (neuron &t : base) {
		for (dentrite &d : t.to) {

		}

	}

}

int main() {



    return 0;
}

/*
3 0 1
1 2 3
1 2 3
*/

/*
1
3
2 1 3
1 2
1 3

*/

1.6

C++
// ????? 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 = 1e4 + 1e1, max_T = 100;

const double max_v = 1, rate_v = 0.9; // 神经元最高电位, 神经元自然点位衰减。

const double rate_et = 0.9;

const double A_up = 0.5, A_down = 0.5;

const int min_dt = 5; // 不应期长度

int Time; // 当前时间

namespace {
	std::mt19937 rd(713);
	std::uniform_real_distribution<double> _rd(0, 1);
	inline int rand() { return int(rd()); }
	inline double _rand() { return double(_rd(rd)); }
}

struct neuron;

struct dendrite {
	int to;
	double w;
	double et; // 资格迹
};

struct neuron {
	std::vector<dendrite> to;
	int tm; // 最近一次神经元施放时间。
	int tm_old;

	double v; // 电位
};

neuron base[max_n]; // 神经
std::vector<int> post[max_n]; // 放电时间

struct layer {
	int L, R; // 这一层的神经元编号为 [L, R]
} ly[max_n];

namespace {
	void link_rand(int k) {
		for (int i = ly[k].L; i <= ly[k].R; ++i) {
			for (int e = 0; e < k; ++e) {

			}
		}
	}
}

namespace {
	double exp_val[(max_T + 10) * 2];
	double exp(int t) {
		return exp_val[t + max_T + 10];
	}
}

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 * exp(base[i].tm_old - Time);
			}
			if (base[i].tm == Time) { // 前神经元本轮放电.
				d.et -= A_down * exp(base[d.to].tm_old - Time);
			}
		}
	}

}

void solve() {
	for (int i = 0; i < max_T + 20; ++i) {
		exp_val[i] = std::exp(i - max_T - 10);
	}
	for (int i = 0; i < max_n; ++i) {
		base[i].tm = -10;
	}
	for ( ; Time < 100; ++Time) {
		run();
	}
}

int main() {



    return 0;
}

/*
3 0 1
1 2 3
1 2 3
*/

/*
1
3
2 1 3
1 2
1 3

*/
原文