Class: MiltonsMachine::Tools::MatrixAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/miltons_machine/tools/matrix_analyzer.rb

Overview

Note:

Performance is an issue right now with larger number of voices and pitches since performance is measured

Class: Matrix Analyzer

Given an array where each element in the array is a group of rows - each row representing ordered musical pitches: permutate each group of rows in parallel using rotation. After each rotation search each column (intersecting all groups) for a pattern of sonorities from a dictionary. If a sonority is found, then tabulate a score for comparison reporting.

Useful for counterpoint such as creating a canon, composing 12t, or deriving set related composition designs

from: number of permutations = x^(n-1) where x = number of columns and n is the number of groups.50 columns and 8 groups of one row in each group would generate 50^7 permutations or 781,250,000,000 possible rotations to search through.

TODO More report filtering options and statistic measurements TODO Performance improvement - allow for start and stop rotation indexes so work can be broken up TODO Performance improvement - parallel forking/threads, better algorithms etc...

See Also:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize(minimax_score = Range.new(0, 99999999), report_details = false)

Constructor

Parameters:

  • minimax_score (Range) (defaults to: Range.new(0, 99999999))

    Minimum to maximum score to display

  • report_details (Boolean) (defaults to: false)

    if true, show details, else summary only



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 81

def initialize( minimax_score = Range.new(0, 99999999), report_details = false )
  @minimax_score     = minimax_score
  @report_details    = report_details
  @groups            = []
  @search_sets       = []
  @summary_totals    = []
  @max_group_index   = 0
  @max_column_index  = 0
  @rotation_count    = 0
  @maximum_rotations = 0
end

Instance Attribute Details

- (Object) groups=(value)

A 3d array for holding horizontal ordered sets (rows) - each set: 1) representing an ordered voice of pitches in the matrix 2) should be rotatable like a cannon 3) encoded in mod12 pitch class notation (0 = c up to 11 = b)



42
43
44
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 42

def groups=(value)
  @groups = value
end

- (Object) max_column_index=(value)

The last index of the columns of the rows e.g. length - 1



60
61
62
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 60

def max_column_index=(value)
  @max_column_index = value
end

- (Object) max_group_index=(value)

The last index of the groups array e.g. length - 1



56
57
58
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 56

def max_group_index=(value)
  @max_group_index = value
end

- (Object) maximum_rotations=(value)

A calculation of the total number of rotations that this process will produce.



68
69
70
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 68

def maximum_rotations=(value)
  @maximum_rotations = value
end

- (Object) minimax_score

Range object - minimum to maximum score that must be met in the results for a solution to be counted.



31
32
33
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 31

def minimax_score
  @minimax_score
end

- (Object) report_details

Show details of the analysis, else summary only.



35
36
37
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 35

def report_details
  @report_details
end

- (Object) rotation_count=(value)

Used to count the total number of permutations (rotations) performed by the run.



64
65
66
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 64

def rotation_count=(value)
  @rotation_count = value
end

- (Object) search_sets=(value)

A 2d array for holding set of pitches to analyze when looking for vertical sonorities. These should already be transformed using Tn or TnI



47
48
49
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 47

def search_sets=(value)
  @search_sets = value
end

- (Object) summary_totals=(value)

Used to collect a final tally of subsets found. For example: summary_totals = 21 means 21 permutations had 9 subsets found in each



52
53
54
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 52

def summary_totals=(value)
  @summary_totals = value
end

Instance Method Details

- (Object) add_forte_set(forte_set_name, number_to_transpose = 0)

Insert a forte set into the search dictionary

Parameters:

  • forte_set_name (String)

    the target set name we are searching

  • number_to_transpose (Integer) (defaults to: 0)

    transpose the submitted set + n

Raises:

  • (KeyError)

    forte_set could not be found



123
124
125
126
127
128
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 123

def add_forte_set( forte_set_name, number_to_transpose = 0 )
  search_set = MiltonsMachine::Core::ForteDictionary.instance.get_set(forte_set_name)
  raise KeyError, "forte_set could not be found" if search_set.nil?

  @search_sets << Set.new( search_set.transpose_mod12(number_to_transpose) )
end

- (Object) add_row(group_id, row, number_to_transpose = 0)

Insert a row into the matrix of voices to search

Parameters:

  • group_id (Integer)

    The group id to add it to (1 - n)

  • row (Array)

    an array of ordered pitches (voice)

  • number_to_transpose (Integer) (defaults to: 0)

    transpose this array Tn 0-11



100
101
102
103
104
105
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 100

def add_row( group_id, row, number_to_transpose = 0 )
  @groups[group_id - 1] ||= []
  @groups[group_id - 1] << MiltonsMachine::Core::ForteSet.new(row).transpose_mod12(number_to_transpose)
  @max_group_index  = @groups.length - 1
  @max_column_index = @groups[0][0].length - 1
end

- (Object) add_search_set(search_set, number_to_transpose = 0)

Insert a set into the search dictionary

Parameters:

  • search_set (Array)

    the target set we are searching

  • number_to_transpose (Integer) (defaults to: 0)

    transpose the submitted set + n



113
114
115
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 113

def add_search_set( search_set, number_to_transpose = 0 )
  @search_sets << Set.new( MiltonsMachine::Core::ForteSet.new(search_set).transpose_mod12(number_to_transpose) )
end

- (Object) run_rotation_analysis

Run the rotation_analysis and print out the results



133
134
135
136
137
# File 'lib/miltons_machine/tools/matrix_analyzer.rb', line 133

def run_rotation_analysis
  initialize_run
  rotate_group
  print_summary
end