Skip to content

Init: Randomized Quasi Monte Carlo Method #4

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

Merged
merged 6 commits into from
Jul 29, 2024

Conversation

Engelsgeduld
Copy link
Collaborator

No description provided.

@Engelsgeduld Engelsgeduld requested review from vkutuev and Desiment July 19, 2024 11:06
.gitignore Outdated
@@ -2,3 +2,4 @@
.mypy_cache/
.pytest_cache/
__pycache__/
.hypothesis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline at the end of file

Returns: approximation for integral of function from 0 to 1

"""
sample = np.random.rand(self.count, self.base_n)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Получающийся таким образом sample имеет равномерное распределение на [0;1], это не тоже самое что последовательность Соболя:
https://en.wikipedia.org/wiki/Sobol_sequence
Отсюда и проблемы с точностью

Здесь sample необходимо брать как матрицу с одинаковыми строчками, где каждая строчка состоит из элементов последовательности Соболя с номерами 1, ...self.base_n. После чего генерировать self.count независимых случайных величин U_1, .... U_B с равномерным распределением на отрезке [0; 1] и i-ую строчку матрицы sample XOR-ить с U_i (это и есть digital shift)

sample = np.random.rand(self.count, self.base_n * i)
approximation, values = self.update(i * self.base_n, values, sample)
current_error_tolerance = self.sigma(values, approximation) * self.z
return approximation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоит возвращать также и current_error_tolerance

for i in range(1, self.i_max):
if current_error_tolerance < self.error_tolerance:
return approximation
sample = np.random.rand(self.count, self.base_n * i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять же, здесь sample необходимо брать как матрицу с одинаковыми строчками, где каждая строчка состоит из элементов последовательности Соболя с номерами

  • начиная с (self.base_n - 1) * i
  • заканчивая self.base_n * (i + 1)

После чего генерировать self.count независимых случайных величин U_1, .... U_B с равномерным распределением на отрезке [0; 1] и i-ую строчку матрицы sample XOR-ить с U_i

@Engelsgeduld Engelsgeduld requested review from Desiment and vkutuev July 23, 2024 12:38

import numpy as np
import numpy._typing as tpg
import scipy
from numba import njit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А точно numba уже нужна?

self.func = func
self.error_tolerance = error_tolerance
self.count = count
self.base_n = base_n
self.i_max = i_max
self.z = scipy.stats.norm.ppf(1 - a / 2)

def independent_estimator(self, values: np._typing.NDArray) -> float:
@staticmethod
def _args_parse(error_tolerance: float, count: int, base_n: int, i_max: int, a: float) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На парсинг не тянет, это скорее валидация

@Engelsgeduld Engelsgeduld merged commit 8da7df8 into main Jul 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants