private void InitializeManaged(IList <Target> targets, DistanceFunc distance, Func <Target, Extraction> targetToExtraction, Func <Extraction, Pronounceable> extractionToPronounceable) { this.targets = targets; this.distance = distance; this.targetToExtraction = targetToExtraction; this.extractionToPronounceable = extractionToPronounceable; this.nativeDistanceDelegate = this.Distance; if (targetToExtraction == null) { try { this.extractions = (IList <Extraction>)targets; } catch { throw new InvalidCastException(string.Format("Can't cast Target type [{0}] to Extraction type [{1}]. You must provide a conversion function 'targetToExtraction'.", typeof(Target), typeof(Extraction))); } } else { this.extractions = new Extraction[targets.Count]; } if (extractionToPronounceable == null) { this.pronounceables = (IList <Pronounceable>) this.extractions; } else { this.pronounceables = new Pronounceable[targets.Count]; } }
public DataSet(IList <IObject> objects, IObject target, DistanceFunc distanceFunc, Func <double, double> kernelFunc) { _objects = objects; Target = target; _distanceFunc = distanceFunc; _kernelFunc = kernelFunc; }
public Light(int intensity, int radius, int capacity, TCODColor color) { _color = color; _intensity = intensity; _radius = radius; _capacity = capacity; _coef = (float)(-intensity) / radius; _elapsed = 0; _distanceFunc = Math.Distance_Euclide; }
public VoronoiDiagram(int size, int seed, VoronoiOptions options) { mSize = size; delDistanceFunc = DistanceFunctions.GetDistanceFunction(options.metric); delCombiningFunc = CombinerFunctions.GetFunction(options.combiner); mNumFeaturePoints = options.numberOfFeaturePoints; mNumSubregions = options.numberOfSubregions; mMultiplier = options.multiplier; aFeaturePoints = new int[0]; mRNG = new LCGRandom(seed); }
public InfluenceMap(int width, int height, double minInfluence, double maxInfluence, DistanceFunc computeDistanceFunc) { this.width = width; this.height = height; this._influenceMap = new double[width][]; for (int i = 0; i < width; i++) { this._influenceMap[i] = new double[height]; } this.computeDistanceFunc = computeDistanceFunc; this.minInfluence = minInfluence; this.maxInfluence = maxInfluence; myHashset = new HashSet <XAndY>(); }
private IDWFunc GetConverter() { DistanceFunc distanceFunction = m_distanceFunction; double[] xCoordinates = m_xCoordinates ?? new double[0]; double[] yCoordinates = m_yCoordinates ?? new double[0]; double[] values = m_values ?? new double[0]; double power = m_power; if (xCoordinates.Length != yCoordinates.Length) { throw new InvalidOperationException($"The number of x-coordinates must match the number of y-coordinates. ({xCoordinates.Length} != {yCoordinates.Length})"); } if (xCoordinates.Length != values.Length) { throw new InvalidOperationException($"The number of coordinates must match the number of values. ({xCoordinates.Length} != {values.Length})"); } if (xCoordinates.Length == 0) { return((x, y) => 0.0D); } return(m_converter ?? (m_converter = (x, y) => { double numerator = 0.0D; double denominator = 0.0D; for (int i = 0; i < xCoordinates.Length; i++) { double distance = distanceFunction(x, y, xCoordinates[i], yCoordinates[i]); if (distance == 0.0D) { return values[i]; } double inverseDistance = Math.Pow(1.0D / distance, power); numerator += values[i] * inverseDistance; denominator += inverseDistance; } return numerator / denominator; })); }
public static float Get3D(float x, float y, float z, CombinerFuncEnum combinerFunc, DistanceFuncEnum distanceFunc) { DistanceFunc _dFunc = null; switch (distanceFunc) { case DistanceFuncEnum.Euclidean: _dFunc = EuclidianDistanceFunc; break; case DistanceFuncEnum.Manhattan: _dFunc = ManhattanDistanceFunc; break; case DistanceFuncEnum.Chebyshev: _dFunc = ChebyshevDistanceFunc; break; } CombinerFunc _cFunc = null; switch (combinerFunc) { case CombinerFuncEnum.D1: _cFunc = CombinerFunc1; // i => i[0]; break; case CombinerFuncEnum.D2MinusD1: _cFunc = CombinerFunc2; //i => i[1] - i[0]; break; case CombinerFuncEnum.D3MinusD1: _cFunc = CombinerFunc3; //i => i[2] - i[0]; break; } return(noise3d(new Vector3(x, y, z), _cFunc, _dFunc)); }
public static DistanceFunc GetDistanceFunction(DistanceMetric distanceMetric) { DistanceFunc ret; switch(distanceMetric) { case DistanceMetric.EuclidianSq: ret = new DistanceFunc(EuclidianSq); break; case DistanceMetric.Euclidian: ret = new DistanceFunc(Euclidian); break; case DistanceMetric.Manhattan: ret = new DistanceFunc(Manhattan); break; case DistanceMetric.Chebyshev: ret = new DistanceFunc(Chebyshev); break; default: ret = new DistanceFunc(EuclidianSq); break; } return ret; }
/// <summary> /// Sets the function to be used to calculate the distance between two points. /// </summary> /// <param name="distanceFunction">The function used to calculate distance between two points.</param> /// <returns>A reference to the inverse distance weighting function.</returns> public InverseDistanceWeightingFunction SetDistanceFunction(DistanceFunc distanceFunction) { m_converter = null; m_distanceFunction = distanceFunction ?? DefaultDistanceFunction; return(this); }
/// <summary> /// Initializes a new instance of the <see cref="FuzzyMatcher{Target, Extraction}"/> class. /// </summary> /// <param name="targets">The set of objects that will be matched against. The order of equal targets is not guaranteed to be preserved.</param> /// <param name="distance">The distance delegate.</param> /// <param name="targetToExtraction">A mapping of the input types to the query(extraction) type. Note that Extraction == Pronounceable for the usual case.</param> /// <param name="isAccelerated">Whether the fuzzy matcher uses accelerated implementation or not.</param> public FuzzyMatcher(IList <Target> targets, DistanceFunc distance, Func <Target, Extraction> targetToExtraction = null, bool isAccelerated = false) : base(isAccelerated, targets, distance, null, targetToExtraction) { }
public WorleyNoise(int Seed, DistanceFunc DFunc, CombinerFunc CFunc) : this(Seed) { DistanceFunction = DFunc; CombinerFunction = CFunc; }
public AcceleratedFuzzyMatcher(IList <Target> targets, DistanceFunc distance, Func <Target, Extraction> targetToExtraction = null) : base(targets, distance, targetToExtraction, true) { }
private ValidationResult LeaveOneOut(IList <IObject> objects, int classCount, DistanceFunc distFunc, KernelFunc kernelFunc, int neighborCount) { var matrix = new int[classCount][]; for (int i = 0; i < classCount; i++) { matrix[i] = new int[classCount]; } objects .AsParallel() .ForAll(obj => Validate(new DataSet(objects.Without(obj).ToList(), obj, distFunc, _kernelDict[kernelFunc]), neighborCount, matrix)); var confMatrix = new ConfusionMatrix(matrix); return(new ValidationResult { DistanceFunc = distFunc, KernelFunc = kernelFunc, NeighborCount = neighborCount + 1, F1Score = (confMatrix.MicroF1Score() + confMatrix.MacroF1Score()) / 2 }); }
/// <summary> /// Initializes a new instance of the <see cref="AbstractFuzzyMatcher{Target,Extraction,Pronounceable}"/> class. /// </summary> /// <param name="isAccelerated">Whether the fuzzy matcher is accelerated or linear.</param> /// <param name="targets">The set of objects that will be matched against. The order of equal targets is not guaranteed to be preserved.</param> /// <param name="distance">The distance delegate.</param> /// <param name="extractionToPronounceable">A mapping of the extraction type to a type understood by the distance function. Note that this is only required if Extraction != Pronounceable</param> /// <param name="targetToExtraction">A mapping of the input types to the query(extraction) type. Note that Extraction == Pronounceable for the usual case.</param> internal AbstractFuzzyMatcher(bool isAccelerated, IList <Target> targets, DistanceFunc distance, Func <Extraction, Pronounceable> extractionToPronounceable, Func <Target, Extraction> targetToExtraction = null) : base(isAccelerated, targets, distance, extractionToPronounceable, targetToExtraction) { }
/// <summary> /// Initializes a new instance of the <see cref="AbstractFuzzyMatcher{Target,Extraction,Pronounceable}"/> class. /// </summary> /// <param name="targets">The set of objects that will be matched against. The order of equal targets is not guaranteed to be preserved.</param> /// <param name="distance">The distance delegate.</param> /// <param name="extractionToPronounceable">A mapping of the extraction type to a type understood by the distance function. Note that this is only required if Extraction != Pronounceable</param> /// <param name="targetToExtraction">A mapping of the input types to the query(extraction) type. Note that Extraction == Pronounceable for the usual case.</param> internal AbstractFuzzyMatcher(IList <Target> targets, DistanceFunc distance, Func <Extraction, Pronounceable> extractionToPronounceable, Func <Target, Extraction> targetToExtraction = null) : this(false, targets, distance, extractionToPronounceable, targetToExtraction) { }
/// <summary> /// Sets the function to be used to calculate the distance between two points. /// </summary> /// <param name="distanceFunction">The function used to calculate distance between two points.</param> /// <returns>A reference to the inverse distance weighting function.</returns> public InverseDistanceWeightingFunction SetDistanceFunction(DistanceFunc distanceFunction) { m_converter = null; m_distanceFunction = distanceFunction ?? DefaultDistanceFunction; return this; }
/// <summary> /// Creates a new instance of the <see cref="InverseDistanceWeightingFunction"/> class. /// </summary> public InverseDistanceWeightingFunction() { m_distanceFunction = DefaultDistanceFunction; m_power = 1; }
static float noise3d(Vector3 input, CombinerFunc combinerFunc, DistanceFunc distanceFunc) { // var value = 0; uint lastRandom; uint numberFeaturePoints; Vector3 randomDiff = new Vector3(0, 0, 0); Vector3 featurePoint = new Vector3(0, 0, 0); int cubeX, cubeY, cubeZ; for (var i = 0; i < DistanceArray.Length; i++) { DistanceArray[i] = 6666; } var evalCubeX = (int)(Mathf.Floor(input.x)); var evalCubeY = (int)(Mathf.Floor(input.y)); var evalCubeZ = (int)(Mathf.Floor(input.z)); for (var i = -1; i < 2; ++i) { for (var j = -1; j < 2; ++j) { for (var k = -1; k < 2; ++k) { cubeX = evalCubeX + i; cubeY = evalCubeY + j; cubeZ = evalCubeZ + k; //2. Generate a reproducible random number generator for the cube lastRandom = lcgRandom(hash((cubeX + Seed) & 0xffffffff, (cubeY) & 0xffffffff, (cubeZ) & 0xffffffff)); //3. Determine how many feature points are in the cube numberFeaturePoints = (uint)probLookup(lastRandom); //4. Randomly place the feature points in the cube for (var l = 0; l < numberFeaturePoints; ++l) { lastRandom = lcgRandom(lastRandom); randomDiff.x = (float)lastRandom / 0x100000000; lastRandom = lcgRandom(lastRandom); randomDiff.y = (float)lastRandom / 0x100000000; lastRandom = lcgRandom(lastRandom); randomDiff.z = (float)lastRandom / 0x100000000; featurePoint = new Vector3(randomDiff.x + cubeX, randomDiff.y + cubeY, randomDiff.z + cubeZ); //5. Find the feature point closest to the evaluation point. //This is done by inserting the distances to the feature points into a sorted list float v = distanceFunc(input, featurePoint); insert(DistanceArray, v); } //6. Check the neighboring cubes to ensure their are no closer evaluation points. // This is done by repeating steps 1 through 5 above for each neighboring cube } } } var color = combinerFunc(DistanceArray); if (color < 0) { color = 0; } if (color > 1) { color = 1; } return(color); }
static float noise2d(Vector2 input, CombinerFunc combinerFunc, DistanceFunc distanceFunc) { uint lastRandom; uint numberFeaturePoints; Vector2 randomDiff = new Vector2(0, 0); Vector2 featurePoint = new Vector2(0, 0); int cubeX, cubeY; for (var i = 0; i < DistanceArray.Length; i++) { DistanceArray[i] = 6666; } var evalCubeX = (int)(Mathf.Floor(input.x)); var evalCubeY = (int)(Mathf.Floor(input.y)); for (var i = -1; i < 2; ++i) { for (var j = -1; j < 2; ++j) { cubeX = evalCubeX + i; cubeY = evalCubeY + j; //2. Generate a reproducible random number generator for the cube lastRandom = lcgRandom(hash((cubeX + Seed) & 0xffffffff, (cubeY) & 0xffffffff)); //3. Determine how many feature points are in the cube numberFeaturePoints = (uint)probLookup(lastRandom); //4. Randomly place the feature points in the cube for (var l = 0; l < numberFeaturePoints; ++l) { lastRandom = lcgRandom(lastRandom); randomDiff.x = (float)lastRandom / 0x100000000; lastRandom = lcgRandom(lastRandom); randomDiff.y = (float)lastRandom / 0x100000000; featurePoint = new Vector2(randomDiff.x + cubeX, randomDiff.y + cubeY); //5. Find the feature point closest to the evaluation point. //This is done by inserting the distances to the feature points into a sorted list float v = distanceFunc(input, featurePoint); insert(DistanceArray, v); } //6. Check the neighboring cubes to ensure their are no closer evaluation points. // This is done by repeating steps 1 through 5 above for each neighboring cube } } var color = combinerFunc(DistanceArray); if (color < 0) { color = 0; } if (color > 1) { color = 1; } return(color); /* * //Declare some values for later use * uint lastRandom, numberFeaturePoints; * Vector2 randomDiff, featurePoint; * int cubeX, cubeY; * * float[] distanceArray = new float[3]; * * //Initialize values in distance array to large values * for (int i = 0; i < distanceArray.Length; i++) * distanceArray[i] = 6666; * * //1. Determine which cube the evaluation point is in * int evalCubeX = (int)Mathf.Floor(input.x); * int evalCubeY = (int)Mathf.Floor(input.y); * * for (int i = -1; i < 2; ++i) * { * for (int j = -1; j < 2; ++j) * { * cubeX = evalCubeX + i; * cubeY = evalCubeY + j; * * //2. Generate a reproducible random number generator for the cube * lastRandom = lcgRandom(hash((uint)(cubeX + inSeed), (uint)(cubeY))); * * //3. Determine how many feature points are in the cube * numberFeaturePoints = probLookup(lastRandom); * //4. Randomly place the feature points in the cube * for (uint l = 0; l < numberFeaturePoints; ++l) * { * lastRandom = lcgRandom(lastRandom); * randomDiff.x = (float)lastRandom / 0x100000000; * * lastRandom = lcgRandom(lastRandom); * randomDiff.y = (float)lastRandom / 0x100000000; * * featurePoint = new Vector2(randomDiff.x + (float)cubeX, randomDiff.y + (float)cubeY); * * //5. Find the feature point closest to the evaluation point. * //This is done by inserting the distances to the feature points into a sorted list * insert(distanceArray, DistanceFunc2(input, featurePoint)); * } * //6. Check the neighboring cubes to ensure their are no closer evaluation points. * // This is done by repeating steps 1 through 5 above for each neighboring cube * } * } * * return Mathf.Clamp01(CombineFunc(distanceArray)); */ }