jszymon / pacal

PaCAL - ProbAbilistic CALculator
GNU General Public License v3.0
22 stars 8 forks source link

Assertion error when adding two r.vs (Normal) #4

Closed shashankrao closed 6 years ago

shashankrao commented 6 years ago

Hi,

I just setup Pacal from your repo (running on Python3). Thank you so much for adding in Python3 support.

The following piece of code gives me an assertion error

X1 = pc.NormalDistr(400, 1)
X2 = pc.NormalDistr(400, 1)
X3 = X1 + X2
X3.summary()

The output I get is:

============= summary =============
ASSERT x is None y= 0.5 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf])
ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)]
ASSERT x is None y= 0.975 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf])
ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)]
ASSERT x is None y= 0.025 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf])
ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)]
ASSERT x is None y= 0.5 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf])
ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)]
  N(400,1)+N(400,1)
                mean  =  nan
                 var  =  nan
            skewness  =  nan
            kurtosis  =  nan
             entropy  =  nan
              median  =  nan
                mode  =  800.0000192897513
--- medianad
      iqrange(0.025)  =  nan
--- interval(0.95)
               range  =  (-inf, inf)
             tailexp  =  (0, 0)
             int_err  =  nan
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pacal/distr.py", line 267, in summary_map
    r['medianad'] = self.medianad()
  File "/usr/local/lib/python3.5/dist-packages/pacal/distr.py", line 187, in medianad
    return self.get_piecewise_pdf().medianad()
  File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1887, in medianad
    f1 = self.copyShiftedAndScaled(shift = -median, scale = 1.0)
  File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1325, in copyShiftedAndScaled
    copyFunction.addSegment(seg.shiftAndScale(shift, scale))
  File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1018, in addSegment
    assert seg>segment or segment>seg, "{}=={}=={}=={}=={}".format(self.segments, seg, segment, seg.a, segment.a)
AssertionError: [MInfSegment, [-inf, nan]]==MInfSegment, [-inf, nan]==Segment, [nan, nan]==-inf==nan

Is this an issue with Python3 package? I would appreciate any quick fix I can apply. Thanks again for supporting this package!

jszymon commented 6 years ago

Hi,

thanks for the report. The issue is now fixed in the master branch (this now included Python3)

Let me know if the problem persists.

All the best

Szymon

On Mon, Jul 2, 2018 at 6:36 AM, Shashank Shashikant Rao < notifications@github.com> wrote:

Hi,

I just setup Pacal from your repo (running on Python3). Thank you so much for adding in Python3 support.

The following piece of code gives me an assertion error

X1 = pc.NormalDistr(400, 1) X2 = pc.NormalDistr(400, 1) X3 = X1 + X2 X3.summary()

The output I get is:

============= summary ============= ASSERT x is None y= 0.5 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf]) ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)] ASSERT x is None y= 0.975 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf]) ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)] ASSERT x is None y= 0.025 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf]) ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)] ASSERT x is None y= 0.5 (MInfSegment, [-inf, 798.0]),(Segment, [798.0, 800.0]),(Segment, [800.0, 802.0]),(PInfSegment, [802.0, inf]) ASSERT x is None vals= [(nan, nan), (nan, nan), (nan, nan), (nan, nan)] N(400,1)+N(400,1) mean = nan var = nan skewness = nan kurtosis = nan entropy = nan median = nan mode = 800.0000192897513 --- medianad iqrange(0.025) = nan --- interval(0.95) range = (-inf, inf) tailexp = (0, 0) int_err = nan Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/pacal/distr.py", line 267, in summary_map r['medianad'] = self.medianad() File "/usr/local/lib/python3.5/dist-packages/pacal/distr.py", line 187, in medianad return self.get_piecewise_pdf().medianad() File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1887, in medianad f1 = self.copyShiftedAndScaled(shift = -median, scale = 1.0) File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1325, in copyShiftedAndScaled copyFunction.addSegment(seg.shiftAndScale(shift, scale)) File "/usr/local/lib/python3.5/dist-packages/pacal/segments.py", line 1018, in addSegment assert seg>segment or segment>seg, "{}=={}=={}=={}=={}".format(self.segments, seg, segment, seg.a, segment.a) AssertionError: [MInfSegment, [-inf, nan]]==MInfSegment, [-inf, nan]==Segment, [nan, nan]==-inf==nan

Is this an issue with Python3 package? I would appreciate any quick fix I can apply. Thanks again for supporting this package!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jszymon/pacal/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFcaVvLipe-PGfvcJQ3bhy0bvEf2unAks5uCaNBgaJpZM4U-rJy .

shashankrao commented 6 years ago

Thank you for the quick resolution Szymon! It seems to have fixed the issue.