Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Median of SampleForecast #3221

Open
alippai opened this issue Sep 30, 2024 · 0 comments
Open

Median of SampleForecast #3221

alippai opened this issue Sep 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@alippai
Copy link

alippai commented Sep 30, 2024

Description

If there are even number of samples, the .median calls quantile(0.5) and that doesn't return the average (like numpy)

ChatGPT suggests the following:

def quantile(self, q: float | str) -> np.ndarray:
    q = Quantile.parse(q).value  # Assuming this returns a float between 0 and 1
    if not 0 <= q <= 1:
        raise ValueError("q should be between 0 and 1")
    
    # Compute the exact position
    pos = q * (self.num_samples - 1)
    
    # Get the integer part of the position
    lower_idx = int(pos)
    
    # Compute the weight for interpolation
    weight = pos - lower_idx
    
    # Handle the edge case where pos is the last index
    if lower_idx + 1 < self.num_samples:
        # Vectorized interpolation
        return self._sorted_samples[lower_idx] * (1 - weight) + self._sorted_samples[lower_idx + 1] * weight
    else:
        # If pos is exactly the last index, return the last sample
        return self._sorted_samples[lower_idx]
        ```
@alippai alippai added the bug Something isn't working label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant