Example #1
0
 void Start()
 {
     if (!Optics.RefractiveObjectIsValid(this))
     {
         throw new UnityException("RefractiveObject  \"" + gameObject.name + "\" is invalid!");
     }
 }
Example #2
0
        private void CreateSimilarityMatrix()
        {
            if (!_projectService.AreAllVarietiesCompared)
            {
                return;
            }

            var optics = new Optics <Variety>(variety => variety.VarietyPairs.Select(pair =>
            {
                double score = 0;
                switch (_similarityMetric)
                {
                case SimilarityMetric.Lexical:
                    score = pair.LexicalSimilarityScore;
                    break;

                case SimilarityMetric.Phonetic:
                    score = pair.PhoneticSimilarityScore;
                    break;
                }
                return(Tuple.Create(pair.GetOtherVariety(variety), 1.0 - score));
            }).Concat(Tuple.Create(variety, 0.0)), 2);

            _modelVarieties.Clear();
            _modelVarieties.AddRange(optics.ClusterOrder(_projectService.Project.Varieties).Select(oe => oe.DataObject));
            SimilarityMatrixVarietyViewModel[] vms = _modelVarieties.Select(v => new SimilarityMatrixVarietyViewModel(_similarityMetric, _modelVarieties, v)).ToArray();
            Varieties = new ReadOnlyList <SimilarityMatrixVarietyViewModel>(vms);
            IsEmpty   = false;
        }
