none
How to incorporate decsion variables (terms) as argument to Math.Exp()? RRS feed

  • Question

  • Trying to do a 2D gaussian fit with the code snippet

    var solver = SolverContext.GetContext();
                var model = solver.CreateModel();
                var decisionsA = spotParamsA.Select(
                    it => new Decision(Domain.RealNonnegative, it.Key));
                model.AddDecisions(decisionsA.ToArray());
                var decisionsB = spotParamsB.Select(
                    it => new Decision(Domain.Real, it.Key));
                model.AddDecisions(decisionsB.ToArray());

                double x, y;
                var objective = new SumTermBuilder(gaussMatrix.Data_1D.Count());
                var sx = model.Decisions.ElementAt(0);          
                var sy = model.Decisions.ElementAt(1);          
                var sf = model.Decisions.ElementAt(2);           
                var cx = model.Decisions.ElementAt(3);           
                var cy = model.Decisions.ElementAt(4);  

    ...

    Inside the loop of stepping through a 2D data

    var v = (dx * dx) * sx_sq_2_inv + (dy * dy) * sy_sq_2_inv;
                     
                        var value = sf * Math.Exp(-v);
                        var diff = gaussMatrix.Data_1D[n++] - value;
                        objective.Add(diff * diff);

    Compiler complained argument 'v' in Math.Exp() must be double.

    How can I rephrase the problem?

    Thanks,

    Daniel

    Wednesday, January 23, 2019 12:09 PM