Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #1032029 // psCollect - collect output of probabilistic actions

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4862L/28K).

1  
// This version is good when the probabilities returned
2  
// are monotonically decreasing. To look for the best results
3  
// when probabilities tend to increase over time, use
4  
// PSCollectMostProbable.
5  
6  
static <A> IVF1<A> psCollect(IProbabilisticScheduler ps, Cl<WithProbability<A>> out) {
7  
  ret a -> {
8  
    if (out != null)
9  
      out.add(withPreciseProbability(ps.currentProbability(), a));
10  
  };
11  
}
12  
13  
svoid <A> psCollect(ProbabilisticScheduler ps,
14  
  Cl<WithProbability<A>> results_out,
15  
  int maxResults,
16  
  IVF1<IVF1<A>> action) {
17  
  action.get(psCollect(ps, results_out));
18  
  stepUntil(ps, () -> l(results_out) >= 10);
19  
}
20  
21  
static <A> L<WithProbability<A>> psCollect(int maxResults, IVF2<IProbabilisticScheduler, IVF1<A>> action) {
22  
  new ProbabilisticScheduler ps;
23  
  new L<WithProbability<A>> results;
24  
  psCollect(ps, results, maxResults, out -> action.get(ps, out));
25  
  ret results;
26  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032029
Snippet name: psCollect - collect output of probabilistic actions
Eternal ID of this version: #1032029/8
Text MD5: 10625de896e36b2c476aee43fcc121a8
Transpilation MD5: ef0b3a2abdfb68d9ea92d103a5d5ee8a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-11 08:39:25
Source code size: 899 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 169 / 247
Version history: 7 change(s)
Referenced in: [show references]