Skip to content

Commit 151f584

Browse files
Update API.md
Improve losses description
1 parent f337cc1 commit 151f584

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docs/API.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,33 @@ auto new_loss = CreateNumDiffFunc1(x, original_loss);
383383
*NOTE* `CreateNumDiffFunc1` is when using first order optimizers which use the gradient only and `CreateNumDiffFunc2` for
384384
second or pseudo-second order methods, which use both gradient and Hessian.
385385
386-
### Losses and Norms
387-
You can play with different losses, robust norms and M-estimators, have a look at `losses.h`.
386+
### Losses, Norms and Robust Norms
387+
You can play with different losses, robust norms and M-estimators, have a look at the `loss` fold er.
388388
389+
All losses and other norms follow the signature: `Name(x, export_or_jacobian)` or `Name(x, threshold, export_or_jacobian)` for robust norms.
390+
391+
* `export_or_jacobian` is either skipped and the loss/norm will be the only output of the function.
392+
* If it is `true`, the Jacobian of the loss will be returned as well as the loss.
393+
* Finally, if it is a matrix/vector representing a forward Jacobian, then the second returned value will be the transformed Jacobian using the chain rule.
394+
395+
Here is an example of how to get a Huber norm.
396+
397+
```cpp
398+
double robust_norm = Huber(y.squaredNorm(), 0.8);
399+
```
400+
401+
Here is another example of how to call a Huber norm and recover the scale/Jacobian of it or the transformed jacobian.
402+
403+
```cpp
404+
const auto &[robust_norm, J] = Huber(y.squaredNorm(), 0.8, true);
405+
406+
or
407+
408+
const auto &[robust_norm, J] = Huber(y.squaredNorm(), 0.8, Jy);
409+
410+
```
411+
412+
There is also various other norms, activation functions and losses.
389413
Here is an example of a loss that uses a Mahalanobis distance with a covariance `C`.
390414
```cpp
391415

@@ -395,3 +419,4 @@ auto loss = [&]<typename T>(const Eigen::Vector<T, 2> &x) {
395419
};
396420

397421
```
422+

0 commit comments

Comments
 (0)