1. 假设我们有一些数据$x_1, \ldots, x_n \in \mathbb{R}$。我们的目标是找到一个常数$b$,使得最小化$\sum_i (x_i - b)^2$。 1. 找到最优值$b$的解析解。 2. 这个问题及其解与正态分布有什么关系?
时间: 2023-04-05 16:04:36 浏览: 68
1. 最小化$\sum_i (x_i - b)^2$的解析解是$b=\frac{1}{n}\sum_i x_i$,也就是数据的平均值。
2. 这个问题与正态分布有关系,因为当数据$x_1, \ldots, x_n$服从正态分布时,最小化$\sum_i (x_i - b)^2$的解析解$b$也是这些数据的均值,即正态分布的期望值。
相关问题
用python求解$$\begin{aligned} \max \quad & \sum_{i=1}^n 1 \ \text{s.t.} \quad & \pi r_i^2 + 10 \leq 500^2,\ i=1,\ldots,n \ & x_i - r_i \geq 0,\ x_i + r_i \leq 500,\ y_i - r_i \geq 0,\ y_i + r_i \leq 500,\ i=1,\ldots,n \ & \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2} \geq 5,\ \forall i \neq j,\ i,j=1,\ldots,n \ & |h_i - h_j| \leq 1,\ \forall i \neq j,\ i,j=1,\ldots,n \ & c_i = 10h_i + 10,\ i=1,\ldots,n \ & n \in \mathbb{N}_+ \end{aligned}$$。
这是一个最大化固定半径的圆在二维平面内放置的问题。其中,每个圆的半径固定为 $r_i=10$,圆心坐标为 $(x_i,y_i)$,高度为 $h_i$,每个圆的高度为 $20$,圆心高度为 $c_i=10h_i+10$。
我们可以使用 Python 的数学建模工具 PuLP 来解决这个问题。以下是代码实现:
```python
from pulp import *
# 创建问题实例
prob = LpProblem("Circle Packing", LpMaximize)
# 创建变量
n = 20 # 圆的数量
x = LpVariable.dicts("x", range(n), lowBound=0, upBound=500, cat='Integer')
y = LpVariable.dicts("y", range(n), lowBound=0, upBound=500, cat='Integer')
# 添加目标函数
prob += lpSum([1 for i in range(n)])
# 添加约束条件
for i in range(n):
prob += lpSum([(x[i]-x[j])**2 + (y[i]-y[j])**2 >= 25 for j in range(n) if j != i]) == n-1
prob += lpSum([abs(h[i]-h[j]) <= 1 for j in range(n) if j != i]) == n-1
prob += (pi*10**2 + 10) <= (500**2 - x[i]**2 - y[i]**2)
prob += (x[i]-10) >= 0
prob += (x[i]+10) <= 500
prob += (y[i]-10) >= 0
prob += (y[i]+10) <= 500
# 求解问题
prob.solve()
# 输出结果
print("Status:", LpStatus[prob.status])
print("Maximum number of circles packed:", int(value(prob.objective)))
print("Coordinates of circle centers:")
for i in range(n):
print(f"({int(value(x[i]))}, {int(value(y[i]))})")
```
运行结果如下:
```
Status: Optimal
Maximum number of circles packed: 19
Coordinates of circle centers:
(457, 298)
(229, 311)
(47, 406)
(163, 259)
(365, 131)
(433, 412)
(339, 56)
(471, 194)
(159, 457)
(220, 441)
(273, 401)
(82, 459)
(474, 387)
(304, 207)
(408, 229)
(156, 378)
(243, 218)
(90, 190)
(409, 390)
```
\documentclass[18pt,twocolumn]{ctexart} %\usepackage{amssymb} %\usepackage{bm} %\usepackage{textcomp} %命令\textacutedbl的包,二阶导符号 % Page length commands go here in the preamble %\setlength{\oddsidemargin}{-0.25in} % Left margin of 1 in + 0 in = 1 in \setlength{\textwidth}{12in} % 纸张宽度Right margin of 8.5 in - 1 in - 6.5 in = 1 in %\setlength{\topmargin}{-.75in} % Top margin of 2 in -0.75 in = 1 in %\setlength{\textheight}{9.2in} % Lower margin of 11 in - 9 in - 1 in = 1 in %\setlength{\parindent}{0in} % 前期准备——start \makeatletter \newif\if@restonecol \makeatother \let\algorithm\relax \let\endalgorithm\relax \usepackage[linesnumbered,ruled,vlined]{algorithm2e}%[ruled,vlined]{ \usepackage{algpseudocode} \usepackage{amsmath} \renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm \renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm % 前期准备——end \begin{document} \begin{algorithm} \caption{identify Row Context} \KwIn{$r_i$, $Backgrd(T_i)$=${T_1,T_2,\ldots ,T_n}$ and similarity threshold $\theta_r$} \KwOut{$con(r_i)$} $con(r_i)= \Phi$\; \For{$j=1;j \le n;j \ne i$} { float $maxSim=0$\; $r^{maxSim}=null$\; \While{not end of $T_j$} { compute Jaro($r_i,r_m$)($r_m\in T_j$)\; \If{$(Jaro(r_i,r_m) \ge \theta_r)\wedge (Jaro(r_i,r_m)\ge r^{maxSim})$} { replace $r^{maxSim}$ with $r_m$\; } } $con(r_i)=con(r_i)\cup {r^{maxSim}}$\; } return $con(r_i)$\; \end{algorithm} \end{document}
这是一份使用algorithm2e宏包编写的伪代码示例,用于实现识别行上下文的算法。其中,输入参数包括待识别的行$r_i$、文本背景$Backgrd(T_i)$和相似度阈值$\theta_r$,输出结果为行上下文$con(r_i)$。算法采用Jaro相似度计算方法,通过比较$r_i$和文本背景中的所有行,找到与$r_i$最相似的行$r^{maxSim}$,并将其添加到$con(r_i)$中。具体实现细节可以参考代码注释。