Aie, indeed I was running my code with sympy 0.7.3. So I guess maybe I
should not trust that result too much ? I'm going to reproduce that with
mathematica or matlab (maybe even take a pen and think... lazy me). Still,
both methods yield the same result when gamma = 1.0 under this version of
sympy.
With the latest version of sympy, the method that appeared to work fine
previously idd fails with the error message that you mentionned. The other
one still works for some value(s) of gamma (1.0 at least). Given that both
contain the expression:
integrate(function_profit(s_theta, s_p, s_p_bar, s_eta)*\
diff(function_cdf_theta(s_theta, s_gamma), s_theta),
(s_theta, 0, 1))
I guess it must be due to the fact that the method which partly works
"first" replaces s_gamma and for some value of gamma it succeeds, while the
other fails as it has to produce a result for any gamma and at least for
some value it can't.
On Fri, Jan 17, 2014 at 2:02 AM, Aaron Meurer <[email protected]> wrote:
> For me
>
> expected_profit = integrate(function_profit(s_theta, s_p, s_p_bar, s_eta)*\
> diff(function_cdf_theta(s_theta,
> s_gamma), s_theta), (s_theta, 0, 1))
>
> gives
>
> ValueError: expected an expression convertible to a polynomial in
> Polynomial ring in _x0, _x1 over
>
> ZZ(s_gamma,s_p**s_eta)[_A0,_A1,_A2,_A3,_A4,_A5,_A6,_A7,_A8,_A9,_A10,_A11,_A12,_A13,_A14,_B0]
> with lex order, got _x0*_x1**9*s_p**(3*s_eta)*(_x1*s_p**s_eta + 1) +
> _x1*s_p**s_eta*(-_x0*_x1**6*s_gamma*s_p**(2*s_eta)*(_A1*_x1**3 +
> 3*_A11*_x0**2*_x1 + _A13*_x1 + _A14 + 2*_A2*_x0*_x1**2 + 2*_A4*_x0 +
> 3*_A5*_x0**2 + 2*_A7*_x0*_x1 + 4*_A8*_x0**3 + _A9*_x1**2) -
> _x1**3*s_p**s_eta*(_B0*_x1**5*s_p**(2*s_eta) + _x1**4*s_p**s_eta*(_A0
> + 3*_A1*_x0*_x1**2 + _A11*_x0**3 + 4*_A12*_x1**3 + _A13*_x0 +
> 2*_A2*_x0**2*_x1 + 3*_A3*_x1**2 + 2*_A6*_x1 + _A7*_x0**2 +
> 2*_A9*_x0*_x1) + _x1**3*s_p**s_eta*(-2*_A0*_x1 - 2*_A1*_x0*_x1**3 -
> 2*_A10 - 2*_A11*_x0**3*_x1 - 2*_A12*_x1**4 - 2*_A13*_x0*_x1 -
> 2*_A14*_x0 - 2*_A2*_x0**2*_x1**2 - 2*_A3*_x1**3 - 2*_A4*_x0**2 -
> 2*_A5*_x0**3 - 2*_A6*_x1**2 - 2*_A7*_x0**2*_x1 - 2*_A8*_x0**4 -
> 2*_A9*_x0*_x1**2)))
>
> This is in the git master.
>
> (by the way, I think you dropped off list).
>
> Aaron Meurer
>
>
>
>
> On Thu, Jan 16, 2014 at 10:47 AM, eTna <[email protected]> wrote:
> > Thanks Aaron for taking the time to answer and sorry not to have
> followed up
> > faster. I'm not sure I get you right. In fact, as exposed below, I write
> > expected profit in two ways which seem to be pretty much the same to
> me..
> > one works for all values of gamma, not the other. So I'm not sure what's
> the
> > difference.
> >
> > # Profit function and cdf
> > s_theta, s_p, s_p_bar, s_eta, s_gamma = symbols('s_theta s_p s_p_bar
> s_eta
> > s_gamma', positive = True)
> >
> > class function_profit(Function):
> > nargs = 4
> >
> > @classmethod
> > def eval(cls, s_theta, s_p, s_p_bar, s_eta):
> > return Piecewise((0.0, s_p > s_p_bar), ((s_p - 0.1)*(s_theta +
> > s_p**(-s_eta)), True))
> >
> >
> > class function_cdf_theta(Function):
> > nargs = 2
> >
> > @classmethod
> > def eval(cls, s_theta, s_gamma):
> > return Piecewise((0.0, s_theta < 0.0), (1.0, s_theta > 1.0),
> > (s_theta**s_gamma, True))
> >
> > # Expected profit written in a way that appears to work fine
> >
> > expected_profit = integrate(function_profit(s_theta, s_p, s_p_bar,
> s_eta)*\
> > diff(function_cdf_theta(s_theta, s_gamma),
> > s_theta), (s_theta, 0, 1))
> >
> > def function_expected_profit(p, p_bar, eta, gamma):
> > return expected_profit.subs([(s_p, p), (s_p_bar, p_bar), (s_eta, eta),
> > (s_gamma, gamma)])
> >
> > p, p_bar, eta, gamma = 0.2, 1.0, 2.0, 0.5
> > print function_expected_profit(p, p_bar, eta, gamma)
> > # 2.53333333333333
> >
> > # Expected profit as I had first written it (works with gamma is 1 but
> not
> > 0.5 etc.)
> >
> > class function_exp_profit(Function):
> > # problem when gamma is not 1... why, should not be different from
> > function_expected_profit
> > nargs = 4
> >
> > @classmethod
> > def eval(cls, s_p, s_p_bar, s_eta, s_gamma):
> > return integrate(function_profit(s_theta, s_p, s_p_bar, s_eta)*\
> > diff(function_cdf_theta(s_theta, s_gamma), s_theta),
> > (s_theta, 0, 1))
> >
> > p, p_bar, eta, gamma = 0.2, 1.0, 2.0, 0.5
> > print function_exp_profit(p, p_bar, eta, gamma)
> > # ValueError: Non-suitable parameters.
> >
> >
> >
> > On Monday, December 23, 2013 5:29:20 AM UTC+1, Aaron Meurer wrote:
> >>
> >> The problem is with Integral(Piecewise((0, Or(s_theta < 0, s_theta >
> >> 1)), (0.5*s_theta**(-0.5)*(0.1*s_theta + 2.5), True)), (s_theta, 0,
> >> 1)).
> >>
> >> Aaron Meurer
> >>
> >> On Sun, Dec 22, 2013 at 10:29 PM, Aaron Meurer <[email protected]>
> wrote:
> >> > This looks like a bug.
> >> >
> >> > Aaron Meurer
> >> >
> >> > On Thu, Dec 19, 2013 at 5:16 PM, eTna <[email protected]> wrote:
> >> >> Hi,
> >> >>
> >> >> Trying to write something with sympy for the first time... I'm stuck
> >> >> with
> >> >> some error and not to sure which way to look. The code is fairly
> short:
> >> >> I
> >> >> define a profit function, a cdf, and would like to compute the
> expected
> >> >> profit for a range of prices, depending on some parameter's value:
> >> >>
> >> >> s_theta, s_p, s_p_bar, s_eta, s_gamma = symbols('s_theta s_p s_p_bar
> >> >> s_eta
> >> >> s_gamma')
> >> >>
> >> >> class function_profit(Function):
> >> >> nargs = 4
> >> >>
> >> >> @classmethod
> >> >> def eval(cls, s_theta, s_p, s_p_bar, s_eta):
> >> >> return Piecewise((0, s_p > s_p_bar), ((s_p - 0.1)*(s_theta +
> >> >> s_p**(-s_eta)), True))
> >> >>
> >> >> class function_cdf_theta(Function):
> >> >> nargs = 2
> >> >>
> >> >> @classmethod
> >> >> def eval(cls, s_theta, s_gamma):
> >> >> return Piecewise((0, s_theta < 0), (1, s_theta > 1),
> >> >> (s_theta**s_gamma,
> >> >> True))
> >> >>
> >> >> class function_expected_profit(Function):
> >> >> nargs = 4
> >> >>
> >> >> @classmethod
> >> >> def eval(cls, s_p, s_p_bar, s_eta, s_gamma):
> >> >> return integrate(function_profit(s_theta, s_p, s_p_bar, s_eta)*\
> >> >> diff(function_cdf_theta(s_theta, s_gamma),
> >> >> s_theta),
> >> >> (s_theta, 0, 1))
> >> >>
> >> >> for gamma in [0.5, 0.7, 1.0]:
> >> >> x_axis = np.linspace(0.1, 2.0, int(round(((2.0-0.1)/0.1)))+1)
> >> >> ls_profits = [function_expected_profit(x, 2.0, 2.0, gamma) for x in
> >> >> x_axis]
> >> >> plt.plot(x_axis, ls_profits, label = 'gamma = %s' %gamma)
> >> >> legend = plt.legend(loc='upper right')
> >> >> plt.show()
> >> >>
> >> >> The profit and cdf functions seem to work fine, the differentiation
> of
> >> >> the
> >> >> cdf as well... but I can compute the expected profit only for gamma =
> >> >> 1.
> >> >> Trying to compute the expected profit with gamma = 0.5, I get
> >> >> "ValueError:
> >> >> Non-suitable parameters.".
> >> >>
> >> >> Many thanks for your time and sorry about the noobish question,
> >> >>
> >> >> Etienne
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >> Groups
> >> >> "sympy" group.
> >> >> To unsubscribe from this group and stop receiving emails from it,
> send
> >> >> an
> >> >> email to [email protected].
> >> >> To post to this group, send email to [email protected].
> >> >> Visit this group at http://groups.google.com/group/sympy.
> >> >> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.