コード例 #1
0
        public bool Validate(ITrail expected, ITrail actual, float threshold)
        {
            var expectedSamples = expected.GetSampledLocations();
            var actualSamples   = expected.GetSampledLocations();

            var  diff        = expectedSamples.Zip(actualSamples, (e, a) => e - a);
            var  normDiff    = diff.Select(d => d.magnitude);
            var  sumNormDiff = normDiff.Aggregate(0.0, (x, y) => x + y);
            var  mse         = sumNormDiff / diff.Count();
            bool isValid     = mse < threshold;

            return(isValid);
        }
コード例 #2
0
        public bool Validate(ITrail expected, ITrail actual, float threshold)
        {
            var expectedSamples = expected.GetSampledLocations();
            var actualSamples   = actual.GetSampledLocations();

            var diff        = expectedSamples.Zip(actualSamples, (e, a) => e - a);
            var normDiff    = diff.Select(d => d.magnitude);
            var maxNormDiff = normDiff.Aggregate(Mathf.NegativeInfinity, (x, y) => Mathf.Max(x, y));

            bool isValid = maxNormDiff < threshold;

            return(isValid);
        }
コード例 #3
0
        public bool Validate(ITrail expected, ITrail actual, float threshold)
        {
            var expectedSamples = expected.GetSampledLocations();
            var actualSamples   = actual.GetSampledLocations();

            var(np_exp, np_act) = prepare_np_input(expectedSamples, actualSamples);

            // we know that the curves are sampled at same time intervals. If we didn't we would need to interpolate
            // both of them (cubic spline or other) and sample at equal times or referably at equal distances.
            // Since we do know, we can skip this phase.
            // Resampling at same-spacial-distances could help, but it would be negligible here.

            //normalize both curves to zero mean to be able to find curves that look the same but are far away
            var one = new int[1]; one[0] = 1;

            var exp_mean       = np.mean(np_exp, one);
            var exp_normalized = np_exp - exp_mean;
            var act_mean       = np.mean(np_act, one);
            var act_normalized = np_act - act_mean;

            // now use rigid body transform optimization, to find the matrix that registers both curves.
            // this can be done because we have ordering on all points.
            // http://nghiaho.com/?page_id=671

            var H = np.dot(exp_normalized, act_normalized.T); // H is 2x2, if it is nxn then flip the order, and get R_act_to_exp

            var(U, S, V) = np.linalg.svd(H);
            if ((double)np.linalg.det(V) < 0)
            {
                V[":, 2"] = -V[":, 2"];
            }
            var R_exp_to_act = np.dot(V, U.T);

            //apply rotation on exp and calculate mse
            var exp_rotated = np.dot(R_exp_to_act, exp_normalized);
            var error       = np.linalg.norm(exp_rotated - act_normalized);

            return(error < threshold);
        }
コード例 #4
0
        public bool Validate(ITrail expected, ITrail actual, float threshold)
        {
            var expectedSamples = expected.GetSampledLocations();
            var actualSamples   = actual.GetSampledLocations();

            int count = expectedSamples.Count();

            for (int i = 0; i < count / 2; i++)
            {
                var  diff        = expectedSamples.Skip(i).Zip(actualSamples.Take(count - i), (e, a) => e - a);
                var  normDiff    = diff.Select(d => d.magnitude);
                var  sumNormDiff = normDiff.Aggregate(0.0, (x, y) => x + y);
                var  mse         = sumNormDiff / diff.Count();
                bool isValid     = mse <= threshold;
                Debug.Log($"mse: {mse}");
                if (isValid)
                {
                    return(true);
                }
            }
            return(false);
        }