Skip to content

Commit f5b440a

Browse files
committed
Merge branch 'develop'
2 parents 9d6887b + c62887c commit f5b440a

File tree

31 files changed

+651
-280
lines changed

31 files changed

+651
-280
lines changed

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ exclude = [
5050
]
5151

5252
[workspace.package]
53-
version = "1.2.17"
53+
version = "1.2.18"
5454
edition = "2024"
5555
authors = ["pkalivas <peterkalivas@gmail.com>"]
5656
description = "A Rust library for genetic algorithms and artificial evolution."
@@ -66,16 +66,16 @@ rand = "0.9.2"
6666
pyo3 = "0.26.0"
6767
numpy ="0.26.0"
6868
rayon = "1.11.0"
69-
serde = { version = "1.0.219", features = ["derive"] }
69+
serde = { version = "1.0.228", features = ["derive"] }
7070
serde_json = { version = "1.0.143" }
7171
tracing = "0.1"
7272
tracing-subscriber = { version = "0.3.20", features = ["env-filter", "fmt"] }
73-
radiate = { version = "1.2.17", path = "crates/radiate", default-features = false }
74-
radiate-core = { version = "1.2.17", path = "crates/radiate-core", default-features = false }
75-
radiate-alters = { version = "1.2.17", path = "crates/radiate-alters", default-features = false }
76-
radiate-selectors = { version = "1.2.17", path = "crates/radiate-selectors", default-features = false }
77-
radiate-engines = { version = "1.2.17", path = "crates/radiate-engines", default-features = false }
78-
radiate-gp = { version = "1.2.17", path = "crates/radiate-gp", default-features = false }
79-
radiate-error = { version = "1.2.17", path = "crates/radiate-error", default-features = false }
80-
radiate-python = { version = "1.2.17", path = "crates/radiate-python", default-features = false }
73+
radiate = { version = "1.2.18", path = "crates/radiate", default-features = false }
74+
radiate-core = { version = "1.2.18", path = "crates/radiate-core", default-features = false }
75+
radiate-alters = { version = "1.2.18", path = "crates/radiate-alters", default-features = false }
76+
radiate-selectors = { version = "1.2.18", path = "crates/radiate-selectors", default-features = false }
77+
radiate-engines = { version = "1.2.18", path = "crates/radiate-engines", default-features = false }
78+
radiate-gp = { version = "1.2.18", path = "crates/radiate-gp", default-features = false }
79+
radiate-error = { version = "1.2.18", path = "crates/radiate-error", default-features = false }
80+
radiate-python = { version = "1.2.18", path = "crates/radiate-python", default-features = false }
8181

crates/radiate-alters/src/crossovers/blend.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
use radiate_core::{AlterResult, Chromosome, Crossover, FloatGene, Gene, random_provider};
22

