None. Solver is part of excel.
Martin said that a user created a solver for bru'n water, implying something separate from the standard excel Solver add-in.
None. Solver is part of excel.
Martin commented that someone did make a solver for his spreadsheet. How much time/work was put in? I'm sure that person wasn't paid and just did it for fun.
The problem with charging for something like this is that it's not an application. It's a spreadsheet with a bunch of formulas.
Also, how mature is the science behind it?
The Brewers Friend calculator seems to be in a position where it would benefit from something like a solver/addition calculator.
No argument about application vs spreadsheet. Unless the application is web based you'll also get into platforms.
People seem happy to just have "something". That doesn't mean that the something that people have is correct, as long it gets them within range, it's all they have to go on.
Let's say that there are optimization algorithms far more sophisticated than the simple matrix Newton's method (Moore-Penrose iteration) needed to solve the profile matching problem and that the Solver that comes with Excel is capable of doing several of these. Solver can also be expanded to solve the huge hairy problems. If the point is that Solver is, algorithmically, overkill, it is. It's just much easier to invoke it than to write the VBasic code to do Moore-Penrose. Someone producing a product for which he is charging money might want to build in the algorithms.The math behind solving optimization problems is way more advanced than what is needed for making automated salt/acid addition calculations. Things like getting as 'close' to a desired ion concentration profile are fairly simple (even taking into account things like requiring all the additions need to be positive) and can be solved in milliseconds.
Actually this problem (predicting mash pH, assuming that's what you meant) is much simpler than the profile matching problem as no matrix algebra is required. One simply computes the proton deficit for each mash component as a function of pH, adds them up and then finds the pH that causes the sum to be 0. Total proton deficit is monotonic in pH so the pH which zeroes it is easily found by root bisection, Newton's method or any of the Solver algorithms.More sophisticated approaches like trying to match a predicted pH to a target pH are also quite feasible since the number of variables in these problems is relatively small by modern standards (maybe a dozen if you include a bunch of different salts and acids),
The worth of the method depends on the proton deficit models. The model is very robust for the water's alkalinity and for any added acids or bases. A simple Taylor series expansion about the DI water mash pH for a given malt is robust if the coefficients were obtained from the titration of a sample of the malt one is going to brew with. Using coefficients from Maltster A's Pilsner malt when you are actually mashing Maltster's B Pilsner malt is less robust and using coefficients from flaked barley for flaked oats even less so....but how worthwhile solving for those will be depends largely on how accurate the pH prediction is,
Because the models' proton deficits are simple error propagation is also quite simple. In other threads from a week or so ago I published some histograms of predicted pH based on assumptions about the errors in individual mash components proton deficits...or how well the errors in the pH prediction can be modeled.
Let's say that there are optimization algorithms far more sophisticated than the simple matrix Newton's method (Moore-Penrose iteration) needed to solve the profile matching problem and that the Solver that comes with Excel is capable of doing several of these. Solver can also be expanded to solve the huge hairy problems. If the point is that Solver is, algorithmically, overkill, it is. It's just much easier to invoke it than to write the VBasic code to do Moore-Penrose. Someone producing a product for which he is charging money might want to build in the algorithms.
Actually this problem (predicting mash pH, assuming that's what you meant) is much simpler than the profile matching problem as no matrix algebra is required. One simply computes the proton deficit for each mash component as a function of pH, adds them up and then finds the pH that causes the sum to be 0. Total proton deficit is monotonic in pH so the pH which zeroes it is easily found by root bisection, Newton's method or any of the Solver algorithms.
The worth of the method depends on the proton deficit models. The model is very robust for the water's alkalinity and for any added acids or bases. A simple Taylor series expansion about the DI water mash pH for a given malt is robust if the coefficients were obtained from the titration of a sample of the malt one is going to brew with. Using coefficients from Maltster A's Pilsner malt when you are actually mashing Maltster's B Pilsner malt is less robust and using coefficients from flaked barley for flaked oats even less so.
Because the models' proton deficits are simple error propagation is also quite simple. In other threads from a week or so ago I published some histograms of predicted pH based on assumptions about the errors in individual mash components proton deficits.
Yes, it can. There is a check box which constrains any cells being varied to the +ive domain. One can impose more involved constraints (cell = constant, cell < constant, cell > another cell etc.)Yes, I agree calling the Excel solver is much easier than writing one's own optimization code (assuming the Excel solver can handle things such as non-negativity constraints and the like - I haven't played around with it much).
For example, Newton's method works fine if you have a twice differentiable objective function without any constraints, but even something like requiring that the salt/acid additions are non-negative puts you outside the realm of problems that can be solved with Newton's method.
More generally, when measuring how close Ax-b is to zero, the sum of squared errors is just one option. ....For example, minimizing the maximum absolute error of any one ion is insensitive to small errors away from the target but ensures that all ions will be within a certain range of the target. These other problems are efficiently solved by standard optimization techniques but can't be solved by with something like Newton's method since the distance functions are no longer differentiable.
Solver is capable of doing problems like this. You can, for example, ask it to minimize proton deficit (predict mash pH) while getting the calcium ion concentration as close to 100 as possible trimming any unneutralized alkalinity with sauermalz.Well, I guess this is semantics, but 'more sophisticated' was referring to an optimization problem where your salt/acid additions are optimized to 1) put the final ion concentrations within some predefined range or make them 'close' to a desired concentration profile and 2) trying to make the predicted mash pH as close as possible to a target pH.
The 'worthwhile' comment simple alludes to the fact that we can always make a mathematical model and solve an optimization problem to 1e-12 precision or whatever, but if the measurements that we're basing the model on are only accurate to within x% then we might not be gaining much over what we'd get from 2 minutes of manually twiddling salt/acid addition values in a spreadsheet.
haven't been reading the forum as regularly as I used to, but I will check out the histograms. If we can make a good estimate of the proton deficit distribution, then it should be possible to calculate "optimal" salt/acid additions which take into account sensitivities to potential errors and produce solutions which will "most likely" give a target pH in a desired range.
I'd argue the function of interest here being something like the sum of squared errors is more out of mathematical convenience and historical precedent than having much physical meaning for the problem. The squared error is making an inherent statistical assumption that the noise in the model is gaussian. For something like least squares regression where you're finding one set of parameters to fit a large number of data points to a model the gaussian assumption is certainly reasonable due to central limit theorem arguments. When you only have a single 'data point' such as a target ion concentration you're trying to match this isn't necessarily the case.Certainly the functions of interest here are differentiable and continuous and the non zero constraint is easily implemented.
What you're describing will sometimes work and sometimes won’t depending on the geometry of the constraint set. For minimizing a quadratic objective function, such as |Ax-b|^2, this certainly can be solved in closed form using a Moore-Penrose pseudo inverse if the system is unconstrained. Because the objective function is quadratic the Newton direction will always point from the current value of x to the unconstrained solution. As a result, when you add constraints you’re going to move from the initial point towards the unconstrained solution until you hit a constraint boundary (or arrive at the unconstrained solution if it lies in the feasible set). Assuming you hit a constraint boundary, you now need to proceed along the constraint boundary; for simple constraints like x>=0 you can remove variables from the ‘active set’ of variables we’re optimizing over once they hit the boundary and continue with a reduced dimensionality problem, but for more complicated constraints this won’t necessarily work. For example, if we want to limit the maximum concentrations of some ions/acids then you’ll have a constraint of the form Mx <= y. Once this is combined with the constraint x>=0, you now have ‘corners’ in the feasible set where you can get stuck, so you’ll potentially need to return variables to the active set and move along a new facet of the constraint set. But, at that point, you’re basically just doing a bizarre form of quadratic programming.If your system is Ax = b with A the matrix of partials at x0, your initial guess at a solution, then your correction to x0 is ∆x = A#(Ax0-b) (A# is Moore-Penrose pseudo inverse of A). If ∆x carries any element of x below 0 you limit that element to 0 and carry on. I won't say that there aren't situations where that might back you into a corner distant from the best solution but it's always worked for me on these problems (and actually any other I've applied it to) anyway. Maybe I shouldn't call this Newton's method but Newton's method is what you get if you do it in 1 dimension.
I’m not totally sure what you’re defining as your error function, but assuming it’s sum_i (p[Ci]/wi – p[Ti]/wi)^2 where Ci is the concentration we’re trying to fit and Ti is the target, then you’ll have to be a bit careful here if you try to apply Newton’s method as this is no longer convex wrt the Ci variables. As a result, the Hessian may not be positive definite and the Newton direction may not give a descent direction. The Excel solver is likely using a version of gradient descent, which should at least give a local minimum, but not necessarily a global minimum.In general, for ion concentration matching, I prefer the error function to be the rms of p[Ci]/wi in other words, to minimize the weighted geometric error (Ci is the concentration of the ion, wi the weight assigned to it an p the -log operator. As this function is clearly differentiable WRT each Ci Moore-Pensrose is suited. More to the point, Solver can certainly handle it. If I want to minimize the error with respect to one of the ions I just put a bigger weight on it.
Solver is capable of doing problems like this. You can, for example, ask it to minimize proton deficit (predict mash pH) while getting the calcium ion concentration as close to 100 as possible trimming any unneutralized alkalinity with sauermalz.
Right, the fact that second order methods like Newton’ or interior point methods (which is basically an augmentation of Newton’s method to handle non-smooth constraints/functions) include the Hessian information (your GDOP is the inverse of the Hessian) is why they will typically be orders of magnitude faster than a first order method like gradient descent. The only downside to them is that the Hessian grows by the number of variables squared, so for large scale problems second order methods aren’t feasible.The beauty of Moore-Penrose (Roger P is on my mind as I just saw 'Theory of Everything') is that the error analysis is built in. A# = GDOP*A_tranpose where GDOP is the dilution of precision matrix so you have to compute it anuyway to get to A# (you don't really, of course if you used SVD on A but it's trivial to do so). If you have estimates for errors, even for consider parameters, it is possible to get covariance estimates for the things you are solving for.
I think you're confusing the two types of problems we have discussed. In the first we have a set of parameters, x, (the amounts of some number of salts) a model that shows how they relate to a set of quantities y which are of interest (concentrations of ions) and a set of desired concentrations for those ions, call it d. If we choose an algorithm that minimizes |Ax - d| we get the mmse solution which is the Euclidean distance between the ion concentration we want and the closest one we can find. The Euclidean distance has obvious intuitive appeal but it has limitations. If we have two points on the surface of the earth at (x1,y1) and (x2,y2) and wish to proceed from one to the other the minimum distance we would have to traverse is sqrt( (x1-x2)^2 + (y1 - y2)^2), the Euclidean distance but if we are forced to walk on streets laid out in a N-S, E-W grid we would be have to walk farther than the Euclidean distance and another measure, |x1 - x2| + |y1 - y2| is more suitable. If we want to compare the color of two batches of beer we measure their colors in L*a*b* space and compute the Euclidean distances between them. This is good for beer (as it's colors are restricted to one quadrant in Lab space but if we were in, say, the paint business we might decide that the Euclidean measure wasn't the best and use one of the modified (near Euclidean but not quite) metrics.I'd argue the function of interest here being something like the sum of squared errors is more out of mathematical convenience and historical precedent than having much physical meaning for the problem. The squared error is making an inherent statistical assumption that the noise in the model is gaussian.
For something like least squares regression where you're finding one set of parameters to fit a large number of data points to a model the gaussian assumption is certainly reasonable due to central limit theorem arguments.
It isn't the case at all because there is no noise.When you only have a single 'data point' such as a target ion concentration you're trying to match this isn't necessarily the case.
What you're describing will sometimes work and sometimes won’t depending on the geometry of the constraint set. For minimizing a quadratic objective function, such as |Ax-b|^2, this certainly can be solved in closed form using a Moore-Penrose pseudo inverse if the system is unconstrained.
Yes, that's the function and I'm sure what you are saying is true. Solver, as supplied with Excel, gives the options of GRG Nonlinear, SimplexLP and 'Evolutionary'. I'm trying to remember as to whether it (Solver) has ever driven me to a bizarre solution. If it has the fix is to simply try another starting point.I’m not totally sure what you’re defining as your error function, but assuming it’s sum_i (p[Ci]/wi – p[Ti]/wi)^2 where Ci is the concentration we’re trying to fit and Ti is the target, then you’ll have to be a bit careful here if you try to apply Newton’s method as this is no longer convex wrt the Ci variables. As a result, the Hessian may not be positive definite and the Newton direction may not give a descent direction. The Excel solver is likely using a version of gradient descent, which should at least give a local minimum, but not necessarily a global minimum.
We don't have that kind of problem here and I think it's important to recognize that. You are obviously very much into this and I'm sure deal with some really hairy problems that require special techniques. Those aren't the problems we have here. We're pretty much limited to picking mass values for a dozen or fewer salts in order to set the concentration of a dozen or fewer ions. The pH estimation problem is so simple that one doesn't really even need Solver. You have a single variable (proton deficit) that is monotonic in pH. A root bisection scheme (which you can set up on the spreadsheet itself without VBasic or any other kind of macro) will solve it.The only downside to them is that the Hessian grows by the number of variables squared, so for large scale problems second order methods aren’t feasible.
It is possible to automate the acid addition, and my spreadsheet Q-Water does that. You can find it on this forum. It is still in development though.
There is a number of problems with automating the mineral addition.
First, multiple minerals that can be used to increase a given ion. Second, all ions should produce the net charge =0.
The only clash may occur here if you would want SO4- lower than what MgSO4 adds. But then it can tell you your minimum SO4- for your chosen level of Mg2+.
What I have described is very powerful.
But how do I minimize both charge for pH calculations and difference between the desired and available water profile? Do I assign some sort of weight to them and add them within 1 cell?
If your users do not care about the bicarbonate (and I've been trying to educate them to focus on alkalinity instead) then you can leave bicarbonate out of the error computation but you must compute charge on bicarbonate (and phosphate and lactate etc.) in order to insure that the net charge, after adjustments, is 0.Or am I supposed to leave HCO- out of desired water profile and ... do something else about it?
Experimenting is the best way to get familiar with it.I have not given it a lot of thought at the moment I'm writing this
Personally, it might be that the easiest solution is to let the alkalinity/bicarbonate free rise and then leverage dilution as a strategy to minimize acid additions. Complicated array probably..
Didn't pay attention to this before but actually DOP = (J_t*J)^-1 i.e. the inverse of the 'square' of the Jacobian.(your GDOP is the inverse of the Hessian)
We already knew this!The two could be merged but as I consider profile chasing a little silly I have never seen the need to do that and so probably never will
I think you're confusing the two types of problems we have discussed. In the first we have a set of parameters, x, (the amounts of some number of salts) a model that shows how they relate to a set of quantities y which are of interest (concentrations of ions) and a set of desired concentrations for those ions, call it d. If we choose an algorithm that minimizes |Ax - d| we get the mmse solution which is the Euclidean distance between the ion concentration we want and the closest one we can find.
The Euclidean distance has obvious intuitive appeal but it has limitations. If we have two points on the surface of the earth at (x1,y1) and (x2,y2) and wish to proceed from one to the other the minimum distance we would have to traverse is sqrt( (x1-x2)^2 + (y1 - y2)^2), the Euclidean distance but if we are forced to walk on streets laid out in a N-S, E-W grid we would be have to walk farther than the Euclidean distance and another measure, |x1 - x2| + |y1 - y2| is more suitable. If we want 5 chloride and 300 sulfate and come up with a solution that gives us 10 chloride and 305 sulfate each of those ions will contribute an equal amount to the error (Euclidean distance between target and realization). That just doesn't seem right as in one case the amount of the ion is off by 50% and in the other by 1.7%. Suppose further that we really don't care very much about the chloride wanting mainly to focus on the sulfate. This suggests that perhaps the scalar f = e_trans*W*e where e is the vector e = log(Ax) - log(d) and W is a diagonal matrix of desired weights might be a better function to minimize. The point is that it is up to the analyst to pick whatever error function he feels gives him the most meaningful measure of the error and the most meaningful solution. I have mentioned earlier that this is the error function I prefer for the ion matching problem.
Youre kind of mincing terms here. If were talking about minimizing the functionDidn't pay attention to this before but actually DOP = (J_t*J)^-1 i.e. the inverse of the 'square' of the Jacobian.
I wouldn’t say I’m “confusing” the two problems, but yes, perhaps making the analogy to statistics was not the best one to make as this seems to have spurred a tangent discussion about various statistical estimators (as an aside, the MMSE estimator is Bayesian,
The MLE estimator is the set of x that minimizes...so if you’re talking about problems like y=Ax-b+e the MMSE estimator is trying to minimize |x-x_true|^2 and only reduces to minimizing |Ax-b|^2 if either a solution Ax=b exists or we assume that the entries of x are uncorrelated, x is uncorrelated with e, e is iid Gaussian,
Then why keep bringing it up?.etc…, but as you mention this is probably not a helpful analogy to make as we’re more in a deterministic setting here).
I would say those are very good reasons for shying away from such metrics. If you can think of a better metric for expressing the difference between one set of ion concentrations and another then propose it and let people decide whether they think that metric is somehow better than the a Euclidean metric or, in particular, enough so to justify the computational complexities.This is essentially the point I was trying to make from the beginning. There are dozens of potentially useful objective functions one could propose for this problem. The Euclidian distance often gets used because people shy away from things like non-differentiable objective functions because they can’t be solved with something like Newton’s method or gradient descent, but there are many standard optimization methods (beyond Newton’s method) which can employed to exactly solve many of these problems.
A, or J as I am calling it now, doesn't have to have to be invertible and beyond that I don't think the log transformation makes J any less invertible than not doing the transformation. I've been fiddling with some matrices based on the ratios in common salts (NaCl, K2SO4 etc) and find in the linear model a J matrix condition number of about 20. Doing the log transformation that actually drops to 7. If convexity were a problem with the log transformation Solver, which uses a gradient method, shouldn't be able to find solutions and I've done hundreds of ion profiles using the weighted log metric with Solver. Nor should I be able to fit curves to power measurements expressed in dB and I've done thousands of those with SVD.As an example, I agree that working with some sort of normalized scale is a good idea, but suppose I don’t like the log transformation you’ve proposed above because it makes a convex problem non-convex and I don’t want to deal with issues like having multiple local-minima which aren’t globally optimal (I realized this log-transformed problem probably can’t be solved in closed form as I mentioned earlier unless A is invertible, which it typically won’t be).
I would certainly never say that there aren't applications where a metric like that might be useful but it would certainly be of no interest to me in this application except perhaps...So instead, suppose I propose defining ...
e = (Ax-b)/b
where here the division is done element wise for each entry of the vector. Now I could solve
min_x |e|^2 subject to x>=0
with a standard Euclidian distance, but instead, maybe I want to solve
min_x max_i {|e_i|} subject to x>=0
i.e. minimize the maximum absolute value of the %error across all ion concentrations... Whether I prefer problem 1 or problem 2 is of course a personal preference, but you’d be hard pressed to solve problem 2 with something like basic Newton’s method unless you get lucky and there exists a solution Ax=b.
Nevertheless, getting back to the point I was making in my first post, there are plenty of standard optimization techniques that can easily handle problem 2 (standard enough that there’s a good chance they’ve been built into Excel).
What you have for DOP above is using the Jacobian of the linear map x-->Ax, which is just J(x) = A.
In the estimation case we have the set of equations [ ]
I would say those [computational complexities] are very good reasons for shying away from such metrics.
If you can think of a better metric for expressing the difference between one set of ion concentrations and another then propose it and let people decide whether they think that metric is somehow better than the a Euclidean metric.
A, or J as I am calling it now, doesn't have to have to be invertible and beyond that I don't think the log transformation makes J any less invertible than not doing the transformation. I've been fiddling with some matrices based on the ratios in common salts (NaCl, K2SO4 etc) and find in the linear model a J matrix condition number of about 20. Doing the log transformation that actually drops to 7. If convexity were a problem with the log transformation Solver, which uses a gradient method, shouldn't be able to find solutions and I've done hundreds of ion profiles using the weighted log metric with Solver. Nor should I be able to fit curves to power measurements expressed in dB and I've done thousands of those with SVD.