Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Java计算点积距离_Java_Arraylist_Hashmap_Dot Product - Fatal编程技术网

用Java计算点积距离

用Java计算点积距离,java,arraylist,hashmap,dot-product,Java,Arraylist,Hashmap,Dot Product,我需要做的是,计算两个客户评级之间的点积距离。客户的评级记录在hashmap中 private HashMap<String,int[]> ratingmap; 下面是在评级分析类中给出的另一个细节 //collection of rated book titles private BookList books; //collection of customers and their ratings private RatingsMap ratings; //use a list

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

private HashMap<String,int[]> ratingmap;
下面是在
评级分析
类中给出的另一个细节

//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;
//分级书名的集合
私人书目;
//收集客户及其评级
私人评级SMAP评级;
//使用评级映射中的客户名称列表在映射中循环
私人ArrayList客户;

可能是成员字段

private RatingsMap ratings;
评级分析中
是名称=>评级的
映射。您在距离法中的任务是:

  • 查找
    name1
    name2
    的评级,并将其存储在局部变量中(hint:使用
    Map
    界面上定义的
    get
    方法)
  • 对上述两个评级进行dot产品分析。您知道如何执行此操作,或者需要提供更多关于此问题中
    评级的含义的信息
  • 返回结果
  • 作为旁注,RatingsMap可以而且应该是更强类型的:

    private RatingsMap<String, Rating> ratings;
    

    请在此上下文中定义“点产品距离”。点产品距离是指两个客户的评级“密切”相关的程度。就像每个客户都被允许对一本书进行评级一样,从我所看到的是,它询问评级有多接近,即差异,但不清楚在这种情况下会涉及到什么计算。请编辑您的问题,以给出一个您希望执行的计算示例。在我看来,不只是减去每个客户的所有int(本例中仅为cust1和cust2)吗?您希望构建两个向量(每个用户一个),其中每个维度都是同一给定书籍的评级?然后计算这些向量的点积。如果未给出评级,请填写“0”,或从向量bc中删除此维度“0”可能与非常负面的评级相同?这对你有意义吗?是的,听起来很合乎逻辑,我能得到一个关于如何执行此操作的活骨架代码吗,因为目前我似乎无法理解。谢谢你,我试试这个,然后再回复你:)评级词在评级r1和评级r2时不起作用,我用“评级”这个词来代替什么很抱歉,我在这方面真的没用这项作业给你上了什么课?评级是一个类公共评级分析(){books=new BookList();ratings=new RatingsMap();customernames=ratings.getCustomerNames();}
    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 ....
        }
    }