Skip to content

Commit

Permalink
Move LeastSquaresSolver' to its own module.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrpugh committed Oct 11, 2015
1 parent 9f7a14f commit cd856bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
3 changes: 2 additions & 1 deletion pycollocation/solvers/__init__.py
Expand Up @@ -2,7 +2,8 @@
Objects imported here will live in the `pycollocation.solvers` namespace
"""
from . solvers import LeastSquaresSolver, Solver, SolverLike
from . over_identified import LeastSquaresSolver
from . solvers import Solver, SolverLike
from . solutions import SolutionLike, Solution

__all__ = ["LeastSquaresSolver", "Solver", "Solution", "SolutionLike",
Expand Down
47 changes: 47 additions & 0 deletions pycollocation/solvers/over_identified.py
@@ -0,0 +1,47 @@
"""
Solvers for over-identified systems.
@author : davidrpugh
"""
from scipy import optimize

from . import solvers


class LeastSquaresSolver(solvers.Solver):

def solve(self, basis_kwargs, boundary_points, coefs_array, nodes, problem,
**solver_options):
"""
Solve a boundary value problem using the collocation method.
Parameters
----------
basis_kwargs : dict
Dictionary of keyword arguments used to build basis functions.
coefs_array : numpy.ndarray
Array of coefficients for basis functions defining the initial
condition.
problem : bvp.TwoPointBVPLike
A two-point boundary value problem (BVP) to solve.
solver_options : dict
Dictionary of options to pass to the non-linear equation solver.
Return
------
solution: solutions.SolutionLike
An instance of the SolutionLike class representing the solution to
the two-point boundary value problem (BVP)
Notes
-----
"""
result = optimize.leastsq(self._compute_residuals,
x0=coefs_array,
args=(basis_kwargs, boundary_points, nodes, problem),
**solver_options)
solution = self._solution_factory(basis_kwargs, result[0], nodes,
problem, result)
return solution
38 changes: 0 additions & 38 deletions pycollocation/solvers/solvers.py
Expand Up @@ -265,41 +265,3 @@ def solve(self, basis_kwargs, boundary_points, coefs_array, nodes, problem,
solution = self._solution_factory(basis_kwargs, result.x, nodes,
problem, result)
return solution


class LeastSquaresSolver(Solver):

def solve(self, basis_kwargs, boundary_points, coefs_array, nodes, problem,
**solver_options):
"""
Solve a boundary value problem using the collocation method.
Parameters
----------
basis_kwargs : dict
Dictionary of keyword arguments used to build basis functions.
coefs_array : numpy.ndarray
Array of coefficients for basis functions defining the initial
condition.
problem : bvp.TwoPointBVPLike
A two-point boundary value problem (BVP) to solve.
solver_options : dict
Dictionary of options to pass to the non-linear equation solver.
Return
------
solution: solutions.SolutionLike
An instance of the SolutionLike class representing the solution to
the two-point boundary value problem (BVP)
Notes
-----
"""
result = optimize.leastsq(self._compute_residuals,
x0=coefs_array,
args=(basis_kwargs, boundary_points, nodes, problem),
**solver_options)
solution = self._solution_factory(basis_kwargs, result[0], nodes,
problem, result)
return solution

0 comments on commit cd856bd

Please sign in to comment.