-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from powei-lin/py-factor
Py factor
- Loading branch information
Showing
15 changed files
with
281 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
__pycache__ | ||
*.so | ||
.DS_Store | ||
.vscode/* | ||
.vscode/* | ||
.venv | ||
.pytest_cache |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import numpy as np | ||
from tiny_solver import Problem, GaussNewtonOptimizer | ||
from tiny_solver.factors import PriorFactor, PyFactor | ||
|
||
|
||
def cost(x, y, z): | ||
r0 = x[0] + 2*y[0] + 4*z[0] | ||
r1 = y[0] * z[0] | ||
return np.array([r0, r1]) | ||
|
||
def main(): | ||
problem = Problem() | ||
pf = PyFactor(cost) | ||
problem.add_residual_block(2, [('x', 1), ('y', 1), ('z', 1),], pf, None) | ||
pp = PriorFactor(np.array([3.0])) | ||
problem.add_residual_block(1, [('x', 1)], pp, None) | ||
gn = GaussNewtonOptimizer() | ||
init_values = {"x": np.array([0.7]), "y": np.array([-30.2]), "z": np.array([123.9])} | ||
result_values = gn.optimize(problem, init_values) | ||
print(result_values) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.