Skip to content

Commit

Permalink
pseudocode tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2Brownlee committed Jan 24, 2011
1 parent 1b43650 commit 0cdba57
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions book/a_immune/negative_selection_algorithm.tex
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ \subsection{Procedure}
\KwOut{\Repertoire}
% algorithm
\Repertoire $\leftarrow \emptyset$\;
\While{$\neg$\StopCondition{}}{
\While{$\neg$\StopCondition{}}{
\Detectors $\leftarrow$ \GenerateRandomDetectors{}\;
\ForEach{\CurrentDetector $\in$ \Repertoire}{
\If{$\neg$\Matches{\CurrentDetector, \SelfData}}{
Expand Down Expand Up @@ -104,7 +104,7 @@ \subsection{Procedure}
% i/o
\KwIn{\InputSamples, \Repertoire}
% algorithm
\For{\CurrentInputSample $\in$ \InputSamples}{
\For{\CurrentInputSample $\in$ \InputSamples}{
\InputSampleClassification $\leftarrow$ ``non-self''\;
\ForEach{\CurrentDetector $\in$ \Repertoire}{
\If{\Matches{\CurrentInputSample, \CurrentDetector}}{
Expand Down
4 changes: 2 additions & 2 deletions book/a_neural/lvq.tex
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ \subsection{Procedure}
\Bmu $\leftarrow$ \SelectBestMatchingUnit{\Pattern, \CodebookVectors}\;
\ForEach{\BmuAttribute $\in$ \Bmu}{
\eIf{\BmuClass $\equiv$ \PatternClass} {
\BmuAttribute $\leftarrow$ \BmuAttribute $+$ \LearningRate $\times$ (\PatternAttribute - \BmuAttribute)
\BmuAttribute $\leftarrow$ \BmuAttribute $+$ \LearningRate $\times$ (\PatternAttribute $-$ \BmuAttribute)
}{
\BmuAttribute $\leftarrow$ \BmuAttribute - \LearningRate $\times$ (\PatternAttribute - \BmuAttribute)
\BmuAttribute $\leftarrow$ \BmuAttribute $-$ \LearningRate $\times$ (\PatternAttribute $-$ \BmuAttribute)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion book/a_neural/som.tex
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ \subsection{Procedure}
\Neighborhood $\leftarrow$ \SelectNeighbors{\Bmu, \CodebookVectors, \Nsize}\;
\ForEach{\Vector $\in $\Neighborhood} {
\ForEach{\VectorAttribute $\in$ \Vector}{
\VectorAttribute $\leftarrow$ \VectorAttribute $+$ \Lrate $\times$ (\PatternAttribute - \VectorAttribute)
\VectorAttribute $\leftarrow$ \VectorAttribute $+$ \Lrate $\times$ (\PatternAttribute $-$ \VectorAttribute)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions book/a_probabilistic/cross_entropy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ \subsection{Procedure}
\SetKwData{Variances}{Variances}
\SetKwData{Best}{$S_{best}$}
\SetKwData{Samples}{Samples}
\SetKwData{SamplesZero}{$Samples_0$}
\SetKwData{SamplesZero}{$Samples_{0}$}
\SetKwData{SelectedSamples}{$Samples_{selected}$}
\SetKwData{Meani}{$Means_i$}
\SetKwData{Variancei}{$Variances_i$}
Expand Down Expand Up @@ -101,8 +101,8 @@ \subsection{Procedure}
}
\EvaluateSamples{\Samples}\;
\SortSamplesByQuality{\Samples}\;
\If{\Cost{\SamplesZero $\leq$ \Cost{\Best}} {
\Best $\leftarrow \Samples_0$\;
\If{\Cost{\SamplesZero} $\leq$ \Cost{\Best}} {
\Best $\leftarrow$ \SamplesZero\;
}
\SelectedSamples $\leftarrow $\SelectBestSamples{\Samples, \NumUpdateSamples}\;
\For{$i=0$ \KwTo \ProblemSize} {
Expand Down
4 changes: 2 additions & 2 deletions book/a_probabilistic/pbil.tex
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ \subsection{Procedure}
}
}
\ForEach{\Bit $\in$ \CurrentBest} {
\VectorBit $\leftarrow$ \VectorBit $\times$ (1.0 - \LearningRate) $+$ \Bit $\times$ \LearningRate\;
\VectorBit $\leftarrow$ \VectorBit $\times$ (1.0 $-$ \LearningRate) $+$ \Bit $\times$ \LearningRate\;
\If{\Rand{} $<$ \ProbabilityMutate} {
\VectorBit $\leftarrow$ \VectorBit $\times$ (1.0 - \MutationFactor) $+$ \Rand{} $\times$ \MutationFactor\;
\VectorBit $\leftarrow$ \VectorBit $\times$ (1.0 $-$ \MutationFactor) $+$ \Rand{} $\times$ \MutationFactor\;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions book/a_stochastic/reactive_tabu_search.tex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ \subsection{Procedure}
\eIf{\HaveVisitedSolutionBefore{\Current, \VisitedSolutions}}{
% RepetitionInterval
\CurrentVisitTime $\leftarrow$ \RetrieveLastTimeVisited{\VisitedSolutions, \Current}\;
\RepetitionInterval $\leftarrow$ \CurrentIteration - \CurrentVisitTime\;
\RepetitionInterval $\leftarrow$ \CurrentIteration $-$ \CurrentVisitTime\;
\CurrentVisitTime $\leftarrow$ \CurrentIteration\;
% check for increase
\If{\RepetitionInterval $<$ 2 $\times$ \ProblemSize}{
Expand All @@ -136,7 +136,7 @@ \subsection{Procedure}
}

% check for reduction
\If{\CurrentIteration - \ProhibitionPeriodTime $>$ \AvgRepetitionInterval}{
\If{\CurrentIteration $-$ \ProhibitionPeriodTime $>$ \AvgRepetitionInterval}{
\ProhibitionPeriod $\leftarrow$ \Max{1, \ProhibitionPeriod $\times$ \Decrease}\;
\ProhibitionPeriodTime $\leftarrow$ \CurrentIteration\;
}
Expand Down Expand Up @@ -169,10 +169,10 @@ \subsection{Procedure}
\KwOut{\Current}
% Algorithm
\AdmissibleCandidateList $\leftarrow$ \GetAdmissibleMoves{\CandidateList}\;
\TabuCandidateList $\leftarrow$ \CandidateList - \AdmissibleCandidateList\;
\TabuCandidateList $\leftarrow$ \CandidateList $-$ \AdmissibleCandidateList\;
% modify
\If{\Size{\AdmissibleCandidateList} $<$ 2} {
\ProhibitionPeriod $\leftarrow$ \ProblemSize - 2\;
\ProhibitionPeriod $\leftarrow$ \ProblemSize $-$ 2\;
\ProhibitionPeriodTime $\leftarrow$ \CurrentIteration\;
}
% aspiration
Expand Down Expand Up @@ -203,7 +203,7 @@ \subsection{Procedure}
% Algorithm
\Tabu $\leftarrow$ FALSE\;
\CurrentFeatureLastUsed $\leftarrow$ \RetrieveTimeFeatureLastUsed{\CurrentFeature}\;
\If{\CurrentFeatureLastUsed $\geq$ \CurrentIteration - \ProhibitionPeriod}{
\If{\CurrentFeatureLastUsed $\geq$ \CurrentIteration $-$ \ProhibitionPeriod}{
\Tabu $\leftarrow$ TRUE\;
}
\Return{\Tabu}\;
Expand Down
2 changes: 1 addition & 1 deletion book/a_swarm/bees_algorithm.tex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ \subsection{Procedure}
\NumRecruitedBees $\leftarrow$ $\emptyset$\;
\eIf{$i <$ \NumEliteSites} {
\NumRecruitedBees $\leftarrow$ \NumEliteBees\;
} {
}{
\NumRecruitedBees $\leftarrow$ \NumOtherBees\;
}
\Neighborhood $\leftarrow$ $\emptyset$\;
Expand Down
13 changes: 12 additions & 1 deletion web/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,16 @@ def replace_functions(map, line)
return line
end

def basic_math_replace(current, replacement)
#puts "[#{current}], [#{replacement}]"
# don't do math where we don't have to
return "&gt;" if current.strip == "$>$"
return "&lt;" if current.strip == "$<$"
return "&ndash;" if current.strip == "$-$"
return "+" if current.strip == "$+$"
return "$#{replacement}$"
end

PSEUDOCODE_KEYWORDS = {"While"=>"While", "If"=>"If", "eIf"=>"If",
"Return"=>"Return", "ForEach"=>"ForEach", "For"=>"For"}

Expand Down Expand Up @@ -852,7 +862,8 @@ def process_pseudocode(lines, caption=nil)
index = 0
line = line.gsub(/\$([^$]+)\$/) do |m|
index += 1
"$#{math[index - 1]}$"
#"$#{math[index - 1]}$"
basic_math_replace(m, math[index-1])
end
end
# replace data
Expand Down

0 comments on commit 0cdba57

Please sign in to comment.