public virtual void TestAddInPlace() { ArrayMath.AddInPlace(d1, 3); for (int i = 0; i < ArrayMath.NumRows(d1); i++) { NUnit.Framework.Assert.AreEqual(d2[i] + 3, 1e-5, d1[i]); } }
/// <summary> /// Merge the given /// <c>Cost</c> /// data with the data in this /// instance. /// </summary> /// <param name="otherCost"/> public virtual void Merge(Classifier.Cost otherCost) { this.cost += otherCost.GetCost(); this.percentCorrect += otherCost.GetPercentCorrect(); ArrayMath.AddInPlace(this.gradW1, otherCost.GetGradW1()); ArrayMath.PairwiseAddInPlace(this.gradb1, otherCost.GetGradb1()); ArrayMath.AddInPlace(this.gradW2, otherCost.GetGradW2()); ArrayMath.AddInPlace(this.gradE, otherCost.GetGradE()); }
// In this method, each tag that is incompatible with the current word // (e.g., apple_CC) gets a default (constant) score instead of its exact score. // The scores of all other tags are computed exactly. private double[] GetApproximateScores(History h) { string[] tags = StringTagsAt(h.current - h.start + LeftWindow()); double[] scores = GetHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: int nDefault = maxentTagger.ySize - tags.Length; double logScore = ArrayMath.LogSum(scores); double logScoreInactiveTags = maxentTagger.GetInactiveTagDefaultScore(nDefault); double logTotal = SloppyMath.LogAdd(logScore, logScoreInactiveTags); ArrayMath.AddInPlace(scores, -logTotal); return(scores); }
public virtual void Test2dAdd() { double[][] d6 = new double[][] { new double[] { 0.26, 0.87, -1.26 }, new double[] { 0.17, 3.21, -1.8 } }; double[][] d7 = new double[][] { new double[] { 0.26, 0.07, -1.26 }, new double[] { 0.17, -3.21, -1.8 } }; double[][] d8 = new double[][] { new double[] { 0.52, 0.94, -2.52 }, new double[] { 0.34, 0.0, -3.6 } }; ArrayMath.AddInPlace(d6, d7); for (int i = 0; i < d8.Length; i++) { for (int j = 0; j < d8[i].Length; j++) { NUnit.Framework.Assert.AreEqual(d8[i][j], 1e-5, d6[i][j]); } } }