论文写作 12: 算法伪代码 (含实例)

算法伪代码是论文的核心之一.

  1. 需要说明输入、输出;
  2. 方法 (函数) 名可写可不写, 如果被别的方法调用就必须写;
  3. 需要写出主要步骤的注释;
  4. 长度控制在 15-30 行;
  5. 可使用数学式子或对已有数学式子的引用;
  6. 不重要的步骤可以省略;
  7. 一般需要进行时间、空间复杂度分析, 并写出配套的 property 以及相应的表格, 以使其更标准.
  8. 在正文中分析伪代码的时候, 对多行引用应该用双连词符, 它会转成一个较长的连词符. 如: Lines 3–4 shows. Tables 4–6 同理. 两个并行的词连接起来 (等价词的复合), 也应该用 Serial–parallel. 参考文献的页码也应该用双连词符 pp. 87–99. multi-label 这里有个从属关系, 就应该用单连词符.

例子:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
以下是该算法的 tex 源码:

\begin{algorithm}[!htb]
	\renewcommand{\algorithmicrequire}{\textbf{Input:}}
	\renewcommand{\algorithmicensure}{\textbf{Output:}}
	\caption{Multi-label active learning through serial-parallel neural networks}
	\label{algorithm: masp}
	\begin{algorithmic}[1]
		\REQUIRE
			data matrix $\mathbf{X}$,
			label matrix $\mathbf{Y}$ for query,
            query budget $Q$,
            cold-start query budget $P$,
            number of representative instances $R$,
            instance batch size $B_i$,
            label batch size $B_l$
		\ENSURE
			queried instance-label pairs $\mathbf{Q}$, prediction network $\Theta$.
        \STATE Initialize the serial-parallel prediction network;
        \STATE $\mathbf{Q} = \emptyset$;\\
        // Stage 1. Cold start.
        \STATE Compute instance representativeness according to Eq. \eqref{equation: dp-representativeness};
        \STATE Select the top-$R$ representative instances to reorganize the training set $\mathbf{X}$;
        \STATE Update $\mathbf{Q}$ and $\mathbf{Y}'$ by querying $B_l$ labels for each of the top $\lfloor Q / B_l \rfloor$ representative instances;
        \STATE Train the prediction network using $\mathbf{X}$ and $\mathbf{Y}'$;\\
        // Stage 2. Main learning process.
		\REPEAT
            \STATE Compute $\hat{\mathbf{Y}}$ using the prediction network and Eq. \eqref{equation: label-prediction};
            \STATE Compute label uncertainty according to Eq. \eqref{equation: label-uncertainty};
            \STATE Query top-$B_i$ uncertain instance-label pairs to update $\mathbf{Q}$ and $\mathbf{Y}'$;
            \STATE Update the prediction network using $\mathbf{X}$ and $\mathbf{Y}'$;\\
		\UNTIL{($|\mathbf{Q}| \geq Q$)}
	\end{algorithmic}
\end{algorithm}
  • 70
    点赞
  • 220
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
以下是浣熊优化算法(Raccoon Optimization Algorithm)的MATLAB伪代码示例: ``` % 初始化种群 population_size = 50; max_generation = 100; dim = 2; % 变量维度 lb = [0, 0]; % 变量下界 ub = [1, 1]; % 变量上界 population = zeros(population_size, dim); for i = 1:population_size population(i, :) = lb + (ub - lb) .* rand(1, dim); end % 迭代更新种群 for generation = 1:max_generation % 计算适应度值 fitness = calculate_fitness(population); % 更新最优解 [~, best_index] = min(fitness); best_solution = population(best_index, :); % 更新种群 new_population = zeros(population_size, dim); for i = 1:population_size % 随机选择三个个体 rand_indices = randperm(population_size, 3); rand_solutions = population(rand_indices, :); % 更新个体位置 rand_index = randperm(3, 1); random_solution = rand_solutions(rand_index, :); delta = abs(rand_solutions(2, :) - rand_solutions(3, :)); new_solution = population(i, :) + sign(random_solution - population(i, :)) .* delta; % 边界处理 new_solution = max(new_solution, lb); new_solution = min(new_solution, ub); new_population(i, :) = new_solution; end population = new_population; end % 计算适应度函数,此处为示例,需根据具体问题自定义 function fitness = calculate_fitness(solution) fitness = sum(solution, 2); end ``` 这段代码是一个简化的浣熊优化算法的实现,其中包括种群初始化、适应度计算、个体位置更新等步骤。在具体应用时,需要根据实际问题自定义适应度函数。请根据实际需求进行适当修改和完善。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值