Esempio n. 1
0
        /// <summary>
        /// Starts the task.
        /// </summary>
        /// <param name="dataSet">The list of objects that to be converted.</param>
        /// <param name="distanceMetric">The distance metric used to scale down dimensions.</param>
        public void Start(IdentifiableDataPointCollection dataSet, IDistanceMetric distanceMetric)
        {
            var args = new TaskRunnerArgumentSet {
                Data = dataSet, DistanceMetric = distanceMetric
            };

            var task = Task.Factory.StartNew <DataConversionResult>(TaskRunner, args);

            // Make sure Success and Failure events are run within the caller thread.
            TaskScheduler currentContext = TaskScheduler.FromCurrentSynchronizationContext();

            task.ContinueWith(TaskComplete, currentContext);
            task.ContinueWith(TaskFaulted, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, currentContext);
        }
Esempio n. 2
0
        private static DataConversionResult TaskRunner(object arg)
        {
            TaskRunnerArgumentSet options = arg as TaskRunnerArgumentSet;

            DistanceMatrix          distanceMatrix = new DistanceMatrix(options.Data, options.DistanceMetric);
            MultiDimensionalScaling mds            = new MultiDimensionalScaling(distanceMatrix);
            Matrix coordinateMatrix = mds.Calculate();

            List <DrawableDataPoint> drawableDataPoints = new List <DrawableDataPoint>();

            for (int col = 0; col < coordinateMatrix.Columns; col++)
            {
                double x = coordinateMatrix[0, col];
                double y = coordinateMatrix[1, col];
                IdentifiableDataPoint originalDataPoint = options.Data[col];
                drawableDataPoints.Add(new DrawableDataPoint(originalDataPoint, x, y));
            }

            var dataPoints = drawableDataPoints.OrderBy(d => d.Group).ToList();

            return(new DataConversionResult(dataPoints, distanceMatrix));
        }