#include <stdio.h>
#include <math.h>
#include <conio.h>
#define pi 3.14159
#define p(x,t) exp(-(x-t)*(x-t)/20)/sqrt(20*pi)
void decision(){
int i,j,type,m,n,flag,state[5],index;
float xx,a[5][5],p[5],e[5],sum,decision;
printf("Welcome to the DECISION_STSTEM!");
printf(" type of the problem,max(key ?0?)or min(key ?1?)? ");
scanf("%d",&type);
printf("type of the decision,without data(key?0?)or with data(key?1?)? ");
scanf("%d",&flag);
printf("number of the actions ");
scanf("%d",&m);
printf("number of the nature states ");
scanf("%d",&n);
for(j=0;j<n;j++)
printf(" t%d",j+1);
printf(" ");
for(i=0;i<m;i++)
{printf("A%d ",i+1);
for(j=0;j<n;j++)
scanf("%f",&a[i][j]);
}
printf("probability of the natural states=? ");
for(j=0;j<n;j++)
scanf("%f",&p[j]);
if(flag)
{printf("given data=? ");
scanf("%f",&xx);
printf("states of nature=? ");
for(j=0;j<n;j++)
scanf("%d",&state[j]);
sum=0;
for(j=0;j<n;j++)
sum+=p[j]*p(xx,state[j]);
for(j=0;j<n;j++)
p[j]=p[j]*p(xx,state[j])/sum;
}
for(i=0;i<m;i++)
{sum=0;
for(j=0;j<n;j++)
sum+=p[j]*a[i][j];
e[i]=sum;
}
decision=e[0];
index=1;
if(type==0)
for(i=1;i<m;i++)
{ if(decision<e[i])
{decision=e[i];
index=i+1;
}
}
else
for(i=0;i<m;i++)
if(decision>e[i])
{decision=e[i];
index=i+1;
}
printf(" ********** ");
printf("Results:");
printf(" ********** ");
printf("expected loss for each course of action based on prior distribution ");
for(i=0;i<m;i++)
printf("%f ",e[i]);
printf(" The optimum expected loss is %f ",decision);
printf(" choose action A( %d )",index);
return;
}
void main(){
decision();
getch();
}
bys.rar_贝叶斯_贝叶斯运筹_贝叶斯预测_运筹学_运筹学实验
版权申诉
29 浏览量
2022-09-24
01:35:52
上传
评论
收藏 192KB RAR 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- python-leetcode面试题解之第198题打家劫舍-题解.zip
- python-leetcode面试题解之第191题位1的个数-题解.zip
- python-leetcode面试题解之第186题反转字符串中的单词II-题解.zip
- 一个基于python的web后端高性能开发框架,下载可用
- python-leetcode面试题解之第179题最大数-题解.zip
- python-leetcode面试题解之第170题两数之和III数据结构设计-题解.zip
- python-leetcode面试题解之第168题Excel表列名称-题解.zip
- python-leetcode面试题解之第167题两数之和II输入有序数组-题解.zip
- python-leetcode面试题解之第166题分数到小数-题解.zip
- python-leetcode面试题解之第165比较版本号-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