Ceres为google开源非线性优化库。

计算微分方法

  • 符号微分  Analytic Derivative
  • 数值微分  Numeric Derivative

Forward Difference

Central Difference

Ridders’ Method

  • 自动微分Automatic Derivative

自动微分可以精确快速的算出微分值。

  1 // Ceres Solver - A fast non-linear least squares minimizer
  2 // Copyright 2015 Google Inc. All rights reserved.
  3 // http://ceres-solver.org/
  4 //
  5 // Redistribution and use in source and binary forms, with or without
  6 // modification, are permitted provided that the following conditions are met:
  7 //
  8 // * Redistributions of source code must retain the above copyright notice,
  9 //   this list of conditions and the following disclaimer.
 10 // * Redistributions in binary form must reproduce the above copyright notice,
 11 //   this list of conditions and the following disclaimer in the documentation
 12 //   and/or other materials provided with the distribution.
 13 // * Neither the name of Google Inc. nor the names of its contributors may be
 14 //   used to endorse or promote products derived from this software without
 15 //   specific prior written permission.
 16 //
 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 27 // POSSIBILITY OF SUCH DAMAGE.
 28 //
 29 // Author: keir@google.com (Keir Mierle)
 30 //
 31 // A simple implementation of N-dimensional dual numbers, for automatically
 32 // computing exact derivatives of functions.
 33 //
 34 // While a complete treatment of the mechanics of automatic differentiation is
 35 // beyond the scope of this header (see
 36 // http://en.wikipedia.org/wiki/Automatic_differentiation for details), the
 37 // basic idea is to extend normal arithmetic with an extra element, "e," often
 38 // denoted with the greek symbol epsilon, such that e != 0 but e^2 = 0. Dual
 39 // numbers are extensions of the real numbers analogous to complex numbers:
 40 // whereas complex numbers augment the reals by introducing an imaginary unit i
 41 // such that i^2 = -1, dual numbers introduce an "infinitesimal" unit e such
 42 // that e^2 = 0. Dual numbers have two components: the "real" component and the
 43 // "infinitesimal" component, generally written as x + y*e. Surprisingly, this
 44 // leads to a convenient method for computing exact derivatives without needing
 45 // to manipulate complicated symbolic expressions.
 46 //
 47 // For example, consider the function
 48 //
 49 //   f(x) = x^2 ,
 50 //
 51 // evaluated at 10. Using normal arithmetic, f(10) = 100, and df/dx(10) = 20.
 52 // Next, argument 10 with an infinitesimal to get:
 53 //
 54 //   f(10 + e) = (10 + e)^2
 55 //             = 100 + 2 * 10 * e + e^2
 56 //             = 100 + 20 * e       -+-
 57 //                     --            |
 58 //                     |             +--- This is zero, since e^2 = 0
 59 //                     |
 60 //                     +----------------- This is df/dx!
 61 //
 62 // Note that the derivative of f with respect to x is simply the infinitesimal
 63 // component of the value of f(x + e). So, in order to take the derivative of
 64 // any function, it is only necessary to replace the numeric "object" used in
 65 // the function with one extended with infinitesimals. The class Jet, defined in
 66 // this header, is one such example of this, where substitution is done with
 67 // templates.
 68 //
 69 // To handle derivatives of functions taking multiple arguments, different
 70 // infinitesimals are used, one for each variable to take the derivative of. For
 71 // example, consider a scalar function of two scalar parameters x and y:
 72 //
 73 //   f(x, y) = x^2 + x * y
 74 //
 75 // Following the technique above, to compute the derivatives df/dx and df/dy for
 76 // f(1, 3) involves doing two evaluations of f, the first time replacing x with
 77 // x + e, the second time replacing y with y + e.
 78 //
 79 // For df/dx:
 80 //
 81 //   f(1 + e, y) = (1 + e)^2 + (1 + e) * 3
 82 //               = 1 + 2 * e + 3 + 3 * e
 83 //               = 4 + 5 * e
 84 //
 85 //               --> df/dx = 5
 86 //
 87 // For df/dy:
 88 //
 89 //   f(1, 3 + e) = 1^2 + 1 * (3 + e)
 90 //               = 1 + 3 + e
 91 //               = 4 + e
 92 //
 93 //               --> df/dy = 1
 94 //
 95 // To take the gradient of f with the implementation of dual numbers ("jets") in
 96 // this file, it is necessary to create a single jet type which has components
 97 // for the derivative in x and y, and passing them to a templated version of f:
 98 //
 99 //   template<typename T>
