Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
powei-lin committed Mar 23, 2024
1 parent e554785 commit 576c4db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
24 changes: 17 additions & 7 deletions examples/python/small_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@


def cost(x, y, z):
r0 = x[0] + 2*y[0] + 4*z[0]
r1 = y[0] * z[0]
return np.array([r0, r1])
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)
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)
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__':

if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion examples/python/try_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from tiny_solver.loss_functions import HuberLoss
import numpy as np


def f(x: np.ndarray, y: np.ndarray):
# print("py ", x*x)
return np.array([2*x[0], x[1]*x[1]*x[1], y[1]*4.0])
return np.array([2 * x[0], x[1] * x[1] * x[1], y[1] * 4.0])


def fa():
print("fa")
Expand Down
2 changes: 1 addition & 1 deletion tiny_solver/factors/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class PriorFactor(Factor):
def __init__(self, x: np.ndarray) -> None: ...

class PyFactor(Factor):
def __init__(self, func: callable) -> None: ...
def __init__(self, func: callable) -> None: ...
2 changes: 0 additions & 2 deletions tiny_solver/tiny_solver.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ class OptimizerOptions:
min_rel_error_decrease_threshold: float = 1e-5,
min_error_threshold: float = 1e-8,
) -> None: ...

def first_derivative_test(f: callable, x): ...

0 comments on commit 576c4db

Please sign in to comment.