Module: Musa::Darwin
- Included in:
- All
- Defined in:
- lib/musa-dsl/generative/darwin.rb
Overview
Evolutionary selection algorithm based on fitness evaluation.
Darwin implements a selection algorithm inspired by natural selection, evaluating and ranking a population of objects based on defined measures (features and dimensions) and weights. Objects are measured, scored, and sorted by fitness for evolutionary algorithms or optimization.
Core Concepts
- Population: Collection of objects to evaluate
-
Measures: Evaluation criteria for each object
- Features: Boolean flags (present/absent)
- Dimensions: Numeric values (continuous)
- Die: Mark object as non-viable (eliminated)
- Weights: Importance multipliers for features/dimensions
- Fitness: Calculated score from normalized dimensions and features
- Selection: Population sorted by fitness (highest first)
Evaluation Process
- Measure: Evaluate each object with measures block
- Normalize: Scale dimension values to 0-1 range
- Weight: Apply weights to dimensions and features
- Score: Calculate total fitness for each object
- Sort: Order population by fitness (descending)
Musical Applications
- Select best harmonic progressions from generated candidates
- Rank melodic variations by aesthetic criteria
- Optimize rhythmic patterns for complexity/simplicity
- Evolve musical structures through iterative selection
A musical selection reads the same way, with the piece's own helpers doing
the judging (a reading: has_parallel_fifths? and friends are yours, not
the framework's):
darwin = Musa::Darwin::Darwin.new do
measures do |progression|
die if has_parallel_fifths?(progression)
dimension :voice_leading, -total_voice_leading_distance(progression)
feature :authentic_cadence if ends_with_V_I?(progression)
feature :plagal_cadence if ends_with_IV_I?(progression)
dimension :chromaticism, -count_chromatic_notes(progression)
end
weight voice_leading: 3.0,
authentic_cadence: 2.0,
plagal_cadence: 1.0,
chromaticism: 1.5
end
best = darwin.select(candidates).first(10)
Defined Under Namespace
Classes: Darwin