|
@@ -11,6 +11,7 @@ import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -26,6 +27,9 @@ public class I2IRecommendStrategy implements ScoreStrategy {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private I2IRecommendRepository i2iRecommendRepository;
|
|
private I2IRecommendRepository i2iRecommendRepository;
|
|
|
|
|
|
|
|
|
|
+ @Value("${i2i.maxScore:5}")
|
|
|
|
|
+ private Double maxScore;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<Score> score(ScoreParam param) {
|
|
public List<Score> score(ScoreParam param) {
|
|
|
List<Score> scores = new ArrayList<>();
|
|
List<Score> scores = new ArrayList<>();
|
|
@@ -49,7 +53,7 @@ public class I2IRecommendStrategy implements ScoreStrategy {
|
|
|
double logScore = Math.log(recommendScore + eps);
|
|
double logScore = Math.log(recommendScore + eps);
|
|
|
// ② 用你真实分布的 log 区间归一化
|
|
// ② 用你真实分布的 log 区间归一化
|
|
|
double logMin = Math.log(0.0001);
|
|
double logMin = Math.log(0.0001);
|
|
|
- double logMax = Math.log(100);
|
|
|
|
|
|
|
+ double logMax = Math.log(maxScore);
|
|
|
double normalized = (logScore - logMin) / (logMax - logMin);
|
|
double normalized = (logScore - logMin) / (logMax - logMin);
|
|
|
normalized = Math.max(0.0, Math.min(1.0, normalized));
|
|
normalized = Math.max(0.0, Math.min(1.0, normalized));
|
|
|
// ③ 指数拉开头部
|
|
// ③ 指数拉开头部
|