API Reference

The API documentation is generated directly from the source. Heavy dependencies are mocked to keep the Read the Docs build lightweight; refer to the project requirements for runtime installation details.

Core Package

Input/Output

Loaders

Neural Networks

Samplers

graphmuse.samplers.extend_score_region_via_neighbor_sampling(cgraph, note_array, region, samples_per_node, sample_rightmost=True)[source]

Wrap the C extension c_extend_score_region_via_neighbor_sampling.

The routine samples neighbours and pre-neighbours that lie directly outside the provided score region.

Parameters:
  • cgraph (Graph) – Score graph implemented in C (attribute of HeteroScoreGraph).

  • note_array (partitura or numpy structured array) – Score representation. Requires onset_div and duration_div integer fields.

  • region (tuple[int, int]) – Inclusive start and exclusive end describing the region boundaries.

  • samples_per_node (int) – Number of samples drawn per node.

  • sample_rightmost (bool, optional) – Whether to compute the right extension, by default True.

Returns:

(left_extension, right_extension) where each element is a tuple (nodes, edges) of sampled indices and associated edge pairs.

Return type:

tuple

Notes

The underlying C routine expects onset_div and duration_div as int32 arrays and the cumulative maximum of onset_div + duration_div.

graphmuse.samplers.graph(edges)[source]

creates a Graph object from a numpy array of edges. It includes type checking.

Parameters:

edges (numpy.ndarray) – a 2D array of integers. The first row contains the source nodes, the second row the destination nodes, the third row the edge types.

Returns:

a Graph object in C

Return type:

Graph

graphmuse.samplers.random_score_region(note_onsets, budget)[source]

Python wrapper function for C Extension function c_random_score_region

It samples a score region of a given budget from a score graph.

Parameters:
  • note_onsets (array/tensor int) – This represents a score graph, as in, the data in this structure determines the edges between nodes required fields: onset_div, duration_div note_array[‘onset_div’] is a non-decreasing integer array note_array[‘duration_div’] is an integer array

  • budget (int) – The maximum number of nodes in the region

Returns:

region – The region to sample from. It is a tuple of two integers, start and end.

Return type:

tuple

graphmuse.samplers.sample_neighbors_in_score_graph(note_array, depth, samples_per_node, targets)[source]

Python wrapper function for C Extension function c_sample_neighbors_in_score_graph Samples Neighbors within a score graph In comparison to other methods involving pre-neighbors, this one doesn’t use a lookup table for the neighborhood of a node, but it computes the neighborhood of a node on the fly which can be done efficiently due to the form that neighborhoods have in score graphs

Parameters:
  • note_array (partitura/numpy.structured array) – This represents a score graph, as in, the data in this structure determines the edges between nodes required fields: onset_div, duration_div note_array[‘onset_div’] is a non-decreasing integer array note_array[‘duration_div’] is an integer array

  • depth (int) – The number of layers that are sampled

  • samples_per_node (int) – The number of samples per node.

  • targets (np.ndarray) – initial value for the sampling iteration

  • Note (c_sample_neighbors_in_score_graph expects onsets and durations to be passed in as int32 integer arrays (see code below))

Returns:

  • samples_per_layer (PyList(type=np.ndarray, length=depth+1)) – List of numpy arrays of nodes (called layers) where the last layer corresponds to ‘targets’ and each n-th layer which isn’t the last is a subset of the pre-neighborhood of the n+1-th layer

  • edges_between_layers (PyList(type=np.ndarray(2, N), length=depth)) – List of numpy arrays of edges which show how 2 consecutive layers in samples_per_layer are connected

  • total_samples (numpy.ndarray) – the union of samples_per_layer

graphmuse.samplers.sample_nodewise(cgraph, depth, samples_per_node, targets)[source]

Python wrapper function for C Extension function c_sample_nodewise Samples nodes within a score graph

Parameters:
  • cgraph (Graph) – The score graph implemented in c. It is an attribute of the HeteroScoreGraph.

  • depth (int) – The number of layers that are sampled

  • samples_per_node (int) – The number of samples per node.

  • targets (np.ndarray) – initial value for the sampling iteration

graphmuse.samplers.sample_preneighbors_within_region(cgraph, region, samples_per_node=10)[source]

Python wrapper function for C Extension function c_sample_preneighbors_within_region Samples the pre-neighbors (or predecessors) within a score region.

Parameters:
  • cgraph (Graph) – The score graph implemented in c. It is an attribute of the HeteroScoreGraph.

  • region (tuple) – The region to sample from. It is a tuple of two integers, start and end. The region is inclusive on the left and exclusive on the right.

  • samples_per_node (int) – The number of samples per node.

  • Note (c_sample_preneighbors_within_region expects the region to be passed as 2 separate integers (see return statement))

Returns:

  • Samples (np.ndarray) – The sampled nodes. It is a 1D array of integers. It might not contain all nodes in the region.

  • edges (np.ndarray (2, num_edges)) – The edges. It is a 2D array of integers. The first row contains the source nodes, the second row the destination nodes.

Utilities