22 #ifndef _SGRISKSHARING_HPP
23 #define _SGRISKSHARING_HPP
31 enum EndowmentMode { Consumption, Endowment};
40 vector< vector<double> > stateProbSum;
41 vector<int> numActions_total;
42 EndowmentMode endowmentMode;
44 double consumption(
int e,
int t)
const
46 assert(E[e]+t*cIncr>=-1e-6);
47 assert(E[e]+t*cIncr<=1+1e-6);
48 double cons = E[e]+t*cIncr;
56 double cdf(
double x)
const
59 return 1-exp(-persistence*max(0.0,x));
64 double probHelper(
int e,
int t,
int ep)
const
67 switch (endowmentMode)
70 mode = consumption(e,t);
77 return ( cdf(E[ep]-mode+eIncr) - cdf(E[ep]-mode-eIncr)
78 + cdf(mode-E[ep]+eIncr) - cdf(mode-E[ep]-eIncr) );
87 numEndowments(_numEndowments),
89 persistence(_persistence),
91 midPoint((_numEndowments-1)/2),
92 stateProbSum(_numEndowments),
93 numActions_total(_numEndowments,1),
96 vector< vector<int> > (_numEndowments,vector<int>(2,1))),
104 for (
int e = 0; e < numEndowments; e++)
106 E[e] = (1.0*e)/(numEndowments-1);
113 eIncr = (E[1]-E[0])/2.0;
114 cIncr = 1.0/( (numEndowments-1)*c2e );
117 for (
int e = 0; e < numEndowments; e++)
119 stateProbSum[e] = vector<double> (numActions_total[e],0);
120 for (
int a = 0; a < numActions_total[e]; a++)
124 stateProbSum[e][a] += probHelper(e,t,ep);
131 int t = actions[1]-actions[0];
132 double c = consumption(state,t);
134 return SGPoint(sqrt(c),sqrt(1-c));
137 virtual double probability(
int e,
const vector<int> & actions,
int ep)
const
139 int t = actions[1]-actions[0];
140 int a = actions[0]+actions[1]*
numActions[e][0];
141 return probHelper(e,t,ep)/stateProbSum[e][a];
147 if ( (actions[0] == 0) || (actions[1] == 0) )