Example #3
0
        private void WriteOutput(TextWriter outputWriter)
        {
            var optics = new Optics <Variety>(variety => variety.VarietyPairs
                                              .Select(pair => Tuple.Create(pair.GetOtherVariety(variety), 1.0 - pair.LexicalSimilarityScore))
                                              .Concat(Tuple.Create(variety, 0.0)), 2);

            Variety[] varieties = optics.ClusterOrder(Project.Varieties).Select(e => e.DataObject).ToArray();
            foreach (Variety variety in varieties)
            {
                outputWriter.Write("\t");
                outputWriter.Write(variety.Name);
            }
            outputWriter.WriteLine();
            for (int i = 0; i < varieties.Length; i++)
            {
                outputWriter.Write(varieties[i].Name);
                int len = IsHalf ? i + 1 : varieties.Length;
                for (int j = 0; j < len; j++)
                {
                    outputWriter.Write("\t");
                    if (i == j)
                    {
                        outputWriter.Write(IsDistance ? "0.00" : "1.00");
                    }
                    else
                    {
                        VarietyPair varietyPair = varieties[i].VarietyPairs[varieties[j]];
                        double      score       = IsDistance ? 1.0 - varietyPair.LexicalSimilarityScore : varietyPair.LexicalSimilarityScore;
                        outputWriter.Write("{0:0.00}", score);
                    }
                }
                outputWriter.WriteLine();
            }
        }
        /// <summary>
        /// Define SimulationInput to describe homogeneous and two layer tissue
        /// </summary>
        /// <returns></returns>
        private void GenerateReferenceDatabase()
        {
            var simulationOptions = new SimulationOptions(
                0,
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Discrete,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
                DatabaseType.pMCDiffuseReflectance
            },
                false, // track statistics
                0.0,   // RR threshold -> 0 = no RR performed
                0);
            var sourceInput = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);
            var detectorInputs = new List <IDetectorInput>()
            {
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                }
            };

            _referenceInputTwoLayerTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                sourceInput,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerRegion(
                    new DoubleRange(0.0, _layerThickness),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerRegion(
                    new DoubleRange(_layerThickness, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectorInputs);

            _factor = 1.0 - Optics.Specular(
                _referenceInputTwoLayerTissue.TissueInput.Regions[0].RegionOP.N,
                _referenceInputTwoLayerTissue.TissueInput.Regions[1].RegionOP.N);
            _referenceOutputTwoLayerTissue = new MonteCarloSimulation(_referenceInputTwoLayerTissue).Run();
            _databaseTwoLayerTissue        = pMCDatabase.FromFile("DiffuseReflectanceDatabase", "CollisionInfoDatabase");
        }
        public void UpdateTest()
        {
            Dictionary <long, float?> reachabilityDistances = new Dictionary <long, float?>();
            Dictionary <long, float?> coreDistancesCache    = new Dictionary <long, float?>();
            HashSet <long>            processed             = new HashSet <long>();

            var points3D = new List <IPointIdFloat>()
            {
                new PointIdFloat(new List <float>()
                {
                    1, 2, 55
                }),
                new PointIdFloat(new List <float>()
                {
                    0, 1, 0.1f
                }),
                new PointIdFloat(new List <float>()
                {
                    3, 3, 0.01f
                }),
                new PointIdFloat(new List <float>()
                {
                    1.5f, 2, -0.03f
                }),
                new PointIdFloat(new List <float>()
                {
                    5, -1, 44
                }),
                new PointIdFloat(new List <float>()
                {
                    15, -51, 73
                }),
                new PointIdFloat(new List <float>()
                {
                    0.5f, -21, 144
                })
            };

            PointIdFloat.SetIds(points3D);
            var p         = points3D[2];
            var epsilon   = 10;
            var minPoints = 3;

            Optics algo  = new Optics(points3D);
            var    seeds = new PriorityQueue <float, IPointIdFloat>();

            processed.Add(p.id);
            var coreDistance = algo.CoreDistance(algo.kdt, coreDistancesCache, p, epsilon, minPoints);

            algo.Update(ref seeds, processed, reachabilityDistances, coreDistancesCache, p, epsilon, minPoints);

            Assert.AreEqual(2, seeds.Count);
            KeyValuePair <float, IPointIdFloat> top;

            seeds.TryPeek(out top);
            Assert.AreEqual(top.Key, coreDistance);
            Assert.AreEqual(points3D[3], top.Value);
        }
        public void ClusterTest()
        {
            var points3D = new List <IPointIdFloat>()
            {
                new PointIdFloat(new List <float>()
                {
                    1, 2, 55
                }),
                new PointIdFloat(new List <float>()
                {
                    0, 1, 0.1f
                }),
                new PointIdFloat(new List <float>()
                {
                    3, 3, 0.01f
                }),
                new PointIdFloat(new List <float>()
                {
                    1.5f, 2, -0.03f
                }),
                new PointIdFloat(new List <float>()
                {
                    5, -1, 44
                }),
                new PointIdFloat(new List <float>()
                {
                    15, -51, 73
                }),
                new PointIdFloat(new List <float>()
                {
                    0.5f, -21, 144
                })
            };

            PointIdFloat.SetIds(points3D);
            var ids = points3D.Select(p => p.id).ToList();

            ids.Sort();

            var epsilon      = 100;
            var epsilonPrime = 10;
            var minPoints    = 3;

            Optics algo  = new Optics(points3D);
            var    seeds = new PriorityQueue <float, IPointIdFloat>();

            OpticsOrdering oo      = algo.Ordering(epsilon, minPoints);
            var            results = oo.Cluster(epsilonPrime);

            Assert.AreEqual(points3D.Count, results.Count);
            var keys = results.Keys.ToList();

            keys.Sort();
            Assert.IsTrue(keys.SequenceEqual(ids));
        }
        public void execute_Monte_Carlo()
        {
            // delete previously generated files
            clear_folders_and_files();

            var input = new SimulationInput(
                100,
                "Output",
                new SimulationOptions(
                    0,
                    RandomNumberGeneratorType.MersenneTwister,
                    AbsorptionWeightingType.Analog,
                    PhaseFunctionType.HenyeyGreenstein,
                    new List <DatabaseType>()
            {
            },             // databases to be written
                    false, // track statistics
                    0.0,   // RR threshold -> 0 = no RR performed
                    0),
                new DirectionalPointSourceInput(
                    new Position(0.0, 0.0, 0.0),
                    new Direction(0.0, 0.0, 1.0),
                    0  // start in air
                    ),
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                new List <IDetectorInput>
            {
                new RSpecularDetectorInput(),
            }
                );

            _specularReflectance = Optics.Specular(input.TissueInput.Regions[0].RegionOP.N,
                                                   input.TissueInput.Regions[1].RegionOP.N);
            _output = new MonteCarloSimulation(input).Run();
        }
Example #8
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("bang");                  //TODO shoot (ABSTRACTION!!!!)
        }
        float rayLength = 5f;

        Optics.LightcastHit lightcastHit;
        Vector3[]           points;
        Optics.Lightcast(muzzle.position, muzzle.forward, out lightcastHit, out points, rayLength);
        for (int i = 1; i < points.Length; i++)
        {
            Debug.DrawLine(points[i - 1], points[i], Color.magenta, 0f, true);
        }
    }
