willi-kappler / darwin-rs

darwin-rs, evolutionary algorithms with rust
MIT License
116 stars 16 forks source link

Use crate random choice for selecting samples by fitness #7

Open StefanoD opened 8 years ago

StefanoD commented 8 years ago

Is there an interest to use the crate random choice in order to select samples by their fitness?

It should be with a runtime of O(n) faster than the existing solution which sorts the samples (O (n * log n))

https://github.com/StefanoD/Rust_Random_Choice

willi-kappler commented 8 years ago

Yes that would be great! I'm currently cleaning up stuff in the develop branch which will lead to v0.3. Including your crate should be quite simple, I'll let you know how it worked.

StefanoD commented 8 years ago

Great! Maybe you can include performance tests; before and after.

willi-kappler commented 8 years ago

It turns out to be a bit more difficult than expected: darwin-rs uses lower values for the fitness where as random choice uses higher values for better fitness. I could pass m - fitness where m is the fitness of the least fittest individual.

StefanoD commented 8 years ago

Or you could modify the calculation of the fitness? What is the upper bound of the biggest value? You could calculate it this way:

let fitness_high = MAX_VALUE - fitness_low;
StefanoD commented 8 years ago

Oh, sorry. You wrote the exact same thing.

willi-kappler commented 8 years ago

No problem ;-) I'll try it and let you know.