You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hivemall.apache.org by takuti <gi...@git.apache.org> on 2017/07/01 14:02:59 UTC
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
GitHub user takuti opened a pull request:
https://github.com/apache/incubator-hivemall/pull/92
[HIVEMALL-5] Java code formatter
## What changes were proposed in this pull request?
In order to make contribution to Hivemall more easier, we need to prepare contribution guide as soon as possible. This PR is the first step toward publishing a complete document on https://hivemall.incubator.apache.org
For now, I added (temporal) contribution guide to README and require contributors to follow specific cording conventions hereafter.
## What type of PR is it?
Documentation?
## What is the Jira issue?
https://issues.apache.org/jira/browse/HIVEMALL-5
---
Originally, `eclipse-style.xml` was created based on google's coding conventions. However, in this PR, I suggest to follow coding conventions of Hive hereafter; since Hivemall clearly stands on Hive, following its conventions should be the most reasonable choice.
@myui If you strongly want to use different kind of conventions, I will update this PR so.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/takuti/incubator-hivemall hive-formatter
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-hivemall/pull/92.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #92
----
commit 2ddc95e1df4448f8b89a127e119e96416e732b59
Author: Takuya Kitazawa <k....@gmail.com>
Date: 2017-07-01T13:37:24Z
Use Hive eclipse formatting style
commit 83cf09b6985fe83c6e9499887dca75f24615b0d6
Author: Takuya Kitazawa <k....@gmail.com>
Date: 2017-07-01T13:39:23Z
Apply formatter
commit cff7ca82e85eb59829594403ec9e0bad7b0e91f7
Author: Takuya Kitazawa <k....@gmail.com>
Date: 2017-07-01T13:54:03Z
Add temporal contribution guide to README
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
Current `eclipse-style.xml` is using modified version of Sun's coding style (no comment formatting), not google one. It's better to evaluate `Google coding style + no comment formatting` though.
Google coding style provides both Eclipse format and IntelliJ format but different formatting is applied due to mismatch in functionality of IDE. So, providing only Eclipse format (which can be loaded in IntelliJ) is preferred.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125170809
--- Diff: core/src/main/java/hivemall/utils/lang/Preconditions.java ---
@@ -26,16 +26,17 @@
public final class Preconditions {
- private Preconditions() {}
+ private Preconditions() {
--- End diff --
`private Preconditions() {}` is preferred.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5] Java code formatter
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
[](https://coveralls.io/builds/12217732)
Coverage increased (+0.05%) to 40.329% when pulling **cff7ca82e85eb59829594403ec9e0bad7b0e91f7 on takuti:hive-formatter** into **ec6d945fe48d64cd5175a2ad0156b8bd387c6138 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125170766
--- Diff: core/src/main/java/hivemall/classifier/AROWClassifierUDTF.java ---
@@ -41,172 +41,165 @@
* In Proc. NIPS, 2009.
* </pre>
*/
-@Description(
- name = "train_arow",
- value = "_FUNC_(list<string|int|bigint> features, int label [, const string options])"
- + " - Returns a relation consists of <string|int|bigint feature, float weight, float covar>",
- extended = "Build a prediction model by Adaptive Regularization of Weight Vectors (AROW) binary classifier")
+@Description(name = "train_arow", value = "_FUNC_(list<string|int|bigint> features, int label [, const string options])"
+ + " - Returns a relation consists of <string|int|bigint feature, float weight, float covar>", extended = "Build a prediction model by Adaptive Regularization of Weight Vectors (AROW) binary classifier")
--- End diff --
too long line.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5-pre] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125588390
--- Diff: core/src/main/java/hivemall/anomaly/SingularSpectrumTransform.java ---
@@ -165,8 +165,8 @@ private double computeScoreSVD(@Nonnull final RealMatrix H, @Nonnull final RealM
/**
* Implicit Krylov Approximation (IKA) based naive scoring.
*
- * Number of iterations for the Power method and QR method is fixed to 1 for efficiency. This
- * may cause failure (i.e. meaningless scores) depending on datasets and initial values.
+ * Number of iterations for the Power method and QR method is fixed to 1 for efficiency. This may cause failure (i.e. meaningless scores)
--- End diff --
Better to set Javadoc comment formatting off for the time being.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125170752
--- Diff: core/src/main/java/hivemall/anomaly/SDAR2D.java ---
@@ -33,129 +33,123 @@
public final class SDAR2D {
- // --------------------------------
- // hyperparameters
-
- /**
- * Forgetfulness parameter
- */
- private final double _r;
+ // --------------------------------
+ // hyperparameters
+
+ /**
+ * Forgetfulness parameter
+ */
+ private final double _r;
+
+ // --------------------------------
+ // parameters
+
+ private final RealMatrix[] _C;
+ private RealVector _mu;
+ private RealMatrix _sigma;
+ private RealVector _muOld;
+ private RealMatrix _sigmaOld;
+
+ private boolean _initialized;
+
+ public SDAR2D(final double r, final int k) {
+ Preconditions.checkArgument(0.d < r && r < 1.d, "Invalid forgetfullness parameter r: " + r);
+ Preconditions.checkArgument(k >= 1, "Invalid smoothing parameter k: " + k);
+ this._r = r;
+ this._C = new RealMatrix[k + 1];
+ this._initialized = false;
+ }
+
+ /**
+ * @param x series of input in LIFO order
+ * @param k AR window size
+ * @return x_hat predicted x
+ * @link https://en.wikipedia.org/wiki/Matrix_multiplication#Outer_product
+ */
+ @Nonnull
+ public RealVector update(@Nonnull final ArrayRealVector[] x, final int k) {
+ Preconditions.checkArgument(x.length >= 1, "x.length MUST be greather than 1: " + x.length);
+ Preconditions.checkArgument(k >= 0, "k MUST be greather than or equals to 0: ", k);
+ Preconditions.checkArgument(k < _C.length, "k MUST be less than |C| but " + "k=" + k + ", |C|="
+ + _C.length);
+
+ final ArrayRealVector x_t = x[0];
+ final int dims = x_t.getDimension();
+
+ if (_initialized == false) {
+ this._mu = x_t.copy();
+ this._sigma = new BlockRealMatrix(dims, dims);
+ assert (_sigma.isSquare());
+ this._initialized = true;
+ return new ArrayRealVector(dims);
+ }
+ Preconditions.checkArgument(k >= 1, "k MUST be greater than 0: ", k);
- // --------------------------------
- // parameters
+ // old parameters are accessible to compute the Hellinger distance
+ this._muOld = _mu.copy();
+ this._sigmaOld = _sigma.copy();
- private final RealMatrix[] _C;
- private RealVector _mu;
- private RealMatrix _sigma;
- private RealVector _muOld;
- private RealMatrix _sigmaOld;
+ // update mean vector
+ // \hat{mu} := (1-r) \hat{µ} + r x_t
+ this._mu = _mu.mapMultiply(1.d - _r).add(x_t.mapMultiply(_r));
- private boolean _initialized;
+ // compute residuals (x - \hat{µ})
+ final RealVector[] xResidual = new RealVector[k + 1];
+ for (int j = 0; j <= k; j++) {
+ xResidual[j] = x[j].subtract(_mu);
+ }
- public SDAR2D(final double r, final int k) {
- Preconditions.checkArgument(0.d < r && r < 1.d, "Invalid forgetfullness parameter r: " + r);
- Preconditions.checkArgument(k >= 1, "Invalid smoothing parameter k: " + k);
- this._r = r;
- this._C = new RealMatrix[k + 1];
- this._initialized = false;
+ // update covariance matrices
+ // C_j := (1-r) C_j + r (x_t - \hat{µ}) (x_{t-j} - \hat{µ})'
+ final RealMatrix[] C = this._C;
+ final RealVector rxResidual0 = xResidual[0].mapMultiply(_r); // r (x_t - \hat{µ})
+ for (int j = 0; j <= k; j++) {
+ RealMatrix Cj = C[j];
+ if (Cj == null) {
+ C[j] = rxResidual0.outerProduct(x[j].subtract(_mu));
+ } else {
+ C[j] = Cj.scalarMultiply(1.d - _r).add(rxResidual0.outerProduct(x[j].subtract(_mu)));
+ }
}
- /**
- * @param x series of input in LIFO order
- * @param k AR window size
- * @return x_hat predicted x
- * @link https://en.wikipedia.org/wiki/Matrix_multiplication#Outer_product
+ // solve A in the following Yule-Walker equation
+ // C_j = ∑_{i=1}^{k} A_i C_{j-i} where j = 1..k, C_{-i} = C_i'
+ /*
+ * /C_1\ /A_1\ /C_0 |C_1' |C_2' | . . . |C_{k-1}' \ |---| |---| |--------+--------+--------+
--- End diff --
This comment should not be formatted.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5-pre] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125588453
--- Diff: core/src/main/java/hivemall/ftvec/binning/NumericHistogram.java ---
@@ -30,11 +30,9 @@
/**
* **THIS CLASS IS IMPORTED FROM HIVE 2.1.0 FOR COMPATIBILITY**
*
- * A generic, re-usable histogram class that supports partial aggregations. The algorithm is a
- * heuristic adapted from the following paper: Yael Ben-Haim and Elad Tom-Tov,
- * "A streaming parallel decision tree algorithm", J. Machine Learning Research 11 (2010), pp.
- * 849--872. Although there are no approximation guarantees, it appears to work well with adequate
- * data and a large (e.g., 20-80) number of histogram bins.
+ * A generic, re-usable histogram class that supports partial aggregations. The algorithm is a heuristic adapted from the following paper: Yael
+ * Ben-Haim and Elad Tom-Tov, "A streaming parallel decision tree algorithm", J. Machine Learning Research 11 (2010), pp. 849--872. Although there are
+ * no approximation guarantees, it appears to work well with adequate data and a large (e.g., 20-80) number of histogram bins.
--- End diff --
same as here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by takuti <gi...@git.apache.org>.
Github user takuti commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125200993
--- Diff: core/src/main/java/hivemall/anomaly/SDAR2D.java ---
@@ -33,129 +33,123 @@
public final class SDAR2D {
- // --------------------------------
- // hyperparameters
-
- /**
- * Forgetfulness parameter
- */
- private final double _r;
+ // --------------------------------
+ // hyperparameters
+
+ /**
+ * Forgetfulness parameter
+ */
+ private final double _r;
+
+ // --------------------------------
+ // parameters
+
+ private final RealMatrix[] _C;
+ private RealVector _mu;
+ private RealMatrix _sigma;
+ private RealVector _muOld;
+ private RealMatrix _sigmaOld;
+
+ private boolean _initialized;
+
+ public SDAR2D(final double r, final int k) {
+ Preconditions.checkArgument(0.d < r && r < 1.d, "Invalid forgetfullness parameter r: " + r);
+ Preconditions.checkArgument(k >= 1, "Invalid smoothing parameter k: " + k);
+ this._r = r;
+ this._C = new RealMatrix[k + 1];
+ this._initialized = false;
+ }
+
+ /**
+ * @param x series of input in LIFO order
+ * @param k AR window size
+ * @return x_hat predicted x
+ * @link https://en.wikipedia.org/wiki/Matrix_multiplication#Outer_product
+ */
+ @Nonnull
+ public RealVector update(@Nonnull final ArrayRealVector[] x, final int k) {
+ Preconditions.checkArgument(x.length >= 1, "x.length MUST be greather than 1: " + x.length);
+ Preconditions.checkArgument(k >= 0, "k MUST be greather than or equals to 0: ", k);
+ Preconditions.checkArgument(k < _C.length, "k MUST be less than |C| but " + "k=" + k + ", |C|="
--- End diff --
@myui Oh, it's huge...I understand what you are afraid ;(
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125184339
--- Diff: core/src/main/java/hivemall/anomaly/SDAR2D.java ---
@@ -33,129 +33,123 @@
public final class SDAR2D {
- // --------------------------------
- // hyperparameters
-
- /**
- * Forgetfulness parameter
- */
- private final double _r;
+ // --------------------------------
+ // hyperparameters
+
+ /**
+ * Forgetfulness parameter
+ */
+ private final double _r;
+
+ // --------------------------------
+ // parameters
+
+ private final RealMatrix[] _C;
+ private RealVector _mu;
+ private RealMatrix _sigma;
+ private RealVector _muOld;
+ private RealMatrix _sigmaOld;
+
+ private boolean _initialized;
+
+ public SDAR2D(final double r, final int k) {
+ Preconditions.checkArgument(0.d < r && r < 1.d, "Invalid forgetfullness parameter r: " + r);
+ Preconditions.checkArgument(k >= 1, "Invalid smoothing parameter k: " + k);
+ this._r = r;
+ this._C = new RealMatrix[k + 1];
+ this._initialized = false;
+ }
+
+ /**
+ * @param x series of input in LIFO order
+ * @param k AR window size
+ * @return x_hat predicted x
+ * @link https://en.wikipedia.org/wiki/Matrix_multiplication#Outer_product
+ */
+ @Nonnull
+ public RealVector update(@Nonnull final ArrayRealVector[] x, final int k) {
+ Preconditions.checkArgument(x.length >= 1, "x.length MUST be greather than 1: " + x.length);
+ Preconditions.checkArgument(k >= 0, "k MUST be greather than or equals to 0: ", k);
+ Preconditions.checkArgument(k < _C.length, "k MUST be less than |C| but " + "k=" + k + ", |C|="
--- End diff --
Here, you can find String concatenation problems.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
I need to rewrite [JIRA issue](https://issues.apache.org/jira/browse/HIVEMALL-5). Let's discuss on the next Monday (or Tues).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by takuti <gi...@git.apache.org>.
Github user takuti commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
@myui Thank you for sharing your opinion! I realized that this issue requires us to undergo significant amount of discussion and modification of the current code.
So, I renamed the title of this PR to **[HIVEMALL-5-pre]** as the first step to publish our fixed version of coding guideline. There is no update in terms of coding conventions, and I just applied the formatter to the current code and updated README for future contributors.
If it's acceptable for you, I like to merge this soon :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5-pre] Java code formatter
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-hivemall/pull/92
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
[](https://coveralls.io/builds/12226444)
Coverage decreased (-0.01%) to 40.264% when pulling **ba6826559ffc14256f6c34daf64a2d2a9c65f664 on takuti:hive-formatter** into **ec6d945fe48d64cd5175a2ad0156b8bd387c6138 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
> I suspect that you want to follow the google coding convention rather than Hive's one.
Right.
But, completely following Google coding style has problems in formatting existing codes. Manual comment rewriting and string concatenation rewriting is required.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
[](https://coveralls.io/builds/12226436)
Coverage increased (+0.3%) to 40.564% when pulling **ba6826559ffc14256f6c34daf64a2d2a9c65f664 on takuti:hive-formatter** into **ec6d945fe48d64cd5175a2ad0156b8bd387c6138 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5] Java code formatter
Posted by takuti <gi...@git.apache.org>.
Github user takuti commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
@myui Could you share how you are planning to re-write the JIRA issue here If possible? Keeping our discussion in public is generally better :)
Overall, I suspect that you want to follow the google coding convention rather than Hive's one. Is it correct? I'm personally okay for any conventions as long as they are well-documented. If we define some exceptions on either google / Hive (oracle) conventions, we manually need to document them ✍️
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
[](https://coveralls.io/builds/12226436)
Coverage increased (+0.3%) to 40.564% when pulling **ba6826559ffc14256f6c34daf64a2d2a9c65f664 on takuti:hive-formatter** into **ec6d945fe48d64cd5175a2ad0156b8bd387c6138 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
[](https://coveralls.io/builds/12228203)
Coverage decreased (-0.01%) to 40.264% when pulling **3d5069420ad06588fabe14fec79215bd91ef139d on takuti:hive-formatter** into **ec6d945fe48d64cd5175a2ad0156b8bd387c6138 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125170781
--- Diff: core/src/main/java/hivemall/classifier/KPAPredictUDAF.java ---
@@ -40,189 +40,187 @@
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
-@Description(
- name = "kpa_predict",
- value = "_FUNC_(@Nonnull double xh, @Nonnull double xk, @Nullable float w0, @Nonnull float w1, @Nonnull float w2, @Nullable float w3)"
- + " - Returns a prediction value in Double")
+@Description(name = "kpa_predict", value = "_FUNC_(@Nonnull double xh, @Nonnull double xk, @Nullable float w0, @Nonnull float w1, @Nonnull float w2, @Nullable float w3)"
+ + " - Returns a prediction value in Double")
public final class KPAPredictUDAF extends AbstractGenericUDAFResolver {
- @Override
- public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
- if (parameters.length != 6) {
- throw new UDFArgumentException(
- "_FUNC_(double xh, double xk, float w0, float w1, float w2, float w3) takes exactly 6 arguments but got: "
- + parameters.length);
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[0])) {
- throw new UDFArgumentTypeException(0, "Number type is expected for xh (1st argument): "
- + parameters[0].getTypeName());
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[1])) {
- throw new UDFArgumentTypeException(1, "Number type is expected for xk (2nd argument): "
- + parameters[1].getTypeName());
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[2])) {
- throw new UDFArgumentTypeException(2, "Number type is expected for w0 (3rd argument): "
- + parameters[2].getTypeName());
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[3])) {
- throw new UDFArgumentTypeException(3, "Number type is expected for w1 (4th argument): "
- + parameters[3].getTypeName());
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[4])) {
- throw new UDFArgumentTypeException(4, "Number type is expected for w2 (5th argument): "
- + parameters[4].getTypeName());
- }
- if (!HiveUtils.isNumberTypeInfo(parameters[5])) {
- throw new UDFArgumentTypeException(5, "Number type is expected for w3 (6th argument): "
- + parameters[5].getTypeName());
- }
-
- return new Evaluator();
+ @Override
+ public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
+ if (parameters.length != 6) {
+ throw new UDFArgumentException(
+ "_FUNC_(double xh, double xk, float w0, float w1, float w2, float w3) takes exactly 6 arguments but got: "
+ + parameters.length);
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[0])) {
+ throw new UDFArgumentTypeException(0, "Number type is expected for xh (1st argument): "
+ + parameters[0].getTypeName());
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[1])) {
+ throw new UDFArgumentTypeException(1, "Number type is expected for xk (2nd argument): "
+ + parameters[1].getTypeName());
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[2])) {
+ throw new UDFArgumentTypeException(2, "Number type is expected for w0 (3rd argument): "
+ + parameters[2].getTypeName());
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[3])) {
+ throw new UDFArgumentTypeException(3, "Number type is expected for w1 (4th argument): "
+ + parameters[3].getTypeName());
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[4])) {
+ throw new UDFArgumentTypeException(4, "Number type is expected for w2 (5th argument): "
+ + parameters[4].getTypeName());
+ }
+ if (!HiveUtils.isNumberTypeInfo(parameters[5])) {
+ throw new UDFArgumentTypeException(5, "Number type is expected for w3 (6th argument): "
+ + parameters[5].getTypeName());
}
- public static class Evaluator extends GenericUDAFEvaluator {
-
- @Nullable
- private transient PrimitiveObjectInspector xhOI, xkOI;
- @Nullable
- private transient PrimitiveObjectInspector w0OI, w1OI, w2OI, w3OI;
-
- public Evaluator() {}
+ return new Evaluator();
+ }
- @Override
- public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException {
- super.init(m, parameters);
+ public static class Evaluator extends GenericUDAFEvaluator {
- // initialize input
- if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) {// from original data
- this.xhOI = HiveUtils.asNumberOI(parameters[0]);
- this.xkOI = HiveUtils.asNumberOI(parameters[1]);
- this.w0OI = HiveUtils.asNumberOI(parameters[2]);
- this.w1OI = HiveUtils.asNumberOI(parameters[3]);
- this.w2OI = HiveUtils.asNumberOI(parameters[4]);
- this.w3OI = HiveUtils.asNumberOI(parameters[5]);
- }
+ @Nullable
+ private transient PrimitiveObjectInspector xhOI, xkOI;
+ @Nullable
+ private transient PrimitiveObjectInspector w0OI, w1OI, w2OI, w3OI;
- return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
- }
+ public Evaluator() {
--- End diff --
`public Evaluator() {}` is preferred as seen in Google coding style.
https://google.github.io/styleguide/javaguide.html#s4.1.3-braces-empty-blocks
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall issue #92: [HIVEMALL-5-pre] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on the issue:
https://github.com/apache/incubator-hivemall/pull/92
Merged with some modifications. 100 spaces for Javadoc comment, as same as Google style, works fine.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-hivemall pull request #92: [HIVEMALL-5] Java code formatter
Posted by myui <gi...@git.apache.org>.
Github user myui commented on a diff in the pull request:
https://github.com/apache/incubator-hivemall/pull/92#discussion_r125170771
--- Diff: core/src/main/java/hivemall/anomaly/SingularSpectrumTransform.java ---
@@ -41,161 +41,160 @@
final class SingularSpectrumTransform implements SingularSpectrumTransformInterface {
- @Nonnull
- private final PrimitiveObjectInspector oi;
- @Nonnull
- private final ScoreFunction scoreFunc;
-
- @Nonnull
- private final int window;
- @Nonnull
- private final int nPastWindow;
- @Nonnull
- private final int nCurrentWindow;
- @Nonnull
- private final int pastSize;
- @Nonnull
- private final int currentSize;
- @Nonnull
- private final int currentOffset;
- @Nonnull
- private final int r;
- @Nonnull
- private final int k;
-
- @Nonnull
- private final DoubleRingBuffer xRing;
- @Nonnull
- private final double[] xSeries;
-
- @Nonnull
- private final double[] q;
-
- SingularSpectrumTransform(@Nonnull Parameters params, @Nonnull PrimitiveObjectInspector oi) {
- this.oi = oi;
- this.scoreFunc = params.scoreFunc;
-
- this.window = params.w;
- this.nPastWindow = params.n;
- this.nCurrentWindow = params.m;
- this.pastSize = window + nPastWindow;
- this.currentSize = window + nCurrentWindow;
- this.currentOffset = params.g;
- this.r = params.r;
- this.k = params.k;
- Preconditions.checkArgument(params.k >= params.r);
-
- // (w + n) past samples for the n-past-windows
- // (w + m) current samples for the m-current-windows, starting from offset g
- // => need to hold past (w + n + g + w + m) samples from the latest sample
- int holdSampleSize = pastSize + currentOffset + currentSize;
-
- this.xRing = new DoubleRingBuffer(holdSampleSize);
- this.xSeries = new double[holdSampleSize];
-
- this.q = new double[window];
- double norm = 0.d;
- for (int i = 0; i < window; i++) {
- this.q[i] = Math.random();
- norm += q[i] * q[i];
- }
- norm = Math.sqrt(norm);
- // normalize
- for (int i = 0; i < window; i++) {
- this.q[i] = q[i] / norm;
- }
+ @Nonnull
+ private final PrimitiveObjectInspector oi;
+ @Nonnull
+ private final ScoreFunction scoreFunc;
+
+ @Nonnull
+ private final int window;
+ @Nonnull
+ private final int nPastWindow;
+ @Nonnull
+ private final int nCurrentWindow;
+ @Nonnull
+ private final int pastSize;
+ @Nonnull
+ private final int currentSize;
+ @Nonnull
+ private final int currentOffset;
+ @Nonnull
+ private final int r;
+ @Nonnull
+ private final int k;
+
+ @Nonnull
+ private final DoubleRingBuffer xRing;
+ @Nonnull
+ private final double[] xSeries;
+
+ @Nonnull
+ private final double[] q;
+
+ SingularSpectrumTransform(@Nonnull Parameters params, @Nonnull PrimitiveObjectInspector oi) {
+ this.oi = oi;
+ this.scoreFunc = params.scoreFunc;
+
+ this.window = params.w;
+ this.nPastWindow = params.n;
+ this.nCurrentWindow = params.m;
+ this.pastSize = window + nPastWindow;
+ this.currentSize = window + nCurrentWindow;
+ this.currentOffset = params.g;
+ this.r = params.r;
+ this.k = params.k;
+ Preconditions.checkArgument(params.k >= params.r);
+
+ // (w + n) past samples for the n-past-windows
+ // (w + m) current samples for the m-current-windows, starting from offset g
+ // => need to hold past (w + n + g + w + m) samples from the latest sample
+ int holdSampleSize = pastSize + currentOffset + currentSize;
+
+ this.xRing = new DoubleRingBuffer(holdSampleSize);
+ this.xSeries = new double[holdSampleSize];
+
+ this.q = new double[window];
+ double norm = 0.d;
+ for (int i = 0; i < window; i++) {
+ this.q[i] = Math.random();
+ norm += q[i] * q[i];
}
-
- @Override
- public void update(@Nonnull final Object arg, @Nonnull final double[] outScores)
- throws HiveException {
- double x = PrimitiveObjectInspectorUtils.getDouble(arg, oi);
- xRing.add(x).toArray(xSeries, true /* FIFO */);
-
- // need to wait until the buffer is filled
- if (!xRing.isFull()) {
- outScores[0] = 0.d;
- } else {
- // create past trajectory matrix and find its left singular vectors
- RealMatrix H = new Array2DRowRealMatrix(window, nPastWindow);
- for (int i = 0; i < nPastWindow; i++) {
- H.setColumn(i, Arrays.copyOfRange(xSeries, i, i + window));
- }
-
- // create current trajectory matrix and find its left singular vectors
- RealMatrix G = new Array2DRowRealMatrix(window, nCurrentWindow);
- int currentHead = pastSize + currentOffset;
- for (int i = 0; i < nCurrentWindow; i++) {
- G.setColumn(i,
- Arrays.copyOfRange(xSeries, currentHead + i, currentHead + i + window));
- }
-
- switch (scoreFunc) {
- case svd:
- outScores[0] = computeScoreSVD(H, G);
- break;
- case ika:
- outScores[0] = computeScoreIKA(H, G);
- break;
- default:
- throw new IllegalStateException("Unexpected score function: " + scoreFunc);
- }
- }
+ norm = Math.sqrt(norm);
+ // normalize
+ for (int i = 0; i < window; i++) {
+ this.q[i] = q[i] / norm;
}
-
- /**
- * Singular Value Decomposition (SVD) based naive scoring.
- */
- private double computeScoreSVD(@Nonnull final RealMatrix H, @Nonnull final RealMatrix G) {
- SingularValueDecomposition svdH = new SingularValueDecomposition(H);
- RealMatrix UT = svdH.getUT();
-
- SingularValueDecomposition svdG = new SingularValueDecomposition(G);
- RealMatrix Q = svdG.getU();
-
- // find the largest singular value for the r principal components
- RealMatrix UTQ = UT.getSubMatrix(0, r - 1, 0, window - 1).multiply(
- Q.getSubMatrix(0, window - 1, 0, r - 1));
- SingularValueDecomposition svdUTQ = new SingularValueDecomposition(UTQ);
- double[] s = svdUTQ.getSingularValues();
-
- return 1.d - s[0];
+ }
+
+ @Override
+ public void update(@Nonnull final Object arg, @Nonnull final double[] outScores)
+ throws HiveException {
+ double x = PrimitiveObjectInspectorUtils.getDouble(arg, oi);
+ xRing.add(x).toArray(xSeries, true /* FIFO */);
+
+ // need to wait until the buffer is filled
+ if (!xRing.isFull()) {
+ outScores[0] = 0.d;
+ } else {
+ // create past trajectory matrix and find its left singular vectors
+ RealMatrix H = new Array2DRowRealMatrix(window, nPastWindow);
+ for (int i = 0; i < nPastWindow; i++) {
+ H.setColumn(i, Arrays.copyOfRange(xSeries, i, i + window));
+ }
+
+ // create current trajectory matrix and find its left singular vectors
+ RealMatrix G = new Array2DRowRealMatrix(window, nCurrentWindow);
+ int currentHead = pastSize + currentOffset;
+ for (int i = 0; i < nCurrentWindow; i++) {
+ G.setColumn(i, Arrays.copyOfRange(xSeries, currentHead + i, currentHead + i + window));
+ }
+
+ switch (scoreFunc) {
+ case svd:
--- End diff --
`case` better to be indented as seen in Google coding style.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---