Scoring rules library for Python

I’m currently using a Python library called “scoringrules” to calculate energy and variogram scores for multivariate forecasts. It serves similar purposes as the scoringRules library in R.

I ran into an array shape problem even though my arrays both have shapes (1, 24).

So I went back to the github page for a test code and I’m facing a similar issue with the test code provided by the original author. The code was run as provided on the github page.

import numpy as np
    import pytest
    from scoringrules._energy import energy_score
    from scoringrules.backend import backends
    # Define the backends you want to test
    RUN_TESTS = ["numba", "jax"]
    # Filter available backends based on RUN_TESTS
    BACKENDS = [b for b in backends.available_backends if b in 
    RUN_TESTS]
   # Register the filtered backends
   for backend in RUN_TESTS:
        backends.register_backend(backend)
    ENSEMBLE_SIZE = 51
    N = 100
    N_VARS = 3
    @pytest.mark.parametrize("backend", BACKENDS)
    def test_energy_score(backend):
        obs = np.random.randn(N, N_VARS)
        fct = np.expand_dims(obs, axis=-2) + np.random.randn(N, 
     ENSEMBLE_SIZE, N_VARS)
        res = energy_score(obs, fct, backend=backend)
        if backend in ["numpy", "numba"]:
            assert isinstance(res, np.ndarray)
        elif backend == "jax":
            assert isinstance(res, jax.Array)
        
    x = test_energy_score(backend)
    print(x)
    print(x.shape)

The test code from the github (https://github.com/frazane/scoringrules/blob/main/tests/test_energy.py) returned this :

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[12], line 32
     29     elif backend == "jax":
     30         assert isinstance(res, jax.Array)
---> 32 x = test_energy_score(backend)
     33 print(x)
     34 print(x.shape)

Cell In[12], line 25, in test_energy_score(backend)
     22 obs = np.random.randn(N, N_VARS)
     23 fct = np.expand_dims(obs, axis=-2) + np.random.randn(N, ENSEMBLE_SIZE, N_VARS)
---> 25 res = energy_score(obs, fct, backend=backend)
     27 if backend in ["numpy", "numba"]:
     28     assert isinstance(res, np.ndarray)

File ~anaconda3Libsite-packagesscoringrules_energy.py:52, in energy_score(forecasts, observations, m_axis, v_axis, backend)
     20 r"""Compute the Energy Score for a finite multivariate ensemble.
     21 
     22 The Energy Score is a multivariate scoring rule expressed as
   (...)
     49     The computed Energy Score.
     50 """
     51 backend = backend if backend is not None else backends._active
---> 52 forecasts, observations = multivariate_array_check(
     53     forecasts, observations, m_axis, v_axis, backend=backend
     54 )
     56 if backend == "numba":
     57     return energy._energy_score_gufunc(forecasts, observations)

File ~anaconda3Libsite-packagesscoringrulescoreutils.py:31, in multivariate_array_check(fcts, obs, m_axis, v_axis, backend)
     29 m_axis = m_axis if m_axis >= 0 else fcts.ndim + m_axis
     30 v_axis = v_axis if v_axis >= 0 else fcts.ndim + v_axis
---> 31 _multivariate_shape_compatibility(fcts, obs, m_axis)
     32 return _multivariate_shape_permute(fcts, obs, m_axis, v_axis, backend=backend)

File ~anaconda3Libsite-packagesscoringrulescoreutils.py:12, in _multivariate_shape_compatibility(fcts, obs, m_axis)
     10 o_shape_broadcast = o_shape[:m_axis] + (f_shape[m_axis],) + o_shape[m_axis:]
     11 if o_shape_broadcast != f_shape:
---> 12     raise ValueError(
     13         f"Forecasts shape {f_shape} and observations shape {o_shape} are not compatible for broadcasting!"
     14     )

ValueError: Forecasts shape (100, 3) and observations shape (100, 51, 3) are not compatible for broadcasting!

Tried to : Test a code for calculating energy score of multivariate forecasts. Forecast array was of shape (100,3) and observation array of shape (100, 51, 3). Several other tries were made where forecast and observation arrays were of the same shape but in vain.

Expected result : Energy score array of shape (100, 3)

New contributor

Alessandro Fabiani Bigaunah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật