本文整理汇总了C#中IAlgorithm.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# IAlgorithm.Prepare方法的具体用法?C# IAlgorithm.Prepare怎么用?C# IAlgorithm.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAlgorithm
的用法示例。
在下文中一共展示了IAlgorithm.Prepare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryExecute
private static bool TryExecute(IAlgorithm alg, int seed, string regressionAlgorithmResultName, out IRegressionModel model, out IRun run) {
model = null;
SetSeed(alg, seed);
using (var wh = new AutoResetEvent(false)) {
Exception ex = null;
EventHandler<EventArgs<Exception>> handler = (sender, args) => {
ex = args.Value;
wh.Set();
};
EventHandler handler2 = (sender, args) => wh.Set();
alg.ExceptionOccurred += handler;
alg.Stopped += handler2;
try {
alg.Prepare();
alg.Start();
wh.WaitOne();
if (ex != null) throw new AggregateException(ex);
run = alg.Runs.Last();
alg.Runs.Clear();
var sols = alg.Results.Select(r => r.Value).OfType<IRegressionSolution>();
if (!sols.Any()) return false;
var sol = sols.First();
if (sols.Skip(1).Any()) {
// more than one solution => use regressionAlgorithmResult
if (alg.Results.ContainsKey(regressionAlgorithmResultName)) {
sol = (IRegressionSolution)alg.Results[regressionAlgorithmResultName].Value;
}
}
var symbRegSol = sol as SymbolicRegressionSolution;
// only accept symb reg solutions that do not hit the estimation limits
// NaN evaluations would not be critical but are problematic if we want to combine all symbolic models into a single symbolic model
if (symbRegSol == null ||
(symbRegSol.TrainingLowerEstimationLimitHits == 0 && symbRegSol.TrainingUpperEstimationLimitHits == 0 &&
symbRegSol.TestLowerEstimationLimitHits == 0 && symbRegSol.TestUpperEstimationLimitHits == 0) &&
symbRegSol.TrainingNaNEvaluations == 0 && symbRegSol.TestNaNEvaluations == 0) {
model = sol.Model;
}
}
finally {
alg.ExceptionOccurred -= handler;
alg.Stopped -= handler2;
}
}
return model != null;
}
示例2: RunAlgorithm
// same as in SamplesUtil
private void RunAlgorithm(IAlgorithm a) {
var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
Exception ex = null;
a.Stopped += (src, e) => { trigger.Set(); };
a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };
a.Prepare();
a.Start();
trigger.WaitOne();
Assert.AreEqual(ex, null);
}