LeastSquaresSolver.solve()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 1
c 5
b 0
f 0
dl 0
loc 34
rs 8.8571
1
"""
2
Solvers for over-identified systems.
3
4
@author : davidrpugh
5
6
"""
7
from scipy import optimize
8
9
from . import solvers
10
11
12
class LeastSquaresSolver(solvers.Solver):
13
14
    def solve(self, basis_kwargs, boundary_points, coefs_array, nodes, problem,
15
              **solver_options):
16
        """
17
        Solve a boundary value problem using the collocation method.
18
19
        Parameters
20
        ----------
21
        basis_kwargs : dict
22
            Dictionary of keyword arguments used to build basis functions.
23
        coefs_array : numpy.ndarray
24
            Array of coefficients for basis functions defining the initial
25
            condition.
26
        problem : bvp.TwoPointBVPLike
27
            A two-point boundary value problem (BVP) to solve.
28
        solver_options : dict
29
            Dictionary of options to pass to the non-linear equation solver.
30
31
        Return
32
        ------
33
        solution: solutions.SolutionLike
34
            An instance of the SolutionLike class representing the solution to
35
            the two-point boundary value problem (BVP)
36
37
        Notes
38
        -----
39
40
        """
41
        result = optimize.leastsq(self._compute_residuals,
42
                                  x0=coefs_array,
43
                                  args=(basis_kwargs, boundary_points, nodes, problem),
44
                                  **solver_options)
45
        solution = self._solution_factory(basis_kwargs, result[0], nodes,
46
                                          problem, result)
47
        return solution
48