-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
space: Implement PropertyLayer and _PropertyGrid #1898
Commits on Dec 25, 2023
-
Configuration menu - View commit details
-
Copy full SHA for be494d3 - Browse repository at this point
Copy the full SHA be494d3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6820b12 - Browse repository at this point
Copy the full SHA 6820b12View commit details -
_PropertyGrid: Implement multi-property cell selection and enhanced a…
…gent movement This commit introduces three significant enhancements for grids based on the _PropertyGrid in the mesa.space module: 1. `select_cells_multi_properties`: Allows for the selection of cells based on multiple property conditions, using a combination of NumPy operations. This method returns a list of coordinates satisfying the specified conditions. 2. `move_agent_to_random_cell`: Enables moving an agent to a random cell that meets specified property conditions, enhancing the flexibility in agent movements. 3. `move_agent_to_extreme_value_cell`: Facilitates moving an agent to a cell with the highest, lowest, or closest property value, based on a specified mode. This method extends agent movement capabilities, allowing for more dynamic and condition-based relocations.
Configuration menu - View commit details
-
Copy full SHA for f3ad411 - Browse repository at this point
Copy the full SHA f3ad411View commit details -
_PropertyGrid: Add optional neighborhood filtering to spatial methods
- Updated `select_cells_multi_properties`, `move_agent_to_random_cell`, and `move_agent_to_extreme_value_cell` methods in the `_PropertyGrid` class to include an optional neighborhood filtering feature. - Added `only_neighborhood` parameter to these methods to allow for conditional operations within a specified neighborhood around an agent's position. - Introduced `get_neighborhood_mask` as a helper function to create a boolean mask for neighborhood-based selections, enhancing performance and readability. - Modified methods to utilize NumPy for efficient array operations, improving the overall performance of grid-based spatial calculations. - Ensured backward compatibility by setting `only_neighborhood` to `False` by default, allowing existing code to function without modification.
Configuration menu - View commit details
-
Copy full SHA for 38faff5 - Browse repository at this point
Copy the full SHA 38faff5View commit details -
PropertyLayer: Check dimensions and dtype on init
Checks on initialization are cheap, and it helps users make the right decision for (NumPy) data type.
Configuration menu - View commit details
-
Copy full SHA for ddeb91c - Browse repository at this point
Copy the full SHA ddeb91cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1216d51 - Browse repository at this point
Copy the full SHA 1216d51View commit details -
Configuration menu - View commit details
-
Copy full SHA for f978f58 - Browse repository at this point
Copy the full SHA f978f58View commit details -
Configuration menu - View commit details
-
Copy full SHA for 900cd62 - Browse repository at this point
Copy the full SHA 900cd62View commit details -
_PropertyGrid: Make _get_neighborhood_mask private
Mark the _get_neighborhood_mask method as private, since it's intended as a helper function for select_cells_multi_properties() and move_agent_to_random_cell()
Configuration menu - View commit details
-
Copy full SHA for 04beb82 - Browse repository at this point
Copy the full SHA 04beb82View commit details -
move_agent_to_extreme_value_cell: remove closest option
closest is more difficult than highest or lowest, since closest needs a target to compare against. For now too complex without proven need, so I removed it.
Configuration menu - View commit details
-
Copy full SHA for 64ee7d3 - Browse repository at this point
Copy the full SHA 64ee7d3View commit details -
tests: Add tests for _PropertyGrid
SingleGrid inherits from _PropertyGrid, so testing though SingleGrid.
Configuration menu - View commit details
-
Copy full SHA for db9779c - Browse repository at this point
Copy the full SHA db9779cView commit details -
PropertyLayer: Fix handling of 'condition' callable in set_cells
Resolved an inconsistency in the set_cells method of our grid class. The method's documentation stated that the 'condition' argument should be a callable (such as a lambda function or a NumPy ufunc), but the implementation incorrectly treated 'condition' as a NumPy array. This update rectifies the implementation to align with the documented behavior. Now, the 'condition' argument is correctly called with the grid data as input, and its output (expected to be a boolean array) is used for conditional in-place updates of the grid. This change ensures that the function operates correctly when provided with callable conditions, fulfilling the intended functionality. Includes: - Calling 'condition' with self.data and using its output for conditional updates. - Adjusted error handling to check the output of the callable, ensuring it's a NumPy array with the correct shape. - Updated comments within the method for clarity.
Configuration menu - View commit details
-
Copy full SHA for 5be029c - Browse repository at this point
Copy the full SHA 5be029cView commit details -
PropertyLayer: Remove unnecessary check in aggregate_property
Whether it's a Lambda function or NumPy ufunc, they can be called the same way.
Configuration menu - View commit details
-
Copy full SHA for 2ac72a5 - Browse repository at this point
Copy the full SHA 2ac72a5View commit details -
_PropertyGrid: Take mask as input for selection functions
Take mask as input for selection functions. This way, it isn't needed to parse all neighbourhood elements. It also allows to use custom masks like for empty cells, etc. get_neighborhood_mask is now a public (not private) method again.
Configuration menu - View commit details
-
Copy full SHA for 6ead379 - Browse repository at this point
Copy the full SHA 6ead379View commit details -
_PropertyGrid: Give option to return list or mask
Give the select_cells_multi_properties method an option to return a mask instead of a list of cells. list is still default.
Configuration menu - View commit details
-
Copy full SHA for f570272 - Browse repository at this point
Copy the full SHA f570272View commit details -
_PropertyGrid: Split move_agent_to_extreme_value_cell into two methods
Split the move_agent_to_extreme_value_cell into two functions: - select_extreme_value_cells, which selects target cells - move_agent_to_extreme_value_cell, which moves the agent to that cell
Configuration menu - View commit details
-
Copy full SHA for 250678b - Browse repository at this point
Copy the full SHA 250678bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 24102c0 - Browse repository at this point
Copy the full SHA 24102c0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6b80a2a - Browse repository at this point
Copy the full SHA 6b80a2aView commit details -
_PropertyGrid: Rename functions to select and move by multiple proper…
…ties Hopefully these names are a little clearer
Configuration menu - View commit details
-
Copy full SHA for 2197bd3 - Browse repository at this point
Copy the full SHA 2197bd3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8afbc99 - Browse repository at this point
Copy the full SHA 8afbc99View commit details -
Optimize select_extreme_value_cells method for performance
This commit introduces several optimizations to the select_extreme_value_cells method of the _PropertyGrid class. These changes are aimed at enhancing the performance, especially for larger datasets, by reducing computational complexity and leveraging efficient numpy array operations. Key Changes: - Condensed the mask application process to a single conditional statement, reducing unnecessary operations when no mask is provided. - Streamlined the calculation of extreme values (maximum or minimum) using direct numpy functions without separate branching. - Optimized the creation of the target mask by utilizing numpy's inherent functions for array comparison, thereby minimizing the computational overhead. - Improved the efficiency of converting the mask to a list of coordinates using np.argwhere and tolist(), which is more suited for numpy arrays. These enhancements ensure that the method is more efficient and performant, particularly when handling large grids or property layers. Fixes: - The method now correctly returns a mask instead of an ndarray of coordinates when return_list is set to False. This fix aligns the method's behavior with its intended functionality and improves its usability in grid operations.
Configuration menu - View commit details
-
Copy full SHA for b0358f9 - Browse repository at this point
Copy the full SHA b0358f9View commit details -
Configuration menu - View commit details
-
Copy full SHA for eedbec7 - Browse repository at this point
Copy the full SHA eedbec7View commit details -
Fix remaining TestPropertyLayer A condition always is a function, never a mask (for now).
Configuration menu - View commit details
-
Copy full SHA for 0351d14 - Browse repository at this point
Copy the full SHA 0351d14View commit details -
Add a test if the coordinate systems are identical
Checks if the property layer and the property grid use coordinates in the same way.
Configuration menu - View commit details
-
Copy full SHA for 50d9602 - Browse repository at this point
Copy the full SHA 50d9602View commit details -
PropertyLayer: Improve ufunc handling and lambda vectorization
This update significantly improves the PropertyLayer's efficiency and robustness, particularly in handling lambda functions and NumPy universal functions (ufuncs). It addresses a critical bug where lambda conditions were incorrectly returning single boolean values instead of boolean arrays (masks) required for grid operations. The enhancements include checks to optimize the use of ufuncs and ensure accurate application based on their argument requirements. Motivation: - The primary motivation for these changes was to fix a bug in the `set_cells` method where lambda functions used as conditions were returning single boolean values instead of boolean arrays. This behavior led to errors and inefficient grid updates. - To address this, we optimized the method to correctly handle lambda functions and vectorize them only when necessary, ensuring they return a mask as required. - Furthermore, the implementation was fine-tuned to better handle NumPy ufuncs, avoiding redundant vectorization and ensuring performance optimization. Details: - Enhanced `set_cells` to properly handle lambda conditions by vectorizing them to return a boolean array that matches the grid's shape. - Added functionality to detect and directly apply NumPy ufuncs in both `set_cells` and `modify_cells`, bypassing unnecessary vectorization. - Implemented a shape check in `set_cells` to ensure the condition results align with the grid's dimensions. - Introduced `ufunc_requires_additional_input`, a utility function that determines if a ufunc needs an extra input, enhancing the accuracy of operations in `modify_cells`. - Ensured that non-ufunc conditions and lambda functions are correctly handled with appropriate vectorization, maintaining backward compatibility and flexibility. - The changes result in a more robust and efficient PropertyLayer, capable of handling a variety of functions with improved performance. Impact: These updates resolve the lambda function bug and significantly boost the PropertyLayer's performance and reliability, especially when dealing with different types of functions. The codebase is now better equipped to handle complex grid operations efficiently and accurately.
Configuration menu - View commit details
-
Copy full SHA for 04718e7 - Browse repository at this point
Copy the full SHA 04718e7View commit details -
Remove move functions from PropertGrid
As can be seen in the tests, movement can be done by selecting cells (with select_cells_by_properties and select_extreme_value_cells) and by then moving to them with the new move_agent_to_one_of.
Configuration menu - View commit details
-
Copy full SHA for a119cd9 - Browse repository at this point
Copy the full SHA a119cd9View commit details -
Configuration menu - View commit details
-
Copy full SHA for b1e6a9b - Browse repository at this point
Copy the full SHA b1e6a9bView commit details
Commits on Dec 29, 2023
-
_Property_grid: Implement single select_cells method
Implement a single select_cells method that incorperates the functionality of both select_cells_by_properties and select_extreme_value_cells. It now also allows multiple extreme values and multiple masks. Further, it adds a boolean to only include empty cells.
Configuration menu - View commit details
-
Copy full SHA for 3d752a4 - Browse repository at this point
Copy the full SHA 3d752a4View commit details -
_PropertyGrid: Keep empty_mask property, fix extreme_value bug
Keeps a property empty_mask, that's updated together with the empties property. But because it's a mask it's incredibly fast for other mask-based operations. Also fix a bug in the extreme_value part of the select() method: It now only considers values from the mask.
Configuration menu - View commit details
-
Copy full SHA for 26d2c80 - Browse repository at this point
Copy the full SHA 26d2c80View commit details -
Configuration menu - View commit details
-
Copy full SHA for 598bdea - Browse repository at this point
Copy the full SHA 598bdeaView commit details
Commits on Jan 6, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 6e12379 - Browse repository at this point
Copy the full SHA 6e12379View commit details -
Configuration menu - View commit details
-
Copy full SHA for 627eccb - Browse repository at this point
Copy the full SHA 627eccbView commit details -
Configuration menu - View commit details
-
Copy full SHA for f5f5065 - Browse repository at this point
Copy the full SHA f5f5065View commit details -
Configuration menu - View commit details
-
Copy full SHA for f96a9ef - Browse repository at this point
Copy the full SHA f96a9efView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3e7bd7b - Browse repository at this point
Copy the full SHA 3e7bd7bView commit details -
Configuration menu - View commit details
-
Copy full SHA for c71c9f5 - Browse repository at this point
Copy the full SHA c71c9f5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 363fb0b - Browse repository at this point
Copy the full SHA 363fb0bView commit details