jambaugh said:
You can solve for K1 and K2 analytically from your first two equations... provided you know H,G, HG, and H2G. Two of these 4 can be eliminated, or rather replaced by H0 and G0 by your second two equations.
It is unclear what you mean by "optimize K1 and K2" if you're talking least square error you're estimating them from random data so as to optimize (minimize) that least square error which you need to be able to express. There will be some choices to make in terms of defining your error function based on which variable you consider to be free and which to be independent, and how much you don't care about that and want to keep the math simpler.
You speak of the 12 experiments represented by 12 equations but what exactly is the experimental data? Which variables are being observed? (And what is the meaning of the three additional quantities A1,A2, and A3 that you're throwing in there.
Before you go about throwing algorithms at the problem you should understand in principle how it would be solved analytically. It looks to me like you're trying to do a non-linear regression problem. So if (I'm making an assumption here in order to proceed) if your experimental data consists of a set of data values for your 4 main variables (H,G, HG, H2G) you can think of that as 12 random points in an abstract 4-dimensional space.
You spoke of H0 and G0 being different for each experiment so you cannot assume these points lie on the same surface defined by the 2nd pair of equations you gave (for a single choice of H0 and G0) so for this problem I would guess you can ignore those constants and stick to the relationship defined by the first two equations. I see two ways to approach this. For a specific choice of K1 and K2 you have 4-2 =2 dimensional surface in that 4-space. As you have it written giving HG and H2G as functions of H and G I would assume you'd treat H and G as independent variables and thus look at the error as the difference between the (HG,H2G) values from your data vs the values predicted by the equation for the values of K1,K2. You would then define some type of error function as:
E1^2 = Sum of (HG - K1 H G)^2
E2^2 = Sum of (H2G - K2 H G)^2
Err^2 = aE1^2+bE2^2
where you're summing over the 12 experiments. (since the two errors depend only on their own respective parameter the weights won't affect anything. The shape of the paraboloid will not affect the location of the minimum point. )
And the task is to choose K1 and K2 to minimize these errors. That's a classic multi-variable optimization problem, the derivatives of the error with respect to each K are:
dE/dK1 = a Sum of - 2 H G (HG - K1 H G)
dE/dK2 = b Sum of - 2 H G (H2G - K2 H G)
Then you set these to zero and solve...
(I'm going to divide by the sample size to convert sums to averages which I place in angle brackets: <H> = 1/12 Sum of H, etc. )
This gives the optimizing equations as:
<H G HG > = K1 <H G>
<H G H2G > = K2 <H G>
So you should average (or sum) over your 12 experiments the products P1 = H*G*HG, and P2 = H*G*H2G and P = H*G then your least square error will be obtained from:
K1 = <P1>/<P> = Sum of P1 / Sum of P
and
K2 = <P2>/<P> = Sum of P2 / Sum of P.
That is the direct non-linear regression using the form of your equations with my assumption about dependent vs independent. You can also work it reversing the dependent and independent pairs or using a wilder combination. You can also ignore dependence and minimize the direct distance from the points to the regression curve (a much nastier optimization problem.) There may also be, in your application, a reason to account for the 2nd two equations which you could bring into the mix by using them to eliminate two of your first 4 variables. I don't think this will have any effect on the answer (subject to keeping the same choice of independent variables) given they have a linear relationship.
I hope that was helpful
Firstly, thank you so much for your help.
You wrote this term to calculate the error : E1^2 = Sum of (HG - K1 H G)^2
This assumes I know HG. I don't know H, G, H2H or HG in any of the experiments actually. I only know H0, G0 and these constants which I labeled ##A_1,A_2,A_3##.
The constants ##A_1, A_2, A_3## are the same across all 12 experiments, but the values for ##A_0,H_0,G_0## change
Also very sorry, I forgot one term in the experimental equations, I forgot to add the ##A_0## term, so I edited the experimental equations above. they are really all of the form $$A_{0m}H_{0m}=A_1H+A_2HG+A_3H_2G\\\\m\in[1,12]\\\\G_0=G_{0m}$$ I had originally left out the ##A_0## term.
So... If I was going to do what you said, I would have something like this for the error (E):
$$E^2=\sum_{m=0}^{12} ( A_{0m}H_{0m}-A_1H-A_2HG-A_3H_2G)^2 $$
or, solving for HG and H2G in terms of K(H)(G), and H in terms of H0, HG, H2G :
$$
E^2 = \sum_{m=0}^{12} A_{0m}H_{0m}-A_1k_1(H)(G)-A_2k_2(H)(G)-A_3(k_1(H)(G)+2k_2(H)(G)-H_{0m})^2
$$
So to calculate this residual sum:
Step 1 guess ##k_1## and ##K_2##.
Step 2 : solve for H, G, HG, H2G given ##k_1,K_2,H_{0m},G_{0m}##
Step 3 : plug all of those numbers into this residual calculation to get the error.
Step 4 : take the derivative of residual with respect to K1 and K2. Set dE^2/dK1 = 0 and dE^2/dK2 = 0. Solve for K1, K2 such that these both equal 0.
Step 5 : repeat until residual error does not noticeably change anymore.
I am a bit confused about step 4, because if I guess K1 and K2, then the residual will be a constant, and the derivative of a constant is 0. But.. if I calculate the residual with my computed values for H, G, HG, H2G given ##k_1,K_2,H_{0m},G_{0m}##, then take the derivative with respect to K1 and K2 pretending these are unknowns again... then maybe I can solve this equation so K1 and K2 = 0?