artofscience / artofscience/SAOR
Implement feature to warn about non-convexity
- Dominant language
- Python
- Stars
- 5
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
It might be nice to try and implement the convexity enforcement as a separate (wrapper) class. At the moment, it seems that we would need to implement the `if self.force_convex` check, as well as the corresponding `enforce_convexity` routines for various instances of the `Approximation` classes. Additionally, there might be different approaches possible in which we would like to enforce convexity. For instance, we could consider other thresholds or values to assign to the second derivatives.
My proposal would be to implement something as follows
```python
class EnforceConvexity(Approximation):
def __init__(self, approximation: Approximation, convexity_enforcer: Callable):
self.approximation = approximation
self.enforcer = convexity_enforcer
def update(self, ...):
self.approximation.update(self, ...)
self.enforcer(self.approximation)
```
which would sit around an existing `Approximation` instance, so initialised as `approximation = EnforceConvexity(Approximation(...), convexity_enforcer)`, where the `convexity_enforcer` could be any function (or class) that takes the approximation as argument
```python
def convexity_enforcer_1(approximation):
for intv in range(len(approximation.ddgddy):
approximation.ddgddy[intv][approximation.ddgddy[intv] < 0] = 0
```
for which we could implement a couple different variants. With such a (or similar) scheme, we could potentially then provide a range of such `enforce_convexity` routines that could work on any `Approximation` without requiring to modify the `update` method of the `Approximation` classes directly.
---
There are of course multiple ways to implement behaviour like this and possibly we should consider a PR/issue for this to see what would be the most appropriate way to insert this into the framework.
_Originally posted by @MaxvdKolk in https://github.com/artofscience/sao/pull/62#discussion_r657285997_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.