0
$\begingroup$

I am using a Module which calculates 3D-data based on 5 parameters and another input dataset. I'd like to fit the result of this modul to another set of data.

Since my code became very long I will break down the idea to a schematic code shown below:

data0 = {{0, 0, 5}, {0, 1, 7}, {1, 0, 9}, {1, 1, 3}}
CalculateData[data_, p0_,p1_] := Module[{data1},
  data1 = calculationBasedOnTheseParameters[data[[i]][[3]]*p1+p0]; 
  Return data1
  ]
data2 = {{0, 0, 10}, {0, 1, 14}, {1, 0, 18}, {1, 1, 6}};
SomeFitFunction[data2, CalculateData[data0, p1,p0], {{p0, 0.1},{p1,2.1}}]

My Problem is that the calculation is based on Interpolation of data0 based on 5 parameters which is the reason why I can't use the LestSquares Function. I did not find a fit function which reduces the LeastSquares of two datasets for a given set of parameters. Of course it might also be possible to extract the values from the data to list. The a function might just compare the average meansquare of every value based on the input parameters; such as

list2 = Table[data2[[i]][3]],{i,1,4}]
(*and the modified function from above:*)
CalculateList[data_, p0_,p1_] := Module[{list1},
  list1 = calculationBasedOnTheseParameters[data[[i]][[3]]*p1+p0]; 
  Return list1
  ]
SomeOtherFitFunction[list2, CalculateList[data0, p1,p0], {{p0, 0.1},{p1,2.1}}]

So do you know a function which works as the wished "Some(Other)FitFunction" in this case?

kind regards Fabian

$\endgroup$

1 Answer 1

0
$\begingroup$

We can use FindMinimum to compute parameters, for example

data0 = {{0, 0, 5}, {0, 1, 7}, {1, 0, 9}, {1, 1, 3}}
CalculateData[data_, p0_, p1_] := 
 Module[{data1}, dim = Dimensions[data]; 
  data1 = Table[
    If[j == 3, data[[i, j]]*p1 + p0, data[[i, j]]], {i, dim[[1]]}, {j,
      dim[[2]]}];
  data1]
data2 = {{0, 0, 10}, {0, 1, 14}, {1, 0, 18}, {1, 1, 6}};

FindMinimum[
 Norm[Mean[data2 - CalculateData[data0, p1, p0]]]^2, {{p0, 1/10}, {p1,
    21/10}}, WorkingPrecision -> 30, AccuracyGoal -> 10, 
 PrecisionGoal -> 10]

Out[]= {1.24738996976747894159133814019*10^-29, {p0 -> 
   1.60810810810810751621742076809, 
  p1 -> 2.35135135135135137085463842344}} 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.