Created
June 6, 2016 06:05
-
-
Save myui/7cfc29182bb16f1921c9fdc47d6f6f17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Hivemall: Hive scalable Machine Learning Library | |
* | |
* Copyright (C) 2015 Makoto YUI | |
* Copyright (C) 2013-2015 National Institute of Advanced Industrial Science and Technology (AIST) | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package hivemall.fm; | |
import javax.annotation.Nullable; | |
import org.apache.hadoop.hive.ql.exec.Description; | |
import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator.AggregationBuffer; | |
@Description(name = "ffm_predict", | |
value = "_FUNC_(double Wi, array<float> Vi, array<float> Vj, double Xi, double Xj)" | |
+ " - Returns a prediction value in Double") | |
public final class FFMPredictUDAF { | |
public static class FFMPredictAggregationBuffer implements AggregationBuffer { | |
private double ret = 0.d; | |
private void merge(final double w0) { | |
ret += w0; | |
} | |
private void merge(final double Wi, @Nullable final float[] Vij, | |
@Nullable final float[] Vji, final double Xi, final double Xj, final int factors) { | |
ret += Xi * Wi; | |
for (int f = 0; f < factors; f++) { | |
ret += Vij[f] * Vji[f] * Xi * Xj; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment