Exemplo n.º 1
0
 def test_solve_quadratic_fixed_supplying_objects(self):
     """
     Same as test_solve_quadratic_fixed, except supplying objects
     rather than functions as targets.
     """
     for solver in solvers:
         iden1 = Identity()
         iden2 = Identity()
         iden3 = Identity()
         iden1.x = 4
         iden2.x = 5
         iden3.x = 6
         iden1.names = ['x1']
         iden2.names = ['x2']
         iden3.names = ['x3']
         iden1.fixed = [True]
         iden3.fixed = [True]
         term1 = [iden1, 1, 1]
         term2 = [iden2, 2, 1 / 4.]
         term3 = [iden3, 3, 1 / 9.]
         prob = LeastSquaresProblem([term1, term2, term3])
         solver(prob)
         self.assertAlmostEqual(prob.objective(), 10)
         self.assertAlmostEqual(iden1.x, 4)
         self.assertAlmostEqual(iden2.x, 2)
         self.assertAlmostEqual(iden3.x, 6)
Exemplo n.º 2
0
 def test_solve_quadratic_fixed_supplying_properties(self):
     """
     Same as test_solve_quadratic_fixed, except supplying @properties
     rather than functions as targets.
     """
     for solver in solvers:
         iden1 = Identity()
         iden2 = Identity()
         iden3 = Identity()
         iden1.x = 4
         iden2.x = 5
         iden3.x = 6
         iden1.names = ['x1']
         iden2.names = ['x2']
         iden3.names = ['x3']
         iden1.fixed = [True]
         iden3.fixed = [True]
         # Try a mix of explicit LeastSquaresTerms and lists
         term1 = [iden1, 'f', 1, 1]
         term2 = [iden2, 'f', 2, 1 / 4.]
         term3 = LeastSquaresTerm.from_sigma(Target(iden3, 'f'), 3, sigma=3)
         prob = LeastSquaresProblem([term1, term2, term3])
         solver(prob)
         self.assertAlmostEqual(prob.objective(), 10)
         self.assertAlmostEqual(iden1.x, 4)
         self.assertAlmostEqual(iden2.x, 2)
         self.assertAlmostEqual(iden3.x, 6)
Exemplo n.º 3
0
 def test_solve_quadratic_fixed(self):
     """
     Same as test_solve_quadratic, except with different weights and x
     and z are fixed, so only y is optimized.
     """
     for solver in solvers:
         iden1 = Identity()
         iden2 = Identity()
         iden3 = Identity()
         iden1.x = 4
         iden2.x = 5
         iden3.x = 6
         iden1.names = ['x1']
         iden2.names = ['x2']
         iden3.names = ['x3']
         iden1.fixed = [True]
         iden3.fixed = [True]
         term1 = (iden1.J, 1, 1)
         term2 = (iden2.J, 2, 1 / 4.)
         term3 = (iden3.J, 3, 1 / 9.)
         prob = LeastSquaresProblem([term1, term2, term3])
         solver(prob)
         self.assertAlmostEqual(prob.objective(), 10)
         self.assertAlmostEqual(iden1.x, 4)
         self.assertAlmostEqual(iden2.x, 2)
         self.assertAlmostEqual(iden3.x, 6)
Exemplo n.º 4
0
 def test_solve_quadratic_fixed_supplying_attributes(self):
     """
     Same as test_solve_quadratic_fixed, except supplying attributes
     rather than functions as targets.
     """
     for solver in solvers:
         iden1 = Identity()
         iden2 = Identity()
         iden3 = Identity()
         iden1.x = 4
         iden2.x = 5
         iden3.x = 6
         iden1.names = ['x1']
         iden2.names = ['x2']
         iden3.names = ['x3']
         iden1.fixed = [True]
         iden3.fixed = [True]
         # Try a mix of explicit LeastSquaresTerms and tuples
         term1 = LeastSquaresTerm(Target(iden1, 'x'), 1, 1)
         term2 = (iden2, 'x', 2, 1 / 4.)
         term3 = (iden3, 'x', 3, 1 / 9.)
         prob = LeastSquaresProblem([term1, term2, term3])
         solver(prob)
         self.assertAlmostEqual(prob.objective(), 10)
         self.assertAlmostEqual(iden1.x, 4)
         self.assertAlmostEqual(iden2.x, 2)
         self.assertAlmostEqual(iden3.x, 6)