файл с примером #4

Merged
altavir merged 1 commits from _/numerics-2022:main into main 2022-11-02 16:48:46 +03:00
4 changed files with 20 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@ -114,11 +114,11 @@ Using the method of Lagrange multipliers, and assuming $A^TA$ to be invertible,
To be specific, consider $n=3$ points, for which we have approximate locations $r_1=(-1,0),\;r_2=(0, 1),\;r_3=(1,0)$ and $k=1$ measurement $\theta_{123}=9\pi/40$. Clearly, our estimates $r_{1,2,3}$ are not consistent with the measured angle and we have to adjust the estimate: $r_i\to \bar{r}_i= r_i+dr_i$ where $dr_i$ should be found from the condition
$$
(\bar{r}_3-\bar{r}_1)\cdot(\bar{r}_3-\bar{r}_1) = |\bar{r}_3-\bar{r}_1||\bar{r}_3-\bar{r}_1|\cos\theta_{123},
(\bar{r}_3-\bar{r}_1)\cdot(\bar{r}_2-\bar{r}_1) = |\bar{r}_3-\bar{r}_1||\bar{r}_2-\bar{r}_1|\cos\theta_{123},
$$
which can be linearized in $dr_i$, assuming this correction will end up small. In this approach, one constructs a single (in general, $k$) equation for six (in general, $2n$) variables, so the system will typically by underdetermined. We can consider this system in the least squares sense, which amounts to determining the smallest correction to all $r_i$ which makes the updated locations consistent with observations. In the particular numerical example above, one may find $dr_1=(-h, 0),\;dr_2=(h, -h),\; dr_3=(0, h)$ where $h=\pi/80\approx 0.04$.
Your task is to write the code, which will accept the current estimate of the positions $r_i$ ($n\times 2$, float) and measurement results $\theta_{ijk}$, which are specified by i) indices of points ($k\times 3$, int) and ii) angles ($k$, float); and will output the derived correction to the point positions $dr_i$ ($n\times 2$, float). You can use the numerical example in this exercise to test your code.
Your task is to write the code, which will accept the current estimate of the positions $r_i$ ($n\times 2$, float) and measurement results $\theta_{ijk}$, which are specified by i) indices of points ($k\times 3$, int) and ii) angles ($k$, float); and will output the derived correction to the point positions $dr_i$ ($n\times 2$, float). You can use the numerical example in this exercise to test your code. This dataset is provided here: \href{https://disk.yandex.ru/d/kNjRT_r3S2xk2A}{dataset 1}, (use np.load with the keys \textrm{r}, \textrm{p}, \textrm{theta} to access input data and \textrm{dr} to access output data). You can find additional testing file with the same structure: \href{https://disk.yandex.ru/d/7aGeQvikiUt1AA}{dataset 2}.
\end{enumerate}
\printbibliography

View File

@ -40,7 +40,7 @@
\title{\texorpdfstring{
Численные методы, осень 2022\\
Задание 3 [Проекторы. Задача наименьших квадратов. QR-разложение.] \\
Всего баллов: 47 \ Срок сдачи: 4 ноября
Всего баллов: 47 \ Срок сдачи (после переноса): 11 ноября
}{}
}
@ -134,27 +134,35 @@ $$
$$
Предполагая, что матрица $A^T A$ обратима, воспользуйтесь методом множителей Лагранжа и получите выражение для точки минимума $x$.
\item (20) Эта задача посвящена локализации точек на плоскости. Рассмотрим $n$ точек с \emph{неточными} координатами: $A_i = \brk{x_i,\, y_i}$. Измерим $m$ углов между некоторыми из них: $\theta_{ijk} = \angle\, A_i A_j A_k$. Наша цель --- используя результаты измерений, уточнить координаты точек.
\item (20) Эта задача посвящена локализации точек на плоскости. Рассмотрим $n$ точек с \emph{неточными} координатами: $A_i = \brk{x_i,\, y_i}$. Измерим $m$ углов между некоторыми из них: $\theta_{ijk} = \angle \brk!{\vv{A_i A}_j,\ \vv{A_i A}_k}$. Наша цель --- используя результаты измерений, уточнить координаты точек.
В качестве примера рассмотрим $n = 3$ точки с приближенными координатами: $A_1 = (1,\, 0),\ A_2 = (-1,\, 0),\ A_3 = (0,\, 1)$ --- и один измеренный угол $\theta_{123} = 9\pi/40$. Так как наши оценки координат не согласуются с измеренным углом, мы должны их скорректировать:
В качестве примера рассмотрим $n = 3$ точки с приближенными координатами: $A_1 = (-1,\, 0),\ A_2 = (0,\, 1),\ A_3 = (1,\, 0)$ --- и один измеренный угол $\theta_{123} = 9\pi/40$. Так как наши оценки координат не согласуются с измеренным углом, мы должны их скорректировать:
$$
x_i \to x_i + dx_i, \quad y_i \to y_i + dy_i,
$$
где $dx_i$ и $dy_i$ находятся из условия
$$
\vv{A_1 A}_2 \cdot \vv{A_3 A}_2 =
\abs{A_1 A_2} \cdot \abs{A_3 A_2} \cdot \cos(\theta_{123})
\vv{A_1 A}_2 \cdot \vv{A_1 A}_3 =
\abs{A_1 A_2} \cdot \abs{A_1 A_3} \cdot \cos(\theta_{123})
$$
Это условие может быть линеаризовано в предположении, что поправки окажутся малыми.
При таком подходе мы конструируем $m = 1$ уравнений для $2n = 6$ переменных. Система обычно оказывается недоопределённой. Но мы можем рассматривать её в смысле метода наименьших квадратов, т.е. пытаться определить наименьшие поправки к координатам, которые делали бы их согласованными с измерениями. В рассмотренном примере можно найти решение
$$
dr_1 = (dx_1,\, dy_1) = (0, h), \quad
dr_2=(-h,\, 0), \quad
dr_3=(h,\, -h), \qquad
\text{ где } h = \pi/80 \approx 0.04
dr_1 = (dx_1,\, dy_1) = (-h,\, 0), \quad
dr_2=(h,\, -h), \quad
dr_3=(0,\, h), \qquad
\text{ где } h \approx \pi/80 \approx 0.04
$$
Ваша задача --- написать код, который принимает текущие оценки координат точек $(n \times 2)$ и измеренные углы $\theta_{ijk}$ ($m$ значений и $m \times 3$ индексов). Возвращать он должен найденные поправки $(n \times 2)$.
Вы можете использовать пример из этого упражнения, чтобы протестировать свой код.
Чтобы протестировать свой код, вы можете использовать \href{https://disk.yandex.ru/d/kNjRT_r3S2xk2A}{пример} из этого упражнения, а также другой \href{https://disk.yandex.ru/d/7aGeQvikiUt1AA}{пример} с б\'{о}льшим числом точек. Загрузить данные можно следующим образом:
\begin{minted}[frame = lines, framesep = \framesep]{python}
with np.load('./data_1.npz') as data:
r = data['r'] # исходные точки
p = data['p'] - 1 # индексы измеренных углов
theta = data['theta'] # углы в радианах
dr = data['dr'] # предполагаемый ответ
\end{minted}
\end{enumerate}