Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
t3du authored Dec 20, 2024
1 parent 644e3ae commit 412b48d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions armory/Sources/armory/logicnode/ProbabilisticOutputNode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package armory.logicnode;

class ProbabilisticOutputNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int) {

var probs: Array<Float> = [];
var probs_acum: Array<Float> = [];
var sum: Float = 0;

for (p in 1...inputs.length){
probs.push(inputs[p].get());
sum += probs[p-1];
}

if (sum > 1){
trace(sum);
for (p in 0...probs.length)
probs[p] /= sum;
}

sum = 0;
for (p in 0...probs.length){
sum += probs[p];
probs_acum.push(sum);
}

var rand: Float = Math.random();

for (p in 0...probs.length){
if (p == 0 && rand <= probs_acum[p]){ runOutput(p); break; }
else if (0 < p && p < probs.length-1 && probs_acum[p-1] < rand && rand <= probs_acum[p]){ runOutput(p); break; }
else if (p == probs.length-1 && probs_acum[p-1] < rand){ runOutput(p); break; }
}
}
}

0 comments on commit 412b48d

Please sign in to comment.