使用命令行修改Ubuntu 24.04的网络设置

Ubuntu里,使用命令行下修改IP地址,网上有很多方案,我最终觉得这个方案(使用Netplan)最好,最根本,记录下来备查

1.使用命令ip link show 查看Ubuntu上可以使用的网络接口名称

2.查找Netplan的配置文件:我们发现配置文件是50-cloud-init.yaml,这个文件取决于你的系统版本和实际环境,文件名可能是01-netcfg.yaml50-cloud-init.yaml

3.打开并编辑 Netplan 配置文件:sudo vi 50-cloud-init.yaml

按照需要修改对应的地址后保存退出。「renderer」配置为networkd,使用 systemd-networkd 作为网络配置的后端。桌面环境使用 NetworkManager,Ubuntu Server 和无头环境使用networkd

4.保存后需要执行 sudo netplan apply使之生效,并执行ip addr showip route show查看修改后的信息

以下是一个简单的GAT(Graph Attention Network)图神经网络的代码示例: ```python import torch import torch.nn as nn import torch.nn.functional as F class GATLayer(nn.Module): def __init__(self, in_features, out_features, dropout=0.6, alpha=0.2): super(GATLayer, self).__init__() self.dropout = dropout self.alpha = alpha self.W = nn.Linear(in_features, out_features, bias=False) self.a = nn.Linear(2*out_features, 1, bias=False) def forward(self, X, adj_matrix): h = self.W(X) N = h.size(0) a_input = torch.cat([h.repeat(1, N).view(N*N, -1), h.repeat(N, 1)], dim=1).view(N, -1, 2*h.size(1)) e = F.leaky_relu(self.a(a_input).squeeze(2), negative_slope=self.alpha) zero_vec = -9e15*torch.ones_like(e) attention = torch.where(adj_matrix > 0, e, zero_vec) attention = F.softmax(attention, dim=1) attention = F.dropout(attention, p=self.dropout, training=self.training) h_prime = torch.matmul(attention, h) return F.elu(h_prime) class GAT(nn.Module): def __init__(self, in_features, hidden_features, out_features, num_layers, dropout=0.6, alpha=0.2): super(GAT, self).__init__() self.hidden_features = hidden_features self.num_layers = num_layers self.layers = nn.ModuleList([GATLayer(in_features, hidden_features, dropout=dropout, alpha=alpha)]) self.layers.extend([GATLayer(hidden_features, hidden_features, dropout=dropout, alpha=alpha) for _ in range(num_layers-2)]) self.layers.append(GATLayer(hidden_features, out_features, dropout=dropout, alpha=alpha)) def forward(self, X, adj_matrix): h = X for layer in self.layers: h = layer(h, adj_matrix) return h ``` 这是一个简单的GAT图神经网络的实现,包括了GATLayer和GAT两个类。GATLayer定义了一个GAT层的操作,GAT则将多个GAT层串联起来构成整个图神经网络。其中,in_features表示输入特征的维度,hidden_features表示隐层特征的维度,out_features表示输出特征的维度,num_layers表示GAT层数,dropout表示dropout率,alpha表示LeakyReLU的斜率。 希望这个代码示例对你有帮助!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值