00001 __copyright__ = """ 00002 Copyright 2008 Sean Ross-Ross 00003 """ 00004 __license__ = """ 00005 This file is part of SLIMpy . 00006 00007 SLIMpy is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 SLIMpy is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>. 00019 """ 00020 00021 00022 from numpy import ceil 00023 00024 def curverat(curvec1,curvec2,cutv): 00025 """ 00026 --latex 00027 This approach is based on rescaling the weighting vectors ( $w_{1}$ 00028 or $w_{2}$ ) in such a way that after the application of the rescaled vectors for soft 00029 thresholding a certain percentage (the n relatively largest coefficients) remain in 00030 the thresholded vector per scale or globally. 00031 The operation is based on the following steps: 00032 \\begin{enumerate} 00033 \\item Initialize a vector of the size of the to be thresholded and thresholding 00034 vector 00035 \\item Calculate the ratio ( rat = curvec1 / curvec2 ) over the total vector. 00036 \\item Sort rat in descending order to evaluate for the coefficients mainly con- 00037 tributing to curvec1 00038 \\item Take the value of the sorted rat vector defined by an initial percentage of 00039 values you want to keep cutv. 00040 \\end{enumerate} 00041 """ 00042 temp = curvec1 / curvec2 00043 sorted_temp = abs(temp).real().sort() 00044 cutoff = int( ceil(len(sorted_temp.getSpace())*cutv) ) 00045 scaling=sorted_temp[cutoff] 00046 00047 return scaling 00048