// $Id$ // // Copyright 2003-2008 Rational Discovery LLC and Greg Landrum // All Rights Reserved // #ifdef WIN32 #define CQUANTIZE_EXPORTS #endif #include "cQuantize.h" #include #include #ifdef WIN32 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 /*********************************************** constructs a variable table for the data passed in The table for a given variable records the number of times each possible value of that variable appears for each possible result of the function. **Arguments** - vals: pointer to double, contains the values of the variable, should be sorted - nVals: int, the length of _vals_ - cuts: pointer to int, the indices of the quantization bounds - nCuts: int, the length of _cuts_ - starts: pointer to int, the potential starting points for quantization bounds - nStarts: int, the length of _starts_ - results: poitner to int, the result codes - nPossibleRes: int, the number of possible result codes **Returns** _varTable_ (a pointer to int), which is also modified in place. **Notes:** - _varTable_ is modified in place - the _results_ array is assumed to be _nVals_ long ***********************************************/ long int * GenVarTable(double *vals,int nVals,int *cuts,int nCuts,int *starts, int *results,int nPossibleRes,long int *varTable) { int nBins = nCuts + 1; int idx,i,iTab; memset(varTable,0,nBins*nPossibleRes*sizeof(long int)); idx = 0; for(i=0;i maxGain){ maxGain = gainHere; memcpy(bestCuts,cuts,nCuts*sizeof(int)); } // recurse on the next vars if needed if(which < nBounds-1){ memcpy(tCuts,cuts,nCuts*sizeof(int)); gainHere = RecurseHelper(vals,nVals,tCuts,nCuts,which+1,starts,nStarts, results,nPossibleRes); if(gainHere > maxGain){ maxGain = gainHere; memcpy(bestCuts,tCuts,nCuts*sizeof(int)); } } // update this cut int oldCut = cuts[which]; cuts[which] += 1; int top,bot; bot = starts[oldCut]; if(oldCut+1 < nStarts) top = starts[oldCut+1]; else top = starts[nStarts-1]; for(i=bot;idata,contigVals->dimensions[0], cuts,nCuts,which,starts,nStarts, (int *)contigResults->data,nPossibleRes); /* ------- Construct the return value ------- */ res = PyTuple_New(2); PyTuple_SetItem(res,0,PyFloat_FromDouble(gain)); cutObj = PyList_New(nCuts); for(i=0;idata; contigResults = (PyArrayObject *)PyArray_ContiguousFromObject(results,PyArray_LONG,1,1); int *res=(int *)contigResults->data; PyObject *startPts = PyList_New(0); int i=0; bool actHomog=true; bool valHomog=true; int start=0; double tol=1e-8; i=0; while(itol) valHomog=false; if(res[i]!=res[start]) actHomog=false; // we have a switch, now we just need to figure out where the // switch is. if(!actHomog && !valHomog){ if(vals[i]-vals[i-1]1 && vals[i]-vals[i-1]