在jsl中设置递归循环你好,
我构建了一个很长的脚本,其中在大型数据表上迭代执行曲线拟合1 列中列出了许多变量。 然而,在该过程结束时,其中一些变量未拟合(该过程由于某种原因失败)。 此时,我创建了之前未拟合的变量的“失败拟合”列表,并从源表创建一个子集(选择其中/包含/子集)并再次运行初始脚本的一部分(该脚本包含在子集表(选定的行、所有列)上的表达式中。
在第二轮拟合结束时,将创建一个新的“失败拟合”列表(通常较小)。
我正在尝试找到一种方法来创建递归循环,其中代码将查找最后一个“失败拟合”列表的大小,如果它大于 0 并且与之前的“失败拟合”列表不同,它将启动另一轮拟合,直到“失败拟合”=0 或与之前的“失败拟合”列表相同(以避免创建无限循环)。
任何建议将不胜感激。
塞巴斯蒂安
数据混合和清理大规模定制视窗Re: 在jsl中设置递归循环@Craige_Hales非常感谢您的建议。 我会尝试这个策略。
塞巴斯蒂安
Re: 在jsl中设置递归循环我不会为此使用递归。 使用 WorkToBeDone 列表和 WorkCompleted 列表以及 FoundSomething 标志。 将你的循环写成这样:
good = function({ method, item),
// use the current strategy/method to test the item
// return 1 if pass, 0 if fail
);
FoundSomething = 1; // flag: are we still making progress?
strategy = 1; // maybe change the strategy after each round
while(FoundSomething,
FoundSomething = 0;
for(i = nitems(WorkToBeDone), i>=1, i -= 1, // backwards because removing items
if( good( strategy, WorkToBeDone[i] ),
insertinto(WorkCompleted, removefrom(WorkToBeDone,i));
FoundSomething = 1;
)
);
strategy += 1; // new strategy for next round
);Re: 在jsl中设置递归循环你好@jthi ,
感谢您的原始输入。 不幸的是,我未能将您的建议转化为可行的脚本。
因此,我附加了我的目标的另一个描述(不是函数脚本,而是“工作流程”)。
希望有人能指出我正确的方向。
谢谢
塞巴斯蒂安
names default to here(1);
clear log();
sourcefitting={"a","b","c","d","e","f"};
/*The sourcefitting list can be 1000s longs and split in batches to perform some curve fitting, parameter extraction and them summarization using a FOR loo into a master table.
The process is expected to fail on some of those batches.
The failed items are identifed/listed into the 'failedfitting" list.
At which point a recursive loop using 'processX' needs to be implemented to take care of the remaining items using a new round of batching and fitting (for some reason the 'failing' process works on smaller batches but predicting which one will failed is not possible hence the need for a recessive loop), until the 'failedfittingX' list' is either empty or is stagnating (processfitting=1) ie the process keeps on failing and running the process another round is not longer warranted.
*/
processX=expr(/* process XYZ*/ //each time the processX is run 2 list are generated "succesfittingX" and "failedfittingX" are generated
//A new list "successfittingX" is generated at the end of the recursive loop
successfitting0={"a","c","d"};
/*
successfitting1={"a","c","d","b"};
successfitting2={"a","c","d","b","e"};
successfitting3={"a","c","d","b","e","f"}*/;// or successfitting3={"a","c","d","b","e"};
successfitting=successfittingX;
//The successfittingX and the sourcefitting lists are compared and a resulting list "failedfittingX" is created:
failedfitting0={"b","e","f"};
/*
failedfitting1={"e","f"};
failedfitting2={"f"};
failedfitting3={}*/; // or failedfitting3={"f"};
failedfitting=failedfittingX;
failednb=Nitems(failedfitting);
if(failedfittingX==failedfittingX-1,progressfitting=1, progressfitting=0);
);
//The issue is about correctly defining the structure recursive loop which uses the previous list to determine wheter the process needs to keep on going or if it is completed
// the use of the function 'recurse' has been suggested
testrec=function({failednb},
if(failednb>0&processfitting=0 ,recurse( processX),show("Done"))
);
testrec(failednb);
Re: 在jsl中设置递归循环你好@jthi ,
谢谢你的提示。 我会尝试一下
塞巴斯蒂安
Re: 在jsl中设置递归循环JMP 确实通过 Recurse() 提供递归。 我想你也可以再次调用相同的函数以使其递归
使用递归():
Names Default To Here(1);
ex rev = Function({s},
If(Length(s) <= 1,
s,
Recurse(Substr(s, 2)) || Left(s, 1)
)
);
ex rev("abcd");
调用相同的函数:
Names Default To Here(1);
ex rev = Function({s},
If(Length(s) <= 1,
s,
ex rev(Substr(s, 2)) || Left(s, 1)
)
);
ex rev("abcd");