/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; var parseError = new ParseError(); _collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); try { ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); } catch { if (_collatorHandle != default(SafeRuleBasedCollatorHandle)) { _collatorHandle.Dispose(); } _collatorHandle = default(SafeRuleBasedCollatorHandle); throw; } }
public KernelConvolution(float[,] kernel, byte size = 3, NormalizationMode normalizationMode = NormalizationMode.TotalKernelValue) { this.normalizationMode = normalizationMode; output = new Output(0, 0, this); Size = size; Kernel = kernel; }
public KernelConvolution(byte size = 3, NormalizationMode normalizationMode = NormalizationMode.TotalKernelValue) { output = new Output(0, 0, this); this.normalizationMode = normalizationMode; Size = size; Kernel = new float[size, size]; }
/** @copydoc LayerParameterBase::Copy */ public override void Copy(LayerParameterBase src) { LossParameter p = (LossParameter)src; m_nIgnoreLabel = p.m_nIgnoreLabel; m_normalization = p.m_normalization; m_bNormalize = p.m_bNormalize; }
public SVector(Joystick[] names, NormalizationMode normalizationMode, bool sendWhenZeroToo) { this.names = names; this.normalizationMode = normalizationMode; this.sendWhenZeroToo = sendWhenZeroToo; events = new ButtonEvents(); JoystickValue = null; JoystickMagnitude = null; isPressed = false; }
static Keyframe[] CopyAndScaleCurveKeys(Keyframe[] orgKeys, Rect rect, NormalizationMode normalization) { Keyframe[] scaledKeys = new Keyframe[orgKeys.Length]; orgKeys.CopyTo(scaledKeys, 0); if (normalization == NormalizationMode.None) { return(scaledKeys); } if (rect.width == 0f || rect.height == 0f || Single.IsInfinity(rect.width) || Single.IsInfinity(rect.height)) { Debug.LogError("CopyAndScaleCurve: Invalid scale: " + rect); return(scaledKeys); } float tangentMultiplier = rect.height / rect.width; switch (normalization) { case NormalizationMode.Normalize: for (int i = 0; i < scaledKeys.Length; ++i) { scaledKeys[i].time = (orgKeys[i].time - rect.xMin) / rect.width; scaledKeys[i].value = (orgKeys[i].value - rect.yMin) / rect.height; if (!Single.IsInfinity(orgKeys[i].inTangent)) { scaledKeys[i].inTangent = orgKeys[i].inTangent / tangentMultiplier; } if (!Single.IsInfinity(orgKeys[i].outTangent)) { scaledKeys[i].outTangent = orgKeys[i].outTangent / tangentMultiplier; } } break; case NormalizationMode.Denormalize: // From normalized to real for (int i = 0; i < scaledKeys.Length; ++i) { scaledKeys[i].time = orgKeys[i].time * rect.width + rect.xMin; scaledKeys[i].value = orgKeys[i].value * rect.height + rect.yMin; if (!Single.IsInfinity(orgKeys[i].inTangent)) { scaledKeys[i].inTangent = orgKeys[i].inTangent * tangentMultiplier; } if (!Single.IsInfinity(orgKeys[i].outTangent)) { scaledKeys[i].outTangent = orgKeys[i].outTangent * tangentMultiplier; } } break; } return(scaledKeys); }
public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; _handle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref _parseError, out status); status.ThrowIfError(_parseError.ToString(rules)); }
public static Keyframe[] NormalizeKeys(Keyframe[] sourceKeys, NormalizationMode normalization, CurveEditor curveEditor) { Rect normalizationRect; if (!GetNormalizationRect(out normalizationRect, curveEditor)) { // No normalization rect, just return a copy of the source keyframes normalization = NormalizationMode.None; } return(CopyAndScaleCurveKeys(sourceKeys, normalizationRect, normalization)); }
public Tensor Normalize(NormalizationMode mode) { switch (mode) { case (NormalizationMode.Standardization): { var avg = this.MeanAll(); double variance = this.Map(r => Math.Pow(r - avg, 2)).MeanAll(); return(this.Map(r => (r - avg) / Math.Sqrt(variance + 0.001))); } } return(null); }
/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); }
public static IESData Parse(string path, NormalizationMode normalizationMode) { string[] array = File.ReadAllLines(path); int num = 0; ParseIES.FindNumberOfAnglesLine(array, ref num); if (num == array.Length - 1) { throw new IESParseException("No line containing number of angles found."); } int numberOfValuesToFind; int num2; PhotometricType photometricType; ParseIES.ReadProperties(array, ref num, out numberOfValuesToFind, out num2, out photometricType); List <float> verticalAngles = ParseIES.ReadValues(array, numberOfValuesToFind, ref num); List <float> horizontalAngles = ParseIES.ReadValues(array, num2, ref num); List <List <float> > list = new List <List <float> >(); for (int i = 0; i < num2; i++) { list.Add(ParseIES.ReadValues(array, numberOfValuesToFind, ref num)); } IESData iesdata = new IESData { VerticalAngles = verticalAngles, HorizontalAngles = horizontalAngles, CandelaValues = list, PhotometricType = photometricType }; ParseIES.NormalizeValues(iesdata, normalizationMode == NormalizationMode.Logarithmic); if (normalizationMode == NormalizationMode.EqualizeHistogram) { ParseIES.EqualizeHistogram(iesdata); } if (photometricType != PhotometricType.TypeA) { ParseIES.DiscardUnusedVerticalHalf(iesdata); ParseIES.SetVerticalAndHorizontalType(iesdata); iesdata.HalfSpotlightFov = ParseIES.CalculateHalfSpotFov(iesdata); } else { ParseIES.PadToSquare(iesdata); } return(iesdata); }
///<summary> /// Produce an Collator instance according to the rules supplied. /// The rules are used to change the default ordering, defined in the /// UCA in a process called tailoring. The resulting Collator pointer /// can be used in the same way as the one obtained by ucol_strcoll. /// </summary> /// <param name="rules">A string describing the collation rules. For the syntax /// of the rules please see users guide.</param> /// <param name="rulesLength">The length of rules, or -1 if null-terminated.</param> /// <param name="normalizationMode">The normalization mode</param> /// <param name="strength">The default collation strength; can be also set in the rules</param> /// <param name="parseError">A pointer to ParseError to recieve information about errors /// occurred during parsing. This argument can currently be set /// to NULL, but at users own risk. Please provide a real structure.</param> /// <param name="status">A pointer to an ErrorCode to receive any errors</param> /// <returns>A pointer to a UCollator. It is not guaranteed that NULL be returned in case /// of error - please use status argument to check for errors.</returns> public static RuleBasedCollator.SafeRuleBasedCollatorHandle ucol_openRules( [MarshalAs(UnmanagedType.LPWStr)] string rules, int rulesLength, NormalizationMode normalizationMode, CollationStrength strength, ref ParseError parseError, out ErrorCode status) { status = ErrorCode.NoErrors; if (CollatorMethods.ucol_openRules == null) { CollatorMethods.ucol_openRules = GetMethod <CollatorMethodsContainer.ucol_openRulesDelegate>(IcuI18NLibHandle, "ucol_openRules"); } return(CollatorMethods.ucol_openRules(rules, rulesLength, normalizationMode, strength, ref parseError, out status)); }
public string NormalizeUrl(string url, string title, out bool blacklist, NormalizationMode mode) { blacklist = false; string left; ArrayList <string> path; ArrayList <KeyDat <string, string> > queryParsed; ParseUrl(url, out left, out path, out queryParsed); string content = title == null ? "" : Normalize(title); string cid = Utils.GetStringHashCode128(content).ToString("N"); queryParsed.InsertSorted(new KeyDat <string, string>("__cid__", cid)); // inject content-id query parameter string url1 = UrlAsString(left, path, queryParsed, null); foreach (string prefix in mBlacklist) { if (url1.StartsWith(prefix)) { blacklist = true; break; } } if (mode == NormalizationMode.Basic) { return(url1); } string url2 = UrlAsString(left, path, queryParsed, new Set <string>()); if (mode == NormalizationMode.DropQuery) { return(url2); } string url3 = ExecuteRules(url1, left, path, queryParsed, mRules); if (url3 == null) { url3 = url2; } return(url3); }
public int NormalizationModeSetting(NormalizationMode normalizationMode, string string1, string string2) { /*The Normalization setting determines whether text is thoroughly * normalized or not in comparison. Even if the setting is off (which * is the default for many locales), text as represented in common usage * will compare correctly (for details, see UTN #5 ). Only if the accent * marks are in non-canonical order will there be a problem. If the * setting is On, then the best results are guaranteed for all possible * text input.There is a medium string comparison performance cost if * this attribute is On, depending on the frequency of sequences that * require normalization. There is no significant effect on sort key * length.If the input text is known to be in NFD or NFKD normalization * forms, there is no need to enable this Normalization option. * Example: * N=X ä = a + ◌̈ < ä + ◌̣ < ạ + ◌̈ * N=O ä = a + ◌̈ < ä + ◌̣ = ạ + ◌̈ */ using (var ucaCollator = new RuleBasedCollator(string.Empty, normalizationMode, CollationStrength.Default)) { return(ucaCollator.Compare(string1, string2)); } }
/// <summary> /// The constructor for the LossParameter. /// </summary> /// <remarks> /// The default VALID normalization mode is used for all loss layers, except /// for the SigmoidCrossEntropyLoss layer which uses BATCH_SIZE as the default /// for historical reasons. /// </remarks> /// <param name="norm">Specifies the default normalization mode.</param> public LossParameter(NormalizationMode norm = NormalizationMode.VALID) { m_normalization = norm; }
public void NormalizeSplatmap(ref float[,,] splatmap, NormalizationMode normalizationMode) { int width = splatmap.GetLength(0); int height = splatmap.GetLength(1); int numChannels = splatmap.GetLength(2); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // Calculate total luminance of this pixel float totalColor = 0f; for (int i = 0; i < numChannels; i++) { totalColor += splatmap[x, y, i]; } // Normalize pixel luminance to 1 using chosen strategy // Todo: inject these strategies using Func<> chosen from a library switch (normalizationMode) { case NormalizationMode.Equal: if (totalColor < 0.01f) { splatmap[x, y, 0] += 1f - totalColor; } else { for (int i = 0; i < numChannels; i++) { splatmap[x, y, i] /= totalColor; } } break; case NormalizationMode.Strongest: float strongestValue = 0f; int strongestChannel = 0; for (int i = 0; i < numChannels; i++) { float channelValue = splatmap[x, y, i]; if (channelValue > strongestValue) { strongestValue = channelValue; strongestChannel = i; } } splatmap[x, y, strongestChannel] += 1f - totalColor; break; case NormalizationMode.First: splatmap[x, y, 0] += 1f - totalColor; break; case NormalizationMode.Last: splatmap[x, y, numChannels - 1] += 1f - totalColor; break; } } } }
internal static ColumnOptionsBase Create(string outputColumnName, string inputColumnName, NormalizationMode mode) { switch (mode) { case NormalizationMode.MinMax: return(new MinMaxColumnOptions(outputColumnName, inputColumnName)); case NormalizationMode.MeanVariance: return(new MeanVarColumnOptions(outputColumnName, inputColumnName)); case NormalizationMode.LogMeanVariance: return(new LogMeanVarColumnOptions(outputColumnName, inputColumnName)); case NormalizationMode.Binning: return(new BinningColumnOptions(outputColumnName, inputColumnName)); case NormalizationMode.SupervisedBinning: return(new SupervisedBinningColumOptions(outputColumnName, inputColumnName)); default: throw Contracts.ExceptParam(nameof(mode), "Unknown normalizer mode"); } }
/// <summary> /// Initializes a new instance of <see cref="NormalizingEstimator"/>. /// </summary> /// <param name="env">Host Environment.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of the column to transform. /// If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="mode">The <see cref="NormalizationMode"/> indicating how to the old values are mapped to the new values.</param> internal NormalizingEstimator(IHostEnvironment env, string outputColumnName, string inputColumnName = null, NormalizationMode mode = NormalizationMode.MinMax) : this(env, mode, (outputColumnName, inputColumnName ?? outputColumnName)) {
private void BuildTargetFilename(string name, string folderHierarchy, bool isCubemap, bool isRaw, NormalizationMode normalizationMode, IESData iesData, out string targetFilePath) { if (!Directory.Exists(Path.Combine(Application.dataPath, string.Format("IES/Imports/{0}", folderHierarchy)))) { Directory.CreateDirectory(Path.Combine(Application.dataPath, string.Format("IES/Imports/{0}", folderHierarchy))); } float num = 0f; if (iesData.PhotometricType == PhotometricType.TypeA) { num = iesData.HorizontalAngles.Max() - iesData.HorizontalAngles.Min(); } else if (!isCubemap) { num = iesData.HalfSpotlightFov * 2f; } string text = ""; if (normalizationMode == NormalizationMode.EqualizeHistogram) { text = "[H] "; } else if (normalizationMode == NormalizationMode.Logarithmic) { text = "[E] "; } string text2; if (isRaw) { text2 = "exr"; } else { text2 = (isCubemap ? "cubemap" : "asset"); } targetFilePath = Path.Combine(Path.Combine("Assets/IES/Imports/", folderHierarchy), string.Format("{0}{1}{2}.{3}", new object[] { text, (iesData.PhotometricType == PhotometricType.TypeA || !isCubemap) ? ("[FOV " + num + "] ") : "", name, text2 })); if (File.Exists(targetFilePath)) { File.Delete(targetFilePath); } }
public string NormalizeUrl(string url, string title, out bool blacklist, NormalizationMode mode) { blacklist = false; string left; ArrayList<string> path; ArrayList<KeyDat<string, string>> queryParsed; ParseUrl(url, out left, out path, out queryParsed); string content = title == null ? "" : Normalize(title); string cid = Utils.GetHashCode128(content).ToString("N"); queryParsed.InsertSorted(new KeyDat<string, string>("__cid__", cid)); // inject content-id query parameter string url1 = UrlAsString(left, path, queryParsed, null); foreach (string prefix in mBlacklist) { if (url1.StartsWith(prefix)) { blacklist = true; break; } } if (mode == NormalizationMode.Basic) { return url1; } string url2 = UrlAsString(left, path, queryParsed, new Set<string>()); if (mode == NormalizationMode.DropQuery) { return url2; } string url3 = ExecuteRules(url1, left, path, queryParsed, mRules); if (url3 == null) { url3 = url2; } return url3; }
public static extern RuleBasedCollator.Handle ucol_openRules([MarshalAs(UnmanagedType.LPWStr)] string rules, int rulesLength, NormalizationMode normalizationMode, CollationStrength strength, ref ParseError parseError, out ErrorCode status);
public static IESData Parse(string path, NormalizationMode normalizationMode) { // Find the line containing the number of vertical and horizontal angles. string[] lines = File.ReadAllLines(path); int lineNumber = 0; FindNumberOfAnglesLine(lines, ref lineNumber); if (lineNumber == lines.Length - 1) { throw new IESParseException("No line containing number of angles found."); } // Read the number of vertical and horizontal angles. int numberOfVerticalAngles, numberOfHorizontalAngles; PhotometricType photometricType; ReadProperties(lines, ref lineNumber, out numberOfVerticalAngles, out numberOfHorizontalAngles, out photometricType); // Read the vertical angles. List <float> verticalAngles = ReadValues(lines, numberOfVerticalAngles, ref lineNumber); // Read the horizontal angles. List <float> horizontalAngles = ReadValues(lines, numberOfHorizontalAngles, ref lineNumber); // Read the candela values for all vertical slices for each horizontal angle. List <List <float> > values = new List <List <float> >(); for (int i = 0; i < numberOfHorizontalAngles; i++) { values.Add(ReadValues(lines, numberOfVerticalAngles, ref lineNumber)); } IESData iesData = new IESData() { VerticalAngles = verticalAngles, HorizontalAngles = horizontalAngles, CandelaValues = values, PhotometricType = photometricType }; // Normalize the candela values, applying the enhanced mode if requested. // The normalized values will also be used to discard practically unlit areas from spot light cookies. NormalizeValues(iesData, normalizationMode == NormalizationMode.Logarithmic); if (normalizationMode == NormalizationMode.EqualizeHistogram) { EqualizeHistogram(iesData); } // Prepare type C (and B, if it ever exists) photometry for possible spotlight cookie usage. if (photometricType != PhotometricType.TypeA) { DiscardUnusedVerticalHalf(iesData); SetVerticalAndHorizontalType(iesData); iesData.HalfSpotlightFov = CalculateHalfSpotFov(iesData); } // Prepare type A (automotive) photometry. else { PadToSquare(iesData); } return(iesData); }
private void BuildTargetFilename(string name, string folderHierarchy, bool isCubemap, bool isRaw, NormalizationMode normalizationMode, IESData iesData, out string targetFilePath) { if (!Directory.Exists(Path.Combine(Application.dataPath, string.Format("IES/Imports/{0}", folderHierarchy)))) { Directory.CreateDirectory(Path.Combine(Application.dataPath, string.Format("IES/Imports/{0}", folderHierarchy))); } // If this in an enhanced import, add the appropriate prefix. float automotiveFov = 0; if (iesData.PhotometricType == PhotometricType.TypeA) { automotiveFov = iesData.HorizontalAngles.Max() - iesData.HorizontalAngles.Min(); } string prefix = ""; if (normalizationMode == NormalizationMode.EqualizeHistogram) { prefix = "[H] "; } else if (normalizationMode == NormalizationMode.Logarithmic) { prefix = "[E] "; } // Set the correct extension. string extension = ""; if (isRaw) { extension = "exr"; } else { extension = isCubemap ? "cubemap" : "asset"; } targetFilePath = Path.Combine(Path.Combine("Assets/IES/Imports/", folderHierarchy), string.Format("{0}{1}{2}.{3}", prefix, iesData.PhotometricType == PhotometricType.TypeA ? "[FOV " + automotiveFov + "] " : "", name, extension)); if (File.Exists(targetFilePath)) { File.Delete(targetFilePath); } }
/// <summary> /// Executes the forward pass in a batch normalization layer /// </summary> /// <param name="mode">The desired normalization mode to apply</param> /// <param name="info">The ifo on the input <see cref="Tensor"/> to process</param> /// <param name="x">The input <see cref="Tensor"/> to normalize</param> /// <param name="factor">The factor for the cumulative moving average</param> /// <param name="mu">A <see cref="Tensor"/> to use to store the temporary median values (used for backpropagation too)</param> /// <param name="sigma2">A <see cref="Tensor"/> to use to store the temporary standard deviation values (used for backpropagation too)</param> /// <param name="gamma">The layer gamma parameters</param> /// <param name="beta">The layer beta parameters</param> /// <param name="y">The output <see cref="Tensor"/> for the current layer</param> public static void BatchNormalizationForward( NormalizationMode mode, in TensorInfo info, in Tensor x,