当前位置: 首页 > news >正文

jquery代码做的网站应用下载app排行榜

jquery代码做的网站,应用下载app排行榜,网站推广有必要吗,网站开发制作入什么科目C 微积分 - 求导 - 自动微分(Automatic Differentiation) flyfish 自动微分(Automatic Differentiation,简称 AD)是一种用于精确计算函数导数的技术。它结合了符号微分的准确性和数值微分的效率。自动微分的核心思想…

C++ 微积分 - 求导 - 自动微分(Automatic Differentiation)

flyfish

自动微分(Automatic Differentiation,简称 AD)是一种用于精确计算函数导数的技术。它结合了符号微分的准确性和数值微分的效率。自动微分的核心思想是利用计算图对函数进行分解,通过链式法则高效地计算导数,而无需进行符号运算或近似计算。自动微分能自动计算复杂函数的精确梯度。

C++ 微积分 - 求导 - 解析法(符号计算、符号微分)
C++ 微积分 - 求导 - 数值法

自动微分的基本概念

1 计算图:
自动微分将计算过程表示为一个有向无环图(DAG),其中节点表示变量或中间计算结果,边表示计算操作。通过这个图,可以追踪每个变量对输出的影响。

2 链式法则:
自动微分利用链式法则逐步计算导数。链式法则表示复合函数的导数为各个部分导数的乘积。
在计算图中,每个节点对输出的贡献可以通过链式法则从后往前累积计算。

3 前向模式和反向模式:
前向模式(Forward Mode):逐个变量进行传播计算,适用于输入变量较少的情况。
反向模式(Reverse Mode):从输出开始逐步传播导数,适用于输出变量较少的情况(如机器学习中的损失函数)。

自动微分提供精确的导数值,而不是近似值。与符号微分相比,自动微分在计算复杂函数时更高效。用户无需手动推导导数,可以直接获得函数的导数。

符号微分:处理复杂函数的导数推导可能非常复杂,容易导致表达式膨胀。
数值微分:容易受到舍入误差的影响,特别是在计算机浮点运算中。

自动微分的强大之处在于它可以自动地应用一系列简单的微积分规则来计算复杂函数的导数。通过重载运算符,Dual 结构体能够使用这些基本规则构建导数,而无需手动推导。

常见求导法则及其实现

1. 加法法则

对于两个函数 f ( x ) f(x) f(x) g ( x ) g(x) g(x),有:
( f ( x ) + g ( x ) ) ′ = f ′ ( x ) + g ′ ( x ) (f(x) + g(x))' = f'(x) + g'(x) (f(x)+g(x))=f(x)+g(x)实现:Dual 结构体中,两个 Dual 对象相加时,值和导数分别相加。

Dual operator+(const Dual& other) const {return Dual(value + other.value, derivative + other.derivative);
}
2. 乘法法则

对于两个函数 f ( x ) f(x) f(x) g ( x ) g(x) g(x),有:
( f ( x ) ⋅ g ( x ) ) ′ = f ′ ( x ) ⋅ g ( x ) + f ( x ) ⋅ g ′ ( x ) (f(x) \cdot g(x))' = f'(x) \cdot g(x) + f(x) \cdot g'(x) (f(x)g(x))=f(x)g(x)+f(x)g(x)实现:Dual 结构体中,两个 Dual 对象相乘时,使用乘积法则计算导数。

Dual operator*(const Dual& other) const {return Dual(value * other.value, value * other.derivative + derivative * other.value);
}
3. 商法则

对于两个函数 f ( x ) f(x) f(x) g ( x ) g(x) g(x),有:
( f ( x ) g ( x ) ) ′ = f ′ ( x ) ⋅ g ( x ) − f ( x ) ⋅ g ′ ( x ) ( g ( x ) ) 2 \left(\frac{f(x)}{g(x)}\right)' = \frac{f'(x) \cdot g(x) - f(x) \cdot g'(x)}{(g(x))^2} (g(x)f(x))=(g(x))2f(x)g(x)f(x)g(x)实现:Dual 结构体中,两个 Dual 对象相除时,使用商法则计算导数。

Dual operator/(const Dual& other) const {return Dual(value / other.value, (derivative * other.value - value * other.derivative) / (other.value * other.value));
}
4. 链式法则

对于复合函数 f ( g ( x ) ) f(g(x)) f(g(x)),有:
( f ( g ( x ) ) ) ′ = f ′ ( g ( x ) ) ⋅ g ′ ( x ) (f(g(x)))' = f'(g(x)) \cdot g'(x) (f(g(x)))=f(g(x))g(x)
自动微分天然支持链式法则,因为每个操作都跟踪其导数,计算过程中自动应用链式法则。

使用基本规则计算复合函数的导数

展示如何使用这些基本规则计算复合函数 h ( x ) = ( x 2 + 1 ) ⋅ sin ⁡ ( x ) h(x) = (x^2 + 1) \cdot \sin(x) h(x)=(x2+1)sin(x) 的导数。

#include <iostream>
#include <cmath>const double M_PI = 3.1415;
// 双数结构体,用于实现前向模式自动微分
struct Dual {double value;      // 函数值double derivative; // 导数值// 构造函数,初始化双数Dual(double v, double d) : value(v), derivative(d) {}// 重载加法运算符Dual operator+(const Dual& other) const {return Dual(value + other.value, derivative + other.derivative);}// 重载乘法运算符Dual operator*(const Dual& other) const {return Dual(value * other.value,value * other.derivative + derivative * other.value);}// 重载正弦函数friend Dual sin(const Dual& x) {return Dual(std::sin(x.value), std::cos(x.value) * x.derivative);}
};int main() {// 初始化 x 为一个双数,值为 π/4,导数为 1Dual x(M_PI / 4, 1.0);// 计算 h(x) = (x^2 + 1) * sin(x)Dual x_squared = x * x; // x^2Dual one(1.0, 0.0);     // 常数 1Dual h = (x_squared + one) * sin(x);// 输出结果std::cout << "h(x) 的值为: " << h.value << std::endl;std::cout << "h(x) 的导数为: " << h.derivative << std::endl;return 0;
}

自动微分法:使用前向模式自动微分来处理更复杂的函数,包括加法、乘法、除法、指数和对数函数。

  1. 结构体 Dual

  2. value 表示函数的值。
    derivative 表示导数的值。
    支持常见的运算符重载(加、减、乘、除、取反)以便进行代数操作。

  3. 数学函数支持:
    实现了 explog 函数,分别表示指数和对数函数的自动微分。

  4. 复杂函数计算:
    compute_function 函数实现了一个复杂的函数 f ( x ) = x 2 + 2 x + e x f(x) = x^2 + 2x + e^x f(x)=x2+2x+ex,并使用自动微分来计算其值和导数。

#include <iostream>
#include <cmath>// Dual number structure for automatic differentiation
struct Dual {double value;      // Function valuedouble derivative; // Derivative valueDual(double v, double d) : value(v), derivative(d) {}// Overload additionDual operator+(const Dual& other) const {return Dual(value + other.value, derivative + other.derivative);}// Overload subtractionDual operator-(const Dual& other) const {return Dual(value - other.value, derivative - other.derivative);}// Overload multiplicationDual operator*(const Dual& other) const {return Dual(value * other.value, value * other.derivative + derivative * other.value);}// Overload divisionDual operator/(const Dual& other) const {return Dual(value / other.value, (derivative * other.value - value * other.derivative) / (other.value * other.value));}// Overload unary minusDual operator-() const {return Dual(-value, -derivative);}
};// Exponential function
Dual exp(const Dual& x) {double exp_value = std::exp(x.value);return Dual(exp_value, exp_value * x.derivative);
}// Logarithm function
Dual log(const Dual& x) {return Dual(std::log(x.value), x.derivative / x.value);
}// Function to compute f(x) = x^2 + 2x + exp(x)
Dual compute_function(const Dual& x) {return x * x + Dual(2.0, 0.0) * x + exp(x);
}int main() {// Initialize x = 1.0 with derivative 1.0 (i.e., d(x)/dx = 1)Dual x(1.0, 1.0);// Compute the function and its derivativeDual result = compute_function(x);std::cout << "Function value at x = " << x.value << " is " << result.value << std::endl;std::cout << "Derivative at x = " << x.value << " is " << result.derivative << std::endl;return 0;
}
http://www.hotlads.com/news/1371.html

相关文章:

  • 做网站去哪个公司好我要安装百度
  • 沈阳营销型网站制作兰州网络推广优化服务
  • 网站设置密码访问百度seo关键词
  • 做外贸的国外平台有哪些英文外链seo兼职
  • 代做课题网站seo销售话术开场白
  • 在局网站 作风建设在线网页服务器
  • 网站推广服务chuseo百度站长链接提交
  • 安卓市场应用商店下载福建seo优化
  • wto最新新闻青岛网络优化厂家
  • 北京响应式网站开发最新热点新闻事件素材
  • 包头市住房和城乡建设局网站百度一下你就知道了百度一下
  • Java怎么做网站密码免费外链平台
  • 网站做直播个人怎么在百度上打广告
  • wordpress 实时预览seo零基础入门到精通200讲
  • 国外炫酷网站欣赏搜索引擎营销例子
  • 本地数据库搭建网站四川旅游seo整站优化
  • 网站后台语言广告设计网站
  • 大众点评怎么做团购网站太原网站关键词排名
  • 网站免费的有没有seo优化技术招聘
  • 域名申请要多久广州aso优化
  • 浙江五联建设有限公司网站软文发稿公司
  • 网站费用百度搜索关键词规则
  • 自己用dw做网站能加声音吗西安疫情最新数据
  • 网站建设要多少钱品牌友情链接发布平台
  • 我想自己做网站可以赚钱百度推广的优势
  • 南通门户网站建设方案社群营销
  • 电脑做网站教学如何进行网络营销策划
  • 阿里云重新备案注销主体还是注销网站职业培训机构哪家最好
  • 做网站和app有什么区别宁波seo外包服务商
  • 漫画做视频在线观看网站互站网