cogrecon.core package¶
Subpackages¶
- cogrecon.core.data_flexing package
- Subpackages
- Submodules
- cogrecon.core.data_flexing.category_data_flexor module
- cogrecon.core.data_flexing.descrambler module
- cogrecon.core.data_flexing.dimension_removal module
- Module contents
- cogrecon.core.visualization package
- Submodules
- cogrecon.core.visualization.vis_iposition module
- cogrecon.core.visualization.vis_spatial_navigation_2room module
- cogrecon.core.visualization.vis_spatial_navigation_4room module
- cogrecon.core.visualization.vis_time_travel_task module
- cogrecon.core.visualization.vis_virtual_morris_water_maze module
- Module contents
Submodules¶
cogrecon.core.batch_pipeline module¶
-
cogrecon.core.batch_pipeline.batch_pipeline(search_directory, out_filename, data_shape=None, dimension=2, accuracy_z_value=1.96, trial_by_trial_accuracy=False, flags=<PipelineFlags.All: 3>, collapse_trials=True, manual_threshold=None, actual_coordinate_prefixes=False, category_independence_enabled=False, category_prefixes=False, order_greedy_deanonymization_enabled=False, order_prefixes=True, removal_dim_indicies=None, _data_coordinates_file_suffix='position_data_coordinates.txt', _order_file_suffix='order.txt', _category_file_suffix='categories.txt', _actual_coordinates_file_suffix='actual_coordinates.txt')[source]¶ This function allows the easy running of the pipeline on a directory and all of the appropriate files in its subdirectories. It will search for the actual coordinates and data files and process them all as specified by the other parameters.
Parameters: - _data_coordinates_file_suffix – (string) the file suffix to search for for data files in batch processing
- _actual_coordinates_file_suffix – (string) the file suffix to search for for actual coordinate files in
batch processing :param _category_file_suffix: (string) the file suffix to search for for category files in batch processing :param _order_file_suffix: (string) the file suffix to search for for order files in batch processing :param search_directory: the directory (string) in which to recursively search for data files :param out_filename: the filename and path (string) into which the data should be saved
Parameters: - data_shape – a shape (list, tuple or numpy array) which describes the structure of the date; (Nt, Ni, d) such that Nt is the number of trials, Ni is the number of items and d is the number of dimensions; if None is given, an attempt will be made to automatically detect the shape from the actual_coordinates file
- accuracy_z_value – a value (float or int) representing the z threshold for counting something as accurate
- trial_by_trial_accuracy – when True, z_value thresholds are used on a trial-by-trial basis for accuracy calculations, when False, the thresholds are computed then collapsed across an individual’s trials
- flags – the value (PipelineFlags) describing what pipeline elements should/should not be run on the data
- collapse_trials – if True, the output file will contain one row per participant, otherwise each trial will be output in an individual row
- removal_dim_indicies – a list of dimension indicies to remove from processing
- dimension – the number of dimensions of the input data
- order_greedy_deanonymization_enabled – whether the greedy, order based deanonymization method should be used in determining the mapping of object to location. Note that if enabled, an order file (or files) is expected.
- category_independence_enabled – whether the items involved have associated categorical information such that they should be processed independently. Note that if enabled, a category file (or files) is expected.
- manual_threshold – a list of manual swap threshold values associated with the specified participant prefixes and trials in the batch process (should be of the same length as the number of trials)
- order_prefixes – whether or not we will look for files associated with order in a one-to-one fashion with data files based on the prefix values
- category_prefixes – whether or not we will look for files associated with category in a one-to-one fashion with data files based on the prefix values
- actual_coordinate_prefixes – whether or not we will look for actual coordinate files in a one-to-one fashion with data files based on the prefix values
Return type: None
-
cogrecon.core.batch_pipeline.get_single_file_result(actual_coordinates, dat, categories=None, data_orders=None, label='', accuracy_z_value=1.96, trial_by_trial_accuracy=True, manual_threshold=None, flags=<PipelineFlags.All: 3>, remove_dims=None, category_independence_enabled=False, order_greedy_deanonymization_enabled=False)[source]¶ This function generates the results for a specific file’s data structure, usually containing multiple trials
Parameters: - actual_coordinates – the correct coordinates for the points - an (Nt, Ni, d) sized list of floats where Nt is the number of trials, Ni is the number of items, and d is the dimensionality of the points
- dat – the data coordinates for the points - an (Nt, Ni, d) sized list of floats where Nt is the number of trials, Ni is the number of items, and d is the dimensionality of the points
- order_greedy_deanonymization_enabled – whether the greedy, order based deanonymization method should be used in determining the mapping of object to location. Note that if enabled, an order file (or files) is expected.
- category_independence_enabled – whether the items involved have associated categorical information such that they should be processed independently. Note that if enabled, a category file (or files) is expected.
- remove_dims – a list of dimension indicies to remove from processing
- data_orders – a list of integer order values for the associated dat input data (should be same shape as dat but without multiple axis dimensions)
- categories – a list of values for the associated dat input categories (should be same shape as dat but without multiple axis dimensions)
- manual_threshold – a list of manual swap threshold values associated with the specified trials in dat (should be of the same length as the number of trials)
- label – the label (string) identifying the participant ID for this file, used for debugging purposes only
- accuracy_z_value – a value (float or int) representing the z threshold for counting something as
- trial_by_trial_accuracy – when True, z_value thresholds are used on a trial-by-trial basis for accuracy calculations, when False, the thresholds are computed then collapsed across an individual’s trials
- flags – the value (PipelineFlags) describing what pipeline elements should/should not be run on the data
Returns: a list, (Nt, r), where Nt is the number of trials and r is the number of result metrics, of results values from the analysis for each trial on a particular file’s data
Return type: list (or empty list)
-
cogrecon.core.batch_pipeline.output_results(results, collapse_trials, agg_functions, out_fp, label)[source]¶
-
cogrecon.core.batch_pipeline.validate_equal_list_shapes(l1, l2, expected_shape=None, l1_name='list1', l2_name='list2')[source]¶ This function validates that two numeric lists have equal shape.
Parameters: - l1 – a list, tuple, or numpy array whose shape should be equal to the shape of l1 and expected_shape (if specified)
- l2 – a list, tuple, or numpy array whose shape should be equal to the shape of l2 and expected_shape (if specified)
- expected_shape – a shape (list, tuple or numpy array) against which both l1 and l2 should be compared to ensure they are equal to it and each other
- l1_name – the name (string) of l1 for debugging
- l2_name – the name (string) of l2 for debugging
-
cogrecon.core.batch_pipeline.validate_list_format(l, require_numeric=False, dimension=None, list_name='list')[source]¶ This function validates that a list is the correct type, dimension, and contains only int and float values (if specified).
Parameters: - l – a list whose type, dimensionality, and contents should be checked; valid types are list, tuple, or numpy array, dimensionality should match dimension, and the contents should all be int or float
- require_numeric – if True, elements must be int or float
- dimension – the expected number of dimensions (integer greater than 0) of the list
- list_name – the name (string) of the list for debugging purposes
cogrecon.core.cogrecon_globals module¶
cogrecon.core.data_structures module¶
-
class
cogrecon.core.data_structures.AnalysisConfiguration(z_value=1.96, trial_by_trial_accuracy=False, manual_threshold=None, flags=<PipelineFlags.All: 3>, greedy_order_deanonymization=False, process_categories_independently=False, is_category=False, category_label=None, debug_labels=[''])[source]¶ The AnalysisConfiguration object is used to store the various global analysis variables of interest which determine the behavior of the pipeline. It is passed to functions which require one of these variables.
-
class
cogrecon.core.data_structures.ParticipantData(trials, identity=None)[source]¶ Bases:
objectThis object contains an entire participant’s data across all trials. It really just wraps up the TrialData object in a list such that any attribute in TrialData can be called in ParticipantData, but the getting and setting functionality will include the trial dimension. This allows data to be conveniently gotten and set in a multi-dimensional way rather than always trial-by-trial.
Note
All attributes in TrialData can be called in ParticipantData.
-
static
category_split_participant(original_participant_data, unique_categories)[source]¶ This helper function splits a ParticipantData object into multiple objects containing unique categories defined by unique_categories. If an item has no category label or does not match one of the labels in unique_categories, it will be added to the unknown_category_participant_data object (the second output in output tuple)
Parameters: - original_participant_data – a ParticipantData object containing categorical data
- unique_categories – a unique list of category labels
Returns: a tuple whose first element is a list of ParticipantData objects associated one-to-one with each unique category and whose second element is a ParticipantData object containing all unlabelled or unknown category items
-
get_all_from_trials(attribute)[source]¶ A helper function which wil lget all the attributes in the TrialData in self.trials as a list of values.
Parameters: attribute – the attribute in a TrialData object in self.trials to get Returns: a list of values from every self.trials element corresponding to the given attribute
-
static
load_from_file(actual_coordinates_filepath, data_coordinates_filepath, expected_shape, dimension=2, category_filepath=None, order_filepath=None)[source]¶ This helper function takes paths to data files and an expected shape and generates a ParticipantData object which contains the file data.
Parameters: - actual_coordinates_filepath – the path to the actual_coordinates.txt file, containing actual/correct/target data coordinates
- data_coordinates_filepath – the path to the position_data_coordinates.txt file, containing participant data coordinates
- expected_shape – a tuple of integers specifying the shape the data should be
- dimension – the expected dimensionality of the data
- category_filepath – a path to the category.txt file, specifying item categories
- order_filepath – a path to the order.txt file, specifying order of placement
Returns: the ParticipantData object containing all appropriate information given the input file paths
-
set_all_to_trials(attribute, value)[source]¶ A helper function which will set all the attributes in the TrialData in self.trials to a list of values.
Parameters: - attribute – the attribute in a TrialData object in self.trials to set
- value – the value list to which each self.trials element should be set
-
static
-
class
cogrecon.core.data_structures.PipelineFlags[source]¶ Bases:
enum.EnumThis class serves as an Enum in order to describe which, if any, pipeline steps should be run on execution.
It acts as a set of flags for each pipeline step (Deanonymize and Global Transform currently), enabling them or disabling them as appropriate. When used as an integer, the integer value can be through of as a binary value whose digit places are associated with boolean values specifying the enabled/disabled state of each pipeline step.
Note
Simple and Unknown both disable all pipeline stages except accuracy and cycle/swap analysis. All runs all steps.
-
All= 3¶
-
Deanonymize= 1¶
-
GlobalTransformation= 2¶
-
Simple= 0¶
-
-
class
cogrecon.core.data_structures.TrialData(actual_points=None, data_points=None, actual_labels=None, data_labels=None, cateogry_labels=None, data_order=None)[source]¶ Bases:
objectThis class is used to store individual trial data. Some functions can and should be only run on a single trial worth of data rather than a whole participant worth.
Note
This object is typically contained within a ParticipantData object.
-
actual_labels¶ Returns: the actual/correct/target labels
-
actual_points¶ Returns: the actual/correct/target points
-
category_labels¶ Returns: the category label list
-
data_labels¶ Returns: the participant data labels
-
data_order¶ Returns: the data order list
-
data_points¶ Returns: the participant data points
-
distance_accuracy_map¶ Returns: the distance accuracy map, if set by the accuracy function
-
distance_threshold¶ Returns: the distance threshold, if set by the accuracy function
-
cogrecon.core.file_io module¶
-
cogrecon.core.file_io.detect_shape_from_file(path, dimension)[source]¶ This function uses the requested dimensionality and path contents of a coordinate file to automatically determine the data shape.
Parameters: - path – a value (string) containing the path of the file from which structure should be detected
- dimension – a value (integer) which represents the dimensionality of the data
Return type: int, int, int
Returns: a tuple containing the trial count, the item count, and the dimensionality
-
cogrecon.core.file_io.enforce_single_file_contents(file_list, name)[source]¶ This function ensures that if file_list contains multiple unique files, an error is thrown, otherwise it simply returns the first element.
Parameters: - file_list – a list of files which should all be the same
- name – the name of the file list type for debugging purposes
Returns: a path to a unique single file or empty list if none was found
-
cogrecon.core.file_io.extract_prefixes_from_file_list_via_suffix(file_list, suffix)[source]¶ This function will return a list of prefixes from files given an expected suffix.
Parameters: - file_list – a list of file paths
- suffix – a suffix whose contents should be removed from the end of the file_list element’s basename
Returns: a list of file prefixes
-
cogrecon.core.file_io.file_list_contents_equal(file_list)[source]¶ This function checks a list of files to ensure the contents are all equal across each file.
Parameters: file_list – a list of file paths Returns: True if all files are equal in contents, False otherwise
-
cogrecon.core.file_io.find_data_files_in_directory(directory, actual_coordinate_prefixes=False, category_prefixes=False, category_independence_enabled=False, order_prefixes=True, order_greedy_deanonymization_enabled=False, _data_coordinates_file_suffix='position_data_coordinates.txt', _order_file_suffix='order.txt', _category_file_suffix='categories.txt', _actual_coordinates_file_suffix='actual_coordinates.txt')[source]¶ This function crawls the specified directory, recursively looking for the actual coordinate file and data files.
Parameters: - directory – the directory (string) in which to recursively search for data files
- _category_file_suffix – the category file suffix for which to search
- _actual_coordinates_file_suffix – the actual coordinate file suffix for which to search
- _order_file_suffix – the order file suffix for which to search
- _data_coordinates_file_suffix – the data file suffix for which to search
- order_prefixes – if True, it is assumed there will be an equal number of order files as data files with identical prefixes, otherwise one file is expected
- category_prefixes – if True, it is assumed there will be an equal number of category files as data files with identical prefixes, otherwise one file is expected
- actual_coordinate_prefixes – if True, it is assumed there will be an equal number of actual coordinate files as data files with identical prefixes, otherwise one file is expected
- order_greedy_deanonymization_enabled – whether the greedy, order based deanonymization method should be used in determining the mapping of object to location. Note that if enabled, an order file (or files) is expected.
- category_independence_enabled – whether the items involved have associated categorical information such that they should be processed independently. Note that if enabled, a category file (or files) is expected.
Return type: string (or None), list of strings (or empty list)
Returns: the actual coordinate filename/path (None if no file was found), a list of the data filenames/paths (empty list if no files were found), a list of category filenames/paths (empty list if no files were found or requested), and a list of order filenames/paths (empty list if no files were found or requested)
-
cogrecon.core.file_io.get_coordinates_from_file(path, expected_shape, dimension=None, data_type=<type 'float'>)[source]¶ This function reads a data file and shapes the data into the appropriate expected shape (usually (Nt, Ni, 2) where Nt is the number of trials (rows) and Ni is the number of items (columns / dimensions)
Parameters: - dimension – the dimensionality of the data (i.e. 2, for 2D for x and y)
- path – a path to a coordinate file
- expected_shape – the expected shape of a coordinate file (if None, the shape will be detected using dimension)
- data_type – the data type of the coordinate file
Returns: a list of shape expected_shape and type data_type
-
cogrecon.core.file_io.get_id_from_file_prefix_via_suffix(path, suffix)[source]¶ This function grabs the first 3 characters of the filename which are assumed to be the participant id
Parameters: - path – the path to a file ending in suffix
- suffix – the ending part of a filename
Returns: the os.path.basename of path with characters of length of suffix removed from the end
-
cogrecon.core.file_io.is_path_exists_or_creatable_portable(pathname)[source]¶ This function helps determine if a pathname exists or is creatable.
This function is guaranteed to _never_ raise exceptions.
Parameters: pathname – the pathname about which it should be determined if it exists or is creatable Returns: True if the passed pathname is a valid pathname on the current OS _and_ either currently exists or is hypothetically creatable in a cross-platform manner optimized for POSIX-unfriendly filesystems; False otherwise.
-
cogrecon.core.file_io.is_path_sibling_creatable(pathname)[source]¶ This function helps determine if a path is creatable.
Parameters: pathname – the pathname about which to determine if it is creatable Returns: True if the current user has sufficient permissions to create siblings (i.e., arbitrary files in the parent directory) of the passed pathname; False otherwise.
-
cogrecon.core.file_io.is_pathname_valid(pathname)[source]¶ Windows-specific error code indicating an invalid pathname.
See Also: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx Official listing of all such codes.
Parameters: pathname – the pathname about which to determine validity Returns: True if the passed pathname is a valid pathname for the current OS; False otherwise.
-
cogrecon.core.file_io.make_singular_filename_values_list(value, expected_length)[source]¶ This function takes a value and produces an appropriate length list of values. If the input is a list of values already, the list will have empty strings appended to it until it is the expected length. If it is greater than the expected length already, it will simply be returned as-is. If it is a list with one element, that element will be duplicated to make the list expected_length and returned. If it is a value, a list containing expected_length numbers of that value will be returned. If none of these apply, a list of empty strings is returned.
Parameters: - value – the value contents of the output list
- expected_length – the expected length of the output list
Returns: a list of length expected_length with contents reflected by value
-
cogrecon.core.file_io.match_file_prefixes(files, prefixes)[source]¶ This function attempts to sort and match the list of files to a list of prefixes for each file.
Parameters: - files – a list of file paths which should be associated with each prefix
- prefixes – a list of prefixes which should be associated with each file path
Returns: a list of files, sorted according to prefixes
cogrecon.core.full_pipeline module¶
-
cogrecon.core.full_pipeline.accuracy(participant_data, analysis_configuration, use_manual_threshold=False)[source]¶ This function computes the accuracy of each item in a ParticipantData object, optionally using a manual threshold.
Parameters: - participant_data – the ParticipantData object
- analysis_configuration – the AnalysisConfiguration object
- use_manual_threshold – if True, the manual threshold from the AnalysisConfiguration object will be used instead of an automatically computed threshold
Returns: the input ParticipantData object with the distance_accuracy_map and distance_threshold attributes populated
-
cogrecon.core.full_pipeline.deanonymize(participant_data, analysis_configuration)[source]¶ This function performs the deanonymization routine on ParticipantData.
Parameters: - participant_data – the ParticipantData object
- analysis_configuration – the AnalysisConfiguration object
Returns: the minimal mapping coordinates, minimal distance scores, minimal score lexicographical positions, and misplacement values for each trial
-
cogrecon.core.full_pipeline.full_pipeline(participant_data, analysis_configuration, visualize=False, visualization_extent=None, fig_size=None)[source]¶ This function is the main pipeline for the new processing methods. When run alone, it just returns the values for a single trial. With visualize=True it will display the results. debug_labels is used to help specify which participant/trial is being observed when running from an external process (it is appended to the debug info). The coordinates are expected to be equal in length of the for (Nt, Ni, 2) where Nt is the number of trials and Ni is the number of items.
Parameters: - participant_data – the ParticipantData object to process
- analysis_configuration – the AnalysisConfiguration object to determine the pipeline configuration
- visualize – if True, the output will be visualized
- visualization_extent – the data bounds to be used for visualization
- fig_size – the size of the output figure in visualization (in inches)
Returns: an output list of all metrics produces in the pipeline whose headers are defined by get_header_labels
-
cogrecon.core.full_pipeline.geometric_transform(participant_data, analysis_configuration)[source]¶ This function performs the geometric transform computation on an entire ParticipantData object.
Parameters: - participant_data – the ParticipantData object
- analysis_configuration – the AnalysisConfiguration object
Returns: a list of the geometric transform results from trial_geometric_transform for each trial in the ParticipantData object
-
cogrecon.core.full_pipeline.get_aggregation_functions()[source]¶ This function gets a list of functions which should be used when collapsing trial data for each column in the output.
Returns: a list of functions to be applied to cross-trial data to collapse it appropriately
-
cogrecon.core.full_pipeline.get_header_labels()[source]¶ This function is responsible for returning the names of the values returned in full_pipeline
Returns: a list of header names for each output column
-
cogrecon.core.full_pipeline.swaps(participant_data, analysis_configuration)[source]¶ This function computes the swap metrics across all trials in a ParticipantData object.
Parameters: - participant_data – the ParticipantData object
- analysis_configuration – the AnalysisConfiguration object
Returns: a list of results from the trial_swaps function for all trials in ParticipantData in order
-
cogrecon.core.full_pipeline.trial_axis_swap(trial_data)[source]¶ This function calculates the original axis swap metrics on a TrialData object.
Parameters: trial_data – a TrialData object Returns: the axis swap value
-
cogrecon.core.full_pipeline.trial_edge_distortion(trial_data)[source]¶ This function calculates the original edge distortion metrics on a TrialData object.
Parameters: trial_data – a TrialData object Returns: the edge distortion value
-
cogrecon.core.full_pipeline.trial_edge_resizing(trial_data)[source]¶ This function calculates the original edge resizing metrics on a TrialData object.
Parameters: trial_data – a TrialData object Returns: the edge resizing value
-
cogrecon.core.full_pipeline.trial_geometric_transform(trial_data, analysis_configuration)[source]¶ This function calculates the geometric transform metrics on a TrialData object.
Parameters: - trial_data – a TrialData object
- analysis_configuration – the AnalysisConfiguration object
Returns: a tuple containing: translation, translation_magnitude, scaling, rotation_theta, transformation_auto_exclusion, num_geometric_transform_points_excluded, transformed_coordinates, dist_threshold
-
cogrecon.core.full_pipeline.trial_swaps(trial_data)[source]¶ This function calculates the swap metrics on a particular TrialData object.
Parameters: trial_data – a TrialData object Returns: a tuple containing: accurate_placements, inaccurate_placements, true_swaps, partial_swaps, cycle_swaps, partial_cycle_swaps, components, misassignment, accurate_misassignment, inaccurate_misassignment, dist_threshold, mean true_swap_distances, mean true_swap_expected_distances, mean partial_swap_distances, mean partial_swap_expected_distances, mean cycle_swap_distances, mean cycle_swap_expected_distances, mean partial_cycle_swap_distances, mean partial_cycle_swap_expected_distances
cogrecon.core.similarity_transform module¶
-
cogrecon.core.similarity_transform.similarity_transform(from_points, to_points)[source]¶ References - [Umeyama’s paper](http://localhost:3690/files/doc/Umeyama_least_square.pdf) - [CarloNicolini’s python implementation](https://gist.github.com/CarloNicolini/7118015)
Modified by Kevin Horecka Feb 11, 2017
Parameters: - from_points – a list of points (list of floats) from which to find a transform
- to_points – a list points (list of floats) to which to find a transform
Returns: the rotation matrix, scaling, and translation between from_points and to_points via SVD
cogrecon.core.tools module¶
-
cogrecon.core.tools.brute_force_find_minimal_mapping(p0, p1)[source]¶ This function performs a brute force optimization, mapping the set of points p0 to the set of points p1 such that the sum of the pairwise distances between the points is minimal.
This function is deprecated as it is slower than find_minimal_mapping. It will ONLY throw a DeprecationWarning and will not return any values.
Parameters: - p0 – a list of points
- p1 – a list of points
-
cogrecon.core.tools.collapse_unique_components(components_list)[source]¶ This function takes a list of components (integer lists) and simplifies it to only contain unique components. It will also remove any NoneTypes and collapse them into just one None in the list.
Parameters: components_list – a list of integer lists Returns: a list of unique integer lists
-
cogrecon.core.tools.find_minimal_mapping(p0, p1)[source]¶ From https://stackoverflow.com/questions/39016821/minimize-total-distance-between-two-sets-of-points-in-python This function uses linear sum assignment to determine the mapping of points p0 to points p1 which minimizes the sum of the pairwise distances between the points.
Parameters: - p0 – a list of points
- p1 – a list of points
Returns: a tuple containing the mapping distance, the lexicographic index of the permutation associated with the minimal mapping, and a reordering of p1 which maps minimally to p0
-
cogrecon.core.tools.generate_random_test_points(number_of_points=5, dimension=2, shuffle_points=True, noise=0.05, num_rerandomed_points=1)[source]¶ This function is for testing. It generates a set of “correct” and “incorrect” points such that the correct points are randomly placed between (0,0) and (1,1) in R2. Then it generates “incorrect” points which are offset randomly up to 10% in the positive direction, shuffled, and where one point is completely random.
Parameters: - number_of_points – the number of points to generate
- dimension – the dimensionality of points to generate
- shuffle_points – if True, the points will be shuffled into a random order
- noise – the amount of noise to randomly move every point (items will move in both positive an negative directions the the magnitude specified here)
- num_rerandomed_points – the number of points which should be randomized at the end to completely random positions
Returns: a tuple containing two lists of points specified by the criteria specified in the input arguments
-
cogrecon.core.tools.greedy_find_minimal_mapping(p0, p1, order)[source]¶ This function performs a minimal mapping of p0 to p1 accounting for order. It does not guarantee that the mapping will be globally minimal, and instead, it treats the problem greedily. The order value specifies the order in which the points should be processed, finding the minimal association on a point-by-point basis. This will often leave the final points with very suboptimal mappings.
NOTE: This function makes a very strong assumption that the nearest neighbor mapping of items in order of placement will produce a reasonable outcome. If the point cloud is even remotely dense, this assumption will likely be false.
Parameters: - p0 – a list of points
- p1 – a list of points
- order – a list of integers specifying the order in which to associate points from p0 to p1 minimally
Returns: a tuple containing the mapping distance, the lexicographic index of the permutation associated with the minimal mapping, and a reordering of p1 which maps to p0
-
cogrecon.core.tools.lerp(start, finish, t)[source]¶ This function performs simple vector linear interpolation on two equal length number lists
Parameters: - start – a list of starting points (list)
- finish – a list of ending points (list)
- t – the distance between 0. and 1. along which to linearly interpolate between the start and finish points
Returns: a list of points some distance (specified by t) between the start and finish points
-
cogrecon.core.tools.lexicographic_index(p)[source]¶ -
Return the lexicographic index of the permutation p among all permutations of its elements. p must be a sequence and all elements of p must be distinct.
# >>> lexicographic_index(‘dacb’) 19 # >>> from itertools import permutations # >>> all(lexicographic_index(p) == i … for i, p in enumerate(permutations(‘abcde’))) True
Parameters: p – a list containing some permutation of elements Returns: the lexicographic index in the permutation space of the given permutation list
-
cogrecon.core.tools.mask_dimensions(data3d, num_dims, remove_dims)[source]¶ This function takes 3-dimensional data and removes particular dimensions from the final axis.
Parameters: - data3d – a data containing trials, items, and dimensions
- num_dims – the number of dimensions in the data
- remove_dims – the dimensions to remove
Returns: 3d data of structure trials, items, dimensions with the dimensions specified by remove_dims removed from the last axis
-
cogrecon.core.tools.mask_points(points, keep_indicies)[source]¶ This function takes a list of points and removes all except for those specified at particular indices.
Parameters: - points – the points to mask
- keep_indicies – the indices to keep
Returns: a list of points which survive the mask
-
cogrecon.core.tools.n_perms(seq)[source]¶ Computes the factorial of the length of seq.
From: https://code.activestate.com/recipes/126037-getting-nth-permutation-of-a-sequence/
Parameters: seq – the sequence whose factorial length should be returned Returns: the factorial of the length of seq
-
cogrecon.core.tools.permutation_from_index(seq, index)[source]¶ Returns the th permutation of (in proper order).
From: https://code.activestate.com/recipes/126037-getting-nth-permutation-of-a-sequence/
Parameters: - seq – the sequence to reorder according to the lexicographical index
- index – the lexicographical index with which to reorder seq
Returns: seq reordered according to the lexicographical index
-
cogrecon.core.tools.sum_of_distance(list1, list2)[source]¶ This function defines the misplacement metric which is used for minimization (in de-anonymization). It is also used to calculate the original misplacement metric.
Parameters: - list1 – a list of points
- list2 – a list of points
Returns: a value representing the sum of pairwise distances between points in list1 and points in list 2
-
cogrecon.core.tools.validate_type(obj, t, name, source)[source]¶ This function calls an assertion to validate a particular object is of a particular type.
Parameters: - obj – The object whose type should be validated.
- t – The expected type.
- name – The name to print for debugging if the assertion fails.
- source – The source of the function call to print if the assertion fails.