-
Notifications
You must be signed in to change notification settings - Fork 214
Constraints - 1 #215
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
Constraints - 1 #215
Conversation
Sync with master tensorflow on upstream
Merge main branch to local branch
Update after losses merge
Fix Javadoc errors (tensorflow#152)
pull type def
Metrics Phase 1 (tensorflow#180)
Pull latest tensorflow master
Change float attributes to double
* | ||
* @param <T> the date type for the weights | ||
*/ | ||
public abstract class Constraint<T extends TNumber> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does an instance of Constraint
need to be specialized to a particular tensor type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
* @return the element-wise square root. | ||
*/ | ||
protected Operand<T> sqrt(Operand<T> x) { | ||
Class<T> type = x.type(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify x
not null
as we do in clip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
private final int[] axes; | ||
|
||
/** | ||
* Create a MaxNorm constraint using {@link #MIN_VALUE_DEFAULT} for the min value, {@link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaxNorm
-> MinMaxNorm
in all constructor header comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
weights, | ||
tf.math.add( | ||
cast(tf, tf.constant(EPSILON), type), | ||
sqrt( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This computation of the norms keeps coming up. Perhaps add a superclass method for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
ReduceSum.keepDims(Boolean.TRUE))))); | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have three instances of this axis-management so far. I could imagine adding a superclass like AbstractNormConstraint
to handle it. (But I could go either way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, there are only 3 Constraint classes that use it. I don't think another class is warranted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
for (AtomicInteger i = new AtomicInteger(); | ||
i.get() < testValues.length; | ||
i.getAndIncrement()) { | ||
MinMaxNorm<TFloat32> instance = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this point forward, the test is erroneously a copy of MinMaxNormTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I'll fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
for (AtomicInteger i = new AtomicInteger(); | ||
i.get() < testValues.length; | ||
i.getAndIncrement()) { | ||
MaxNorm<TFloat32> instance = new MaxNorm<>(tf, testValues[i.get()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erroneously a copy of MaxNormTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I'll fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
return result; | ||
} | ||
|
||
/** Test of call method, of class MaxNorm. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaxNorm
-> UnitNorm
(not just in the comment, but in the code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I'll fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
Add norm method on Constraint that is leveraged by the xxxxNorm constraints. Fix unit test cases to properly test the actual classes (oops). Fix Javadoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right this one is ready to to, thanks @JimClarke5 and thanks @deansher for reviewing it!
Adding Constraints.
Constraints impose constraints on weight values.
This does not include the RadialConstraint as that requires
while
operations.This should be independent class that do not have dependencies on other framework packages.