// $Id$ // // Copyright (C) 2001-2008 greg Landrum and Rational Discovery LLC // @@ All Rights Reserved @@ // This file is part of the RDKit. // The contents are covered by the terms of the BSD license // which is included in the file license.txt, found at the root // of the RDKit source tree. // #ifdef WIN32 #define CENTROPY_EXPORTS #endif #include "cEntropy.h" #include #include #if defined(WIN32) && defined(CENTROPY_EXPORTS) BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } #endif /************ calculates the informational entropy of the values in an array **Arguments** - tPtr: pointer to a long int array containing the data - dim: long int containing the length of the _tPtr_ array. **Returns** a double ************/ template double InfoEntropy(T *tPtr,long int dim) { int i; T nInstances = 0; double accum=0.0,d; for(i=0;idescr->type_num == PyArray_DOUBLE || ((PyArrayObject *)resultsArray)->descr->type_num == PyArray_FLOAT){ resultsContig = (PyArrayObject *)PyArray_ContiguousFromObject(resultsArray,PyArray_DOUBLE,1,1); res = InfoEntropy((double *)(resultsContig->data), (long int)(resultsContig->dimensions[0])); } else { resultsContig = (PyArrayObject *)PyArray_ContiguousFromObject(resultsArray,PyArray_LONG,1,1); res = InfoEntropy((long int *)(resultsContig->data), (long int)(resultsContig->dimensions[0])); } Py_DECREF(resultsContig); return Py_BuildValue("d",res); } CENTROPY_API double InfoGain(long int *dMat,long int dim1,long int dim2) { int i,j; long int *variableRes, *overallRes; double gain,term2; int tSum; variableRes = (long int *)calloc(dim1,sizeof(long int)); // do the row sums for(i=0;idata; dim1 = varMatContig->dimensions[0]; dim2 = varMatContig->dimensions[1]; gain = InfoGain(dMat,dim1,dim2); Py_DECREF(varMatContig); return Py_BuildValue("d",gain); } // ------------- Initialization foo -------------------- static PyMethodDef cEntropyMethods[] = { {"InfoEntropy",cEntropy_InfoEntropy,METH_VARARGS}, {"InfoGain",cEntropy_InfoGain,METH_VARARGS}, {NULL,NULL} }; CENTROPY_API void initcEntropy() { (void) Py_InitModule("cEntropy",cEntropyMethods); import_array(); }