csp21-09-3脉冲神经网络66分版

本文描述了作者在编程竞赛中使用脉冲神经网络模型解决一个问题的过程,尝试了优化但未成功,最终得分66分。文章详细介绍了神经元结构、脉冲源、突触更新以及时间复杂度的考虑。
摘要由CSDN通过智能技术生成

拿到这道题就直接进行模拟了,然后果不其然超时了,目前没有想到有效的优化思路,尝试了优化,但还是66分,先留个66分版的在这。

//2109-3脉冲神经网络----66分版 
#include<bits/stdc++.h>
using namespace std;

static unsigned long ne = 1;

/* 伪随机函数 */
int myrand(void) {
    ne = ne * 1103515245 + 12345;
    return((unsigned)(ne/65536) % 32768);
}

double t;
int N, S, P, T;
vector<int> lo[2005]; // 编号---时间 
// 定义神经元结构
struct sjy {
	int id;
	double v, u; // T时刻的最大最小值 
	double a, b, c, d;
	double I=0;
	int count=0; // 最终求这个的最大值最小值 
	void cal_vu() {
		double v0 = v, u0 = u;
		v = v0 + t*(0.04*v0*v0+5*v0+140-u0) + I; // 强度要先更新
		u = u0 + t*a*(b*v0-u0); 
	}
	void update(int nowt) {
		if(v>=30) {
			v = c;
			u = u + d;
			count++;
			lo[id].push_back(nowt); // 发送脉冲给出突触 
		}
		I = 0; // k时刻之后需要将强度清零---注意前后关系,后续检查 
	}
}ss[1005]; 

// 定义脉冲源
struct mcy {
	int id;
	double r;
	void update(int nowt) {
		if(r>myrand()) {
//			cout << "脉冲时间:" << nowt <<endl;
			lo[id].push_back(nowt);
		}
	}
}mm[1005]; 

// 定义突触
struct tc {
	double w;
	int D;
	int s, t;
	void update(int nowt) {
		if(!lo[s].empty()) {
			for(auto it=lo[s].begin(); it!=lo[s].end(); it++) {
				if(nowt-*it==D){
					ss[t].I += w; // 向出结点神经元发送强度脉冲 
//					it = lo[s].erase(it); // 不能在单个突触內部删除!! 
				}
			}
		}
	}
}tt[1005]; 

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// 读取输入 
	cin >> N >> S >> P >> T >> t;
	int sum=0;
	while(sum<N) {
		int rn;
		double v, u, a, b, c, d;
		cin >> rn >> v >> u >> a >> b >> c >> d;
		for(int i=0; i<rn; i++) {
			ss[sum+i].id = sum+i, ss[sum+i].v = v, ss[sum+i].u = u, ss[sum+i].a = a, ss[sum+i].b = b, ss[sum+i].c = c, ss[sum+i].d = d;
		}
		sum += rn;
	}
	for(int i=0; i<P; i++) {
		cin >> mm[i].r;
		mm[i].id = N+i;
	}
//	cout << "||||"<< endl;
	for(int i=0; i<S; i++) {
		cin >> tt[i].s >> tt[i].t >> tt[i].w >> tt[i].D;
	}
//	cout << "||||"<< endl;
	for(int nowt=1; nowt<=T; nowt++) { // 程序主循环 
//		cout << nowt << "-----时刻:" <<endl; 
		// 更新脉冲源
		for(int x=0; x<P; x++) {
			mm[x].update(nowt);
		} 
		// 更新突触
		for(int x=0; x<S; x++) {
			tt[x].update(nowt);
		} 
		 
		// 更新神经元
		for(int x=0; x<N; x++) {
			ss[x].cal_vu();
			ss[x].update(nowt);
		} 
//		cout << ss[0].v << endl;
	}
	// 记录结果
	vector<double> vv;
	vector<int> cc;
	for(int i=0; i<N; i++) {
		vv.push_back(ss[i].v);
		cc.push_back(ss[i].count);
	} 
	sort(vv.begin(), vv.end()); sort(cc.begin(), cc.end()); // 默认升序 
	printf("%.3f %.3f\n", vv[0], vv[N-1]);
	printf("%d %d\n", cc[0], cc[N-1]);
//	cout << std::fixed << std::setprecision(3) << vv[0] << " "<<vv[N-1] << endl;
//	cout << cc[0]  << " " << cc[N-1] << endl;
	return 0;
	
} 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值