- swap function based on the logistic curve copyright 2009-2012 Blair Armstrong, Christine Watson, David Plaut This file is part of SOS SOS is free software: you can redistribute it and/or modify it for academic and non-commercial purposes under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. For commercial or for-profit uses, please contact the authors (sos@cnbc.cmu.edu). SOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
0001 % - swap function based on the logistic curve 0002 % 0003 % copyright 2009-2012 Blair Armstrong, Christine Watson, David Plaut 0004 % 0005 % This file is part of SOS 0006 % 0007 % SOS is free software: you can redistribute it and/or modify 0008 % it for academic and non-commercial purposes 0009 % under the terms of the GNU General Public License as published by 0010 % the Free Software Foundation, either version 3 of the License, or 0011 % (at your option) any later version. For commercial or for-profit 0012 % uses, please contact the authors (sos@cnbc.cmu.edu). 0013 % 0014 % SOS is distributed in the hope that it will be useful, 0015 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 % GNU General Public License for more details. 0018 0019 % You should have received a copy of the GNU General Public License 0020 % along with SOS (see COPYING.txt). 0021 % If not, see <http://www.gnu.org/licenses/>. 0022 0023 0024 classdef logisticpSwapFunction < genericpSwapFunction 0025 %% Creates and provides support for selecting swap probabilities based on the logistic function 0026 0027 properties 0028 end 0029 0030 methods 0031 0032 %% shouldSwap(deltaCost,temp) 0033 function flag = shouldSwap(obj,deltaCost,temp) 0034 %calculates p(swap) based on deltaCost and temperature, using logistic function 0035 % 0036 % Currently implemented using OO design in anticipation of 0037 % possible expansion of the code, though this is not strictly 0038 % necessary at present. 0039 % 0040 %Parameters: 0041 % deltaCost - diff in cost between curCost and swapCost 0042 % temp - temperature 0043 0044 % since we want to make swaps when cost is negative, the 0045 % negative sign that would usually proceed the net input 0046 % (delta cost) is removed in this version of the logistic fcn. 0047 p= 1/(1+exp(deltaCost*1/temp)); 0048 0049 if rand <= p 0050 flag = 1; 0051 else 0052 flag = 0; 0053 end 0054 end 0055 end 0056 end 0057