【问题标题】:Calculating the dotproduct distance in Java在Java中计算点积距离
【发布时间】:2012-05-24 11:23:42
【问题描述】:

我需要做的是,计算两个客户评分之间的点积距离。客户的评分记录在哈希图中。

private HashMap<String,int[]> ratingmap;

hashmap 中的键是客户名称,与之相关的是该客户的评分(他对书籍的评分)

我该怎么做?

/**
 * calculate dot product distance between the ratings of two customers
 * @param name1 String name of customer 
 * @param name2 String name of customer 
 * @return int distance or ILLEGAL_INPUT if name1 or name2 are not customers
 */
public int distance(String name1, String name2) 
{
    return 0; //replace with code
}

这是RatingsAnalysis 课程中给出的另一点细节

//collection of rated book titles
private BookList books;
//collection of customers and their ratings
private RatingsMap ratings;
//use a list of customer names from the ratings map for looping through the map
private ArrayList<String> customernames;

【问题讨论】:

  • 请在此上下文中定义“点积距离”。
  • 点积距离是两个客户的评级之间的“密切”关系。就像每个客户都可以对一本书进行评分一样,据我所知,它询问评分的接近程度,即差异
  • 但不清楚在这种情况下会涉及什么计算。请编辑您的问题,以举例说明您要执行的计算。
  • 难道不只是减去每个客户的所有 int(在这种情况下只有 cust1 和 cust2)
  • 在我看来,您想构建两个向量(每个用户一个),其中每个维度都是同一本书的评分?然后计算这些向量的点积。 . .如果没有给出评级,你会填写“0”还是从向量中删除这个维度,bc。 “0”可能与非常负面的评级相同?这对你有意义吗?

标签: java arraylist hashmap dot-product


【解决方案1】:

大概是会员字段

private RatingsMap ratings;

RatingsAnalysis 中是名称=> 评级的Map。你在distance 方法中的任务是这样的:

  1. 查找name1name2 的评分并将它们存储在局部变量中(提示:使用get 接口上定义的get 方法)
  2. 对上面获得的这两个评级执行点积分析。您要么知道如何执行此操作,要么需要提供有关此问题中 Rating 含义的更多信息。
  3. 返回结果

附带说明,RatingsMap 可以而且应该是更强类型的:

private RatingsMap<String, Rating> ratings;

编辑:添加请求的骨架代码...

public int distance(String name1, String name2) 
{
    Rating r1 = this.ratings.get(name1);
    Rating r2 = this.ratings.get(name2);

    if(r1 != null && r2 != null) { 
       return ....
    }
}

【讨论】:

  • 是的,听起来合乎逻辑,我可以得到一个关于如何执行此操作的行走骨架代码,因为目前我似乎无法弄清楚
  • 谢谢你,我试试这个然后回复你:)
  • Rating r1 和 Rating r2 中的“Rating”字不起作用,我可以用“Rating”这个词代替什么?对不起,我在这方面真的没用
  • 本次作业中为您安排了哪些课程?评级是一门课
  • public RatingsAnalysis() { books = new BookList();评级 = 新评级地图(); customernames = rating.getCustomerNames(); }
猜你喜欢
  • 2014-11-14
  • 1970-01-01
  • 2014-02-03
  • 2014-05-15
  • 1970-01-01
  • 2012-04-30
  • 2016-12-16
  • 1970-01-01
  • 2019-03-31
相关资源
最近更新 更多