Skip to content

Commit

Permalink
Fix conditional cluster map & issues with Bonferroni (#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Jan 9, 2023
1 parent 7f542c7 commit 5109e6b
Show file tree
Hide file tree
Showing 32 changed files with 720 additions and 786 deletions.
17 changes: 9 additions & 8 deletions Algorithms/tsne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
TSNE::TSNE(double* X, int N, int D, double* Y,
int no_dims, double perplexity, double theta ,
int num_threads, int max_iter, int n_iter_early_exag,
int random_state, bool skip_random_init, int verbose,
unsigned int random_state, bool skip_random_init, int verbose,
double early_exaggeration, double learning_rate,
double *final_error)
: X(X), N(N), D(D), Y(Y), no_dims(no_dims), perplexity(perplexity) , theta(theta),
Expand Down Expand Up @@ -95,6 +95,14 @@ void TSNE::run(boost::lockfree::queue<int>& tsne_queue,
#endif
#endif

if (skip_random_init != true) {
if(random_state >= 0) {
srand((unsigned int) random_state);
} else {
srand((unsigned int) time(NULL));
}
}

/*
======================
Step 1
Expand Down Expand Up @@ -178,13 +186,6 @@ void TSNE::run(boost::lockfree::queue<int>& tsne_queue,
stop_lying_iter = 0; // Immediately stop lying. Passed Y is close to the true solution.
}
else {
if (skip_random_init != true) {
if(random_state >= 0) {
srand((unsigned int) random_state);
} else {
srand(time(NULL));
}
}
for (int i = 0; i < N * no_dims; i++) {
Y[i] = randn();
}
Expand Down
4 changes: 2 additions & 2 deletions Algorithms/tsne.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TSNE
int no_dims = 2, double perplexity = 30, double theta = .5,
int num_threads = 1, int max_iter = 1000,
int n_iter_early_exag = 250,
int random_state = 0, bool init_from_Y = false, int verbose = 0,
unsigned int random_state = 0, bool init_from_Y = false, int verbose = 0,
double early_exaggeration = 12, double learning_rate = 200,
double *final_error = NULL);

Expand Down Expand Up @@ -57,7 +57,7 @@ class TSNE
int num_threads;
int max_iter;
int n_iter_early_exag;
int random_state;
unsigned int random_state;
bool skip_random_init;
int verbose;
double early_exaggeration;
Expand Down
6 changes: 3 additions & 3 deletions BuildTools/macosx/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ build-geoda-mac:
cp /usr/local/opt/gdal/share/gdal/* build/GeoDa.app/Contents/Resources/gdaldata
cp libraries/lib/libwx_osx_cocoau-3.1.4.0.0.dylib build/GeoDa.app/Contents/Frameworks/libwx_osx_cocoau-3.1.dylib
cp libraries/lib/libwx_osx_cocoau_gl-3.1.4.0.0.dylib build/GeoDa.app/Contents/Frameworks/libwx_osx_cocoau_gl-3.1.dylib
cp /usr/local/opt/gdal/lib/libgdal.31.dylib build/GeoDa.app/Contents/Frameworks
cp /usr/local/opt/gdal/lib/libgdal.32.dylib build/GeoDa.app/Contents/Frameworks
install_name_tool -id "GeoDa" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libwx_osx_cocoau_gl-3.1.dylib" "@executable_path/../Frameworks/libwx_osx_cocoau_gl-3.1.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libwx_osx_cocoau-3.1.dylib" "@executable_path/../Frameworks/libwx_osx_cocoau-3.1.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "/usr/local/opt/gdal/lib/libgdal.31.dylib" "@executable_path/../Frameworks/libgdal.31.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "/opt/homebrew/opt/gdal/lib/libgdal.31.dylib" "@executable_path/../Frameworks/libgdal.31.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "/usr/local/opt/gdal/lib/libgdal.32.dylib" "@executable_path/../Frameworks/libgdal.32.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
install_name_tool -change "/opt/homebrew/opt/gdal/lib/libgdal.32.dylib" "@executable_path/../Frameworks/libgdal.32.dylib" build/GeoDa.app/Contents/MacOS/GeoDa
python3 install_name.py $(GEODA_HOME)/build/GeoDa.app/Contents/Frameworks "Developer ID Application: Geodapress LLC (26M5NG43GP)"
install_name_tool -change "@executable_path/../Frameworks/libwx_osx_cocoau-3.1.4.0.0.dylib" "@executable_path/../Frameworks/libwx_osx_cocoau-3.1.dylib" build/GeoDa.app/Contents/Frameworks/libwx_osx_cocoau_gl-3.1.dylib
codesign -f --timestamp -o runtime -s "Developer ID Application: Geodapress LLC (26M5NG43GP)" build/GeoDa.app/Contents/Frameworks/libwx_osx_cocoau_gl-3.1.dylib
Expand Down
2 changes: 1 addition & 1 deletion BuildTools/macosx/GeoDa.m1.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n#python3 install_name.py $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/opt/gdal/lib/libgdal.31.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/Cellar/[email protected]/1.1.1o/lib/libcrypto.1.1.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.4.0.0.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.4.0.0.dylib\n #install_name_tool -change \"@rpath/libgeos.3.10.1.dylib\" \"/opt/homebrew/opt/geos/lib/libgeos.3.10.1.dylib\" /opt/homebrew/Cellar/geos/3.10.1/lib/libgeos_c.1.16.0.dylib\n #codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/Cellar/geos/3.10.1/lib/libgeos_c.1.16.0.dylib\nelse\n mkdir $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks\n cp /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.4.0.0.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libwx_osx_cocoau-3.1.dylib\n cp /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.4.0.0.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libwx_osx_cocoau_gl-3.1.dylib\n cp /usr/local/opt/gdal/lib/libgdal.29.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libgdal.29.dylib\n install_name_tool -id \"GeoDa\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.dylib\" \"@executable_path/../Frameworks/libwx_osx_cocoau_gl-3.1.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.dylib\" \"@executable_path/../Frameworks/libwx_osx_cocoau-3.1.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/usr/local/opt/gdal/lib/libgdal.29.dylib\" \"@executable_path/../Frameworks/libgdal.29.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/opt/homebrew/opt/gdal/lib/libgdal.29.dylib\" \"@executable_path/../Frameworks/libgdal.29.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n python3 install_name.py $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\"\n codesign -f --timestamp -o runtime -s \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n codesign -f --timestamp -o runtime -s \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app\nfi\n";
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n#python3 install_name.py $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/opt/gdal/lib/libgdal.32.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/Cellar/[email protected]/1.1.1o/lib/libcrypto.1.1.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.4.0.0.dylib\n codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.4.0.0.dylib\n #install_name_tool -change \"@rpath/libgeos.3.10.1.dylib\" \"/opt/homebrew/opt/geos/lib/libgeos.3.10.1.dylib\" /opt/homebrew/Cellar/geos/3.10.1/lib/libgeos_c.1.16.0.dylib\n #codesign -f -s \"Apple Development: [email protected] (AN5USPSZF6)\" /opt/homebrew/Cellar/geos/3.10.1/lib/libgeos_c.1.16.0.dylib\nelse\n mkdir $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks\n cp /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.4.0.0.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libwx_osx_cocoau-3.1.dylib\n cp /Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.4.0.0.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libwx_osx_cocoau_gl-3.1.dylib\n cp /usr/local/opt/gdal/lib/libgdal.29.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libgdal.29.dylib\n install_name_tool -id \"GeoDa\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau_gl-3.1.dylib\" \"@executable_path/../Frameworks/libwx_osx_cocoau_gl-3.1.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/Users/xun/github/geoda/BuildTools/macosx/libraries/lib/libwx_osx_cocoau-3.1.dylib\" \"@executable_path/../Frameworks/libwx_osx_cocoau-3.1.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/usr/local/opt/gdal/lib/libgdal.29.dylib\" \"@executable_path/../Frameworks/libgdal.29.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n install_name_tool -change \"/opt/homebrew/opt/gdal/lib/libgdal.29.dylib\" \"@executable_path/../Frameworks/libgdal.29.dylib\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n python3 install_name.py $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\"\n codesign -f --timestamp -o runtime -s \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/GeoDa\n codesign -f --timestamp -o runtime -s \"0046C0AE0D6933F7CD8A67875F820AF13CD63439\" $TARGET_BUILD_DIR/$PRODUCT_NAME.app\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
23 changes: 21 additions & 2 deletions BuildTools/macosx/code_sign.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
import os, sys
import os, sys, re
from shutil import copyfile

processed_items = {}
Expand All @@ -10,12 +10,30 @@ def ProcessDependency(dylib_path, cid):
else:
processed_items[dylib_path] = True

if dylib_path == '@rpath/libgeos.3.11.1.dylib':
dylib_path = '/opt/homebrew/opt/geos/lib/libgeos.3.11.1.dylib'
if dylib_path == '@rpath/libgeos.3.11.0.dylib':
dylib_path = '/opt/homebrew/opt/geos/lib/libgeos.3.11.0.dylib'
if dylib_path == '@loader_path/libicuuc.71.dylib':
dylib_path = '/opt/homebrew/opt/icu4c/lib/libicuuc.71.dylib'
if dylib_path == '@loader_path/libicudata.71.dylib':
dylib_path = '/opt/homebrew/opt/icu4c/lib/libicudata.71.dylib'
if dylib_path == '@loader_path/libbrotlicommon.1.dylib':
dylib_path = '/opt/homebrew/opt/brotli/lib/libbrotlicommon.1.dylib'

if dylib_path == '@rpath/libIlmThread-3_1.30.dylib':
dylib_path = '/usr/local/opt/openexr/lib/libIlmThread-3_1.30.dylib'
if dylib_path == '@rpath/libIex-3_1.30.dylib':
dylib_path = '/usr/local/opt/openexr/lib/libIex-3_1.30.dylib'
if dylib_path == '@rpath/libOpenEXR-3_1.30.dylib':
dylib_path = '/usr/local/opt/openexr/lib/libOpenEXR-3_1.30.dylib'
if dylib_path == '@rpath/libOpenEXRCore-3_1.30.dylib':
dylib_path = '/usr/local/opt/openexr/lib/libOpenEXRCore-3_1.30.dylib'

m = re.search('@rpath/(libaws.*)', dylib_path)
if m:
dylib_path = '/usr/local/opt/aws-sdk-cpp/lib/' + m.group(1)


print("Process:", dylib_path)
#cmd = "codesign -f -s - "
Expand All @@ -32,4 +50,5 @@ def ProcessDependency(dylib_path, cid):

# e.g.
# python3 code_sign.py /opt/homebrew/opt/gdal/lib/libgdal.29.dylib "Apple Development: [email protected] (AN5USPSZF6)"
ProcessDependency(sys.argv[1], sys.argv[2])
# python3 code_sign.py /opt/homebrew/opt/gdal/lib/libgdal.32.dylib "Apple Development: [email protected] (AN5USPSZF6)"
ProcessDependency(sys.argv[1], sys.argv[2])
2 changes: 1 addition & 1 deletion BuildTools/macosx/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CPUS=2
# Install boost 1.75
brew install boost

# Install libgdal 3.3
# Install libgdal 3.6
brew install gdal

cd $GEODA_HOME
Expand Down
20 changes: 18 additions & 2 deletions BuildTools/macosx/install_name.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
import os, sys
import os, sys, re
from shutil import copyfile

framework_path = sys.argv[1] #e.g. '/Users/xun/Github/geoda/BuildTools/macosx/build/GeoDa.app/Contents/Frameworks'
Expand All @@ -21,6 +21,8 @@ def ProcessDependency(dir_path, dylib_name):
copyitem = '/usr/local/opt/geos/lib/libgeos.dylib'
if item == '@rpath/libgeos.3.11.0.dylib':
copyitem = '/usr/local/opt/geos/lib/libgeos.dylib'
if item == '@rpath/libgeos.3.11.1.dylib':
copyitem = '/usr/local/opt/geos/lib/libgeos.dylib'
if item == '@loader_path/libicuuc.70.dylib':
copyitem = '/usr/local/opt/icu4c/lib/libicuuc.70.dylib'
if item == '@loader_path/libicuuc.71.dylib':
Expand All @@ -29,6 +31,20 @@ def ProcessDependency(dir_path, dylib_name):
copyitem = '/usr/local/opt/icu4c/lib/libicudata.70.dylib'
if item == '@loader_path/libicudata.71.dylib':
copyitem = '/usr/local/opt/icu4c/lib/libicudata.71.dylib'
if item == '@loader_path/libbrotlicommon.1.dylib':
copyitem = '/usr/local/opt/brotli/lib/libbrotlicommon.1.dylib'
if item == '@rpath/libIlmThread-3_1.30.dylib':
copyitem = '/usr/local/opt/openexr/lib/libIlmThread-3_1.30.dylib'
if item == '@rpath/libIex-3_1.30.dylib':
copyitem = '/usr/local/opt/openexr/lib/libIex-3_1.30.dylib'
if item == '@rpath/libOpenEXR-3_1.30.dylib':
copyitem = '/usr/local/opt/openexr/lib/libOpenEXR-3_1.30.dylib'
if item == '@rpath/libOpenEXRCore-3_1.30.dylib':
copyitem = '/usr/local/opt/openexr/lib/libOpenEXRCore-3_1.30.dylib'

m = re.search('@rpath/(libaws.*)', item)
if m:
copyitem = '/usr/local/opt/aws-sdk-cpp/lib/' + m.group(1)

if item.startswith('/usr/lib') == False and item.startswith('/System') == False and (codesign_only or item.startswith('@executable_path/')==False):
print("Process:", item)
Expand All @@ -51,4 +67,4 @@ def ProcessDependency(dir_path, dylib_name):

ProcessDependency(framework_path, "libwx_osx_cocoau_gl-3.1.dylib")
ProcessDependency(framework_path, "libwx_osx_cocoau-3.1.dylib")
ProcessDependency(framework_path, "libgdal.31.dylib")
ProcessDependency(framework_path, "libgdal.32.dylib")
16 changes: 11 additions & 5 deletions DialogTools/nbrMatchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@ void LocalMatchCoordinator::job(size_t nbr_sz, size_t idx, uint64_t seed_start)
// compute pseudo-p-value
sigVal[idx] = (countLarger + 1.0)/(permutations+1);

if (sigVal[idx] <= 0.0001) sigCat[idx] = 4;
if (sigVal[idx] <= 0.00001) sigCat[idx] = 5;
else if (sigVal[idx] <= 0.0001) sigCat[idx] = 4;
else if (sigVal[idx] <= 0.001) sigCat[idx] = 3;
else if (sigVal[idx] <= 0.01) sigCat[idx] = 2;
else if (sigVal[idx] <= 0.05) sigCat[idx]= 1;
Expand All @@ -1061,12 +1062,13 @@ void LocalMatchCoordinator::SetSignificanceFilter(int filter_id)
return;
}
// 0: >0.05 1: 0.05, 2: 0.01, 3: 0.001, 4: 0.0001
if (filter_id < 1 || filter_id > 4) return;
if (filter_id < 1 || filter_id > 5) return;
significance_filter = filter_id;
if (filter_id == 1) significance_cutoff = 0.05;
if (filter_id == 2) significance_cutoff = 0.01;
if (filter_id == 3) significance_cutoff = 0.001;
if (filter_id == 4) significance_cutoff = 0.0001;
if (filter_id == 5) significance_cutoff = 0.00001;
wxLogMessage("Exiting AbstractCoordinator::SetSignificanceFilter()");
}

Expand All @@ -1077,6 +1079,7 @@ std::vector<wxString> LocalMatchCoordinator::GetDefaultCategories()
cats.push_back("p = 0.01");
cats.push_back("p = 0.001");
cats.push_back("p = 0.0001");
cats.push_back("p = 0.00001");
return cats;
}

Expand All @@ -1087,6 +1090,7 @@ std::vector<double> LocalMatchCoordinator::GetDefaultCutoffs()
cutoffs.push_back(0.01);
cutoffs.push_back(0.001);
cutoffs.push_back(0.0001);
cutoffs.push_back(0.00001);
return cutoffs;
}

Expand Down Expand Up @@ -1287,8 +1291,8 @@ void LocalMatchSignificanceCanvas::CreateAndUpdateCategories()
int set_perm = gs_coord->permutations;
stop_sig = 1.0 / (1.0 + set_perm);

wxString def_cats[4] = {str_p005, str_p001, str_p0001, str_p00001};
double def_cutoffs[4] = {0.05, 0.01, 0.001, 0.0001};
wxString def_cats[5] = {str_p005, str_p001, str_p0001, str_p00001, str_p000001};
double def_cutoffs[5] = {0.05, 0.01, 0.001, 0.0001, 0.00001};

int cat_idx = 1;
for (int j=s_f-1; j < 4; j++) {
Expand All @@ -1314,7 +1318,9 @@ void LocalMatchSignificanceCanvas::CreateAndUpdateCategories()
} else {
int s_f = gs_coord->GetSignificanceFilter();
for (int i=0, iend=gs_coord->num_obs; i<iend; i++) {
if (p_val[i] <= 0.0001) {
if (p_val[i] <= 0.00001) {
cat_data.AppendIdToCategory(t, 6-s_f, i);
} else if (p_val[i] <= 0.0001) {
cat_data.AppendIdToCategory(t, 5-s_f, i);
} else if (p_val[i] <= 0.001) {
cat_data.AppendIdToCategory(t, 4-s_f, i);
Expand Down
Loading

0 comments on commit 5109e6b

Please sign in to comment.