在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");