Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickets/DM-13806 #53

Merged
merged 2 commits into from May 3, 2018
Merged

Tickets/DM-13806 #53

merged 2 commits into from May 3, 2018

Conversation

natelust
Copy link
Contributor

@natelust natelust commented Apr 5, 2018

No description provided.

using Moments = Eigen::Matrix<double, 6, 1>;
using Jacobian = Eigen::Matrix<double, 6, 6>;
using FirstMoment = Eigen::Matrix<double, 2, 1>;
using SecondMoment = Eigen::Matrix<double, 2, 2>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add using Element = double; and then parameterize the rest on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* maximally likely image moments given moments measured from an image. As such the class
* provides two methods in addition to the at method already mentioned. One method computes the
* biased weighted moments given the specified weight and "true" moments, and the other computes
* the derivative of the objective function along each of the image moment variables.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not start every sentence with "This class".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this easier to read

* moments intrinsic to an object, and a vector of moments representing a weighting function.
*
* The class is constructed with the moments of weight function, and the moments of the object
* are set by calling the at method. This allows a single instance to be reused to evaluate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See later comments about at.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched name to setParameters

* The class is constructed with the moments of weight function, and the moments of the object
* are set by calling the at method. This allows a single instance to be reused to evaluate
* multiple positions in object moment space. This structure is computationally more efficient
* as well since the weight function would remain constant for many evaluation of image moments

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

* a normalized weight function.
*/
MomentsModel(Moments const & W): W(W) {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also explicitly default or delete copy/move constructors / assignment operators and destructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Calculates and returns the derivatives for the alpha components.
auto makeAlphaGrad(Moments const & Q, Moments const & W) {
double muBottom, sigBottom;
std::tie(muBottom, sigBottom) = makeAlphaGradDivisors(Q, W);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love some structured bindings ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me too

if (abs(zeroTruth - zeroRes) > tol) {
return false;
}
return approxEqual(firstRes, firstTruth, tol);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (abs(zeroTruth - zeroRes) < tol) && approxEqual(firstRes, firstTruth, tol)? Or move the first test higher to prevent the assignment cost? Or just leave these as they are, since they are minor tests anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not worth worrying about in the test that will get called a small number of time, and with small length vectors

return false;
}
return approxEqual(firstRes, firstTruth, tol);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, i'd move all these tests out of here. Since they obscure the implementation of the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed above


// Sets the location in moment space to evaluate
void MomentsModel::at(Moments const & inputQ) {
Q = Moments(inputQ);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just assign?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

// Returns the value of the weighted biased moments calculation
Moments MomentsModel::computeValues() {
return value;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compute anything. Also why is value singular and computeValues plural? Perhaps getValue would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change value to plural. Also this signature was chosen so in the future someone my substitute a different objective function where the work may be done in the computeValues function, and the api will stay the same

Add a class which functions as an objective functional model of
biased weighted moments and its derivatives given input moments
and weights. This is intended to be used in conjunction with an
optimizer to find the moments which maximize the likelyhood of
moments given input measurements from data.
@natelust natelust merged commit 992bcf4 into master May 3, 2018
@ktlim ktlim deleted the tickets/DM-13806 branch August 25, 2018 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants