4.3.3 Annealing - WangLabTHU/GPro GitHub Wiki
hcwang and qxdu edited on Aug 4, 2023, 1 version
Simulated annealing (SA) is a method for solving unconstrained and bound-constrained optimization problems. The method models the physical process of heating a material and then slowly lowering the temperature to decrease defects, thus minimizing the system energy.
At each iteration of the simulated annealing algorithm, a new point is randomly generated. The distance of the new point from the current point, or the extent of the search, is based on a probability distribution with a scale proportional to the temperature. The algorithm accepts all new points that lower the objective, but also, with a certain probability, points that raise the objective. By accepting points that raise the objective, the algorithm avoids being trapped in local minima in early iterations and is able to explore globally for better solutions.
Simulated Annealing algorithm can be used for implicit space optimization of our WGAN model. The schematic diagram of a workflow is shown below[1].
Caution: The current algorithm defaults to using the WGAN generator and CNNK15 predictor. Please provide the model you have already trained. This program will search for the most effective hidden space
params | description | default value |
---|---|---|
generator_modelpath | trained model path of generator | None |
predictor_modelpath | trained model path of predictor | None |
natural_datapath | natural sequences datapath | None |
savepath | final results saving directory | None |
z_dim | dimension of hidden state for WGAN model | 128 |
seq_len | sequence length | 50 |
params | description | default value |
---|---|---|
MaxIter | Maximum Iteration epoch | 1000 |
MaxPoolsize | length of final selecting results | 2000 |
alpha | Temperature annealing coefficient | 0.98 |
tInital | Initial Temperature | 1 |
tFinal | Final Temperature | 0.01 |
meanMarkov | The average number of moves on a Markov chain at each temperature | 100 |
scale | Initial step size | 0.5 |
Before executing optimizer, you should have trained a generator and a predictor.
A simple demo will work like:
from gpro.optimizer.heuristic.annealing import AnnealingAlgorithm
# (1) define the generator
default_root = "your working directory"
generator_modelpath = os.path.join(str(default_root), 'checkpoints/wgan/checkpoints/net_G_12.pth')
# (2) define the predictor
predictor_modelpath = os.path.join(default_root), 'checkpoints/cnn_k15/checkpoint.pth')
# (3) select the highly-expressed sequence
natural_datapath = default_root + '/data/diffusion_prediction/seq.txt'
tmp = AnnealingAlgorithm(generator_modelpath=generator_modelpath, predictor_modelpath=predictor_modelpath,
natural_datapath=natural_datapath, savepath="./optimization/Annealing")
tmp.run()
Resulting files consists of compared_with_natural.pdf
, ExpIter.txt
, ExpIter.csv
files | description |
---|---|
compared_with_natural.pdf | Box plot comparing model generated results with natural results |
ExpIter.txt | Save the FASTA file for the final result sequence |
ExpIter.csv | Save the sequences and predictions for the final result sequence |
A box plot is shown below.
[1] Yang, Li. (2022). Research on Logistics Distribution Vehicle Path Optimization Based on Simulated Annealing Algorithm. Advances in Multimedia. 2022. 1-8. 10.1155/2022/7363279.