Example #1
0
    public List <Record> GetPredictedCluster(Vector3 pos, Vector3 rot, HashSet <Record[]> origin_clusters, List <Cluster> clusterDes)
    {
        var exchangeAxis = new ExchangeAxis();

        Record[] predicted_cluster = null;
        double   maxValue          = -100;

        Debug.Log("现在朝向" + rot);
        Coeffecient     getCoefficient = new Coeffecient();
        int             count          = 0;
        List <Record[]> clusters       = origin_clusters.ToList();

        foreach (var cluster in clusters)
        {
            //数据块的距离(暂时按照cluster0计算)
            //Vector3 clusterCenterPos = exchangeAxis.ModelIndex_to_unityPos((float)cluster[0].posX, (float)cluster[0].posY, (float)cluster[0].posZ);
            Vector3 centerPos        = GetCenterPoint(cluster);
            Vector3 clusterCenterPos = exchangeAxis.ModelIndex_to_unityPos((float)centerPos.x, (float)centerPos.y, (float)centerPos.z);
            double  distance         = GetDistance(pos, clusterCenterPos);
            //偏角
            double avertence = GetAvertence(pos, rot, clusterCenterPos);
            //兴趣度系数(需改进)
            //double coefficient = getCoefficient.GetCoefficeent(cluster);
            double coefficient = 0;
            double value       = coefficient + distance + avertence + clusterDes[count].gaze;
            if (distance < 10)
            {
                predicted_cluster = clusters[clusterDes[count].getMaxProId()];
                break;
            }
            //double value = clusterDes[count].gaze;

            count++;

            Debug.Log("=====兴趣度系数是" + value + "=====");
            //计算每个cluster的interest_value(需改进)加入数量?
            //只选取 “一个” 最优的cluster(需改进)
            if (value > maxValue)
            {
                maxValue          = value;
                predicted_cluster = cluster;
            }
        }
        return(predicted_cluster.ToList());
        //List<Record> Unitypos_predicted_cluster = new List<Record>();
        //List<Record> oho = predicted_cluster.ToList();
        //if (predicted_cluster!=null)
        //{
        //    foreach (var box in predicted_cluster)
        //    {
        //        Vector3 pos1 = exchangeAxis.ModelIndex_to_unityPos((float)box.posX, (float)box.posY,(float)box.posZ);
        //        Vector3 rot1 = new Vector3((float)box.rotX, (float)box.rotY, (float)box.rotZ);
        //        Unitypos_predicted_cluster.Add(new Record(pos1,rot1));

        //    }
        //}

        //return Unitypos_predicted_cluster;
    }
Example #2
0
        public HashSet <Record[]> Dbscan(out List <int> clusterIds, out List <Cluster> clusterDes)
        {
            HashSet <Record[]> clusters;

            Record[] featureData = { };

            //List<Record> testPoints = Launcher.instance.history.GetRecords();
            List <Record> testPoints = new List <Record>();

            using (StreamReader sr = new StreamReader(Application.streamingAssetsPath + "/" + Launcher.instance.GetSceneName + "/history.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    string[] _record = line.Split('=');
                    string[] liness  = _record[1].Split('_');
                    string[] lines0  = liness[0].Split(',');
                    string[] lines1  = liness[1].Split(',');
                    Vector3  tmpPos  = new Vector3(float.Parse(lines0[0]), float.Parse(lines0[1]), float.Parse(lines0[2]));
                    Vector3  tmpRot  = new Vector3(float.Parse(lines1[0]), float.Parse(lines1[1]), float.Parse(lines1[2]));
                    testPoints.Add(new Record(tmpPos, tmpRot));
                }
            }



            List <Record> testPointsIndex = new List <Record>();
            var           exchangeAxis    = new ExchangeAxis();

            foreach (var testPoint in testPoints)
            {
                //Vector3 iIdex =
                //    exchangeAxis.UnityPos_to_modelIndex(new Vector3((float)testPoint.posX, (float)testPoint.posY, (float)testPoint.posZ));
                //testPointsIndex.Add(new Record(iIdex, new Vector3((float)testPoint.rotX, (float)testPoint.rotY, (float)testPoint.rotZ)));
                testPointsIndex.Add(new Record(new Vector3((float)testPoint.posX, (float)testPoint.posY, (float)testPoint.posZ),
                                               new Vector3((float)testPoint.rotX, (float)testPoint.rotY, (float)testPoint.rotZ)));
            }

            //
            //            string path = Application.streamingAssetsPath + "/" + Launcher.instance.GetSceneName + "/history.txt";
            //            Debug.Log(path+"---------------------------");
            //            //读取数据点
            //            using (StreamReader sr = new StreamReader(path))
            //            {
            //                string line;
            //                while ((line = sr.ReadLine()) != null)
            //                {
            //                    if (line == "") { continue; }
            //                    line = line.Replace("(", "").Replace(")", "");
            //                    string[] lines = line.Split(',');
            //                    testPoints.Add(newRecord(float.Parse(lines[0]), float.Parse(lines[1]), float.Parse(lines[2])));
            //                }
            //            }

            /*
             * //添加测试点
             * for (int i = 0; i < 1000; i++)
             * {
             *  //Test Points
             *  testPoints.Add(newRecord(1000,2,3));
             *  testPoints.Add(newRecord(1000,3,3));
             *  testPoints.Add(newRecord(1000,4,5));
             *  testPoints.Add(newRecord(1000,1,3));
             *  testPoints.Add(newRecord(1000,3,1));
             *
             *  testPoints.Add(newRecord(2000,3,3));
             *  testPoints.Add(newRecord(2000,7,5));
             *
             *  testPoints.Add(newRecord(6,2,3));
             *  testPoints.Add(newRecord(6,3,3));
             *  testPoints.Add(newRecord(6,4,5));
             *
             *  testPoints.Add(newRecord(3000,1,3));
             *  testPoints.Add(newRecord(3000,3,1));
             *  testPoints.Add(newRecord(3000,7,5));
             *  testPoints.Add(newRecord(3000,3,3));
             * }
             */
            Debug.Log("Total number of the counts: " + testPoints.Count);
            featureData = testPointsIndex.ToArray();
            var dbs = new DbscanAlgorithm <Record>((x, y) => Math.Sqrt(((x.posX - y.posX) * (x.posX - y.posX)) + ((x.posY - y.posY) * (x.posY - y.posY)) + ((x.posZ - y.posZ) * (x.posZ - y.posZ))));

            clusterIds = new List <int>();
            dbs.ComputeClusterDbscan(allPoints: featureData, epsilon: 3, minPts: 15, clusters: out clusters, ref clusterIds);
            clusterDes = dbs.GetClusterDes(clusters, clusterIds, Launcher.instance.history.getAllBrowseRecord());
            //dbs.ComputeClusterDbscan(allPoints: featureData, epsilon:10, minPts: 40, clusters: out clusters);
            Debug.Log("Below is the Result of the DBscan");
            //int count1 = 0;
            //foreach (Record[] i in clusters)
            //{
            //    Debug.Log("--------Cluster: "+(++count1)+"--------");
            //    Debug.Log(i[0].posX+"  "+i[0].posY+"  "+i[0].posZ);
            //}
            return(clusters);
        }