Example #9
0
        public void Export(Stream stream, CogProject project, SimilarityMetric similarityMetric)
        {
            var optics = new Optics <Variety>(variety => variety.VarietyPairs.Select(pair =>
            {
                double score = 0;
                switch (similarityMetric)
                {
                case SimilarityMetric.Lexical:
                    score = pair.LexicalSimilarityScore;
                    break;

                case SimilarityMetric.Phonetic:
                    score = pair.PhoneticSimilarityScore;
                    break;
                }
                return(Tuple.Create(pair.GetOtherVariety(variety), 1.0 - score));
            }).Concat(Tuple.Create(variety, 0.0)), 2);

            Variety[] varietyArray = optics.ClusterOrder(project.Varieties).Select(oe => oe.DataObject).ToArray();
            using (var writer = new StreamWriter(new NonClosingStreamWrapper(stream)))
            {
                foreach (Variety variety in varietyArray)
                {
                    writer.Write("\t");
                    writer.Write(variety.Name);
                }
                writer.WriteLine();
                for (int i = 0; i < varietyArray.Length; i++)
                {
                    writer.Write(varietyArray[i].Name);
                    for (int j = 0; j < varietyArray.Length; j++)
                    {
                        writer.Write("\t");
                        if (i != j)
                        {
                            VarietyPair varietyPair = varietyArray[i].VarietyPairs[varietyArray[j]];
                            double      score       = similarityMetric == SimilarityMetric.Lexical ? varietyPair.LexicalSimilarityScore : varietyPair.PhoneticSimilarityScore;
                            writer.Write("{0:0.00}", score);
                        }
                    }
                    writer.WriteLine();
                }
            }
        }
Example #10
0
        public void Export(Stream stream, CogProject project, SimilarityMetric similarityMetric)
        {
            var optics = new Optics<Variety>(variety => variety.VarietyPairs.Select(pair =>
                {
                    double score = 0;
                    switch (similarityMetric)
                    {
                        case SimilarityMetric.Lexical:
                            score = pair.LexicalSimilarityScore;
                            break;
                        case SimilarityMetric.Phonetic:
                            score = pair.PhoneticSimilarityScore;
                            break;
                    }
                    return Tuple.Create(pair.GetOtherVariety(variety), 1.0 - score);
                }).Concat(Tuple.Create(variety, 0.0)), 2);

            Variety[] varietyArray = optics.ClusterOrder(project.Varieties).Select(oe => oe.DataObject).ToArray();
            using (var writer = new StreamWriter(new NonClosingStreamWrapper(stream)))
            {
                foreach (Variety variety in varietyArray)
                {
                    writer.Write("\t");
                    writer.Write(variety.Name);
                }
                writer.WriteLine();
                for (int i = 0; i < varietyArray.Length; i++)
                {
                    writer.Write(varietyArray[i].Name);
                    for (int j = 0; j < varietyArray.Length; j++)
                    {
                        writer.Write("\t");
                        if (i != j)
                        {
                            VarietyPair varietyPair = varietyArray[i].VarietyPairs[varietyArray[j]];
                            double score = similarityMetric == SimilarityMetric.Lexical ? varietyPair.LexicalSimilarityScore : varietyPair.PhoneticSimilarityScore;
                            writer.Write("{0:0.00}", score);
                        }
                    }
                    writer.WriteLine();
                }
            }
        }
