Tps adaptive mesh refinement#132
Conversation
|
note: this PR started from #129 and should be rebased/merged after that one. |
Codecov Report
@@ Coverage Diff @@
## develop #132 +/- ##
==========================================
- Coverage 95.66% 95.6% -0.07%
==========================================
Files 29 29
Lines 2005 2023 +18
==========================================
+ Hits 1918 1934 +16
- Misses 87 89 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## develop #132 +/- ##
===========================================
+ Coverage 95.65% 95.71% +0.06%
===========================================
Files 29 29
Lines 2000 2029 +29
===========================================
+ Hits 1913 1942 +29
Misses 87 87
Continue to review full report at Codecov.
|
a73c24c to
e6ba38c
Compare
|
rebased to master |
| sortind = np.argsort(delta[ind]) | ||
|
|
||
| if niter == max_iter: | ||
| logger.warning( |
There was a problem hiding this comment.
are we sure you want to not raise an exception here, seems the client of this should be in control of whether to accept the result and move on. It could raise an Exception and return the newtf in the exception.
There was a problem hiding this comment.
added the exception... not sure how to raise and return the newtf at the same time
| return newtf | ||
|
|
||
| src = np.vstack((src, self.src[ind[sortind[0: nworst]]])) | ||
| return self.adaptive_mesh_estimate( |
There was a problem hiding this comment.
Could we wrap the computation here as a class/static method? It looks like there is a lot of setup (relating to origin points, etc) that can be run once and passed to another recursive method, which can make this more readable for the future.
trivial change to retrigger build
| logger.addHandler(logging.StreamHandler(sys.stdout)) | ||
|
|
||
|
|
||
| class AdaptiveMeshEstimationError(Exception): |
There was a problem hiding this comment.
sorry to be nitpicky, but this should subclass EstimationError, or we can make EstimationError have an keyword argument of transform=None, so that it works whether you want to pass on the transform calculated or not, but code can be written to generically catch all EstimationErrors
There was a problem hiding this comment.
that's fine, I can't quite imagine a use case where you would/should use a failed result... but you seem to. So, I don't mind making it what you're after.
There was a problem hiding this comment.
oh! well.. actually I was intuiting because you had it as a warning before that you had a use case in mind to use the transform, so i was trying to accommodate that.
There was a problem hiding this comment.
so what do we want to do... 1) leave this as is 2) make it subclass EstimateError 3) simply remove all this pass up the transform in the exception business.
There was a problem hiding this comment.
In a scipy iterative solver situation, I've come to expect the behavior that a solution is always returned, but a max iter message pops up. That's what I was originally going for with the logger message:
from scipy.optimize import minimize, rosen, rosen_der
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
res = minimize(rosen, x0, method='Nelder-Mead', tol=1e-6, options={'maxiter': 1000, 'disp': True})
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 295
Function evaluations: 494
print(res.__class__)
<class 'scipy.optimize.optimize.OptimizeResult'>
del res
res = minimize(rosen, x0, method='Nelder-Mead', tol=1e-6, options={'maxiter': 10, 'disp': True})
Warning: Maximum number of iterations has been exceeded.
print(res.__class__)
<class 'scipy.optimize.optimize.OptimizeResult'>
There was a problem hiding this comment.
but maybe a better precedent is just bombing out like in our polynomial transform:
https://github.com/fcollman/render-python/blob/d5ccfafd75e5a3694e989e9c97397d315c9b0c52/renderapi/transform/leaf/polynomial_models.py#L231-L234
There was a problem hiding this comment.
yeah i like bombing out better personally.
|
|
||
|
|
||
| class AdaptiveMeshEstimationError(EstimationError): | ||
| def __init__(self, value, transform): |
There was a problem hiding this comment.
This is a tricky thing to do in python. I'm pretty sure that trying to raise something like this in e.g. a multiprocessing pool will cause hanging since the reduction function pickle uses will not treat it nicely. There is a way around this, but correct behavior should be tested if we go this route (which I think is okay).
|
nudge. |
Do you have a thin plate spline mesh that you suspect is overkill and is really chapping your hide? Maybe, something like this?

This PR adds an adaptive mesh estimator to create a new smaller transform that matches the original one on the control points. This can reduce the computation time associated with the tform() method, for example.
code below provided for example to reproduce this plot