Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalivas committed Jan 9, 2025
2 parents 0e17823 + 7fca47d commit 13d422a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,36 +438,36 @@ comprehensive list of examples.
const MIN_SCORE: f32 = 0.01;

fn main() {
let graph_codex = GraphCodex::regression(2, 1).set_outputs(vec![op::sigmoid()]);
random_provider::set_seed(501);
let graph_codex = GraphCodex::regression(2, 1).with_output(Op::sigmoid());

let regression = Regression::new(get_sample_set(), ErrorFunction::MSE);

let engine = GeneticEngine::from_codex(&graph_codex)
.minimizing()
.alter(alters!(
GraphCrossover::new(0.5, 0.5),
NodeMutator::new(0.1, 0.05),
OperationMutator::new(0.1, 0.05),
GraphMutator::new(vec![
NodeMutate::Forward(NodeType::Weight, 0.05),
NodeMutate::Forward(NodeType::Aggregate, 0.03),
NodeMutate::Forward(NodeType::Gate, 0.03),
NodeMutate::Forward(NodeType::Edge, 0.05),
NodeMutate::Forward(NodeType::Vertex, 0.03),
]),
))
.fitness_fn(move |genotype: Graph<f32>| {
.fitness_fn(move |genotype: Graph<Op<f32>>| {
let mut reducer = GraphReducer::new(&genotype);
Score::from_f32(regression.error(|input| reducer.reduce(input)))
})
.build();

let result = engine.run(|output| {
println!("[ {:?} ]: {:?}", output.index, output.score().as_float());
println!("[ {:?} ]: {:?}", output.index, output.score().as_float(),);
output.index == MAX_INDEX || output.score().as_float() < MIN_SCORE
});

display(&result);
}

fn display(result: &EngineOutput<NodeChromosome<f32>, Graph<f32>>) {
fn display(result: &EngineContext<GraphChromosome<Op<f32>>, Graph<Op<f32>>>) {
let mut reducer = GraphReducer::new(&result.best);
for sample in get_sample_set().get_samples().iter() {
let output = &reducer.reduce(&sample.1);
Expand All @@ -480,7 +480,7 @@ comprehensive list of examples.
println!("{:?}", result)
}

fn get_sample_set() -> DataSet<f32> {
fn get_sample_set() -> DataSet {
let inputs = vec![
vec![0.0, 0.0],
vec![1.0, 1.0],
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nav:
- Selectors: selectors.md
- Alterers: alterers.md
- Metrics: metrics.md
- Extensions: extensions.md
- Genetic Programming: gp.md
- Examples: examples.md
theme:
favicon: assets/radiate.ico
Expand Down
3 changes: 1 addition & 2 deletions radiate-examples/xor-graph/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use radiate::*;
use radiate_gp::*;
use random_provider::set_seed;

const MAX_INDEX: i32 = 500;
const MIN_SCORE: f32 = 0.01;

fn main() {
set_seed(501);
random_provider::set_seed(501);
let graph_codex = GraphCodex::regression(2, 1).with_output(Op::sigmoid());

let regression = Regression::new(get_sample_set(), ErrorFunction::MSE);
Expand Down

0 comments on commit 13d422a

Please sign in to comment.