| 920 | |
| 921 | template <typename der_funct, typename T> |
| 922 | double unconstrained_gradient_magnitude ( |
| 923 | const der_funct& grad, |
| 924 | const T& x, |
| 925 | const T& lower, |
| 926 | const T& upper |
| 927 | ) |
| 928 | { |
| 929 | T g = grad(x); |
| 930 | |
| 931 | double unorm = 0; |
| 932 | |
| 933 | for (long i = 0; i < g.size(); ++i) |
| 934 | { |
| 935 | if (lower(i) < x(i) && x(i) < upper(i)) |
| 936 | unorm += g(i)*g(i); |
| 937 | else if (x(i) == lower(i) && g(i) < 0) |
| 938 | unorm += g(i)*g(i); |
| 939 | else if (x(i) == upper(i) && g(i) > 0) |
| 940 | unorm += g(i)*g(i); |
| 941 | } |
| 942 | |
| 943 | return unorm; |
| 944 | } |
| 945 | |
| 946 | template <typename der_funct, typename T> |
| 947 | double unconstrained_gradient_magnitude_neg_funct ( |
no test coverage detected