graphkit-learn
graphkit-learn copied to clipboard
function generate_median_preimages_by_class() does not work correctly sometimes
When using the function generate_median_preimages_by_class(), the results after the first class are not correct when I run the code in Ubuntu terminal using # python3 ....
The answer here says it has something to do with the Cython and conda. I do have conda installed. So I use a fresh virtual environment without conda and the results seems correct, but I still do not know exactly why.
Reproducing code example:
Here is the test.py:
import multiprocessing
import functools
from gklearn.utils.kernels import deltakernel, gaussiankernel, kernelproduct
from gklearn.preimage.utils import generate_median_preimages_by_class
def xp_median_preimage_1_1():
"""xp 1_1: Letter-high, sspkernel.
"""
# set parameters.
ds_name = 'Letter-high'
mpg_options = {'fit_method': 'k-graphs',
'init_ecc': [3, 3, 1, 3, 3],
'ds_name': ds_name,
'parallel': True, # False
'time_limit_in_sec': 0,
'max_itrs': 100,
'max_itrs_without_update': 3,
'epsilon_residual': 0.01,
'epsilon_ec': 0.1,
'verbose': 2}
mixkernel = functools.partial(kernelproduct, deltakernel, gaussiankernel)
sub_kernels = {'symb': deltakernel, 'nsymb': gaussiankernel, 'mix': mixkernel}
kernel_options = {'name': 'structuralspkernel',
'edge_weight': None,
'node_kernels': sub_kernels,
'edge_kernels': sub_kernels,
'compute_method': 'naive',
'parallel': 'imap_unordered',
# 'parallel': None,
'n_jobs': multiprocessing.cpu_count(),
'normalize': True,
'verbose': 2}
ged_options = {'method': 'IPFP',
'initialization_method': 'RANDOM', # 'NODE'
'initial_solutions': 1, # 1
'edit_cost': 'LETTER2',
'attr_distance': 'euclidean',
'ratio_runs_from_initial_solutions': 1,
'threads': multiprocessing.cpu_count(),
'init_option': 'EAGER_WITHOUT_SHUFFLED_COPIES'}
mge_options = {'init_type': 'MEDOID',
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'refine': False}
save_results = True
# print settings.
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
print('kernel_options:', kernel_options)
print('ged_options:', ged_options)
print('mge_options:', mge_options)
print('save_results:', save_results)
# generate preimages.
for fit_method in ['k-graphs', 'expert', 'random', 'random', 'random']:
print('\n-------------------------------------')
print('fit method:', fit_method, '\n')
mpg_options['fit_method'] = fit_method
generate_median_preimages_by_class(ds_name, mpg_options, kernel_options, ged_options, mge_options, save_results=save_results, save_medians=True, plot_medians=True, load_gm='auto', dir_save='../results/xp_median_preimage/')
if __name__ == "__main__":
#### xp 1_1: Letter-high, sspkernel.
xp_median_preimage_1_1()
Error message:
When I run in Ubuntu terminal:
python3 test.py
The output results are not correct after the first class. However, If I remove the first class before computation, then the results of the first class in the remainder (the original second class) is correct, and the results of the new second class (the original third class) is wrong. This problem does not occur in Spyder3 (4.1.1) console IPython 7.0.1 or fresh virtualenv with only Python modules required installed.
graphkit-learn/Python version information:
Python 3.6.9 graphkit-learn 0.1 Ubuntu 18.04.4 LTS