100 //   T f(const T &x, const T &y) {
101 //     return x * x + x * y;
102 //   }
103 //
104 //   // The "2" means there should be 2 dual number components.
105 //   // It computes the partial derivative at x=10, y=20.
106 //   Jet<double, 2> x(10, 0);  // Pick the 0th dual number for x.
107 //   Jet<double, 2> y(20, 1);  // Pick the 1st dual number for y.
108 //   Jet<double, 2> z = f(x, y);
109 //
110 //   LOG(INFO) << "df/dx = " << z.v[0]
111 //             << "df/dy = " << z.v[1];
112 //
113 // Most users should not use Jet objects directly; a wrapper around Jet objects,
114 // which makes computing the derivative, gradient, or jacobian of templated
115 // functors simple, is in autodiff.h. Even autodiff.h should not be used
116 // directly; instead autodiff_cost_function.h is typically the file of interest.
117 //
118 // For the more mathematically inclined, this file implements first-order
119 // "jets". A 1st order jet is an element of the ring
120 //
121 //   T[N] = T[t_1, ..., t_N] / (t_1, ..., t_N)^2
122 //
123 // which essentially means that each jet consists of a "scalar" value 'a' from T
124 // and a 1st order perturbation vector 'v' of length N:
125 //
126 //   x = a + \sum_i v[i] t_i
127 //
128 // A shorthand is to write an element as x = a + u, where u is the perturbation.
129 // Then, the main point about the arithmetic of jets is that the product of
130 // perturbations is zero:
131 //
132 //   (a + u) * (b + v) = ab + av + bu + uv
133 //                     = ab + (av + bu) + 0
134 //
135 // which is what operator* implements below. Addition is simpler:
136 //
137 //   (a + u) + (b + v) = (a + b) + (u + v).
138 //
139 // The only remaining question is how to evaluate the function of a jet, for
140 // which we use the chain rule:
141 //
142 //   f(a + u) = f(a) + f'(a) u
143 //
144 // where f'(a) is the (scalar) derivative of f at a.
145 //
146 // By pushing these things through sufficiently and suitably templated
147 // functions, we can do automatic differentiation. Just be sure to turn on
148 // function inlining and common-subexpression elimination, or it will be very
149 // slow!
150 //
151 // WARNING: Most Ceres users should not directly include this file or know the
152 // details of how jets work. Instead the suggested method for automatic
153 // derivatives is to use autodiff_cost_function.h, which is a wrapper around
154 // both jets.h and autodiff.h to make taking derivatives of cost functions for
155 // use in Ceres easier.
156 
157 #ifndef CERES_PUBLIC_JET_H_
158 #define CERES_PUBLIC_JET_H_
159 
160 #include <cmath>
161 #include <iosfwd>
162 #include <iostream>  // NOLINT
163 #include <limits>
164 #include <string>
165 
166 #include "Eigen/Core"
167 //#include "ceres/internal/port.h"
168 
169 namespace ceres {
170 
171     template <typename T, int N>
172     struct Jet {
173         enum { DIMENSION = N };
174         typedef T Scalar;
175 
176         // Default-construct "a" because otherwise this can lead to false errors about
177         // uninitialized uses when other classes relying on default constructed T
178         // (where T is a Jet<T, N>). This usually only happens in opt mode. Note that
179         // the C++ standard mandates that e.g. default constructed doubles are
180         // initialized to 0.0; see sections 8.5 of the C++03 standard.
181         Jet() : a() {
182             v.setZero();
183         }
184 
185         // Constructor from scalar: a + 0.
186         explicit Jet(const T& value) {
187             a = value;
188             v.setZero();
189         }
190 
191         // Constructor from scalar plus variable: a + t_i.
192         Jet(const T& value, int k) {
193             a = value;
194             v.setZero();
195             v[k] = T(1.0);
196         }
197 
198         // Constructor from scalar and vector part
199         // The use of Eigen::DenseBase allows Eigen expressions
200         // to be passed in without being fully evaluated until
201         // they are assigned to v
202         template<typename Derived>
203         EIGEN_STRONG_INLINE Jet(const T& a, const Eigen::DenseBase<Derived> &v)
204             : a(a), v(v) {
205         }
206 
207         // Compound operators
208         Jet<T, N>& operator+=(const Jet<T, N> &y) {
209             *this = *this + y;
210             return *this;
211         }
212 
213         Jet<T, N>& operator-=(const Jet<T, N> &y) {
214             *this = *this - y;
215             return *this;
216         }
217 
218         Jet<T, N>& operator*=(const Jet<T, N> &y) {
219             *this = *this * y;
220             return *this;
221         }
222 
223         Jet<T, N>& operator/=(const Jet<T, N> &y) {
224             *this = *this / y;
225             return *this;
226         }
227 
228         // Compound with scalar operators.
229         Jet<T, N>& operator+=(const T& s) {
230             *this = *this + s;
231             return *this;
232         }
233 
234         Jet<T, N>& operator-=(const T& s) {
235             *this = *this - s;
236             return *this;
237         }
238 
239         Jet<T, N>& operator*=(const T& s) {
240             *this = *this * s;
241             return *this;
242         }
243 
244         Jet<T, N>& operator/=(const T& s) {
245             *this = *this / s;
246             return *this;
247         }
248 
249         // The scalar part.
250         T a;
251 
252         // The infinitesimal part.
253         //
254         // We allocate Jets on the stack and other places they might not be aligned
255         // to X(=16 [SSE], 32 [AVX] etc)-byte boundaries, which would prevent the safe
256         // use of vectorisation.  If we have C++11, we can specify the alignment.
257         // However, the standard gives wide latitude as to what alignments are valid,
258         // and it might be that the maximum supported alignment *guaranteed* to be
259         // supported is < 16, in which case we do not specify an alignment, as this
260         // implies the host is not a modern x86 machine.  If using < C++11, we cannot
261         // specify alignment.
262 
263 #if defined(EIGEN_DONT_VECTORIZE)
264         Eigen::Matrix<T, N, 1, Eigen::DontAlign> v;
265 #else
266         // Enable vectorisation iff the maximum supported scalar alignment is >=
267         // 16 bytes, as this is the minimum required by Eigen for any vectorisation.
268         //
269         // NOTE: It might be the case that we could get >= 16-byte alignment even if
270         //       max_align_t < 16.  However we can't guarantee that this
271         //       would happen (and it should not for any modern x86 machine) and if it
272         //       didn't, we could get misaligned Jets.
273         static constexpr int kAlignOrNot =
274             // Work around a GCC 4.8 bug
275             // (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56019) where
276             // std::max_align_t is misplaced.
277 #if defined (__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 8
278             alignof(::max_align_t) >= 16
279 #else
280             alignof(std::max_align_t) >= 16
281 #endif
282             ? Eigen::AutoAlign : Eigen::DontAlign;
283 
284 #if defined(EIGEN_MAX_ALIGN_BYTES)
285         // Eigen >= 3.3 supports AVX & FMA instructions that require 32-byte alignment
286         // (greater for AVX512).  Rather than duplicating the detection logic, use
287         // Eigen's macro for the alignment size.
288         //
289         // NOTE: EIGEN_MAX_ALIGN_BYTES can be > 16 (e.g. 32 for AVX), even though
290         //       kMaxAlignBytes will max out at 16.  We are therefore relying on
291         //       Eigen's detection logic to ensure that this does not result in
292         //       misaligned Jets.
293 #define CERES_JET_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES
294 #else
295         // Eigen < 3.3 only supported 16-byte alignment.
296 #define CERES_JET_ALIGN_BYTES 16
297 #endif
298 
299         // Default to the native alignment if 16-byte alignment is not guaranteed to
300         // be supported.  We cannot use alignof(T) as if we do, GCC 4.8 complains that
301         // the alignment 'is not an integer constant', although Clang accepts it.
302         static constexpr size_t kAlignment = kAlignOrNot == Eigen::AutoAlign
303             ? CERES_JET_ALIGN_BYTES : alignof(double);
304 
305 #undef CERES_JET_ALIGN_BYTES
306         alignas(kAlignment)Eigen::Matrix<T, N, 1, kAlignOrNot> v;
307 #endif
308     };
309 
310     // Unary +
311     template<typename T, int N> inline
312         Jet<T, N> const& operator+(const Jet<T, N>& f) {
313         return f;
314     }
315 
316     // TODO(keir): Try adding __attribute__((always_inline)) to these functions to
317     // see if it causes a performance increase.
318 
319     // Unary -
320     template<typename T, int N> inline
321         Jet<T, N> operator-(const Jet<T, N>&f) {
322         return Jet<T, N>(-f.a, -f.v);
323     }
324 
325     // Binary +
326     template<typename T, int N> inline
327         Jet<T, N> operator+(const Jet<T, N>& f,
328             const Jet<T, N>& g) {
329         return Jet<T, N>(f.a + g.a, f.v + g.v);
330     }
331 
332     // Binary + with a scalar: x + s
333     template<typename T, int N> inline
334         Jet<T, N> operator+(const Jet<T, N>& f, T s) {
335         return Jet<T, N>(f.a + s, f.v);
336     }
337 
338     // Binary + with a scalar: s + x
339     template<typename T, int N> inline
340         Jet<T, N> operator+(T s, const Jet<T, N>& f) {
341         return Jet<T, N>(f.a + s, f.v);
342     }
343 
344     // Binary -
345     template<typename T, int N> inline
346         Jet<T, N> operator-(const Jet<T, N>& f,
347             const Jet<T, N>& g) {
348         return Jet<T, N>(f.a - g.a, f.v - g.v);
349     }
350 
351     // Binary - with a scalar: x - s
352     template<typename T, int N> inline
353         Jet<T, N> operator-(const Jet<T, N>& f, T s) {
354         return Jet<T, N>(f.a - s, f.v);
355     }
356 
357     // Binary - with a scalar: s - x
358     template<typename T, int N> inline
359         Jet<T, N> operator-(T s, const Jet<T, N>& f) {
360         return Jet<T, N>(s - f.a, -f.v);
361     }
362 
363     // Binary *
364     template<typename T, int N> inline
365         Jet<T, N> operator*(const Jet<T, N>& f,
366             const Jet<T, N>& g) {
367         return Jet<T, N>(f.a * g.a, f.a * g.v + f.v * g.a);
368     }
369 
370     // Binary * with a scalar: x * s
371     template<typename T, int N> inline
372         Jet<T, N> operator*(const Jet<T, N>& f, T s) {
373         return Jet<T, N>(f.a * s, f.v * s);
374     }
375 
376     // Binary * with a scalar: s * x
377     template<typename T, int N> inline
378         Jet<T, N> operator*(T s, const Jet<T, N>& f) {
379         return Jet<T, N>(f.a * s, f.v * s);
380     }
381 
382     // Binary /
383     template<typename T, int N> inline
384         Jet<T, N> operator/(const Jet<T, N>& f,
385             const Jet<T, N>& g) {
386         // This uses:
387         //
388         //   a + u   (a + u)(b - v)   (a + u)(b - v)
389         //   ----- = -------------- = --------------
390         //   b + v   (b + v)(b - v)        b^2
391         //
392         // which holds because v*v = 0.
393         const T g_a_inverse = T(1.0) / g.a;
394         const T f_a_by_g_a = f.a * g_a_inverse;
395         return Jet<T, N>(f_a_by_g_a, (f.v - f_a_by_g_a * g.v) * g_a_inverse);
396     }
397 
398     // Binary / with a scalar: s / x
399     template<typename T, int N> inline
400         Jet<T, N> operator/(T s, const Jet<T, N>& g) {
401         const T minus_s_g_a_inverse2 = -s / (g.a * g.a);
402         return Jet<T, N>(s / g.a, g.v * minus_s_g_a_inverse2);
403     }
404 
405     // Binary / with a scalar: x / s
406     template<typename T, int N> inline
407         Jet<T, N> operator/(const Jet<T, N>& f, T s) {
408         const T s_inverse = T(1.0) / s;
409         return Jet<T, N>(f.a * s_inverse, f.v * s_inverse);
410     }
411 
412     // Binary comparison operators for both scalars and jets.
413 #define CERES_DEFINE_JET_COMPARISON_OPERATOR(op) \
414 template<typename T, int N> inline \
415 bool operator op(const Jet<T, N>& f, const Jet<T, N>& g) { \
416   return f.a op g.a; \
417 } \
418 template<typename T, int N> inline \
419 bool operator op(const T& s, const Jet<T, N>& g) { \
420   return s op g.a; \
421 } \
422 template<typename T, int N> inline \
423 bool operator op(const Jet<T, N>& f, const T& s) { \
424   return f.a op s; \
425 }
426     CERES_DEFINE_JET_COMPARISON_OPERATOR(< )  // NOLINT
427         CERES_DEFINE_JET_COMPARISON_OPERATOR(<= )  // NOLINT
428         CERES_DEFINE_JET_COMPARISON_OPERATOR(> )  // NOLINT
429         CERES_DEFINE_JET_COMPARISON_OPERATOR(>= )  // NOLINT
430         CERES_DEFINE_JET_COMPARISON_OPERATOR(== )  // NOLINT
431         CERES_DEFINE_JET_COMPARISON_OPERATOR(!= )  // NOLINT
432 #undef CERES_DEFINE_JET_COMPARISON_OPERATOR
433 
434                                                    // Pull some functions from namespace std.
435                                                    //
436                                                    // This is necessary because we want to use the same name (e.g. 'sqrt') for
437                                                    // double-valued and Jet-valued functions, but we are not allowed to put
438                                                    // Jet-valued functions inside namespace std.
439         using std::abs;
440     using std::acos;
441     using std::asin;
442     using std::atan;
443     using std::atan2;
444     using std::cbrt;
445     using std::ceil;
446     using std::cos;
447     using std::cosh;
448     using std::exp;
449     using std::exp2;
450     using std::floor;
451     using std::fmax;
452     using std::fmin;
453     using std::hypot;
454     using std::isfinite;
455     using std::isinf;
456     using std::isnan;
457     using std::isnormal;
458     using std::log;
459     using std::log2;
460     using std::pow;
461     using std::sin;
462     using std::sinh;
463     using std::sqrt;
464     using std::tan;
465     using std::tanh;
466 
467     // Legacy names from pre-C++11 days.
468     inline bool IsFinite(double x) { return std::isfinite(x); }
469     inline bool IsInfinite(double x) { return std::isinf(x); }
470     inline bool IsNaN(double x) { return std::isnan(x); }
471     inline bool IsNormal(double x) { return std::isnormal(x); }
472 
473     // In general, f(a + h) ~= f(a) + f'(a) h, via the chain rule.
474 
475     // abs(x + h) ~= x + h or -(x + h)
476     template <typename T, int N> inline
477         Jet<T, N> abs(const Jet<T, N>& f) {
478         return f.a < T(0.0) ? -f : f;
479     }
480 
481     // log(a + h) ~= log(a) + h / a
482     template <typename T, int N> inline
483         Jet<T, N> log(const Jet<T, N>& f) {
484         const T a_inverse = T(1.0) / f.a;
485         return Jet<T, N>(log(f.a), f.v * a_inverse);
486     }
487 
488     // exp(a + h) ~= exp(a) + exp(a) h
489     template <typename T, int N> inline
490         Jet<T, N> exp(const Jet<T, N>& f) {
491         const T tmp = exp(f.a);
492         return Jet<T, N>(tmp, tmp * f.v);
493     }
494 
495     // sqrt(a + h) ~= sqrt(a) + h / (2 sqrt(a))
496     template <typename T, int N> inline
497         Jet<T, N> sqrt(const Jet<T, N>& f) {
498         const T tmp = sqrt(f.a);
499         const T two_a_inverse = T(1.0) / (T(2.0) * tmp);
500         return Jet<T, N>(tmp, f.v * two_a_inverse);
501     }
502 
503     // cos(a + h) ~= cos(a) - sin(a) h
504     template <typename T, int N> inline
505         Jet<T, N> cos(const Jet<T, N>& f) {
506         return Jet<T, N>(cos(f.a), -sin(f.a) * f.v);
507     }
508 
509     // acos(a + h) ~= acos(a) - 1 / sqrt(1 - a^2) h
510     template <typename T, int N> inline
511         Jet<T, N> acos(const Jet<T, N>& f) {
512         const T tmp = -T(1.0) / sqrt(T(1.0) - f.a * f.a);
513         return Jet<T, N>(acos(f.a), tmp * f.v);
514     }
515 
516     // sin(a + h) ~= sin(a) + cos(a) h
517     template <typename T, int N> inline
518         Jet<T, N> sin(const Jet<T, N>& f) {
519         return Jet<T, N>(sin(f.a), cos(f.a) * f.v);
520     }
521 
522     // asin(a + h) ~= asin(a) + 1 / sqrt(1 - a^2) h
523     template <typename T, int N> inline
524         Jet<T, N> asin(const Jet<T, N>& f) {
525         const T tmp = T(1.0) / sqrt(T(1.0) - f.a * f.a);
526         return Jet<T, N>(asin(f.a), tmp * f.v);
527     }
528 
529     // tan(a + h) ~= tan(a) + (1 + tan(a)^2) h
530     template <typename T, int N> inline
531         Jet<T, N> tan(const Jet<T, N>& f) {
532         const T tan_a = tan(f.a);
533         const T tmp = T(1.0) + tan_a * tan_a;
534         return Jet<T, N>(tan_a, tmp * f.v);
535     }
536 
537     // atan(a + h) ~= atan(a) + 1 / (1 + a^2) h
538     template <typename T, int N> inline
539         Jet<T, N> atan(const Jet<T, N>& f) {
540         const T tmp = T(1.0) / (T(1.0) + f.a * f.a);
541         return Jet<T, N>(atan(f.a), tmp * f.v);
542     }
543 
544     // sinh(a + h) ~= sinh(a) + cosh(a) h
545     template <typename T, int N> inline
546         Jet<T, N> sinh(const Jet<T, N>& f) {
547         return Jet<T, N>(sinh(f.a), cosh(f.a) * f.v);
548     }
549 
550     // cosh(a + h) ~= cosh(a) + sinh(a) h
551     template <typename T, int N> inline
552         Jet<T, N> cosh(const Jet<T, N>& f) {
553         return Jet<T, N>(cosh(f.a), sinh(f.a) * f.v);
554     }
555 
556     // tanh(a + h) ~= tanh(a) + (1 - tanh(a)^2) h
557     template <typename T, int N> inline
558         Jet<T, N> tanh(const Jet<T, N>& f) {
559         const T tanh_a = tanh(f.a);
560         const T tmp = T(1.0) - tanh_a * tanh_a;
561         return Jet<T, N>(tanh_a, tmp * f.v);
562     }
563 
564     // The floor function should be used with extreme care as this operation will
565     // result in a zero derivative which provides no information to the solver.
566     //
567     // floor(a + h) ~= floor(a) + 0
568     template <typename T, int N> inline
569         Jet<T, N> floor(const Jet<T, N>& f) {
570         return Jet<T, N>(floor(f.a));
571     }
572 
573     // The ceil function should be used with extreme care as this operation will
574     // result in a zero derivative which provides no information to the solver.
575     //
576     // ceil(a + h) ~= ceil(a) + 0
577     template <typename T, int N> inline
578         Jet<T, N> ceil(const Jet<T, N>& f) {
579         return Jet<T, N>(ceil(f.a));
580     }
581 
582     // Some new additions to C++11:
583 
584     // cbrt(a + h) ~= cbrt(a) + h / (3 a ^ (2/3))
585     template <typename T, int N> inline
586         Jet<T, N> cbrt(const Jet<T, N>& f) {
587         const T derivative = T(1.0) / (T(3.0) * cbrt(f.a * f.a));
588         return Jet<T, N>(cbrt(f.a), f.v * derivative);
589     }
590 
591     // exp2(x + h) = 2^(x+h) ~= 2^x + h*2^x*log(2)
592     template <typename T, int N> inline
593         Jet<T, N> exp2(const Jet<T, N>& f) {
594         const T tmp = exp2(f.a);
595         const T derivative = tmp * log(T(2));
596         return Jet<T, N>(tmp, f.v * derivative);
597     }
598 
599     // log2(x + h) ~= log2(x) + h / (x * log(2))
600     template <typename T, int N> inline
601         Jet<T, N> log2(const Jet<T, N>& f) {
602         const T derivative = T(1.0) / (f.a * log(T(2)));
603         return Jet<T, N>(log2(f.a), f.v * derivative);
604     }
605 
606     // Like sqrt(x^2 + y^2),
607     // but acts to prevent underflow/overflow for small/large x/y.
608     // Note that the function is non-smooth at x=y=0,
609     // so the derivative is undefined there.
610     template <typename T, int N> inline
611         Jet<T, N> hypot(const Jet<T, N>& x, const Jet<T, N>& y) {
612         // d/da sqrt(a) = 0.5 / sqrt(a)
613         // d/dx x^2 + y^2 = 2x
614         // So by the chain rule:
615         // d/dx sqrt(x^2 + y^2) = 0.5 / sqrt(x^2 + y^2) * 2x = x / sqrt(x^2 + y^2)
616         // d/dy sqrt(x^2 + y^2) = y / sqrt(x^2 + y^2)
617         const T tmp = hypot(x.a, y.a);
618         return Jet<T, N>(tmp, x.a / tmp * x.v + y.a / tmp * y.v);
619     }
620 
621     template <typename T, int N> inline
622         const Jet<T, N>& fmax(const Jet<T, N>& x, const Jet<T, N>& y) {
623         return x < y ? y : x;
624     }
625 
626     template <typename T, int N> inline
627         const Jet<T, N>& fmin(const Jet<T, N>& x, const Jet<T, N>& y) {
628         return y < x ? y : x;
629     }
630 
631     // Bessel functions of the first kind with integer order equal to 0, 1, n.
632     //
633     // Microsoft has deprecated the j[0,1,n]() POSIX Bessel functions in favour of
634     // _j[0,1,n]().  Where available on MSVC, use _j[0,1,n]() to avoid deprecated
635     // function errors in client code (the specific warning is suppressed when
636     // Ceres itself is built).
637     inline double BesselJ0(double x) {
638 #if defined(CERES_MSVC_USE_UNDERSCORE_PREFIXED_BESSEL_FUNCTIONS)
639         return _j0(x);
640 #else
641         return j0(x);
642 #endif
643     }
644     inline double BesselJ1(double x) {
645 #if defined(CERES_MSVC_USE_UNDERSCORE_PREFIXED_BESSEL_FUNCTIONS)
646         return _j1(x);
647 #else
648         return j1(x);
649 #endif
650     }
651     inline double BesselJn(int n, double x) {
652 #if defined(CERES_MSVC_USE_UNDERSCORE_PREFIXED_BESSEL_FUNCTIONS)
653         return _jn(n, x);
654 #else
655         return jn(n, x);
656 #endif
657     }
658 
659     // For the formulae of the derivatives of the Bessel functions see the book:
660     // Olver, Lozier, Boisvert, Clark, NIST Handbook of Mathematical Functions,
661     // Cambridge University Press 2010.
662     //
663     // Formulae are also available at http://dlmf.nist.gov
664 
665     // See formula http://dlmf.nist.gov/10.6#E3
666     // j0(a + h) ~= j0(a) - j1(a) h
667     template <typename T, int N> inline
668         Jet<T, N> BesselJ0(const Jet<T, N>& f) {
669         return Jet<T, N>(BesselJ0(f.a),
670             -BesselJ1(f.a) * f.v);
671     }
672 
673     // See formula http://dlmf.nist.gov/10.6#E1
674     // j1(a + h) ~= j1(a) + 0.5 ( j0(a) - j2(a) ) h
675     template <typename T, int N> inline
676         Jet<T, N> BesselJ1(const Jet<T, N>& f) {
677         return Jet<T, N>(BesselJ1(f.a),
678             T(0.5) * (BesselJ0(f.a) - BesselJn(2, f.a)) * f.v);
679     }
680 
681     // See formula http://dlmf.nist.gov/10.6#E1
682     // j_n(a + h) ~= j_n(a) + 0.5 ( j_{n-1}(a) - j_{n+1}(a) ) h
683     template <typename T, int N> inline
684         Jet<T, N> BesselJn(int n, const Jet<T, N>& f) {
685         return Jet<T, N>(BesselJn(n, f.a),
686             T(0.5) * (BesselJn(n - 1, f.a) - BesselJn(n + 1, f.a)) * f.v);
687     }
688 
689     // Jet Classification. It is not clear what the appropriate semantics are for
690     // these classifications. This picks that std::isfinite and std::isnormal are "all"
691     // operations, i.e. all elements of the jet must be finite for the jet itself
692     // to be finite (or normal). For IsNaN and IsInfinite, the answer is less
693     // clear. This takes a "any" approach for IsNaN and IsInfinite such that if any
694     // part of a jet is nan or inf, then the entire jet is nan or inf. This leads
695     // to strange situations like a jet can be both IsInfinite and IsNaN, but in
696     // practice the "any" semantics are the most useful for e.g. checking that
697     // derivatives are sane.
698 
699     // The jet is finite if all parts of the jet are finite.
700     template <typename T, int N> inline
701         bool isfinite(const Jet<T, N>& f) {
702         if (!std::isfinite(f.a)) {
703             return false;
704         }
705         for (int i = 0; i < N; ++i) {
706             if (!std::isfinite(f.v[i])) {
707                 return false;
708             }
709         }
710         return true;
711     }
712 
713     // The jet is infinite if any part of the Jet is infinite.
714     template <typename T, int N> inline
715         bool isinf(const Jet<T, N>& f) {
716         if (std::isinf(f.a)) {
717             return true;
718         }
719         for (int i = 0; i < N; ++i) {
720             if (std::isinf(f.v[i])) {
721                 return true;
722             }
723         }
724         return false;
725     }
726 
727 
728     // The jet is NaN if any part of the jet is NaN.
729     template <typename T, int N> inline
730         bool isnan(const Jet<T, N>& f) {
731         if (std::isnan(f.a)) {
732             return true;
733         }
734         for (int i = 0; i < N; ++i) {
735             if (std::isnan(f.v[i])) {
736                 return true;
737             }
738         }
739         return false;
740     }
741 
742     // The jet is normal if all parts of the jet are normal.
743     template <typename T, int N> inline
744         bool isnormal(const Jet<T, N>& f) {
745         if (!std::isnormal(f.a)) {
746             return false;
747         }
748         for (int i = 0; i < N; ++i) {
749             if (!std::isnormal(f.v[i])) {
750                 return false;
751             }
752         }
753         return true;
754     }
755 
756     // Legacy functions from the pre-C++11 days.
757     template <typename T, int N>
758     inline bool IsFinite(const Jet<T, N>& f) {
759         return isfinite(f);
760     }
761 
762     template <typename T, int N>
763     inline bool IsNaN(const Jet<T, N>& f) {
764         return isnan(f);
765     }
766 
767     template <typename T, int N>
768     inline bool IsNormal(const Jet<T, N>& f) {
769         return isnormal(f);
770     }
771 
772     // The jet is infinite if any part of the jet is infinite.
773     template <typename T, int N> inline
774         bool IsInfinite(const Jet<T, N>& f) {
775         return isinf(f);
776     }
777 
778     // atan2(b + db, a + da) ~= atan2(b, a) + (- b da + a db) / (a^2 + b^2)
779     //
780     // In words: the rate of change of theta is 1/r times the rate of
781     // change of (x, y) in the positive angular direction.
782     template <typename T, int N> inline
783         Jet<T, N> atan2(const Jet<T, N>& g, const Jet<T, N>& f) {
784         // Note order of arguments:
785         //
786         //   f = a + da
787         //   g = b + db
788 
789         T const tmp = T(1.0) / (f.a * f.a + g.a * g.a);
790         return Jet<T, N>(atan2(g.a, f.a), tmp * (-g.a * f.v + f.a * g.v));
791     }
792 
793 
794     // pow -- base is a differentiable function, exponent is a constant.
795     // (a+da)^p ~= a^p + p*a^(p-1) da
796     template <typename T, int N> inline
797         Jet<T, N> pow(const Jet<T, N>& f, double g) {
798         T const tmp = g * pow(f.a, g - T(1.0));
799         return Jet<T, N>(pow(f.a, g), tmp * f.v);
800     }
801 
802     // pow -- base is a constant, exponent is a differentiable function.
803     // We have various special cases, see the comment for pow(Jet, Jet) for
804     // analysis:
805     //
806     // 1. For f > 0 we have: (f)^(g + dg) ~= f^g + f^g log(f) dg
807     //
808     // 2. For f == 0 and g > 0 we have: (f)^(g + dg) ~= f^g
809     //
810     // 3. For f < 0 and integer g we have: (f)^(g + dg) ~= f^g but if dg
811     // != 0, the derivatives are not defined and we return NaN.
812 
813     template <typename T, int N> inline
814         Jet<T, N> pow(double f, const Jet<T, N>& g) {
815         if (f == 0 && g.a > 0) {
816             // Handle case 2.
817             return Jet<T, N>(T(0.0));
818         }
819         if (f < 0 && g.a == floor(g.a)) {
820             // Handle case 3.
821             Jet<T, N> ret(pow(f, g.a));
822             for (int i = 0; i < N; i++) {
823                 if (g.v[i] != T(0.0)) {
824                     // Return a NaN when g.v != 0.
825                     ret.v[i] = std::numeric_limits<T>::quiet_NaN();
826                 }
827             }
828             return ret;
829         }
830         // Handle case 1.
831         T const tmp = pow(f, g.a);
832         return Jet<T, N>(tmp, log(f) * tmp * g.v);
833     }
834 
835     // pow -- both base and exponent are differentiable functions. This has a
836     // variety of special cases that require careful handling.
837     //
838     // 1. For f > 0:
839     //    (f + df)^(g + dg) ~= f^g + f^(g - 1) * (g * df + f * log(f) * dg)
840     //    The numerical evaluation of f * log(f) for f > 0 is well behaved, even for
841     //    extremely small values (e.g. 1e-99).
842     //
843     // 2. For f == 0 and g > 1: (f + df)^(g + dg) ~= 0
844     //    This cases is needed because log(0) can not be evaluated in the f > 0
845     //    expression. However the function f*log(f) is well behaved around f == 0
846     //    and its limit as f-->0 is zero.
847     //
848     // 3. For f == 0 and g == 1: (f + df)^(g + dg) ~= 0 + df
849     //
850     // 4. For f == 0 and 0 < g < 1: The value is finite but the derivatives are not.
851     //
852     // 5. For f == 0 and g < 0: The value and derivatives of f^g are not finite.
853     //
854     // 6. For f == 0 and g == 0: The C standard incorrectly defines 0^0 to be 1
855     //    "because there are applications that can exploit this definition". We
856     //    (arbitrarily) decree that derivatives here will be nonfinite, since that
857     //    is consistent with the behavior for f == 0, g < 0 and 0 < g < 1.
858     //    Practically any definition could have been justified because mathematical
859     //    consistency has been lost at this point.
860     //
861     // 7. For f < 0, g integer, dg == 0: (f + df)^(g + dg) ~= f^g + g * f^(g - 1) df
862     //    This is equivalent to the case where f is a differentiable function and g
863     //    is a constant (to first order).
864     //
865     // 8. For f < 0, g integer, dg != 0: The value is finite but the derivatives are
866     //    not, because any change in the value of g moves us away from the point
867     //    with a real-valued answer into the region with complex-valued answers.
868     //
869     // 9. For f < 0, g noninteger: The value and derivatives of f^g are not finite.
870 
871     template <typename T, int N> inline
872         Jet<T, N> pow(const Jet<T, N>& f, const Jet<T, N>& g) {
873         if (f.a == 0 && g.a >= 1) {
874             // Handle cases 2 and 3.
875             if (g.a > 1) {
876                 return Jet<T, N>(T(0.0));
877             }
878             return f;
879         }
880         if (f.a < 0 && g.a == floor(g.a)) {
881             // Handle cases 7 and 8.
882             T const tmp = g.a * pow(f.a, g.a - T(1.0));
883             Jet<T, N> ret(pow(f.a, g.a), tmp * f.v);
884             for (int i = 0; i < N; i++) {
885                 if (g.v[i] != T(0.0)) {
886                     // Return a NaN when g.v != 0.
887                     ret.v[i] = std::numeric_limits<T>::quiet_NaN();
888                 }
889             }
890             return ret;
891         }
892         // Handle the remaining cases. For cases 4,5,6,9 we allow the log() function
893         // to generate -HUGE_VAL or NaN, since those cases result in a nonfinite
894         // derivative.
895         T const tmp1 = pow(f.a, g.a);
896         T const tmp2 = g.a * pow(f.a, g.a - T(1.0));
897         T const tmp3 = tmp1 * log(f.a);
898         return Jet<T, N>(tmp1, tmp2 * f.v + tmp3 * g.v);
899     }
900 
901     // Note: This has to be in the ceres namespace for argument dependent lookup to
902     // function correctly. Otherwise statements like CHECK_LE(x, 2.0) fail with
903     // strange compile errors.
904     template <typename T, int N>
905     inline std::ostream &operator<<(std::ostream &s, const Jet<T, N>& z) {
906         s << "[" << z.a << " ; ";
907         for (int i = 0; i < N; ++i) {
908             s << z.v[i];
909             if (i != N - 1) {
910                 s << ", ";
911             }
912         }
913         s << "]";
914         return s;
915     }
916 
917 }  // namespace ceres
918 
919 namespace Eigen {
920 
921     // Creating a specialization of NumTraits enables placing Jet objects inside
922     // Eigen arrays, getting all the goodness of Eigen combined with autodiff.
923     template<typename T, int N>
924     struct NumTraits<ceres::Jet<T, N>> {
925         typedef ceres::Jet<T, N> Real;
926         typedef ceres::Jet<T, N> NonInteger;
927         typedef ceres::Jet<T, N> Nested;
928         typedef ceres::Jet<T, N> Literal;
929 
930         static typename ceres::Jet<T, N> dummy_precision() {
931             return ceres::Jet<T, N>(1e-12);
932         }
933 
934         static inline Real epsilon() {
935             return Real(std::numeric_limits<T>::epsilon());
936         }
937 
938         static inline int digits10() { return NumTraits<T>::digits10(); }
939 
940         enum {
941             IsComplex = 0,
942             IsInteger = 0,
943             IsSigned,
944             ReadCost = 1,
945             AddCost = 1,
946             // For Jet types, multiplication is more expensive than addition.
947             MulCost = 3,
948             HasFloatingPoint = 1,
949             RequireInitialization = 1
950         };
951 
952         template<bool Vectorized>
953         struct Div {
954             enum {
955 #if defined(EIGEN_VECTORIZE_AVX)
956                 AVX = true,
957 #else
958                 AVX = false,
959 #endif
960 
961                 // Assuming that for Jets, division is as expensive as
962                 // multiplication.
963                 Cost = 3
964             };
965         };
966 
967         static inline Real highest() { return Real(std::numeric_limits<T>::max()); }
968         static inline Real lowest() { return Real(-std::numeric_limits<T>::max()); }
969     };
970 
971 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
972     // Specifying the return type of binary operations between Jets and scalar types
973     // allows you to perform matrix/array operations with Eigen matrices and arrays
974     // such as addition, subtraction, multiplication, and division where one Eigen
975     // matrix/array is of type Jet and the other is a scalar type. This improves
976     // performance by using the optimized scalar-to-Jet binary operations but
977     // is only available on Eigen versions >= 3.3
978     template <typename BinaryOp, typename T, int N>
979     struct ScalarBinaryOpTraits<ceres::Jet<T, N>, T, BinaryOp> {
980         typedef ceres::Jet<T, N> ReturnType;
981     };
982     template <typename BinaryOp, typename T, int N>
983     struct ScalarBinaryOpTraits<T, ceres::Jet<T, N>, BinaryOp> {
984         typedef ceres::Jet<T, N> ReturnType;
985     };
986 #endif  // EIGEN_VERSION_AT_LEAST(3, 3, 0)
987 
988 }  // namespace Eigen
989 
990 #endif  // CERES_PUBLIC_JET_H_
Jet

 

