第二章 所用的源程序 【PT主文件中的函数】

 

。。。。。。。。。。。。。。。。。。。。。。。。。。。。

PT 主文件中的函数

。。。。。。。。。。。。。。。。。。。。。。。。。。。。 

#include <time.h>
#include<fstream>
using namespace std;
#include"function.cpp"
void main(void)
{
	ifstream fin("self.txt");
	ifstream fin1("test.txt");
	ifstream fin2("control.txt");
	ofstream   fout("PT-result.xls",ios::app);
	QueueElementType rr;
	long double cost;
	for(int i=0;i<NS;i++)
	{
		fin>>self[i].x;
		fin>>self[i].y; 
	}
	long double x,y;
	long double p_d;
	long double area_non;
	for(int i=0;i<NT;i++)
	{
		fin1>>test[i].x;
		fin1>>test[i].y;
		fin1>>test[i].z;
	}
	fin2>>n_time;
	fin2>>n_r;
	long double *Array[3];
	for(int j=0;j<3;j++)
	{
		Array[j]=new long double[n_r];
	}
	long double *Array_s[5];
	for(int j=0;j<5;j++)
	{
		Array_s[j]=new long double[n_time];
	}
	for(int i=0;i<n_r;i++)
	{
		fin2>>Array[0][i];                      //rs
		fin2>>Array[1][i];                      //r0
		fin2>>Array[2][i];                      //p_d
	}
	fout<<endl<<endl;  
	fout<<"Radius"<<'\t'<<'\t'<<"dr_max"<<'\t'<<"dr_min"<<'\t'<<"dr_mean"<<'\t'<<"dr_sd"<<'\t'<<'\t'<<"can_max"<<'\t'<<"can_min"<<'\t'<<"can_mean"<<'\t'<<"can_sd"<<'\t'<<'\t'<<"mature_max"<<'\t'<<"mature_min"<<'\t'<<"mature_mean"<<'\t'<<"mature_sd"<<'\t'<<'\t'<<"cost_max"<<'\t'<<"cost_min"<<'\t'<<"cost_mean"<<'\t'<<"cost_sd"<<endl;  
	for(int i=0;i<n_r;i++)
	{
		rs=Array[0][i];
		r0=Array[1][i];
		p_d=Array[2][i];
		cout<<i+1<<endl;
		for(int i=0;i<NS;i++)
		{
			self[i].r=rs;
		}
		for(int j=0;j<n_time;j++)
		{
			srand((unsigned)time(NULL));
			area_non=area_nonself(self);
			detector.clear();
			p1=&Q;
			InitQueue(p1);
			s_all=0;
			sum=0;
			QueueElementType e;
			e.x=0.5;
			e.y=0.5;
			e.r=0.5;
			EnQueue(p1,e);
			while(p1->front!=p1->rear)          //  if Q is not null ......................................................		 
			{ 
				DeQueue(p1,&e);
				PT_detec(e.x,e.y,e.r);
				if(s_all/area_non>p_d)
					break;
				if(sum>1000000)
					break;
			};
			cost=sum/detector.size();
			Array_s[0][j]=sum;                     //    the number of the candidate detectors                                                           
			Array_s[1][j]=detector.size();         //    the number of the mature detectors
			Array_s[2][j]=cost;                    //    the cost to generate one mature detector
			long double count_1_true=0;
			long double count_1_false=0;
			long double count_2_flase=0;
			long double count_2_true=0;
			long double count_1=0;
			long double dr=0;
			long double fa=0;
			for(int i=0;i<NT;i++)
			{
				int	flag=0;
				for(int j=0;j<detector.size();j++)
				{
					if(intersect(detector[j],test[i]))
					{
						count_1++;
						flag=1;
						if(test[i].z==0)
							count_1_true++;// true abnormal   TN          
						else
							count_1_false++;// false abnormal   FN           
						break;
					}
				}
				if(flag==0)
				{
					if(test[i].z==0)								
						count_2_flase++;// false normal    FP              
					else
						count_2_true++;//  true   normal    TP           
				}
			}
			dr=count_1_true/(count_1_true+count_2_flase);                 //  
			fa=count_1_false/(count_1_false+count_2_true);                 // 
			Array_s[3][j]=dr;                                              //  the detection rate   
			Array_s[4][j]=fa;                                              // false alarm rate
		}   
		long  double can_max=_max(Array_s[0]);               // Max
		long double can_min=_min(Array_s[0]);                //Min
		long double can_mean=mean(Array_s[0]);               // Mean
		long double can_sd=sd(Array_s[0],can_mean);           // Stardard deviation
		long  double mature_max=_max(Array_s[1]);
		long double mature_min=_min(Array_s[1]);
		long double mature_mean=mean(Array_s[1]);
		long double mature_sd=sd(Array_s[1],mature_mean);
		long  double cost_max=_max(Array_s[2]);
		long double cost_min=_min(Array_s[2]);
		long double cost_mean=mean(Array_s[2]);
		long double cost_sd=sd(Array_s[2],cost_mean);
		long  double dr_max=_max(Array_s[3]);
		long double dr_min=_min(Array_s[3]);
		long double dr_mean=mean(Array_s[3]);
		long double dr_sd=sd(Array_s[3],dr_mean);
		long  double fa_max=_max(Array_s[4]);
		long double fa_min=_min(Array_s[4]);
		long double fa_mean=mean(Array_s[4]);
		long double fa_sd=sd(Array_s[4],fa_mean);
		fout<<rs<<'\t'<<'\t'<<dr_max<<'\t'<<dr_min<<'\t'<<dr_mean<<'\t'<<dr_sd<<'\t'<<'\t'<<can_max<<'\t'<<can_min<<'\t'<<can_mean<<'\t'<<can_sd<<'\t'<<'\t'<<mature_max<<'\t'<<mature_min<<'\t'<<mature_mean<<'\t'<<mature_sd<<'\t'<<'\t'<<cost_max<<'\t'<<cost_min<<'\t'<<cost_mean<<'\t'<<cost_sd<<endl;
	}      
	fout<<p_d<<endl;
	cout<<"ok!"<<endl;
	char c;
	cin>>c;
}
 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清水迎朝阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值