代码优化

This commit is contained in:
tarzan
2023-04-04 14:55:49 +08:00
parent 43c55193c9
commit e648b7823f
3 changed files with 8 additions and 8 deletions

View File

@@ -50,8 +50,8 @@ public class CoreMath {
* @return double * @return double
*/ */
private static double relateDist(List<RelateDTO> xList, List<RelateDTO> yList,int type) { private static double relateDist(List<RelateDTO> xList, List<RelateDTO> yList,int type) {
List<Integer> xs= Lists.newArrayList(); List<Double> xs= Lists.newArrayList();
List<Integer> ys= Lists.newArrayList(); List<Double> ys= Lists.newArrayList();
xList.forEach(x->{ xList.forEach(x->{
yList.forEach(y->{ yList.forEach(y->{
if(type==0){ if(type==0){
@@ -79,7 +79,7 @@ public class CoreMath {
* @author tarzan * @author tarzan
* @date 2020年07月31日 17:03:20 * @date 2020年07月31日 17:03:20
*/ */
public static double getRelate(List<Integer> xs, List<Integer> ys){ public static double getRelate(List<Double> xs, List<Double> ys){
int n=xs.size(); int n=xs.size();
//至少有两个元素 //至少有两个元素
if (n<2) { if (n<2) {

View File

@@ -21,7 +21,7 @@ public class RelateDTO {
/** 物品id */ /** 物品id */
private Integer itemId; private Integer itemId;
/** 指数 */ /** 指数 */
private Integer index; private Double index;
} }

View File

@@ -21,6 +21,9 @@ public class FileDataSource {
public static String folderPath; public static String folderPath;
static {
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
}
/** /**
@@ -31,7 +34,6 @@ public class FileDataSource {
* @date 2020年07月31日 16:53:40 * @date 2020年07月31日 16:53:40
*/ */
public static List<RelateDTO> getData() { public static List<RelateDTO> getData() {
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
List<RelateDTO> relateList = Lists.newArrayList(); List<RelateDTO> relateList = Lists.newArrayList();
try { try {
FileInputStream out = new FileInputStream(folderPath+"\\u.data"); FileInputStream out = new FileInputStream(folderPath+"\\u.data");
@@ -43,7 +45,7 @@ public class FileDataSource {
String[] ht = newline.split(" "); String[] ht = newline.split(" ");
Integer userId = Integer.parseInt(ht[0]); Integer userId = Integer.parseInt(ht[0]);
Integer movieId = Integer.parseInt(ht[1]); Integer movieId = Integer.parseInt(ht[1]);
Integer rating = Integer.parseInt(ht[2]); Double rating = Double.parseDouble(ht[2]);
RelateDTO dto = new RelateDTO(userId, movieId, rating); RelateDTO dto = new RelateDTO(userId, movieId, rating);
relateList.add(dto); relateList.add(dto);
} }
@@ -61,7 +63,6 @@ public class FileDataSource {
* @date 2020年07月31日 16:54:51 * @date 2020年07月31日 16:54:51
*/ */
public static List<UserDTO> getUserData() { public static List<UserDTO> getUserData() {
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
List<UserDTO> userList = Lists.newArrayList(); List<UserDTO> userList = Lists.newArrayList();
try { try {
FileInputStream out = new FileInputStream(folderPath+"\\u.user"); FileInputStream out = new FileInputStream(folderPath+"\\u.user");
@@ -94,7 +95,6 @@ public class FileDataSource {
* @date 2020年07月31日 16:54:22 * @date 2020年07月31日 16:54:22
*/ */
public static List<ItemDTO> getItemData() { public static List<ItemDTO> getItemData() {
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
List<ItemDTO> itemList = Lists.newArrayList(); List<ItemDTO> itemList = Lists.newArrayList();
try { try {
FileInputStream out = new FileInputStream(folderPath+"\\u.item"); FileInputStream out = new FileInputStream(folderPath+"\\u.item");