转载于:https://www.cnblogs.com/larry-xia/p/10658503.html

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. 2014年---移动端webapp个人年度总结

    我今年是由零基础开始入门的&#xff0c;刚好我第一家公司入职后就马上让我接手做ipad版的专题app了。(一入门就是移动端开发&#xff0c;是幸运也是艰辛的开始)。 我是自学前端的&#xff0c;当然&#xff0c;对Bootstrap&#xff0c;JQuery mobile这2个UI框架肯定是熟悉他们是…...

    2024/4/5 12:43:30
  2. Vue-cli创建vue项目以及配置文件梳理

    介绍 vue-cli是vue提供构建单页应用的脚手架。它能够帮助开发者快速的创建vue项目。这篇文章主要介绍如何使用vue-cli&#xff0c;以及它创建的vue项目结构。还有就是对于build目录下的配置文件进行一些梳理总结。 安装vue-cli 安装vue-cli十分简单&#xff0c;执行下面的命…...

    2024/4/19 22:27:03
  3. node.js react_使用Node和React.js构建实时Twitter流

    node.js react介绍 (Introduction) Welcome to the second installation of Learning React, a series of articles focused on becoming proficient and effective with Facebooks React library. If you havent read the first installation, Getting Started and Concepts, …...

    2024/4/13 23:01:50
  4. AngularJS之备忘与诀窍

    译自:《angularjs》 备忘与诀窍 目前为止&#xff0c;之前的章节已经覆盖了Angular所有功能结构中的大多数&#xff0c;包括指令,服务,控制器,资源以及其它内容.但是我们知道有时候仅仅阅读是不够的.有时候&#xff0c;我们并不在乎那些功能机制是如果运行的,我们仅仅想知道如何…...

    2024/4/13 23:02:10
  5. ROS机器人导航之初实现

    1./home/hao/catkin_lh/src/arbotix_ros arbotix_ros是官方给的包 sudo apt-get install ros-kinetic-arbotix-* 具体的下载位置ros工程包的scr中 作用&#xff1a;给出了仿真机器人需要的里程计和TF坐标转化关系launch文件调用代码<node name"arbotix" pkg…...

    2024/4/13 23:01:55
  6. [pixhawk笔记]6-uORB流程及关键函数解析

    本文中将结合代码、文档及注释&#xff0c;给出uORB执行流程及关键函数的解析&#xff0c;由于uORB的机制实现较为复杂&#xff0c;所以本文主要学习如何使用uORB的接口来实现通信。回到上一篇笔记中的代码&#xff1a; #include <px4_config.h> #include <px4_tasks.…...

    2024/4/15 11:05:44
  7. Build a Basic CRUD App with Vue.js and nodejs

    https://developer.okta.com/blog/2018/02/15/build-crud-app-vuejs-node#add-authentication-with-okta I’ve danced the JavaScript framework shuffle for years starting with jQuery, then on to Angular. After being frustrated with Angular’s complexity, I found R…...

    2024/4/20 1:29:12
  8. okta使用_如何使用Okta向您的Vue应用添加身份验证

    okta使用This article was originally published on the Okta developer blog. Thank you for supporting the partners who make SitePoint possible. 本文最初发布在Okta开发人员博客上 。 感谢您支持使SitePoint成为可能的合作伙伴。 I’ve danced the JavaScript framewor…...

    2024/4/13 23:02:10
  9. stack.h file_使用Filestack构建MEAN Stack File Uploader应用

    stack.h file介绍 ( Introduction ) Filepicker is a web service which helps us developers smoothly handle file uploading. An amazing feature it provides is to let users to choose the source from where to upload a picture, so you can easily upload a picture f…...

    2024/4/13 23:02:15
  10. 脏值检查

    脏值检查&#xff0c;通过digest遍历所有的watcher&#xff0c;最终得到统一的数据&#xff0c;再更新view。脏值检查Change Detection内部的一个非常重要的阶段——digest阶段, 当系统进入此阶段时&#xff0c;将会进行数据检查, 它的处理流程如下:标记dirty false遍历所有通…...

    2024/4/5 12:41:19
  11. 你所要知道的所有关于Angular的变化检测机制

    原文地址&#xff1a;Everything you need to know about change detection in Angular 如果想像我一样全面的了解Angular的脏值检测机制&#xff0c;除了浏览源代码之外别无他法&#xff0c;网上可没有太多可用信息。大部分文章都提到&#xff0c;Angular中每个组件都自带一个…...

    2024/4/18 10:51:56
  12. Angular4 组件变化检测总结 (Change Detection)

    看了很多有关的文章&#xff0c;也认真观看了Angular2 团队放在youtube的相关演讲视频。&#xff08;你懂的&#xff09; Change Detection In Angular 2 我也想用自己的理解总结一下Angular2/4组件变化的原理。内容分这么几个小节&#xff1a; 什么操作会引发组件绑定属性变…...

    2024/4/13 23:02:10
  13. angular1.x 脏检测

    写在前面 双向绑定是angular的大亮点&#xff0c;然后支撑它的就是脏检测。一直对脏检测都有一些理解&#xff0c;却没有比较系统的概念。 以下是我阅读网上博文以及angular高级程序设计的理解与总结。 接收指导与批评。 脏检查&#xff1a; 将原对象赋值一份快照。在某个时间&…...

    2024/4/18 19:09:44
  14. angular 脏检查机制

    很久没有写点东西了&#xff0c;从今天起&#xff0c;在博客园对自己过往的工作&#xff0c;学习和生活做一些梳理&#xff0c;总结和温故。今天窗外的阳光不那么任性&#xff0c;天空白云点点&#xff0c;蝉鸣依旧嘹亮&#xff0c;安静地坐在阳台上&#xff0c;吹着风&#xf…...

    2024/4/13 23:01:50
  15. Angular--变更检测策略

    概述 简单来说变化检测就是Angular用来检测视图与模型之间绑定的值是否发生了改变&#xff0c;当检测到模型中绑定的值发生改变时&#xff0c;则同步到视图上&#xff0c;反之&#xff0c;当检测到视图上绑定的值发生改变时&#xff0c;则回调对应的绑定函数。 什么情况下会引起…...

    2024/4/13 23:02:00
  16. 关于Angular的变更检测(Change Detection)

    如果你像我一样&#xff0c;想对Angular的变更检测机制有一个深入的理解&#xff0c;由于在网上并没有多少有用的信息&#xff0c;你只能去看源码。大多数文章都会提到每一个组件都会有一个属于自己的变更检测器&#xff08;change detector&#xff09;&#xff0c;它负责检查…...

    2024/4/13 23:03:05
  17. Angular 4 依赖注入教程之七 ValueProvider的使用

    目录 Angular 4 依赖注入教程之一 依赖注入简介Angular 4 依赖注入教程之二 组件服务注入Angular 4 依赖注入教程之三 ClassProvider的使用Angular 4 依赖注入教程之四 FactoryProvider的使用Angular 4 依赖注入教程之五 FactoryProvider配置依赖对象Angular 4 依赖注入教程之六…...

    2024/4/13 23:02:50
  18. Angular No provider for EffectsRootModule错误消息的出现原因和修复方式

    错误消息&#xff1a; main.ts:12 NullInjectorError: R3InjectorError(AppModule)[EffectsFeatureModule -> EffectsRootModule -> EffectsRootModule -> EffectsRootModule]: NullInjectorError: No provider for EffectsRootModule! at NullInjector.get (http://l…...

    2024/4/13 23:02:45
  19. angular的provider服务

    <!DOCTYPE html> <html><head><meta charset"UTF-8"><title>自定义服务其他的方式</title><script src"day2/src/angular.js"></script><style type"text/css"></style></head&…...

    2024/4/17 5:14:57
  20. Angularjs前端项目环境搭建

    Angularjs前端项目环境搭建 AngularJs是Google工程师研发的一款JS框架&#xff0c;官方文档中对它的描述是&#xff0c;它是完全使用JavaScript编写的客户端技术&#xff0c;同其他历史悠久的Web技术&#xff08;HTML&#xff0c;CSS等&#xff09;配合使用&#xff0c;使得Web…...

    2024/4/18 15:14:17

