Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annealing #3242

Closed
lukknapen opened this issue Apr 29, 2024 · 3 comments
Closed

Annealing #3242

lukknapen opened this issue Apr 29, 2024 · 3 comments

Comments

@lukknapen
Copy link

How to use annealing ?
Because we have a giant discontinuity in modestats.png (see added file) we want to apply annealing (advised by Ihab).
In config.xml we use

      <param name="activateAnnealingModule" value="true" />
      <!--
      <param name="endValue" value="0.00011" />
      <param name="annealType" value="geometric" />
      <param name="annealParameter" value="globalInnovationRate" />
      <param name="halfLife" value="0.5" />
      <param name="shapeFactor" value="0.89" />
      -->
   </module>
  • Note that all but one of the settings are commented out.
  • Defining any parameter except activateAnnealingModule seems to raise an exception.
  • The source code ReplanningAnnealerConfigGroup.java seems to specify more parameters.
    public enum AnnealOption {linear, geometric, exponential, msa, sigmoid, disabled}

    public enum AnnealParameterOption {
        globalInnovationRate, BrainExpBeta, PathSizeLogitBeta, learningRate
    }

   // ....
    public static class AnnealingVariable extends ReflectiveConfigGroup {

        public static final String GROUP_NAME = "AnnealingVariable";
        private static final String START_VALUE = "startValue";
        private static final String END_VALUE = "endValue";
        private static final String ANNEAL_TYPE = "annealType";
        private static final String DEFAULT_SUBPOP = "defaultSubpopulation";
        private static final String ANNEAL_PARAM = "annealParameter";
        private static final String HALFLIFE = "halfLife";
        private static final String SHAPE_FACTOR = "shapeFactor";
        private String defaultSubpop = null;
        private Double startValue = null;
        private double endValue = 0.0001;
        private double shapeFactor = 0.9;
        private double halfLife = 100.0;
        private AnnealOption annealType = AnnealOption.disabled;
        private AnnealParameterOption annealParameter = AnnealParameterOption.globalInnovationRate;

   // ....
        @Override
        public Map<String, String> getComments() {
            Map<String, String> map = super.getComments();
            map.put(HALFLIFE,
                    "this parameter enters the exponential and sigmoid formulas. May be an iteration or a share, i.e. 0.5 for halfLife at 50% of iterations. Exponential: startValue / exp(it/halfLife)");
            map.put(SHAPE_FACTOR, "sigmoid: 1/(1+e^(shapeFactor*(it - halfLife))); geometric: startValue * shapeFactor^it; msa: startValue / it^shapeFactor");
            map.put(ANNEAL_TYPE, "options: linear, exponential, geometric, msa, sigmoid and disabled (no annealing).");
            map.put(ANNEAL_PARAM,
                    "list of config parameters that shall be annealed. Currently supported: globalInnovationRate, BrainExpBeta, PathSizeLogitBeta, learningRate. Default is globalInnovationRate");
            map.put(DEFAULT_SUBPOP, "subpopulation to have the global innovation rate adjusted. Not applicable when annealing with other parameters.");
            map.put(START_VALUE, "start value for annealing.");
            map.put(END_VALUE, "final annealing value. When the annealing function reaches this value, further results remain constant.");
            return map;
        }
    }

but i do not understand why these parameters cannot be used (do not understand the mechanism behind this code)

  • We used both matsim-15 (2023-Apr release) and matsim-2024.0 ("24.0-RC1 (Spring 2024)") and both behave in a similar way.
  • In logfile.log only one parameter
    modestats
    for module replanningAnnealer is listed.
  • At this moment we use annealing using the ''standard'' setting (whatever that may be).

Thanks for your help
luk

@jfbischoff
Copy link
Collaborator

jfbischoff commented Apr 30, 2024

Hi Luk,
you need to define the parameters per Annealing Variable, i.e., it should look like this:

	<!-- Activate the scaling of replanning modules using an annealing approach rather than fixed rates. -->
	<param name="activateAnnealingModule" value="true" />
	<parameterset type="AnnealingVariable" >
		<!-- list of config parameters that shall be annealed. Currently supported: globalInnovationRate, BrainExpBeta, PathSizeLogitBeta, learningRate. Default is globalInnovationRate -->
		<param name="annealParameter" value="globalInnovationRate" />
		<!-- options: linear, exponential, geometric, msa, sigmoid and disabled (no annealing). -->
		<param name="annealType" value="sigmoid" />
		<!-- subpopulation to have the global innovation rate adjusted. Not applicable when annealing with other parameters. -->
		<param name="defaultSubpopulation" value="regular" />
		<!-- final annealing value. When the annealing function reaches this value, further results remain constant. -->
		<param name="endValue" value="0.01" />
		<!-- this parameter enters the exponential and sigmoid formulas. May be an iteration or a share, i.e. 0.5 for halfLife at 50% of iterations. Exponential: startValue / exp(it/halfLife) -->
		<param name="halfLife" value="0.425" />
		<!-- sigmoid: 1/(1+e^(shapeFactor*(it - halfLife))); geometric: startValue * shapeFactor^it; msa: startValue / it^shapeFactor -->
		<param name="shapeFactor" value="0.05" />
		<!-- start value for annealing. -->
		<param name="startValue" value="0.65" />
	</parameterset>
</module>

With the settings above, the stopwatch for a typical run in our setup looks like that:
One can clearly see that there is more replanning initially, which is gradually being reduced.

grafik

Note that multiple subpopulations are only supported in the 2024 RC, before that defining the same Annealing Variables for multiple subpopulations led to an error.

@jfbischoff
Copy link
Collaborator

Mhm, somehow github swallows the first line of the xml snippet, this is what it looks like properly
grafik

@lukknapen
Copy link
Author

lukknapen commented Apr 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants