# Development

## November 2013

1. Refinement of log b values. This imposes a natural non-negativity constraint on the b values. It also improves the refinement stability and speed.
2. Protection against refinement diverging uses shift-cutting. This change is based on the observation that problems with refinement usually have a chemical origin rather than being due to computational factors. This was the system used in Miniquad, but replaced in Superquad by use of the Marquardt parameter.

The refinement of logb requires the Jacobian elements to be calculated as This formula is already used to calculate the “relative shifts” on the b values in earlier Hyperquad versions, so the only change in the program was to the way the shifts are applied, as absolute shifts to log b values.

Confirmation of the correctness of the use of logb as variable to refine is provided by the behavious of the objective function being minimized. This diagram show contours of the objective function for the system sartrigly, as a function of the two logb values that are to be refined. The minimum is in the centre of the diagram. The contours are near to being ellipses, the ideal shape for a least-squares minimization, in the region logb±1.In fact the refinement converges in just 3 iterations when starting in the bottom right corner of this diagram. With Hyperquad2008 the same refinement requires 6 iterations.

## October 2008: Algorithms used in Hyperquad2008

### Betas are constrained to be positive

Thermodynamics requires that equilibrium constants have positive values, as DG = -RT lnK and K = eln K is always positive. It was decided as far back as MINIQUAD (1974) that equilibrium constants would be allowed to have negative values during a refinement rather than make the refinement to fail because a value was physically impossible. The logic of this decision was that the values might return to the positive domain. The downside of this strategy is that it conflicts with another physical requirement, namely, that the free concentration of a reagent cannot have a negative value.

At each cycle of refinement the values of the equilibrium constant are adjusted by adding increments, elements of the shift vector db.

b b + db

In Hyperquad2008 a simple constraint is introduced. If, during refinement, an equilibrium constant is tending towards a negative value, the length of the shift vector is reduced such that the value of log b for that species is reduced by 0.5. Typically, if an equilibrium constant value is initially badly over-estimated, the shift vector might be too long, leading, possibly, to a negative value. In this case the reduction in length of the shift vector will be effective. If the tendency towards a negative value persists the refinement is terminated.

An alternative strategy would be to refine log b values. This strategy was rejected for two reasons. a) the refinement process is less efficient and b) it would force all constants to have positive values, even when a species is not present in the equilibria.

### Divergence during refinement

Divergence is the phenomenon where the sum of squared residuals increases from one refinement cycle to the next. This can occur because the least-squares system is non-linear, so convergence at any one iteration is not guaranteed. Divergence occurs when the shift vector, db, is either too long or pointing away from the place where the sum of squares has its minimum value, or both. In MINIQUAD the problem of divergence was addressed by reducing the length of the shift vector. However, with SUPERQUAD and subsequent programs the Marquardt parameter was introduced. The effect of increasing this parameter is to rotate the shift vector towards the direction of steepest descent and to reduce its length. In principle this is a more powerful method, but it proved tricky to apply in practice, especially when a beta value had a negative value.

In Hyperquad2008 we have returned to shift-cutting:. The length of the shift vector is successively reduced by a factor of two until a lower sum of squares is found. Unlike with MINIQUAD, there is no optimisation of the length of the shift vector. This strategy is probably less efficient than one using the Marquardt parameter, but the speed of modern computers is such that this is no longer an important issue. If the length is reduced by a factor of 1000 or more, the refinement is terminated.

### Calculation of free concentrations

The free concentrations are found by solving the mass-balance equations. This can be illustrated by considering equilibria involving the protonation of a dibasic ligand, when the mass-balance equations are (omitting electrical charges)

TL= [L] +b11[L][H]+b12[L][H]2

TH= [H] +b11[L][H]+2b12[L][H]2-b0 -1[H]-1

The unknown free concentrations [L] and [H] are found by a variation of Newton's method for non-linear equations. In all previous programs this required that the free concentration be constrained, somewhat artificially, to always have positive values. In Hyperquad2008 it is the values of ln[L] and ln[H] that are refined. This process is less efficient but the non-negativity constraint applies naturally with the change of variable.

## Setember 2005: HyperQuad Data files

A new format for data files for programs in the Hyperquad suite has been developed. The new files have the extension HQD. The format is based on the XML concept where data items or groups of data items are enclosed in specific tags. For example a temperature in degrees centigrade could be stored as <TC>25</TC>. Thus all the data required to define a chemical model for a set of equilibria are enclosed in the tags <model> ... </model> and this data is accesible to all programs, Hyperquad, HypSpec, HypNMR, HypDH and HySS. The advantage of this new format is that a single file will suffice for any or all of the programs. Further, additional items can be added to the standard and files without the additional data will still be readable by the programs.

A particular feature is the "integration" of HySS with the other programs through the sharing of the common model section in the data file. Stability Constants home page