Skip to content

Instantly share code, notes, and snippets.

View SarvagyaVaish's full-sized avatar

Survy Vaish SarvagyaVaish

View GitHub Profile
### Keybase proof
I hereby claim:
* I am Sarvagyavaish on github.
* I am survy (https://keybase.io/survy) on keybase.
* I have a public key whose fingerprint is A329 DF37 01E3 CCBD CE44 AA48 899A B582 D345 1844
To claim this, I am signing this object:
import numpy as np
import cv2
import math
def hsv2rgb(h, s, v):
h = float(h)
s = float(s)
v = float(v)
h60 = h / 60.0
h60f = math.floor(h60)
import numpy as np
import cv2
import math
cap = cv2.VideoCapture(0)
ret, frame_large = cap.read()
scale = 0.5
frame = cv2.resize(frame_large, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
y, x, c = np.shape(frame)
center = (y/2, x/2)
@SarvagyaVaish
SarvagyaVaish / leading.java
Last active March 2, 2017 04:02
Calculating proper leading
TextView title_TextView = (TextView) findViewById(R.id.title);
Paint title_Paint = title_TextView.getPaint();
Paint.FontMetrics title_FontMetrics = title_Paint.getFontMetrics();
TextView subheading_TextView = (TextView) findViewById(R.id.subheading);
Paint subheading_Paint = subheading_TextView.getPaint();
Paint.FontMetrics subheading_FontMetrics = subheading_Paint.getFontMetrics();
Log.d("Survy", "title descent: " + title_FontMetrics.descent);
Log.d("Survy", "title ascent: " + title_FontMetrics.ascent);

What is it?

  • an algorithm to solve non-linear least squares minimization problems
  • finds a local minima, not necessarily the global minima
  • alternatives: Gauss–Newton, gradient-descent

Why use it?

  • LM algorithm combines the advantages of gradient-descent and Gauss-Newton
  • allows for initial values to be further away from solution than Gauss-Newton
  • gradient-descent dominates until a canyon is reached, after which Gauss-Newton takes over
//
// Create a KDL kinematic Chain.
//
// A Chain is made up of Segments. Each Segment consists of a Joint and a Frame.
// The Joint indicates how the Frame moves - rotation or translation about / along an axis.
//
Chain kdlChain = Chain();
Joint joint1(Joint::None);
-10.00 -685.80
-9.50 -647.10
-9.00 -602.00
-8.50 -548.90
-8.00 -524.20
-7.50 -490.10
-7.00 -430.60
-6.50 -412.10
-6.00 -345.20
-5.50 -344.10
struct LMFunctor
{
// Compute 'm' errors, one for each data point, for the given parameter values in 'x'
int operator()(const Eigen::VectorXf &x, Eigen::VectorXf &fvec) const
{
// TODO
}
// Compute the jacobian of the errors
int df(const Eigen::VectorXf &x, Eigen::MatrixXf &fjac) const
// Compute 'm' errors, one for each data point, for the given parameter values in 'x'
int operator()(const Eigen::VectorXf &x, Eigen::VectorXf &fvec) const
{
// 'x' has dimensions n x 1
// It contains the current estimates for the parameters.
// 'fvec' has dimensions m x 1
// It will contain the error for each data point.
float aParam = x(0);
// Compute the jacobian of the functions
int df(const Eigen::VectorXf &x, Eigen::MatrixXf &fjac) const
{
// 'x' has dimensions n x 1
// It contains the current estimates for the parameters.
// 'fjac' has dimensions m x n
// It will contain the jacobian of the errors, calculated numerically in this case.
float epsilon;