diff --git a/spatial_access/Models.py b/spatial_access/Models.py index 09538bf..82b3199 100644 --- a/spatial_access/Models.py +++ b/spatial_access/Models.py @@ -542,14 +542,14 @@ def _log_category_weight_dict(self, category_weight_dict): self.logger.info("Using weights: {}".format(presented_weight_dict)) def calculate(self, upper_threshold, category_weight_dict=None, - normalize=False, normalize_type='z_score'): + normalize=False, normalize_type='minmax'): """ Args: category_weight_dict: category_weight_dict: dictionary of {category : [numeric weights]} or None upper_threshold: time in seconds. normalize: boolean. If true, results will be normalized from 0 to 100. - normalize_type: 'z_score'. + normalize_type: 'z_score', 'minmax' Returns: DataFrame. Raises: UnexpectedNormalizeColumnsException @@ -630,7 +630,7 @@ def _normalize(self, column, normalize_type): Normalize results. Args: column: which column to normalize. - normalize_type: 'z-score' + normalize_type: 'z-score', 'minmax' Raises: UnexpectedEmptyColumnException @@ -642,6 +642,12 @@ def _normalize(self, column, normalize_type): - self.model_results[column].mean()) / self.model_results[column].std() except ZeroDivisionError: raise UnexpectedEmptyColumnException(column) + elif normalize_type == 'minmax': + try: + normalize_factor = self.model_results[column].max() - self.model_results[column].min() + except ZeroDivisionError: + raise RuntimeError("column max == column min ({})".format(self.model_results[column].max())) + self.model_results[column] = (self.model_results[column] - self.model_results[column].min()) / normalize_factor else: raise UnexpectedNormalizeTypeException(normalize_type) diff --git a/spatial_access/__init__.py b/spatial_access/__init__.py index dc8cafb..8354de2 100644 --- a/spatial_access/__init__.py +++ b/spatial_access/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.1.18' +__version__ = '1.0.0' __author__ = 'Logan Noel (lmnoel)' __url__ = 'https://github.com/GeoDaCenter/spatial_access' __license__ = 'GPL' \ No newline at end of file diff --git a/spatial_access/src/CMakeLists.txt b/spatial_access/src/CMakeLists.txt deleted file mode 100644 index eeb4e73..0000000 --- a/spatial_access/src/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.13) -set(CMAKE_CXX_STANDARD 11) -set (CMAKE_CXX_FLAGS "-O3") -#set(CMAKE_CXX_FLAGS -march=native) -include_directories(include) -set(SOURCE_FILES - Serializer.cpp - Matrix.cpp - threadUtilities.cpp - csvParser.cpp - tmxParser.cpp) -project(matrix) -add_executable(matrix ${SOURCE_FILES}) \ No newline at end of file diff --git a/spatial_access/src/Matrix.cpp b/spatial_access/src/Matrix.cpp deleted file mode 100644 index a60d66a..0000000 --- a/spatial_access/src/Matrix.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// This is a test file used for development of the package -// it should be removed prior to distribution - -#include -#include "transitMatrix.h" -#include -#include -#include -#include - -int main() -{ - transitMatrix matrix2; - matrix2.readCSV("ct_health.csv"); -// matrix2.printDataFrame(); - matrix2.getValuesBySource(17031841100, true); - - return 0; -}; - - diff --git a/tests/test_Models.py b/tests/test_Models.py index 1d599fa..da287b5 100644 --- a/tests/test_Models.py +++ b/tests/test_Models.py @@ -400,7 +400,8 @@ def test_16(self): 'D': [4, 3, 1], 'C': [1]} coverage_model.transit_matrix = self.mock_transit_matrix_values(coverage_model.transit_matrix) - coverage_model.calculate(category_weight_dict=category_weight_dict, upper_threshold=700, normalize=True) + coverage_model.calculate(category_weight_dict=category_weight_dict, upper_threshold=700, normalize=True, + normalize_type='z_score') assert almost_equal(coverage_model.model_results['all_categories_score'].max(), 1.336) assert almost_equal(coverage_model.model_results['all_categories_score'].min(), -1.336) @@ -441,11 +442,20 @@ def test_18(self): category_weight_dict = {'A': [5, 4, 3, 2, 1], 'D': [4, 3, 1]} coverage_model.transit_matrix = self.mock_transit_matrix_values(coverage_model.transit_matrix) - coverage_model.calculate(category_weight_dict=category_weight_dict, upper_threshold=200, normalize=['A']) + coverage_model.calculate(category_weight_dict=category_weight_dict, upper_threshold=200, normalize=['A'], + normalize_type='z_score') assert almost_equal(coverage_model.model_results['A_score'].max(), 2.041) assert almost_equal(coverage_model.model_results['A_score'].min(), -0.408) + coverage_model.calculate(category_weight_dict=category_weight_dict, upper_threshold=200, normalize=True, + normalize_type='minmax') + assert almost_equal(coverage_model.model_results['A_score'].max(), 1.0) + assert almost_equal(coverage_model.model_results['A_score'].min(), 0.0) + assert almost_equal(coverage_model.model_results['D_score'].max(), 1.0) + assert almost_equal(coverage_model.model_results['D_score'].min(), 0.0) + + def test_19(self): """ Test the DestFloatingCatchmentAreaModel aggregation.