3-
/// The [BlendCrossover] is a crossover operator that blends the genes of two parent chromosomes
4-
/// to produce two offspring chromosomes.
5-
/// This operator is specifically designed for chromosomes containing [FloatGene]s.
3+
/// The [BlendCrossover] is a crossover operator that blends [FloatGene] alleles from two parent chromosomes to create offspring.
4+
/// The blending is controlled by the `alpha` parameter, which determines the extent of blending between the two alleles.
5+
/// The formula used for blending is:
6+
///
7+
/// ```text
8+
/// new_allele_one = allele_one - (alpha * (allele_two - allele_one))
9+
/// new_allele_two = allele_two - (alpha * (allele_one - allele_two))
10+
/// ```
611
#[derive(Debug, Clone, PartialEq)]
712
pub struct BlendCrossover {
813
rate: f32,

crates/radiate-alters/src/crossovers/edge_recombine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::collections::{HashMap, HashSet};
44
// Example: Parents [1,2,3,4,5] and [1,3,5,2,4]
55
// Edge table: 1->[2,3], 2->[1,4], 3->[2,5], 4->[5,2], 5->[4,3]
66
// Offspring: [1,2,4,5,3] (following edges when possible)
7-
87
#[derive(Debug, Clone, PartialEq)]
98
pub struct EdgeRecombinationCrossover {
109
rate: f32,

crates/radiate-alters/src/crossovers/mean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use radiate_core::{AlterResult, ArithmeticGene, Chromosome, Crossover, random_provider};
22

3-
/// The `MeanCrossover` is a simple crossover method that replaces the genes of the first chromosome
3+
/// The [MeanCrossover] is a simple crossover method that replaces the genes of the first chromosome
44
/// with the mean of the two genes. The mean is calculated by adding the two genes together and dividing
55
/// by two.
66
///
7-
/// This crossover can only be used with `ArithmeticGene`s and can be largely benifitial. However, keep
7+
/// This crossover can only be used with [ArithmeticGene]`s and can be largely benifitial. However, keep
88
/// in mind that because we are taking the mean of two genes, this results in children that
99
/// converge towards a common distribution. This can be useful in some cases, but it can also
1010
/// result in a loss of diversity in the population in others.

crates/radiate-core/src/domain/cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<T> Drop for MutCell<T> {
9595
if self.consumed {
9696
return;
9797
}
98+
9899
unsafe {
99100
if (*self.inner).ref_count.fetch_sub(1, Ordering::Release) == 1 {
100101
std::sync::atomic::fence(Ordering::Acquire);

crates/radiate-core/src/domain/random_provider.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn set_seed(seed: u64) {
6767
///
6868
/// For floating point types, the number will be in the range [0, 1).
6969
/// For integer types, the number will be in the range [0, MAX).
70+
#[inline]
7071
pub fn random<T>() -> T
7172
where
7273
T: SampleUniform,
@@ -76,11 +77,13 @@ where
7677
}
7778

7879
/// Generates a random boolean with the given probability of being true.
80+
#[inline]
7981
pub fn bool(prob: f64) -> bool {
8082
RandomProvider::bool(prob)
8183
}
8284

8385
/// Generates a random number of type T in the given range.
86+
#[inline]
8487
pub fn range<T>(range: std::ops::Range<T>) -> T
8588
where
8689
T: SampleUniform + PartialOrd,
@@ -89,13 +92,15 @@ where
8992
}
9093

9194
/// Chooses a random item from the given slice.
95+
#[inline]
9296
pub fn choose<T>(items: &[T]) -> &T {
9397
let index = range(0..items.len());
9498
&items[index]
9599
}
96100

97101
/// Generates a random number from a Gaussian distribution with the given mean and standard deviation.
98102
/// The Box-Muller transform is used to generate the random number.
103+
#[inline]
99104
pub fn gaussian(mean: f64, std_dev: f64) -> f64 {
100105
let u1: f64 = RandomProvider::random();
101106
let u2: f64 = RandomProvider::random();
@@ -106,18 +111,21 @@ pub fn gaussian(mean: f64, std_dev: f64) -> f64 {
106111
}
107112

108113
/// Shuffles the given slice in place.
114+
#[inline]
109115
pub fn shuffle<T>(items: &mut [T]) {
110116
let instance = RandomProvider::global();
111117
items.shuffle(&mut *instance.rng.lock().unwrap());
112118
}
113119

114120
/// Generates a vector of indexes from 0 to n-1 in random order.
121+
#[inline]
115122
pub fn indexes(range: std::ops::Range<usize>) -> Vec<usize> {
116123
let mut indexes = range.collect::<Vec<usize>>();
117124
shuffle(&mut indexes);
118125
indexes
119126
}
120127

128+
#[inline]
121129
pub fn weighted_choice(weights: &[f32]) -> usize {
122130
let mut rng = RandomProvider::get_rng();
123131

crates/radiate-core/src/genome/population.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ mod test {
358358
population[i].set_score(Some(Score::from(i)));
359359
}
360360

361-
let mut minimize_population = population.clone();
362-
let mut maximize_population = population.clone();
361+
// deep clone population
362+
let mut minimize_population = Population::from(&population);
363+
let mut maximize_population = Population::from(&population);
363364

364365
Optimize::Minimize.sort(&mut minimize_population);
365366
Optimize::Maximize.sort(&mut maximize_population);

crates/radiate-core/src/stats/distribution.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ pub struct Distribution {
1111
}
1212

1313
impl Distribution {
14+
#[inline(always)]
1415
pub fn push(&mut self, value: f32) {
1516
self.statistic.add(value);
1617
self.last_sequence.push(value);
1718
}
1819

20+
#[inline(always)]
1921
pub fn add(&mut self, value: &[f32]) {
2022
self.clear();
2123
for v in value {

crates/radiate-core/src/stats/metrics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl MetricSet {
108108
}
109109
}
110110

111+
#[inline(always)]
111112
pub fn merge(&mut self, other: &MetricSet) {
112113
for (name, metric) in other.iter() {
113114
if let Some(existing_metric) = self.metrics.get_mut(name) {
@@ -144,6 +145,7 @@ impl MetricSet {
144145
}
145146
}
146147

148+
#[inline(always)]
147149
pub fn add_labels(&mut self, name: &'static str, labels: Vec<MetricLabel>) {
148150
if let Some(m) = self.metrics.get_mut(name) {
149151
for label in labels {
@@ -152,6 +154,7 @@ impl MetricSet {
152154
}
153155
}
154156

157+
#[inline(always)]
155158
pub fn upsert<'a>(&mut self, name: &'static str, update: impl Into<MetricUpdate<'a>>) {
156159
if let Some(m) = self.metrics.get_mut(name) {
157160
m.apply_update(update);
@@ -161,6 +164,7 @@ impl MetricSet {
161164
}
162165
}
163166

167+
#[inline(always)]
164168
pub fn add_or_update<'a>(&mut self, metric: Metric) {
165169
if let Some(m) = self.metrics.get_mut(metric.name()) {
166170
m.apply_update(metric.last_value());
@@ -169,6 +173,7 @@ impl MetricSet {
169173
}
170174
}
171175

176+
#[inline(always)]
172177
pub fn add(&mut self, metric: Metric) {
173178
self.metrics.insert(metric.name(), metric);
174179
}
@@ -282,20 +287,24 @@ impl Metric {
282287
self.labels.as_ref()
283288
}
284289

290+
#[inline(always)]
285291
pub fn with_labels(mut self, labels: Vec<MetricLabel>) -> Self {
286292
self.labels.get_or_insert_with(HashSet::new).extend(labels);
287293
self
288294
}
289295

296+
#[inline(always)]
290297
pub fn add_label(&mut self, label: MetricLabel) {
291298
self.labels.get_or_insert_with(HashSet::new).insert(label);
292299
}
293300

301+
#[inline(always)]
294302
pub fn upsert<'a>(mut self, update: impl Into<MetricUpdate<'a>>) -> Self {
295303
self.apply_update(update);
296304
self
297305
}
298306

307+
#[inline(always)]
299308
pub fn apply_update<'a>(&mut self, update: impl Into<MetricUpdate<'a>>) {
300309
let update = update.into();
301310
match update {

crates/radiate-core/src/stats/statistics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl Statistic {
8989
self.sum.value()
9090
}
9191

92+
#[inline(always)]
9293
pub fn variance(&self) -> f32 {
9394
let mut value = f32::NAN;
9495
if self.count == 1 {
@@ -100,10 +101,12 @@ impl Statistic {
100101
value
101102
}
102103

104+
#[inline(always)]
103105
pub fn std_dev(&self) -> f32 {
104106
self.variance().sqrt()
105107
}
106108

109+
#[inline(always)]
107110
pub fn skewness(&self) -> f32 {
108111
let mut value = f32::NAN;
109112
if self.count >= 3 {
@@ -122,6 +125,7 @@ impl Statistic {
122125
value
123126
}
124127

128+
#[inline(always)]
125129
pub fn kurtosis(&self) -> f32 {
126130
let mut value = f32::NAN;
127131
if self.count >= 4 {
@@ -141,6 +145,7 @@ impl Statistic {
141145
value
142146
}
143147

148+
#[inline(always)]
144149
pub fn add(&mut self, value: f32) {
145150
self.count += 1;
146151

0 commit comments

Comments
 (0)