test_Robust.py
Go to the documentation of this file.
1 """
2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
4 All Rights Reserved
5 
6 See LICENSE for the license information
7 
8 Simple unit test for custom robust noise model.
9 Author: Fan Jiang
10 """
11 import unittest
12 
13 import numpy as np
14 from gtsam.utils.test_case import GtsamTestCase
15 
16 import gtsam
17 
18 
20 
22  k = 10.0
23 
24  def custom_weight(e):
25  abs_e = abs(e)
26  return 1.0 if abs_e <= k else k / abs_e
27 
28  def custom_loss(e):
29  abs_e = abs(e)
30  return abs_e * abs_e / 2.0 if abs_e <= k else k * abs_e - k * k / 2.0
31 
32  custom_robust = gtsam.noiseModel.Robust.Create(
33  gtsam.noiseModel.mEstimator.Custom(custom_weight, custom_loss,
34  gtsam.noiseModel.mEstimator.Base.ReweightScheme.Scalar,
35  "huber"),
37  f = gtsam.PriorFactorDouble(0, 1.0, custom_robust)
38  v = gtsam.Values()
39  v.insert(0, 0.0)
40 
41  self.assertAlmostEqual(f.error(v), 0.125)
42 
43 if __name__ == "__main__":
44  unittest.main()
gtsam::noiseModel::Robust::Create
static shared_ptr Create(const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise)
Definition: NoiseModel.cpp:740
gtsam::noiseModel::mEstimator::Custom
Definition: LossFunctions.h:555
test_Robust.TestRobust.test_RobustLossAndWeight
def test_RobustLossAndWeight(self)
Definition: test_Robust.py:21
gtsam::utils.test_case
Definition: test_case.py:1
gtsam::Values
Definition: Values.h:65
test_Robust.TestRobust
Definition: test_Robust.py:19
gtsam::utils.test_case.GtsamTestCase
Definition: test_case.py:15
gtsam::noiseModel::Isotropic::Sigma
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
Definition: NoiseModel.cpp:624
abs
#define abs(x)
Definition: datatypes.h:17


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:08