Changeset 86420e in git
- Timestamp:
- Aug 7, 2019, 10:18:55 AM (4 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- 0696a360fd5622a1c1f3cf64fc8282f0ecf1b8bd
- Parents:
- bb8cdbbda3604b0b59579d1fa969c8d5ca30f07b
- Location:
- machine_learning
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
machine_learning/ml_python/common/lookuptable.py
rbb8cdbb r86420e 116 116 vectors, file_list = create_table(dictionary=dictionary, 117 117 attempt_cached=False) 118 119 def is_lookup_initialised(): 120 """ 121 Check whether the various files exist, return True if so, False 122 otherwise. 123 """ 124 retvalue = True 125 tbz2_path = os.path.join(HELP_FILE_PATH, "helpfiles.tbz2") 126 if not os.path.isdir(HELP_FILE_PATH) or not os.path.isfile(tbz2_path): 127 retvalue = False 128 if not os.path.isfile(KEYWORDS_FILE): 129 retvalue = False 130 if not os.path.isfile(VECTORS_NPY) or not os.path.isfile(HELPFILE_NPY): 131 retvalue = False 132 133 return retvalue -
machine_learning/ml_python/tests/common/test_lookuptable.py
rbb8cdbb r86420e 47 47 init_table_on_system() 48 48 49 def test_is_lookup_initialised(self): 50 tbz2_path = os.path.join(HELP_FILE_PATH, "helpfiles.tbz2") 51 os.remove(tbz2_path) 52 self.assertFalse(is_lookup_initialised()) 53 init_table_on_system() 54 self.assertTrue(is_lookup_initialised()) 55 56 os.remove(KEYWORDS_FILE) 57 self.assertFalse(is_lookup_initialised()) 58 init_table_on_system() 59 self.assertTrue(is_lookup_initialised()) 60 61 os.remove(VECTORS_NPY) 62 self.assertFalse(is_lookup_initialised()) 63 init_table_on_system() 64 self.assertTrue(is_lookup_initialised()) 65 49 66 50 67 if __name__ == '__main__': -
machine_learning/ml_python/tests/model/test_predictor.py
rbb8cdbb r86420e 33 33 files = np.array(["file1", "file2", "file3"]) 34 34 35 testvec = normalise_vector(np.array([1, 1, 1])) 35 testvec1 = normalise_vector(np.array([1, 1, 1])) 36 testvec2 = normalise_vector(np.array([1, 3, 10])) 36 37 37 38 print("distance to 1") 38 print(vector_distance(testvec, vector1)) 39 print("vec1:", vector_distance(testvec1, vector1)) 40 print("vec2:", vector_distance(testvec2, vector1)) 39 41 print() 40 42 print("distance to 2") 41 print(vector_distance(testvec, vector2)) 43 print("vec1:", vector_distance(testvec1, vector2)) 44 print("vec2:", vector_distance(testvec2, vector2)) 42 45 print() 43 46 print("distance to 3") 44 print(vector_distance(testvec, vector3)) 47 print("vec1:", vector_distance(testvec1, vector3)) 48 print("vec2:", vector_distance(testvec2, vector2)) 45 49 print() 46 50 47 51 predictor.fit(vectors, files) 48 prediction = predictor.predict(np.array([testvec])) 52 prediction = predictor.predict(np.array([])) 53 self.assertEqual(len(prediction), 0) 54 prediction = predictor.predict(np.array([testvec1])) 55 self.assertEqual(prediction[0], "file2") 56 self.assertEqual(len(prediction), 1) 57 prediction = predictor.predict(np.array([testvec1, testvec2])) 49 58 print("Prediction:") 50 59 print(prediction) 51 60 self.assertEqual(prediction[0], "file2") 61 self.assertEqual(prediction[1], "file1") 62 self.assertEqual(len(prediction), 2) 52 63 53 64 -
machine_learning/mlpredict.c
rbb8cdbb r86420e 21 21 int ml_is_initialised() 22 22 { 23 /* 24 * TODO 25 */ 26 return 1; 23 int retvalue = 1; 24 int t_value = 0; 25 PyObject *pValue = NULL; 26 27 if (!Py_IsInitialized()) { 28 retvalue = 0; 29 } else { 30 /* python system is initialised */ 31 pValue = call_python_function(LOOKUPTABLE, IS_LOOKUP_INITIALISED); 32 /* is this a boolean? */ 33 if (pValue != NULL && PyBool_Check(pValue)) { 34 t_value = PyObject_IsTrue(pValue); 35 /* errors? */ 36 if (t_value == -1) { 37 PyErr_Print(); 38 retvalue = 0; 39 } else { 40 /* no errors */ 41 retvalue = t_value; 42 } 43 Py_DECREF(pValue); 44 } else { 45 retvalue = 0; 46 } 47 } 48 return retvalue; 27 49 } 28 50 … … 38 60 int ml_initialise() 39 61 { 40 char lookuptable[] = "common.lookuptable";41 char init_table_on_system[] = "init_table_on_system";42 62 PyObject *pValue = NULL; 43 63 … … 45 65 Py_Initialize(); 46 66 } 47 pValue = call_python_function( lookuptable, init_table_on_system);67 pValue = call_python_function(LOOKUPTABLE, INIT_TABLE_ON_SYSTEM); 48 68 if (pValue != NULL) { 49 69 Py_DECREF(pValue); … … 56 76 57 77 /** 58 * Finalize the python interpreter 78 * A wrapper for Py_Finalize, checking whether it is necessary in the first 79 * place. 59 80 * 60 81 * @return An integer: 1 if successful, 0 if not. … … 62 83 int ml_finalise() 63 84 { 85 int retvalue = 1; 64 86 if (Py_IsInitialized()) { 65 87 Py_Finalize(); 88 retvalue = 1; 89 } else { 90 retvalue = 0; 66 91 } 67 return 1;92 return retvalue; 68 93 } 69 94 -
machine_learning/mlpredict.h
rbb8cdbb r86420e 17 17 #define HELP_FILE_URL "ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/src/4-1-2/doc.tbz2" 18 18 #define HELP_FILE_PATH "helpfiles/singular" 19 20 #define LOOKUPTABLE "common.lookuptable" 21 #define IS_LOOKUP_INITIALISED "is_lookup_initialised" 22 #define INIT_TABLE_ON_SYSTEM "init_table_on_system" 19 23 20 24 /** -
machine_learning/testml.c
rbb8cdbb r86420e 1 1 #include <stdio.h> 2 #include <Python.h> 2 3 #include "mlpredict.h" 3 4 … … 9 10 return 1; 10 11 } 12 13 i = ml_is_initialised(); 14 printf("Returnvalue for ml_is_initialised: %d\n", i); 15 Py_Initialize(); 16 17 i = ml_is_initialised(); 18 printf("Returnvalue for ml_is_initialised: %d\n", i); 19 11 20 i = ml_initialise(); 12 printf("Returnvalue for initialise: %d\n", i); 21 printf("Returnvalue for ml_initialise: %d\n", i); 22 23 i = ml_is_initialised(); 24 printf("Returnvalue for ml_is_initialised: %d\n", i); 13 25 14 26 i = ml_finalise(); 15 printf("Returnvalue for finalise: %d\n", i);27 printf("Returnvalue for ml_finalise: %d\n", i); 16 28 17 29 return 0;
Note: See TracChangeset
for help on using the changeset viewer.