diff --git a/data b/data index 5abc4108801..4788158ef84 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5abc41088015f9174f93dc951a0ba96c7c5c0c9c +Subproject commit 4788158ef84957a70b434688a69a275854048351 diff --git a/examples/undocumented/python_modular/kernel_histogram_word_string_modular.py b/examples/undocumented/python_modular/kernel_histogram_word_string_modular.py index f584db1f7e7..140bbf3c52d 100644 --- a/examples/undocumented/python_modular/kernel_histogram_word_string_modular.py +++ b/examples/undocumented/python_modular/kernel_histogram_word_string_modular.py @@ -5,34 +5,32 @@ traindat = lm.load_dna('../data/fm_train_dna.dat') testdat = lm.load_dna('../data/fm_test_dna.dat') label_traindat = lm.load_labels('../data/label_train_dna.dat') -parameter_list=[[traindat,testdat,label_traindat,3,0,False],[traindat,testdat,label_traindat,3,0,False]] +parameter_list=[[traindat,testdat,label_traindat,1,1e1, 1e0],[traindat,testdat,label_traindat,1,1e4,1e4]] -def kernel_histogram_word_string_modular (fm_train_dna=traindat,fm_test_dna=testdat,label_train_dna=label_traindat,order=3,gap=0,reverse=False): +def kernel_histogram_word_string_modular (fm_train_dna=traindat,fm_test_dna=testdat,label_train_dna=label_traindat,order=3,ppseudo_count=1,npseudo_count=1): from modshogun import StringCharFeatures, StringWordFeatures, DNA, BinaryLabels from modshogun import HistogramWordStringKernel, AvgDiagKernelNormalizer from modshogun import PluginEstimate#, MSG_DEBUG - reverse = reverse charfeat=StringCharFeatures(DNA) #charfeat.io.set_loglevel(MSG_DEBUG) charfeat.set_features(fm_train_dna) feats_train=StringWordFeatures(charfeat.get_alphabet()) - feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse) + feats_train.obtain_from_char(charfeat, order-1, order, 0, False) charfeat=StringCharFeatures(DNA) charfeat.set_features(fm_test_dna) feats_test=StringWordFeatures(charfeat.get_alphabet()) - feats_test.obtain_from_char(charfeat, order-1, order, gap, reverse) + feats_test.obtain_from_char(charfeat, order-1, order, 0, False) - pie=PluginEstimate() + pie=PluginEstimate(ppseudo_count,npseudo_count) labels=BinaryLabels(label_train_dna) pie.set_labels(labels) pie.set_features(feats_train) pie.train() kernel=HistogramWordStringKernel(feats_train, feats_train, pie) - kernel.set_normalizer(AvgDiagKernelNormalizer()) km_train=kernel.get_kernel_matrix() kernel.init(feats_train, feats_test) pie.set_features(feats_test) diff --git a/examples/undocumented/python_modular/mathematics_linsolver_cg.py b/examples/undocumented/python_modular/mathematics_linsolver_cg.py index 1e4ad20e450..c251b17395f 100644 --- a/examples/undocumented/python_modular/mathematics_linsolver_cg.py +++ b/examples/undocumented/python_modular/mathematics_linsolver_cg.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -from numpy import * +import numpy from scipy.io import mmread # Loading an example sparse matrix of dimension 479x479, real, unsymmetric -mtx=mmread('../../../data/logdet/west0479.mtx.gz') +mtx=mmread('../../../data/logdet/west0479.mtx') parameter_list=[[mtx,6000,10]] @@ -18,8 +18,8 @@ def mathematics_linsolver_cg (matrix=mtx,max_iter=1000,seed=10): A=matrix.transpose()*matrix+eye(rows, cols) # Create a random vector (b) of the system Ax=b - random.seed(seed) - b=array(random.randn(rows)) + numpy.random.seed(seed) + b=numpy.array(numpy.random.randn(rows)) # create linear system with linear operator and vector from scipy.sparse import csc_matrix @@ -38,7 +38,7 @@ def mathematics_linsolver_cg (matrix=mtx,max_iter=1000,seed=10): # verifying the solution via direct solving from scipy.sparse.linalg import spsolve, eigsh y=spsolve(A,b) - print(sqrt(sum(map(lambda z: z*z,x-y)))) + print(numpy.linalg.norm(x-y)) return x diff --git a/examples/undocumented/python_modular/mathematics_logdet.py b/examples/undocumented/python_modular/mathematics_logdet.py index 52a3836198f..8ad6bc0c276 100644 --- a/examples/undocumented/python_modular/mathematics_logdet.py +++ b/examples/undocumented/python_modular/mathematics_logdet.py @@ -4,7 +4,7 @@ from scipy.io import mmread # Loading an example sparse matrix of dimension 479x479, real, unsymmetric -mtx=mmread('../../../data/logdet/west0479.mtx.gz') +mtx=mmread('../../../data/logdet/west0479.mtx') parameter_list=[[mtx,100,60,1]] diff --git a/examples/undocumented/python_modular/structure_dynprog_modular.py b/examples/undocumented/python_modular/structure_dynprog_modular.py index 57eb69850aa..b9298489128 100644 --- a/examples/undocumented/python_modular/structure_dynprog_modular.py +++ b/examples/undocumented/python_modular/structure_dynprog_modular.py @@ -65,6 +65,11 @@ def loads(str): return unpickler.load() def structure_dynprog_modular (fname): + import sys + + #pickle is not compatible between python2 -> 3 + if sys.version_info[0]>2: + return data_dict = loads(gzip.GzipFile(fname).read()) #data_dict = loadmat('../data/DynProg_example_py.dat.mat', appendmat=False, struct_as_record=False) diff --git a/src/shogun/base/Parameter.cpp b/src/shogun/base/Parameter.cpp index 3a4b743924d..2714b786a0a 100644 --- a/src/shogun/base/Parameter.cpp +++ b/src/shogun/base/Parameter.cpp @@ -3197,7 +3197,7 @@ bool TParameter::equals(TParameter* other, float64_t accuracy) SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y) for (index_t i=0; i<*m_datatype.m_length_y; ++i) { - SG_SDEBUG("comparing element %d which is %d byes from start\n", + SG_SDEBUG("comparing element %d which is %d bytes from start\n", i, x); void* pointer_a=&((*(char**)m_parameter)[x]); @@ -3283,7 +3283,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if ((data1 && !data2) || (!data1 && data2)) { - SG_SDEBUG("leaving TParameter::compare_ptype(): data1 is at %p while " + SG_SINFO("leaving TParameter::compare_ptype(): data1 is at %p while " "data2 is at %p\n", data1, data2); return false; } @@ -3304,7 +3304,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_BOOL: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_BOOL: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3317,7 +3317,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_CHAR: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_CHAR: " "data1=%c, data2=%c\n", casted1, casted2); return false; } @@ -3330,7 +3330,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_INT8: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_INT8: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3343,7 +3343,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_UINT8: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT8: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3356,7 +3356,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_INT16: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_INT16: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3369,7 +3369,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_UINT16: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT16: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3382,7 +3382,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_INT32: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_INT32: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3395,7 +3395,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_UINT32: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT32: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3408,7 +3408,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_INT64: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_INT64: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3421,7 +3421,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_UINT64: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT64: " "data1=%d, data2=%d\n", casted1, casted2); return false; } @@ -3434,7 +3434,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_FLOAT32: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT32: " "data1=%f, data2=%f\n", casted1, casted2); return false; } @@ -3447,7 +3447,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_FLOAT64: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT64: " "data1=%f, data2=%f\n", casted1, casted2); return false; } @@ -3459,7 +3459,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, floatmax_t casted2=*((floatmax_t*)data2); if (CMath::abs(casted1-casted2)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_FLOATMAX: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOATMAX: " "data1=%f, data2=%f\n", casted1, casted2); return false; } @@ -3474,7 +3474,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, if (CMath::abs(casted1_real-casted2_real)>accuracy || CMath::abs(casted1_imag-casted2_imag)>accuracy) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_COMPLEX128: " + SG_SINFO("leaving TParameter::compare_ptype(): PT_COMPLEX128: " "data1=%f+i%f, data2=%f+i%f\n", casted1_real, casted1_imag, casted2_real, casted2_imag); @@ -3499,7 +3499,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, { if (!(casted1->equals(casted2, accuracy))) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_SGOBJECT " + SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT " "equals returned false\n"); return false; } @@ -3508,7 +3508,7 @@ bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2, { if (!(casted2->equals(casted1, accuracy))) { - SG_SDEBUG("leaving TParameter::compare_ptype(): PT_SGOBJECT " + SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT " "equals returned false\n"); return false; } diff --git a/src/shogun/lib/DataType.cpp b/src/shogun/lib/DataType.cpp index d342ed49eda..4651c3b91d4 100644 --- a/src/shogun/lib/DataType.cpp +++ b/src/shogun/lib/DataType.cpp @@ -67,26 +67,26 @@ bool TSGDataType::equals_without_length(TSGDataType other) { if (m_ctype!=other.m_ctype) { - SG_SDEBUG("leaving TSGDataType::equals_wihtout_length(): container types are " + SG_SDEBUG("leaving TSGDataType::equals_without_length(): container types are " "different\n"); return false; } if (m_stype!=other.m_stype) { - SG_SDEBUG("leaving TSGDataType::equals_wihtout_length(): struct types are " + SG_SDEBUG("leaving TSGDataType::equals_without_length(): struct types are " "different\n"); return false; } if (m_ptype!=other.m_ptype) { - SG_SDEBUG("leaving TSGDataType::equals_wihtout_length(): primitive types are " + SG_SDEBUG("leaving TSGDataType::equals_without_length(): primitive types are " "different\n"); return false; } - SG_SDEBUG("leaving TSGDataType::equals_wihtout_length(): data types " + SG_SDEBUG("leaving TSGDataType::equals_without_length(): data types " "without lengths are equal\n"); return true; } diff --git a/tests/integration/python_modular/tester.py b/tests/integration/python_modular/tester.py index a7110cbd566..ebfadf8e539 100755 --- a/tests/integration/python_modular/tester.py +++ b/tests/integration/python_modular/tester.py @@ -10,6 +10,9 @@ from generator import setup_tests, get_fname, blacklist, get_test_mod, run_test +def is_python2(): + return sys.version_info[0]==2 + def typecheck(a, b): if str(type(a)).find('shogun')>=0 and \ str(type(a)).find('Labels')>=0 and \ @@ -42,6 +45,8 @@ def compare(a, b, tolerance, sgtolerance): # print debug output in case of failure if not result: + pickle.dump(a, open('/tmp/a','wb')) + pickle.dump(b, open('/tmp/b','wb')) print("Equals failed with debug output") old_loglevel=a.io.get_loglevel() a.io.set_loglevel(modshogun.MSG_INFO) @@ -93,7 +98,7 @@ def compare_dbg_helper(a, b, tolerance, sgtolerance): print("Length mismatch (len(a)=%d vs len(b)=%d)" % (len(a), len(b))) return False for obj1, obj2 in zip(a,b): - if not compare_dbg(obj1, obj2, tolerance): + if not compare_dbg(obj1, obj2, tolerance, sgtolerance): return False return True @@ -212,21 +217,22 @@ def tester(tests, cmp_method, opts): for f in failed: print("\t" + f[0]) - print("Detailed failures:") - for f in failed: - print("\t" + f[0]) - got=get_split_string(f[1]) - expected=get_split_string(f[2]) - #print "=== EXPECTED ==========" - #import pdb - #pdb.set_trace() - #print '\n'.join(expected) - #print "=== GOT ===============" - #print '\n'.join(got) - print("====DIFF================") - print('\n'.join(difflib.unified_diff(expected, got, fromfile='expected', tofile='got'))) - print("====EOT================") - print("\n\n\n") + if is_python2(): + print("Detailed failures:") + for f in failed: + print("\t" + f[0]) + got=get_split_string(f[1]) + expected=get_split_string(f[2]) + #print "=== EXPECTED ==========" + #import pdb + #pdb.set_trace() + #print '\n'.join(expected) + #print "=== GOT ===============" + #print '\n'.join(got) + print("====DIFF================") + print('\n'.join(difflib.unified_diff(expected, got, fromfile='expected', tofile='got'))) + print("====EOT================") + print("\n\n\n") sys.exit(1) sys.exit(0)