# Which optimization algorithm to max a single parameter by searching a landscape of five parameters?

Background: We're operating a small betatron which makes use of a vacuum tube where electrons are accelerated circularly. First, they get injected (like inserted) and contracted (like squeezed). After a while, these electrons exit the tube and hit a target and convert (hopefully) into photons which will be used as x-rays:

source / sketch

The amount of x-rays correspond to a deposited energy: The more x-rays, the higher the energy.

input parameters: injection time, injection length, contraction time, contraction length, current
output parameter: energy


Now the thing is, that these vacuum tubes don't last so long (some dozens up to hundreds of hours). The problem arises when such a tube is replaced as the individual operational parameters change as each of these tubes are some kind of unique: Their manufacture differs very slightly. And this causes a lot of effort on our side each time a tube is replaced. These tubes are operated by means of five parameters which are mostly electronic features (injection time, injection length, contraction time, contraction length, current). At the moment, we run a sloppy, greedy algorithm which was okish to get back to work but meanwhile it's clearly too much effort needed all the time. That's why we are looking to optimize this procedure. Do you have an idea how to figure out a promising algorithm (and for which an usable code exists)? I'm aware of some algorithms in general (evolutionary, salesman, gradient descent and stuff) but I totally lack any feeling or even a real broad and depth knowledge about this topic. I guess, in the end, it is located in control engineering. The algorithm needs to be run on a micro-controller and it should finish within some minutes but the faster, the better. The goal of the algorithm would be to find the highest deposited energy dose by checking these five parameters. The dose can be measured within/by the machine.

The tubes are operated via five parameters (injection time, injection length, contraction time, contraction length, current) which result in a certain amount of deposited energy, which is measured. So, the device should be able to control itself by varying those five parameters and, thus, maximizing the measured energy. I don't think there is any knowledge required about how betatrons work, as it's ultimately searching a landscape spanned by six parameters, of which five can be varied, and discovering the maximum. A difficulty might be, that there are several maxima. For sure, the global maximum is sought. The five control parameters are controlled electronically, so there shouldn't be any uncertainty about them.

edit: The calculations run on a UPD703103 NEC, which is a 32 bit single controller and the machine itself is controlled by a FPGA of which we don't have specs. One single parameter constellation is observed within 10-30 seconds. The whole process shouldn't last more than around 3 minutes. The point now is, the regions of all parameters are free (you can decide whether you wanna' scan current from 0 to 10 Ampere or within 5 to 15 Ampere or even only 7 to 10 Ampere and so on) as well as the step sizes. Ultimately, we wanna' maximize this here:

Ideally, there would be a single sharp peak at 100 but due to pulse-to-pulse variations, it's not that sharp. But the goal would be to come as close as possible to such a peak.

• I don't think it's possible to answer this question in this generality. Show us some formulas for how that problem is formulated, what the variables are (in symbols), what the parameters are (things that can not be varied), and what the objective function looks like. Apr 6, 2022 at 15:45
• there is no objective function or formula we know. I guess there would be no issue if we had this. We're basically guessing parameters and fix them if the energy is good enough.
– Ben
Apr 6, 2022 at 16:00
• Right, but I didn't ask for a formula representation for the function $f(x_1,\ldots,x_n)$. It's a function in the sense of an input output relationship: You stick an $x$ in and you get $f(x)$ back. There doesn't need to be a formula behind it. It can be a measurement process. But one typically knows something about the function, for example whether it's convex, has one or many minima, how many variables it depends on, etc. One can often plot it. All of these "qualitative" properties of $f(x)$ matter when choosing the right algorithm. Apr 6, 2022 at 23:38
• @njuffa's comment is the right one: How fast could you do a measurement? If that could be done quickly, a simple finite difference steepest descent algorithm might be all you need. Or a Nelder-Mead simplex algorithm. Apr 7, 2022 at 20:09
• @WolfgangBangerth Thanks for your responses! Ok, got it. It may sound odd but we don't know this. All I can say is, that there might be several maxima, but not always. We don't understand the physics, yet, we understand only how the machine itself works, means, what does the machine do when we vary parameters. But we absolutely do not understand how this affects the tube and its working parameters. That's we it is trial and error all the time. And it's often differently, we were guessing about some tendencies but we couldn't prove them so far and they don't fit always.
– Ben
Apr 11, 2022 at 6:15

I'd do the following:

before your tube burns out do an automated parameter sweep of reasonable range for your 5 parameters. That should give you a rough idea of the maxima/minima involved, and which parameters have the highest influence. Typically there is one or two parameters which are a lot more important than the other ones.

In a second step you pray that your next tubes characteristic will be somewhat like the one you measured, at least when it comes to the number of maxima/minima etc.

Determine reasonable starting values for your 5 parameters (i.e. last tube-optimum) and then do a flavor of a gradient descent optimization.

If you can not assume that your tube characteristics are somewhat similar to the predecessors, than no optimization in the world will save you from doing the full sweep.

• Thank you! I'm not sure how to determine the time point to sweep the parameters as we don't know the failure of the tubes. It's too effortful to check them manually, even if possible at all. Why gradient descent? Because it's fast? What about some bayesian optimization as this would fit to your assumption, that tubes should be similar, at least somehow, or?
– Ben
Apr 11, 2022 at 12:28
• You could also do the sweep when you set up a new tube, but then you spend the measurement time when your tube is at best quality for calibration. Gradient descent is the easiest to implement and there are readily available libraries in all the major languages. Essentially, as long as the function you are optimizing is smooth and your starting values are 'close' to your optimum then most algorithms will perform fine. Don't waste your time on choosing the algorithm if it saves you a minute in the end. I bet what you are doing with that tube is more interesting:-) Apr 12, 2022 at 9:02
• Based on the problem description, it doesn't sound like a gradient is readily available, so saying gradient descent is easy to implement here is misleading. Apr 16, 2022 at 1:59
• The standard approach would be to use finite differences, i.e., you take two measurements and use them to calculate the gradient between them. If you want to go without that you can have a read of en.wikipedia.org/wiki/Derivative-free_optimization Apr 19, 2022 at 6:18
• I don't think that you are really limited by computational effort. Your UPD703103 NEC should be able to calculate the next iteration step in a couple of miliseconds. It is possible that the different optimizations will need a different amount of measurement cycles which take longer than the computation. So I guess you are optimizing for mininum-amount-of-measurements. I can't really say which of them will be best for your case. If computation should really be the bottleneck, then 30\$ for a raspberry pi is cheaper than thinking about the problem for an hour:-) Apr 19, 2022 at 14:19