2.2 Linear algibra

#pytorch笔记 

以后打算用优快云作为记笔记的地方,去年9月份本来就有这样的想法,后来因为种种原因搁置了。现在还存着去年的草稿。

对于张量降维度

a=torch.arange(24).reshape(2,3,4)
Out[24]: 
tensor([[[ 0,  1,  2,  3],
         [ 4,  5,  6,  7],
         [ 8,  9, 10, 11]],
        [[12, 13, 14, 15],
         [16, 17, 18, 19],
         [20, 21, 22, 23]]])

a是个三阶张量/ 三维张量

a.sum(dim=0/1/2)这里,dim(axis)=0表示,对0维度的进行相加也就是说把这一维消除/这一维度相加。

默认情况下,调用求和函数会沿所有的轴降低张量的维度,使它变为一个标量。 我们还可以指定张量沿哪一个轴来通过求和降低维度。 以矩阵为例,为了通过求和所有行的元素来降维(轴0),可以在调用函数时指定axis=0。 由于输入矩阵沿0轴降维以生成输出向量,因此输入轴0的维数在输出形状中消失。

如果想要对n阶张量进行所有元素求和,直接a.sum()即可。

当然,如果想要不断分层求和也可以:

A.sum(axis=[0, 1])  # 结果和A.sum()相同

一个与求和相关的量是平均值(mean或average)。 我们通过将总和除以元素总数来计算平均值。 在代码中,我们可以调用函数来计算任意形状张量的平均值。

A.mean(), A.su
03-12
### Linear in IT Context In the realm of Information Technology (IT), "linear" can refer to multiple concepts depending on the specific area being discussed. One prominent application is within machine learning and data processing algorithms where linear models play a crucial role. #### Linear Models in Machine Learning A **linear model** assumes that there exists a linear relationship between input variables \(X\) and output variable \(Y\). This type of model uses parameters or weights applied directly to each feature without any transformation into higher dimensions, making these models highly interpretable but potentially less powerful compared to non-linear alternatives when dealing with complex datasets[^1]. For instance, consider simple linear regression which fits a straight line through points representing pairs of observations: \[ Y = \beta_0 + \beta_1 X + \epsilon \] Where: - \(Y\) represents the dependent variable, - \(X\) denotes independent features, - \(\beta_0,\beta_1\) are coefficients estimated from training samples, - And \(\epsilon\) stands for error term accounting for unexplained variance not captured by predictors included in our equation. ```python import numpy as np from sklearn.linear_model import LinearRegression # Example dataset creation np.random.seed(42) X = 2 * np.random.rand(100, 1) y = 4 + 3 * X + np.random.randn(100, 1) # Model fitting process using scikit-learn library model = LinearRegression() model.fit(X, y) ``` Another aspect involves how certain architectures handle sequential inputs like text sequences; here, traditional recurrent neural networks might struggle due to vanishing gradient problems over long contexts unlike more recent transformer-based approaches capable of handling much longer dependencies efficiently via self-attention mechanisms rather than strictly adhering to purely linear connections between tokens throughout an entire sequence length limitation seen previously before innovations such as Parallel Context Window were introduced.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值