Example #11
0
        public void execute_Monte_Carlo()
        {
            // delete any previously generated files
            clear_folders_and_files();

            _input = new SimulationInput(
                100,
                "Output",
                new SimulationOptions(
                    0,
                    RandomNumberGeneratorType.MersenneTwister,
                    AbsorptionWeightingType.Analog,
                    PhaseFunctionType.HenyeyGreenstein,
                    new List <DatabaseType>()
            {
            },            // databases to be written
                    true, // track statistics
                    0.0,  // RR threshold -> 0 = no RR performed
                    0),
                new DirectionalPointSourceInput(
                    new Position(0.0, 0.0, 0.0),
                    new Direction(0.0, 0.0, 1.0),
                    1 // start off inside tissue
                    ),
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                new List <IDetectorInput>
            {
                new RDiffuseDetectorInput()
                {
                    TallySecondMoment = true
                },
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), TallySecondMoment = true
                },
                new ROfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new ROfRhoAndOmegaDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Omega = new DoubleRange(0.05, 1.0, 20)
                },                                                                                                                 // frequency sampling points (not bins)
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new TOfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new AOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new ATotalDetectorInput(),
                new FluenceOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new FluenceOfRhoAndZAndTimeDetectorInput()
                {
                    Rho  = new DoubleRange(0.0, 10.0, 101),
                    Z    = new DoubleRange(0.0, 10.0, 101),
                    Time = new DoubleRange(0.0, 1.0, 11)
                },
                new RadianceOfRhoAndZAndAngleDetectorInput()
                {
                    Rho   = new DoubleRange(0.0, 10.0, 101),
                    Z     = new DoubleRange(0.0, 10.0, 101),
                    Angle = new DoubleRange(-Math.PI / 2, Math.PI / 2, 5)
                }
            }
                );

            _output = new MonteCarloSimulation(_input).Run();

            _simulationStatistics = SimulationStatistics.FromFile(_input.OutputName + "/statistics.txt");

            _factor = 1.0 - Optics.Specular(
                _input.TissueInput.Regions[0].RegionOP.N,
                _input.TissueInput.Regions[1].RegionOP.N);
        }
Example #12
0
        public void execute_Monte_Carlo()
        {
            // delete previously generated files
            clear_folders_and_files();

            var simulationOptions = new SimulationOptions(
                0,
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Continuous,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
                DatabaseType.pMCDiffuseReflectance
            },
                false, // track statistics
                0.0,   // RR threshold -> 0 = no RR performed
                0);
            var sourceInput = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);
            var detectorInputs = new List <IDetectorInput>()
            {
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
                new ROfFxDetectorInput()
                {
                    Fx = new DoubleRange(0.0, 0.5, 11)
                },
                new ROfFxAndTimeDetectorInput()
                {
                    Fx = new DoubleRange(0.0, 0.5, 11), Time = new DoubleRange(0.0, 1.0, 101)
                }
            };

            _referenceInputOneLayerTissue = new SimulationInput(
                100,
                "",  // can't create folder in isolated storage
                simulationOptions,
                sourceInput,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectorInputs);
            _factor = 1.0 - Optics.Specular(
                _referenceInputOneLayerTissue.TissueInput.Regions[0].RegionOP.N,
                _referenceInputOneLayerTissue.TissueInput.Regions[1].RegionOP.N);
            _referenceOutputOneLayerTissue = new MonteCarloSimulation(_referenceInputOneLayerTissue).Run();

            _databaseOneLayerTissue = pMCDatabase.FromFile("DiffuseReflectanceDatabase", "CollisionInfoDatabase");
        }
        public void execute_Monte_Carlo()
        {
            // delete previously generated files
            clear_folders_and_files();

            // instantiate common classes
            var simulationOptions = new SimulationOptions(
                0,
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Discrete,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
            },         // databases to be written
                false, // track statistics
                0.0,   // RR threshold -> 0 = no RR performed
                0);
            var source = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);      // start inside tissue
            var detectors = new List <IDetectorInput>
            {
                new RDiffuseDetectorInput(),
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), TallySecondMoment = true
                },
                new ROfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101), TallySecondMoment = true
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new ROfRhoAndOmegaDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Omega = new DoubleRange(0.05, 1.0, 20)
                },                                                                                                                      // DJC - edited to reflect frequency sampling points (not bins)
                new ROfFxDetectorInput()
                {
                    Fx = new DoubleRange(0.0, 0.5, 51)
                },
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new TOfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new TOfFxDetectorInput()
                {
                    Fx = new DoubleRange(0.0, 0.5, 51)
                },
                new AOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new AOfXAndYAndZDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101),
                    Y = new DoubleRange(-10.0, 10.0, 101),
                    Z = new DoubleRange(0.0, 10.0, 101),
                    TallySecondMoment = true
                },
                new ATotalDetectorInput()
                {
                    TallySecondMoment = true
                },
                new FluenceOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new FluenceOfXAndYAndZDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 11),
                    Y = new DoubleRange(-10.0, 10.0, 11),
                    Z = new DoubleRange(0.0, 10.0, 11),
                    TallySecondMoment = true
                },
                new FluenceOfXAndYAndZAndOmegaDetectorInput()
                {
                    X     = new DoubleRange(-10.0, 10.0, 11),
                    Y     = new DoubleRange(-10.0, 10.0, 11),
                    Z     = new DoubleRange(0.0, 10.0, 11),
                    Omega = new DoubleRange(0.05, 1.0, 20)
                },
                new RadianceOfRhoAtZDetectorInput()
                {
                    ZDepth = _dosimetryDepth, Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new RadianceOfRhoAndZAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0, Math.PI, 5)
                },
                new RadianceOfFxAndZAndAngleDetectorInput()
                {
                    Fx = new DoubleRange(0.0, 0.5, 51), Z = new DoubleRange(0.0, 10, 101), Angle = new DoubleRange(0, Math.PI, 5)
                },
                new RadianceOfXAndYAndZAndThetaAndPhiDetectorInput()
                {
                    X     = new DoubleRange(-10.0, 10.0, 11),
                    Y     = new DoubleRange(-10.0, 10.0, 11),
                    Z     = new DoubleRange(0.0, 10.0, 11),
                    Theta = new DoubleRange(0.0, Math.PI, 5),      // theta (polar angle)
                    Phi   = new DoubleRange(-Math.PI, Math.PI, 5), // phi (azimuthal angle)
                },
                new ReflectedMTOfRhoAndSubregionHistDetectorInput()
                {
                    Rho              = new DoubleRange(0.0, 10.0, 101), // rho bins MAKE SURE AGREES with ROfRho rho specification for unit test below
                    MTBins           = new DoubleRange(0.0, 500.0, 51), // MT bins
                    FractionalMTBins = new DoubleRange(0.0, 1.0, 11)
                },
                new TransmittedMTOfRhoAndSubregionHistDetectorInput()
                {
                    Rho              = new DoubleRange(0.0, 10.0, 101), // rho bins MAKE SURE AGREES with TOfRho rho specification for unit test below
                    MTBins           = new DoubleRange(0.0, 500.0, 51), // MT bins
                    FractionalMTBins = new DoubleRange(0.0, 1.0, 11)
                },
                new ReflectedMTOfXAndYAndSubregionHistDetectorInput()
                {
                    X                 = new DoubleRange(-10.0, 10.0, 101),
                    Y                 = new DoubleRange(-10.0, 10.0, 101),
                    MTBins            = new DoubleRange(0.0, 500.0, 51), // MT bins
                    FractionalMTBins  = new DoubleRange(0.0, 1.0, 11),
                    TallySecondMoment = true
                },
                new TransmittedMTOfXAndYAndSubregionHistDetectorInput()
                {
                    X                = new DoubleRange(-10.0, 10.0, 101),
                    Y                = new DoubleRange(-10.0, 10.0, 101),
                    MTBins           = new DoubleRange(0.0, 500.0, 51), // MT bins
                    FractionalMTBins = new DoubleRange(0.0, 1.0, 11)
                }
            };

            _inputOneLayerTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputOneLayerTissue = new MonteCarloSimulation(_inputOneLayerTissue).Run();

            _inputTwoLayerTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, _layerThickness),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(_layerThickness, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputTwoLayerTissue = new MonteCarloSimulation(_inputTwoLayerTissue).Run();

            _factor = 1.0 - Optics.Specular(
                _inputOneLayerTissue.TissueInput.Regions[0].RegionOP.N,
                _inputOneLayerTissue.TissueInput.Regions[1].RegionOP.N);
        }