Example #3
0
    public Cluster GetPredictedCluster(Vector3 pos, Vector3 rot, List <Cluster> clusterNet, List <Record> gazePoints)
    {
        var exchangeAxis = new ExchangeAxis();
        //Record[] predicted_cluster = null;
        Cluster predicted_cluster = null;
        double  maxValue          = -100;

        Debug.Log("现在朝向" + rot);
        Coeffecient getCoefficient = new Coeffecient();
        int         count          = 0;
        //List<Record[]> clusters= origin_clusters.ToList();
        Dictionary <int, double> _distanceDic = distanceDic(clusterNet, pos);
        var minPair = _distanceDic.Keys.Select(x => new { x, y = _distanceDic[x] }).OrderBy(x => x.y).First();
        var minId   = minPair.x;
        var minDis  = _distanceDic[minId];

        _distanceDic.Remove(minId);
        var secPair = _distanceDic.Keys.Select(x => new { x, y = _distanceDic[x] }).OrderBy(x => x.y).First();
        var secId   = secPair.x;
        var secDis  = _distanceDic[secId];

        if (Math.Abs(minDis - secDis) < 10)
        {
            if (Math.Abs(GetAvertence(pos, rot, clusterNet[minId].center)) < 0.25)
            {
                predicted_cluster = clusterNet[minId];
            }
            else
            {
                predicted_cluster = clusterNet[secId];
            }
        }
        else
        {
            foreach (var _cluster in clusterNet)
            {
                if (_cluster.id == minId)
                {
                    continue;
                }
                double value = _cluster.gazePro + clusterNet[minId].getPro(_cluster.id) + _cluster.getSilCoe(clusterNet[minId]);
                if (value > maxValue)
                {
                    maxValue          = value;
                    predicted_cluster = _cluster;
                }
            }
        }
        //foreach (var _cluster in clusterNet)
        //{
        //    //var cluster = _cluster.points;
        //    //数据块的距离(暂时按照cluster0计算)
        //    //Vector3 clusterCenterPos = exchangeAxis.ModelIndex_to_unityPos((float)cluster[0].posX, (float)cluster[0].posY, (float)cluster[0].posZ);
        //    Vector3 centerPos = _cluster.center;
        //    //Vector3 clusterCenterPos = exchangeAxis.ModelIndex_to_unityPos((float)centerPos.x, (float)centerPos.y, (float)centerPos.z);
        //    //double distance = GetDistance(pos,clusterCenterPos);
        //    double distance = GetDistance(pos, centerPos);
        //    //偏角
        //    //double avertence = GetAvertence(pos,rot, clusterCenterPos);
        //    double avertence = GetAvertence(pos, rot, centerPos);
        //    //兴趣度系数(需改进)
        //    //double coefficient = getCoefficient.GetCoefficeent(cluster);
        //    double coefficient = 0;
        //    double value = coefficient+distance+avertence + clusterNet[count].gaze;
        //    if(distance<10)
        //    {
        //        //predicted_cluster = clusters[clusterNet[count].getMaxProId()];
        //        predicted_cluster= clusterNet[clusterNet[count].getMaxProId()];
        //        break;
        //    }
        //    //double value = clusterNet[count].gaze;

        //    count++;

        //    Debug.Log("=====兴趣度系数是"+value+"=====");
        //    //计算每个cluster的interest_value(需改进)加入数量?
        //    //只选取 “一个” 最优的cluster(需改进)
        //    if (value > maxValue)
        //    {
        //        maxValue = value;
        //        predicted_cluster = _cluster;
        //    }
        //}
        return(predicted_cluster);
        //List<Record> Unitypos_predicted_cluster = new List<Record>();
        //List<Record> oho = predicted_cluster.ToList();
        //if (predicted_cluster!=null)
        //{
        //    foreach (var box in predicted_cluster)
        //    {
        //        Vector3 pos1 = exchangeAxis.ModelIndex_to_unityPos((float)box.posX, (float)box.posY,(float)box.posZ);
        //        Vector3 rot1 = new Vector3((float)box.rotX, (float)box.rotY, (float)box.rotZ);
        //        Unitypos_predicted_cluster.Add(new Record(pos1,rot1));

        //    }
        //}

        //return Unitypos_predicted_cluster;
    }