Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.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
MyMediaLiteJava推荐方法_Java_C#_Recommendation Engine - Fatal编程技术网

MyMediaLiteJava推荐方法

MyMediaLiteJava推荐方法,java,c#,recommendation-engine,Java,C#,Recommendation Engine,我在MyMediaLiteJava中发现了这一点( 在gitHub上)是不推荐的方法,因为它在该推荐程序的C#版本中。 例如,在C#MyMediaLite文档中,随机推荐程序是方法推荐(int user\u id,int n=-1,ICollectionignore\u items=null,ICollectioncandidate\u items=null),但在Java版本中没有这样的方法。。或者我错过了什么我只想尝试至少随机获得推荐的项目我还尝试将推荐方法从C#重新编写为JAVA,但对我来

我在MyMediaLiteJava中发现了这一点( 在gitHub上)是不推荐的方法,因为它在该推荐程序的C#版本中。 例如,在C#MyMediaLite文档中,随机推荐程序是方法
推荐(int user\u id,int n=-1,ICollectionignore\u items=null,ICollectioncandidate\u items=null)
,但在Java版本中没有这样的方法。。或者我错过了什么
我只想尝试至少随机获得推荐的项目
我还尝试将推荐方法从C#重新编写为JAVA,但对我来说这有点太难了,因为我不知道一些C#与JAVA的相似之处。我将在这里推荐C#上的方法代码,也许我会得到一些建议

public virtual System.Collections.Generic.IList<Tuple<int, float>> Recommend(
        int user_id, int n = -1,
        System.Collections.Generic.ICollection<int> ignore_items = null,
        System.Collections.Generic.ICollection<int> candidate_items = null)
    {
        if (candidate_items == null)
            candidate_items = Enumerable.Range(0, MaxItemID - 1).ToList();
        if (ignore_items == null)
            ignore_items = new int[0];

        System.Collections.Generic.IList<Tuple<int, float>> ordered_items;

        if (n == -1)
        {
            var scored_items = new List<Tuple<int, float>>();
            foreach (int item_id in candidate_items)
                if (!ignore_items.Contains(item_id))
                {
                    float score = Predict(user_id, item_id);
                    if (score > float.MinValue)
                        scored_items.Add(Tuple.Create(item_id, score));
                }
            ordered_items = scored_items.OrderByDescending(x => x.Item2).ToArray();
        }
        else
        {
            var comparer = new DelegateComparer<Tuple<int, float>>( (a, b) => a.Item2.CompareTo(b.Item2) );
            var heap = new IntervalHeap<Tuple<int, float>>(n, comparer);
            float min_relevant_score = float.MinValue;

            foreach (int item_id in candidate_items)
                if (!ignore_items.Contains(item_id))
                {
                    float score = Predict(user_id, item_id);
                    if (score > min_relevant_score)
                    {
                        heap.Add(Tuple.Create(item_id, score));
                        if (heap.Count > n)
                        {
                            heap.DeleteMin();
                            min_relevant_score = heap.FindMin().Item2;
                        }
                    }
                }

            ordered_items = new Tuple<int, float>[heap.Count];
            for (int i = 0; i < ordered_items.Count; i++)
                ordered_items[i] = heap.DeleteMax();
        }

        return ordered_items;
    }
public virtual System.Collections.Generic.IList建议(
int user_id,int n=-1,
System.Collections.Generic.ICollection ignore_items=null,
System.Collections.Generic.ICollection候选者_items=null)
{
if(候选项==null)
候选项=Enumerable.Range(0,MaxItemID-1).ToList();
if(忽略_项==null)
忽略_项=新整数[0];
System.Collections.Generic.IList订购的\u项;
如果(n==-1)
{
var评分项目=新列表();
foreach(候选项中的int item\u id)
如果(!ignore_items.Contains(item_id))
{
浮动分数=预测(用户id、项目id);
如果(分数>浮点值)
添加(Tuple.Create(item_id,score));
}
ordered_items=得分的_items.OrderByDescending(x=>x.Item2.ToArray();
}
其他的
{
var comparer=新的DelegateComparer((a,b)=>a.Item2.CompareTo(b.Item2));
var heap=新的间隔堆(n,比较器);
浮动最小相关分数=浮动最小值;
foreach(候选项中的int item\u id)
如果(!ignore_items.Contains(item_id))
{
浮动分数=预测(用户id、项目id);
如果(分数>最小相关分数)
{
添加(Tuple.Create(item_id,score));
如果(heap.Count>n)
{
heap.DeleteMin();
最小相关分数=heap.FindMin().Item2;
}
}
}
ordered_items=新元组[heap.Count];
对于(int i=0;i
您是否尝试就此联系作者?没有,尚未尝试。我应该试试吗?如果有人知道,为什么他们在Java版本中遗漏了这个方法,那么是那些人决定这么做的,对吧?你有没有试着联系作者?没有,没有尝试过。我应该试试吗?如果有人知道,为什么他们在Java版本中忽略了这个方法,那么是那些人决定这么做的,对吗?