Example #14
0
        /// <summary>
        /// Method that determines whether photon reflects or refracts across interface.  When this
        /// method is called photon is sitting on boundary of region and CurrentRegionIndex is Index
        /// of region photon had been in.
        /// </summary>
        public void CrossRegionOrReflect()
        {
            double cosTheta      = _tissue.GetAngleRelativeToBoundaryNormal(this);
            double nCurrent      = _tissue.Regions[CurrentRegionIndex].RegionOP.N;
            int    neighborIndex = _tissue.GetNeighborRegionIndex(this);
            double nNext         = _tissue.Regions[neighborIndex].RegionOP.N;

            double coscrit;

            if (nCurrent > nNext)
            {
                coscrit = Math.Sqrt(1.0 - (nNext / nCurrent) * (nNext / nCurrent));
            }
            else
            {
                coscrit = 0.0;
            }

            double probOfReflecting;
            double cosThetaSnell;

            // call Fresnel be default to have uZSnell set, used to be within else
            probOfReflecting = Optics.Fresnel(nCurrent, nNext, cosTheta, out cosThetaSnell);
            if (cosTheta <= coscrit)
            {
                probOfReflecting = 1.0;
            }
            //else
            //    probOfReflecting = Optics.Fresnel(nCurrent, nNext, cosTheta, out cosThetaSnell);

            /* Decide whether or not photon goes to next region */
            // perform first check so that rng not called on pseudo-collisions
            if ((probOfReflecting == 0.0) || (_rng.NextDouble() > probOfReflecting)) // transmitted
            {
                // if at border of system
                if (_tissue.OnDomainBoundary(this.DP.Position) && !_firstTimeEnteringDomain)
                {
                    DP.StateFlag = DP.StateFlag.Add(_tissue.GetPhotonDataPointStateOnExit(DP.Position));

                    // adjust CAW weight for portion of track prior to exit
                    if (Absorb == AbsorbContinuous)
                    {
                        AbsorbContinuous();
                    }

                    CurrentRegionIndex = neighborIndex;
                    //don't need to update these unless photon not dead upon exiting tissue
                    //DP.Direction.Ux *= nCurrent / nNext;
                    //DP.Direction.Uy *= nCurrent / nNext;
                    //DP.Direction.Uz = uZSnell;
                }
                else // not on domain boundary, at internal interface or first time enter tissue, pass to next
                {
                    CurrentRegionIndex = neighborIndex;
                    DP.Direction       = _tissue.GetRefractedDirection(DP.Position, DP.Direction,
                                                                       nCurrent, nNext, cosThetaSnell);
                    if (_firstTimeEnteringDomain)
                    {
                        _firstTimeEnteringDomain = false;
                    }
                }
            }
            else  // don't cross, reflect
            {
                DP.Direction = _tissue.GetReflectedDirection(DP.Position, DP.Direction);
                // check if specular reflection
                if (_firstTimeEnteringDomain)
                {
                    DP.StateFlag = DP.StateFlag.Add(PhotonStateType.PseudoSpecularTissueBoundary);
                }
            }
        }
        public void execute_Monte_Carlo()
        {
            // delete previously generated files
            clear_folders_and_files();

            // instantiate common classes
            var simulationOptions = new SimulationOptions(
                0,
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Discrete,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
            },         // databases to be written
                false, // track statistics
                0.0,   // RR threshold -> 0 = no RR performed
                0);
            var source = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);      // start inside tissue
            var detectors =
                new List <IDetectorInput>
            {
                new RDiffuseDetectorInput(),
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-200.0, 200.0, 401), Y = new DoubleRange(-200.0, 200.0, 401)
                },
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new ATotalDetectorInput(),
            };

            _inputOneRegionTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputOneRegionTissue = new MonteCarloSimulation(_inputOneRegionTissue).Run();

            _inputTwoRegionTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new SingleVoxelTissueInput(
                    new VoxelTissueRegion(
                        new DoubleRange(-5, 5),
                        new DoubleRange(-5, 5),
                        new DoubleRange(1e-9, 5),                  // smallest Z.Start with tests passing is 1e-9
                        new OpticalProperties(0.01, 1.0, 0.8, 1.4) //debug with g=1
                        ),
                    new LayerTissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),                  // debug with thin slab d=2
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)), // debug with g=1
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputTwoRegionTissue = new MonteCarloSimulation(_inputTwoRegionTissue).Run();

            _factor = 1.0 - Optics.Specular(
                _inputOneRegionTissue.TissueInput.Regions[0].RegionOP.N,
                _inputOneRegionTissue.TissueInput.Regions[1].RegionOP.N);
        }
        public void execute_Monte_Carlo()
        {
            // delete any previously generated files
            clear_folders_and_files();

            // instantiate common classes
            var simulationOptions = new SimulationOptions(
                0,     // rng seed = same as linux (0)
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Continuous,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
            },           // databases to be written
                false,   // track statistics
                0.0,     // RR threshold -> 0 = no RR performed
                0);
            var source = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);     // start inside tissue
            var detectors =
                new List <IDetectorInput>
            {
                new ATotalDetectorInput(),
                new RDiffuseDetectorInput()
                {
                    TallySecondMoment = true
                },
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), TallySecondMoment = true
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new ROfRhoAndOmegaDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Omega = new DoubleRange(0.05, 1.0, 20)
                },                                                                                                                      // DJC - edited to reflect frequency sampling points (not bins)
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new TOfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new ReflectedTimeOfRhoAndSubregionHistDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
            };
            // one tissue layer
            var inputOneLayerTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);

            _outputOneLayerTissue = new MonteCarloSimulation(inputOneLayerTissue).Run();
            // two tissue layers with same optical properties
            var inputTwoLayerTissue = new SimulationInput(
                100,
                "Output",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, _layerThickness),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(_layerThickness, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);

            _outputTwoLayerTissue = new MonteCarloSimulation(inputTwoLayerTissue).Run();

            _factor = 1.0 - Optics.Specular(
                inputOneLayerTissue.TissueInput.Regions[0].RegionOP.N,
                inputOneLayerTissue.TissueInput.Regions[1].RegionOP.N);
        }
        public void CoreDistanceTest()
        {
            var points3D = new List <IPointIdFloat>()
            {
                new PointIdFloat(new List <float>()
                {
                    1, 2, 55
                }),
                new PointIdFloat(new List <float>()
                {
                    0, 1, 0.1f
                }),
                new PointIdFloat(new List <float>()
                {
                    3, 3, 0.01f
                }),
                new PointIdFloat(new List <float>()
                {
                    1.5f, 2, -0.03f
                }),
                new PointIdFloat(new List <float>()
                {
                    5, -1, 44
                }),
                new PointIdFloat(new List <float>()
                {
                    15, -51, 73
                }),
                new PointIdFloat(new List <float>()
                {
                    0.5f, -21, 144
                })
            };

            PointIdFloat.SetIds(points3D);

            var p = new PointIdFloat(new List <float>()
            {
                1, 2, 3
            });

            Optics algo = new Optics(points3D);
            Dictionary <long, float?> coreDist = new Dictionary <long, float?>();

            // - Tests with no cache -

            //Not enough points in the tree
            Assert.IsNull(algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 1000, 40));
            Assert.IsNull(algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 1000, points3D.Count + 1));

            //Not enough points in the epsilon-neighbourhood
            Assert.IsNull(algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 1, 2));
            Assert.IsNull(algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 10, 6));

            var result = algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 1000, points3D.Count);

            Assert.AreEqual(p.DistanceTo(points3D[6]), result);

            points3D.ForEach(point =>
            {
                result = algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), point, 0.00001f, 1);
                Assert.AreEqual(0, result);
            });

            Assert.IsNull(algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 1, 1));
            Assert.AreEqual(p.DistanceTo(points3D[3]), algo.CoreDistance(algo.kdt, new Dictionary <long, float?>(), p, 5, 1));

            //Tests - using cache -
            Assert.AreEqual(0, coreDist.Count);
            float?tmp;

            Assert.IsNull(algo.CoreDistance(algo.kdt, coreDist, p, 1000, 40));
            Assert.IsTrue(coreDist.ContainsKey(p.id));
            coreDist.TryGetValue(p.id, out tmp);
            Assert.IsNull(tmp);

            coreDist.Clear();

            result = algo.CoreDistance(algo.kdt, coreDist, p, 1000, points3D.Count);
            Assert.AreEqual(p.DistanceTo(points3D[6]), result);

            Assert.IsTrue(coreDist.ContainsKey(p.id));
            coreDist.TryGetValue(p.id, out tmp);
            Assert.AreEqual(result, tmp);
        }
