在线等,大虾帮忙看看问题在哪?

skyhawkf119 2009-04-12 08:53:26
各位大虾,
小弟在各位大虾的帮助下,写了如下代码,想实现从一组数据当中,对每类数据实现近似均衡的采样,但发现程序只运行一次就跳出了,请问问题出在哪??谢谢。

coreNum = 0;
int sampleNum = 0;
int nr_class = sg_info->nr_class;

while (1)
{
int j =0;
// choose a small subset as initialization
while ((j < nr_class)&&(sampleNum < INITIAL_CS))
{
int idx;
int rand32bit = random();
int start = sg_info->start[j];
int count = sg_info->count[j];
int pos = start + (rand32bit%count);
idx = sg_info->perm[pos];
if (chklist[idx] < 1)
{
chklist[idx] = 1;
sampled_flag[idx] = 1;//bug here

coreIdx[coreNum] = idx;
outAlpha[sampleNum] = 1.0/INITIAL_CS;
tempD[sampleNum] = 0.0;

j++;
sampleNum++;
coreNum++;
}
}
break;
}

}
...全文
73 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanlee007 2009-04-12
  • 打赏
  • 举报
回复
近似均衡的采样?
j < nr_class?
sampleNum < INITIAL_CS?
skyhawkf119 2009-04-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xylicon 的回复:]

coreNum  = 0;
int sampleNum = 0;
int nr_class  = sg_info->nr_class;

while (1)
{
int j =0;
// choose a small subset as initialization
while ((j < nr_class)&&(sampleNum < INITIAL_CS))
{
int idx;
int rand32bit = random();
int start    = sg_info->start[j];
int count    = sg_info->count[j];
int pos      = start + (rand32bit%count);
idx      = sg_info->perm[pos];
if (chklist[idx]…
[/Quote]
while (1) 改成sampleNum < INITIAL_CS ,去掉break就好了。
已经明白了,就是不知道有没有更好的写法,您有建议吗?
xylicon 2009-04-12
  • 打赏
  • 举报
回复

coreNum = 0;
int sampleNum = 0;
int nr_class = sg_info->nr_class;

while (1)
{
int j =0;
// choose a small subset as initialization
while ((j < nr_class)&&(sampleNum < INITIAL_CS))
{
int idx;
int rand32bit = random();
int start = sg_info->start[j];
int count = sg_info->count[j];
int pos = start + (rand32bit%count);
idx = sg_info->perm[pos];
if (chklist[idx] < 1)
{
chklist[idx] = 1;
sampled_flag[idx] = 1;//bug here

coreIdx[coreNum] = idx;
outAlpha[sampleNum] = 1.0/INITIAL_CS;
tempD[sampleNum] = 0.0;

j++;
sampleNum++;
coreNum++;
}
}
break;
}

}

这个break写在那里当然就会跳出了。

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