最新文章

  1. C#面:.NET默认的委托类型有哪几种?

    C# .NET默认的委托类型有以下几种&#xff1a; Action&#xff1a;Action 是一个泛型委托类型&#xff0c;它可以接受0到16个参数&#xff0c;并且没有返回值。例如&#xff0c;Action<int> 表示一个接受一个int类型参数的委托。Func&#xff1a;Func 也是一个泛型委托类…...

    2024/4/20 5:40:38
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. composer常见错误解决

    在Java中&#xff0c;常见的问题和解决方法包括&#xff1a; 内存不足错误&#xff1a;Java应用程序在运行时可能会遇到内存不足的错误。可以通过增加JVM的堆内存大小来解决&#xff0c;可以通过设置-Xms和-Xmx参数来指定初始堆大小和最大堆大小。 java -Xms2G -Xmx4G YourAppl…...

    2024/4/19 7:50:06
  4. 《c++》多态案例一.电脑组装

    一.代码展示 #include <iostream> using namespace std; class CPU { public://抽象计算函数virtual void calculate() 0;};class CVideoCard { public://抽象显示函数virtual void display() 0;}; class Memory { public://抽象存储函数virtual void storage() 0;};…...

    2024/4/19 7:49:33
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/4/19 14:24:02
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/4/19 18:20:22
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/4/19 11:57:31
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/4/19 11:57:31
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/4/19 11:57:52
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/4/19 11:57:53
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/4/19 11:58:14
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/4/19 11:58:20
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/4/19 23:45:49
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/4/19 11:58:39
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/4/19 11:58:51
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/4/20 3:12:02
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/4/19 11:59:15
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/4/19 11:59:23
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/4/19 11:59:44
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/4/19 11:59:48
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/4/19 12:00:06
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/4/19 16:57:22
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/4/19 12:00:25
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/4/19 12:00:40
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57