Example #18
0
        public void execute_Monte_Carlo()
        {
            // instantiate common classes
            var simulationOptions = new SimulationOptions(
                0,
                RandomNumberGeneratorType.MersenneTwister,
                AbsorptionWeightingType.Discrete,
                PhaseFunctionType.HenyeyGreenstein,
                new List <DatabaseType>()
            {
            },         // databases to be written
                false, // track statistics
                0.0,   // RR threshold -> 0 = no RR performed
                0);
            var source = new DirectionalPointSourceInput(
                new Position(0.0, 0.0, 0.0),
                new Direction(0.0, 0.0, 1.0),
                1);      // start inside tissue
            var detectors =
                new List <IDetectorInput>
            {
                new RDiffuseDetectorInput(),
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), TallySecondMoment = true
                },
                new ROfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-200.0, 200.0, 401), Y = new DoubleRange(-200.0, 200.0, 401)
                },
                new ROfRhoAndOmegaDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Omega = new DoubleRange(0.0, 1.0, 21)
                },
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new TOfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new AOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new ATotalDetectorInput(),
                new FluenceOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new RadianceOfRhoAndZAndAngleDetectorInput()
                {
                    Rho   = new DoubleRange(0.0, 10.0, 101),
                    Z     = new DoubleRange(0.0, 10.0, 101),
                    Angle = new DoubleRange(-Math.PI / 2, Math.PI / 2, 5)
                }
            };

            _inputOneRegionTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputOneRegionTissue = new MonteCarloSimulation(_inputOneRegionTissue).Run();

            _inputTwoRegionTissue = new SimulationInput(
                100,
                "",
                simulationOptions,
                source,
                new SingleEllipsoidTissueInput(
                    new EllipsoidRegion(
                        new Position(0, 0, 1),
                        0.5,
                        0.5,
                        0.5,
                        new OpticalProperties(0.01, 1.0, 0.8, 1.4) //debug with g=1
                        ),
                    new LayerRegion[]
            {
                new LayerRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerRegion(
                    new DoubleRange(0.0, 20.0),                  // debug with thin slab d=2
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)), // debug with g=1
                new LayerRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                detectors);
            _outputTwoRegionTissue = new MonteCarloSimulation(_inputTwoRegionTissue).Run();

            _factor = 1.0 - Optics.Specular(
                _inputOneRegionTissue.TissueInput.Regions[0].RegionOP.N,
                _inputOneRegionTissue.TissueInput.Regions[1].RegionOP.N);
        }
        public void OrderingTest()
        {
            IReadOnlyDictionary <long, long>    orderingMapping;
            IReadOnlyCollection <IPointIdFloat> ordering;

            var points3D = new List <IPointIdFloat>()
            {
                new PointIdFloat(new List <float>()
                {
                    1, 2, 55
                }),
                new PointIdFloat(new List <float>()
                {
                    0, 1, 0.1f
                }),
                new PointIdFloat(new List <float>()
                {
                    3, 3, 0.01f
                }),
                new PointIdFloat(new List <float>()
                {
                    1.5f, 2, -0.03f
                }),
                new PointIdFloat(new List <float>()
                {
                    5, -1, 44
                }),
                new PointIdFloat(new List <float>()
                {
                    15, -51, 73
                }),
                new PointIdFloat(new List <float>()
                {
                    0.5f, -21, 144
                })
            };

            PointIdFloat.SetIds(points3D);
            var epsilon   = 10;
            var minPoints = 3;

            Optics algo  = new Optics(points3D);
            var    seeds = new PriorityQueue <float, IPointIdFloat>();

            OpticsOrdering oo = algo.Ordering(epsilon, minPoints);

            ordering        = oo.ordering;
            orderingMapping = oo.orderingMapping;

            Assert.AreEqual(points3D.Count, ordering.Count);
            Assert.IsTrue(SequenceEquivalent(points3D, ordering.ToList(), PointIdFloat.PointsComparison));
            Assert.AreEqual(points3D.Count, orderingMapping.Count);

            for (long i = 0; i < orderingMapping.Count; i++)
            {
                Assert.IsTrue(orderingMapping.Values.Contains(i));
            }
            foreach (var p in points3D)
            {
                Assert.IsTrue(orderingMapping.ContainsKey(p.id));
            }
            Assert.IsTrue(oo.reachabilityDistances.Count > 0);
            foreach (var p in points3D)
            {
                Assert.IsTrue(oo.coreDistancesCache.ContainsKey(p.id));
            }
        }
Example #20
0
 private void CreateSimilarityMatrix()
 {
     var optics = new Optics<Variety>(variety => variety.VarietyPairs.Select(pair =>
         {
             double score = 0;
             switch (_similarityMetric)
             {
                 case SimilarityMetric.Lexical:
                     score = pair.LexicalSimilarityScore;
                     break;
                 case SimilarityMetric.Phonetic:
                     score = pair.PhoneticSimilarityScore;
                     break;
             }
             return Tuple.Create(pair.GetOtherVariety(variety), 1.0 - score);
         }).Concat(Tuple.Create(variety, 0.0)), 2);
     _modelVarieties.Clear();
     _modelVarieties.AddRange(optics.ClusterOrder(_projectService.Project.Varieties).Select(oe => oe.DataObject));
     SimilarityMatrixVarietyViewModel[] vms = _modelVarieties.Select(v => new SimilarityMatrixVarietyViewModel(_similarityMetric, _modelVarieties, v)).ToArray();
     Varieties = new ReadOnlyList<SimilarityMatrixVarietyViewModel>(vms);
     IsEmpty = false;
 }