public MultipleTimeSeries(Tuple<TimeSeriesLink, TimeSeries>[] src,bool includeValues = true) { if(includeValues) TimeSeries = src.Select(item => new SlimTimeSeries(item.Item1,item.Item2)).ToArray(); else TimeSeries = src.Select(item => new TimeSeriesFullSummary(item.Item1, item.Item2)).ToArray(); }
public ChunkTable(GameSave gameSave, Tuple<int, int, Chunk>[] chunks) : this(gameSave, chunks.Select(x => x.Item1).ToArray(), chunks.Select(x => x.Item2).ToArray(), chunks.Select(x => x.Item3).ToArray()) { }
public PropertyChoicesFacetViaMethod(MethodInfo optionsMethod, IFacetHolder holder) : base(holder) { method = optionsMethod; parameterNamesAndTypes = optionsMethod.GetParameters().Select(p => new Tuple<string, INakedObjectSpecification>(p.Name.ToLower(), NakedObjectsContext.Reflector.LoadSpecification(p.ParameterType))).ToArray(); parameterNames = parameterNamesAndTypes.Select(pnt => pnt.Item1).ToArray(); }
public TableRenderer(string title, Tuple<string, int>[] headers) { _title = title; _headers = headers; _totalWidth = _headers.Sum(h => h.Item2) + (_headers.Count() - 1) * 3; _rowTemplate = "| " + String.Join(" | ", _headers.Select((h, i) => "{" + i + ",-" + h.Item2 + "}").ToArray()) + " |"; }
public ItemsWithConflictingHighestScoreException(Tuple<IValueProvider, IProbe>[] itemsWithConflictingScore, int highestScore) : base(string.Format( "items: {0} with conflicting highest score of {1} exists, cannot determine default", string.Concat(itemsWithConflictingScore.Select(x=>x.Item1.ToString())), highestScore)) { ItemsWithConflictingScore = itemsWithConflictingScore; HighestScore = highestScore; }
public LogItem[][] GetItems(Tuple<CriteriaType, DateTime, int, bool>[] parameters) { using (var connection = _connectionFactory.Create()) { return parameters.Select(p => _repository.GetItems(connection, p.Item1, p.Item2, p.Item3, p.Item4)).ToArray(); } }
public static string AsString(Tuple<string, object>[] keyValues) { return keyValues.Count() == 1 ? keyValues.First().Item2 as string : keyValues.Select(k => string.Format("{0}='{1}'", k.Item1, k.Item2)) .Aggregate((c, n) => c + "," + n); }
public ActionChoicesFacetViaMethod(MethodInfo choicesMethod, Type choicesType, IFacetHolder holder, bool isMultiple = false) : base(holder) { this.choicesMethod = choicesMethod; this.choicesType = choicesType; this.isMultiple = isMultiple; parameterNamesAndTypes = choicesMethod.GetParameters().Select(p => new Tuple<string, INakedObjectSpecification>(p.Name.ToLower(), NakedObjectsContext.Reflector.LoadSpecification(p.ParameterType))).ToArray(); parameterNames = parameterNamesAndTypes.Select(pnt => pnt.Item1).ToArray(); }
public PropertyChoicesFacetx(MethodInfo optionsMethod, Tuple<string, IObjectSpecImmutable>[] parameterNamesAndTypes, ISpecification holder) : base(typeof (IPropertyChoicesFacet), holder) { method = optionsMethod; this.parameterNamesAndTypes = parameterNamesAndTypes; parameterNames = parameterNamesAndTypes.Select(pnt => pnt.Item1).ToArray(); methodDelegate = DelegateUtils.CreateDelegate(method); }
public void Show(string trainerMatchcode, Tuple<string,string>[] trainings, string error) { dynamic vm = new ExpandoObject(); vm.TrainerMatchcode = trainerMatchcode; vm.Trainings = trainings.Select(tr => new {Id = tr.Item1, Matchcode = tr.Item2}).ToArray(); vm.Error = error; _portal.SharedResponse = _portal.View["Trainingsuebersicht.Main.html", vm]; }
public void AwardMarks(int awarderId, Tuple<int, int>[] guessMarks) { var player = new Player(awarderId); var marks = guessMarks.Select( gm => Tuple.Create(this.repository.Query<IGuessDTO>(g => g.Id == gm.Item1).FirstOrDefault(), gm.Item2)).ToArray(); player.AwardMarks(marks); }
// aggregate all the basket consitituents data public DatedDataCollectionGen<double> AggregateBasketCollections(Tuple<CustomBasket, DatedDataCollectionGen<double>>[] basketsWithData) { var results = basketsWithData.Select(basketData => { var rolledSeries = RollOverBasket(basketData); return rolledSeries.MultiplyBy(basketData.Item1.Weight); }); return results.Add(); }
public ActionChoicesFacetViaMethod(MethodInfo choicesMethod, Tuple<string, IObjectSpecImmutable>[] parameterNamesAndTypes, Type choicesType, ISpecification holder, bool isMultiple = false) : base(holder) { this.choicesMethod = choicesMethod; this.choicesType = choicesType; IsMultiple = isMultiple; ParameterNamesAndTypes = parameterNamesAndTypes; parameterNames = parameterNamesAndTypes.Select(pnt => pnt.Item1).ToArray(); choicesDelegate = DelegateUtils.CreateDelegate(choicesMethod); }
static int[] GetHandValue(Tuple<int, string>[] hand) { Predicate<Tuple<int, string>[]> isFlush = c => c.Select(f => f.Item2).Distinct().Count() == 1; List<int> handRanks = hand.Select(c => c.Item1).OrderByDescending(c => c).ToList(); int straightValue = IsStraight(handRanks); if (isFlush(hand) && straightValue != -1) return new int[] { 10, straightValue }; List<int> kind4 = HasSets(handRanks, new int[] { 4, 1 }); if (kind4 != null) { kind4.Insert(0, 9); return kind4.ToArray(); } List<int> kind32 = HasSets(handRanks, new int[] { 3, 2 }); if (kind32 != null) { kind32.Insert(0, 8); return kind32.ToArray(); } if (isFlush(hand)) return new int[] { 7, handRanks.Max() }; if (straightValue != -1) return new int[] { 6, straightValue }; List<int> kind311 = HasSets(handRanks, new int[] { 3, 1, 1 }); if (kind311 != null) { kind311.Insert(0, 5); return kind311.ToArray(); } List<int> kind221 = HasSets(handRanks, new int[] { 2, 2, 1 }); if (kind221 != null) { kind221.Insert(0, 4); return kind221.ToArray(); } List<int> kind2111 = HasSets(handRanks, new int[] { 2, 1, 1, 1 }); if (kind2111 != null) { kind2111.Insert(0, 3); return kind2111.ToArray(); } handRanks.Insert(0, 0); return handRanks.ToArray(); }
public void Setup() { queryable = new List<SomeModel>() { new SomeModel() { Category = 1, DisplayName = "Cheddar", Id = 123, Scale = 123.456d, Discounted = true } }.AsQueryable(); dataTablesParam = new DataTablesParam(); columns = TypeExtensions.GetSortedProperties<SomeModel>().Select((p, i) => Tuple.Create(i, new ColInfo(p.Name, p.PropertyType))).ToArray(); dataTablesParam.sSearchColumns = new List<string>(columns.Select(c => null as string)); dataTablesParam.bSearchable = new List<bool>(columns.Select(c => true)); }
public void Setup() { queryable = new List<SomeModel>() { new SomeModel() { Category = 1, DisplayName = "Cheddar", Id = 123, Scale = 123.456d, Discounted = true, Cost = 123 } }.AsQueryable(); dataTablesParam = new DataTablesParam(); columns = DataTablesTypeInfo<SomeModel>.Properties.Select((p, i) => Tuple.Create(i, new DataTablesPropertyInfo(p.PropertyInfo, new DataTablesAttributeBase[]{}))).ToArray(); dataTablesParam.sSearchColumns = new List<string>(columns.Select(c => null as string)); dataTablesParam.bSearchable = new List<bool>(columns.Select(c => true)); }
public BondStructureOTR(Focus focus_, Tuple<int,BondMarket,double>[] points_) : base(points_.GetDescription()) { Points = points_; m_focus = focus_; foreach (BondMarket mkt in points_.Select(x => x.Item2).Distinct()) { CountryBondSource.GetInstance(mkt).OTRCache.ItemAdded += handleCachedChanged; CountryBondSource.GetInstance(mkt).OTRCache.ItemRemoved += handleCachedChanged; } rebuild(); }
public BondStructureCMT(Focus focus_, Tuple<int,BondMarket,double>[] points_) : base(points_.GetDescription()) { Points = points_; Focus = focus_; m_bits = Points.Select(x => x.Item2) .Distinct() .Select(x => CountryBondSource.GetInstance(x).GetSmoothCurveGroupForFocus(Focus).LiveCMT) .ToDictionary(x => x.Market, x => x); subscribeToFit(); setPriorValue(); RecalculateLive(); }
public string ValidateParms(INakedObjectAdapter nakedObjectAdapter, Tuple<string, INakedObjectAdapter>[] parms) { foreach (NakedObjectValidationMethod validator in ValidateMethods) { Tuple<string, INakedObjectAdapter>[] matches = validator.ParameterNames.Select(name => parms.SingleOrDefault(p => p.Item1.ToLower() == name)).Where(p => p != null).ToArray(); if (matches.Count() == validator.ParameterNames.Count()) { INakedObjectAdapter[] parameters = matches.Select(p => p.Item2).ToArray(); string result = validator.Execute(nakedObjectAdapter, parameters); if (result != null) return result; } else { string actual = parms.Select(s => s.Item1).Aggregate((s, t) => s + " " + t); LogNoMatch(validator, actual); } } return null; }
public void Enumerator_WhenEnumerated_ReturnsUnderlyingFactObjectsInOrder() { //Arrange var tuple0 = new Tuple(null); var tuple1 = new Tuple(tuple0, new Fact(1), null); var tuple2 = new Tuple(tuple1, new Fact(2), null); var tuple3 = new Tuple(tuple2, new Fact(3), null); //Act var target = tuple3.Select(f => f.Object).ToArray(); //Assert Assert.AreEqual(3, target.Length); Assert.AreEqual(1, target[0]); Assert.AreEqual(2, target[1]); Assert.AreEqual(3, target[2]); }
public void Setup() { //TODO: this became an integration test - proper ProjectionCoreService and ProjectionManager testing is required as well _bus.Subscribe(_consumer); _processingQueues = GivenProcessingQueues(); _manager = new ProjectionManager( GetInputQueue(), GetInputQueue(), _processingQueues.Select(v => v.Item1).ToArray(), _timeProvider, RunProjections.All, _initializeSystemProjections); _bus.Subscribe<ProjectionManagementMessage.Internal.CleanupExpired>(_manager); _bus.Subscribe<ProjectionManagementMessage.Internal.Deleted>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.Started>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.Stopped>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.Prepared>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.Faulted>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.StateReport>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.ResultReport>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.StatisticsReport>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.SlaveProjectionReaderAssigned>(_manager); _bus.Subscribe<ProjectionManagementMessage.Post>(_manager); _bus.Subscribe<ProjectionManagementMessage.UpdateQuery>(_manager); _bus.Subscribe<ProjectionManagementMessage.GetQuery>(_manager); _bus.Subscribe<ProjectionManagementMessage.Delete>(_manager); _bus.Subscribe<ProjectionManagementMessage.GetStatistics>(_manager); _bus.Subscribe<ProjectionManagementMessage.GetState>(_manager); _bus.Subscribe<ProjectionManagementMessage.GetResult>(_manager); _bus.Subscribe<ProjectionManagementMessage.Disable>(_manager); _bus.Subscribe<ProjectionManagementMessage.Enable>(_manager); _bus.Subscribe<ProjectionManagementMessage.Abort>(_manager); _bus.Subscribe<ProjectionManagementMessage.SetRunAs>(_manager); _bus.Subscribe<ProjectionManagementMessage.Reset>(_manager); _bus.Subscribe<ProjectionManagementMessage.StartSlaveProjections>(_manager); _bus.Subscribe<ClientMessage.WriteEventsCompleted>(_manager); _bus.Subscribe<ClientMessage.ReadStreamEventsBackwardCompleted>(_manager); _bus.Subscribe<ClientMessage.WriteEventsCompleted>(_manager); _bus.Subscribe<SystemMessage.StateChangeMessage>(_manager); foreach(var q in _processingQueues) SetUpCoreServices(q.Item1, q.Item2, q.Item3); //Given(); WhenLoop(); }
public bool[] ItWorks(TimeSpan timespan, Tuple<int, bool>[] events) { var innerTrigger = TriggerTestHelpers.SequenceTrigger(events.Select(x => x.Item2).ToArray()); var now = DateTime.UtcNow; var trigger = new OncePerTimespanTriggerFake(innerTrigger, timespan); var results = new List<bool>(); foreach(var @event in events) { trigger.SetNow(now.AddSeconds(@event.Item1)); var result = trigger.Check(); results.Add(result); } return results.ToArray(); }
/// <param name="path">Application relative path to the module directory.</param> /// <param name="resources">All the unresolved resources found in the module.</param> /// <param name="isResourceOrderFixed">When true, the resources will not be sorted by their dependency ordering.</param> public UnresolvedModule(string path, UnresolvedResource[] resources, string location, bool isResourceOrderFixed) { this.path = path; this.location = location; var pathsInModule = new HashSet<string>(resources.Select(resource => resource.Path)); partition = PartitionResourceReferences(resources, pathsInModule); // Store all the references to external resources. this.externalReferences = partition.SelectMany(p => p.Item2).Distinct().ToArray(); // The resources now only contain references found in this module. var resolvedResources = partition.Select(p => p.Item1).ToArray(); if (isResourceOrderFixed) { this.resources = resolvedResources; } else { this.resources = OrderScriptsByDependency(resolvedResources); } }
public void AwardMarks(Tuple<IGuessDTO, int>[] marks) { var chainId = marks[0].Item1.Chain.Id; if(marks.Select(m => m.Item1.Chain.Id).Any(x => x != chainId)) { throw new InvalidOperationException(); } var chain = this.Repository.Query<IChainDTO>(c => c.Id == chainId).FirstOrDefault(); var chainComplete = new CompleteChain(chain); if (chainComplete.HasMarksAssigned(this.Id)) { throw new InvalidOperationException(); } foreach(var mark in marks) { //this.Repository.Insert<IMarkDTO>(new MarkDTO() {Guess = mark.Item1, Score = mark.Item2, Awarder = this}); } }
private static void DoSv(Tuple<double[], double>[] classified) { var stripped = classified.Select(t => new Tuple<double[], double>(t.Item1.Skip(1).ToArray(), t.Item2)) .ToArray(); var q = GetQ(stripped); //all are 0 or more var lcc = new LinearConstraintCollection( Enumerable.Range(0, stripped.Length) .Select(i => new LinearConstraint(1) { VariablesAtIndices = new[] { i }, ShouldBe = ConstraintType.GreaterThanOrEqualTo, Value = 0.0, CombinedAs= new []{1.0} //??? })); //and they zero out with the classificaiton lcc.Add( //new LinearConstraint(stripped.Select(t => t.Item2).ToArray()) { Value = 0, ShouldBe = ConstraintType.EqualTo } new LinearConstraint(stripped.Length) { Value = 0, ShouldBe = ConstraintType.EqualTo, VariablesAtIndices = Enumerable.Range(0, stripped.Length).ToArray(), CombinedAs = stripped.Select(t => t.Item2).ToArray() } ); var solver = new GoldfarbIdnaniQuadraticSolver(stripped.Length, lcc); solver.Minimize(q, neg1Array(stripped.Length)); //b = 1/y - w_*x_ var tmp = solver.Solution.Zip(stripped, (alpha, s) => s.Item1.Select(x => x * alpha * s.Item2)) .Aggregate(VAdd).ToList(); var support = solver.Solution.Zip(stripped, (alpha, s) => Math.Abs(alpha) > 0.0001 ? s : null).Where(x => x != null).ToArray(); var offset = GetOffset(support, tmp); //I'm pretty sure this calculation for b is wrong: you get a different one for each of elements... tmp.Insert(0, offset); var wSupp = Norm( tmp.ToArray()); }
internal static string MultipleApplicableRegistrationsFound(Type serviceType, Tuple<Type, Type, InstanceProducer>[] overlappingRegistrations) => string.Format(CultureInfo.InvariantCulture, "Multiple applicable registrations found for {0}. The applicable registrations are {1}. " + "If your goal is to make one registration a fallback in case another registration is not " + "applicable, make the fallback registration last using RegisterConditional and make sure " + "the supplied predicate returns false in case the Handled property is true.", serviceType.ToFriendlyName(), overlappingRegistrations.Select(BuildRegistrationName).ToCommaSeparatedText());
private static Tuple<double, double>[] TransformValues(Tuple<double, double>[] orig, double fromDist, double toDist, double fromPerc, double toPerc, bool isUpGraph) { double percentMinRange = 0; double percentMaxRange = 1; if (!isUpGraph) { // The slope is going down, so reverse the min/max percentMinRange = 1; percentMaxRange = 0; } return orig.Select(o => Tuple.Create( UtilityCore.GetScaledValue(fromDist, toDist, 0, 1, o.Item1), UtilityCore.GetScaledValue(fromPerc, toPerc, percentMinRange, percentMaxRange, o.Item2) )).ToArray(); }
private static Tuple<double, double>[] ReverseY(Tuple<double, double>[] orig) { return orig. Select(o => Tuple.Create(o.Item1, 1d - o.Item2)). ToArray(); }
private static void testCluter() { int ss = 100, sq = 100, k = 10, m = 10; // 采样数,G取前k,S取前m int randcount = 5, randtake = 10, randselect = 3; var timer = new MyTimer(); var templatefiles = Directory.GetFiles(@"D:\Play Data\字符模板"); int templatecount = templatefiles.Length; var templateChars = new string[templatecount]; var templatePoints = new Vector2[templatecount][]; //var templatesc = new double[templatecount][,]; var templatesc = new double[templatecount][][]; #region 计算模板的SC for (int f = 0; f < templatecount; ++f) { string file = templatefiles[f], filename = Path.GetFileNameWithoutExtension(file); using (Image<Gray, Byte> img = new Image<Gray, byte>(file)) { var samples = getEdge(img).Sample(ss); templatesc[f] = Jim.OCR.ShapeContext2D.ShapeContext.ComputeSC2(samples); templatePoints[f] = samples.Select(p => new Vector2(p.X, p.Y)).ToArray(); } templateChars[f] = filename; Console.Write(filename); } Console.WriteLine(); Debug("模板读取完成"); #endregion #region 处理字符 foreach (string file in Directory.GetFiles(@"D:\Play Data\字符")) { string filename = Path.GetFileNameWithoutExtension(file); if (filename != "AB") continue; timer.Restart(); Image<Bgr, Byte> img = new Image<Bgr, Byte>(file); var samples = getEdge(img.Convert<Gray, Byte>()).Sample(sq); //double[,] SCQ = Jim.OCR.ShapeContext2D.ShapeContext.ComputeSC(samples); double[][] SCQ = Jim.OCR.ShapeContext2D.ShapeContext.ComputeSC2(samples); var Q_Points = samples.Select(p => new Vector2(p.X, p.Y)).ToArray(); var mmg = img.Convert<Bgr, Byte>(); Graphics g = Graphics.FromImage(mmg.Bitmap); Q_Points.ToList().ForEach(v => { mmg[(int)v.Y, (int)v.X] = new Bgr(0, 0, 255); }); var point_distance = new ValueIndexPair<double>[sq][]; #region 计算采样点之间的距离 for (int i = 0; i < sq; ++i) { double xi = Q_Points[i].X, yi = Q_Points[i].Y; point_distance[i] = new ValueIndexPair<double>[sq]; for (int j = 0; j < sq; ++j) { double xj = Q_Points[j].X, yj = Q_Points[j].Y; point_distance[i][j] = new ValueIndexPair<double> { Value = Math.Sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj)), Index = j }; } Array.Sort(point_distance[i], (a, b) => a.Value.CompareTo(b.Value)); } #endregion var randpoints = new int[randcount][]; #region 随机取randcount个点,并在其周围randtake个点中取randselect个 for (int i = 0; i < randcount; ++i) { int pi = rand.Next(Q_Points.Length); var p = Q_Points[pi]; mmg.Draw(new CircleF(new PointF((float)p.X, (float)p.Y), 2), new Bgr(255, 0, 0), 1); randpoints[i] = new int[randselect]; bool[] vi = Utils.InitArray<bool>(randtake, false); for (int cnt = 0; cnt < randselect; ) { int rnd = rand.Next(randtake); if (!vi[rnd]) { vi[rnd] = true; randpoints[i][cnt++] = rnd; } } for (int ppp = 0; ppp < randselect; ++ppp) { var pt = Q_Points[point_distance[pi][randpoints[i][ppp]].Index]; //g.DrawString(i.ToString(), new Font("Arial", 7), new SolidBrush(Color.FromArgb(0, 128, 0)), new PointF((float)pt.X, (float)pt.Y)); } } #endregion #region 为这randcount组RSC分别选最好的模板 var rscmatch = new Tuple<int, double, Vector2>[randcount]; // <Si, d, L> for (int rc = 0; rc < randcount; ++rc) { var rsc_matches = new Tuple<double, Vector2>[templatecount]; // <d, L> for (int i = 0; i < templatecount; ++i) { #region 拷贝出一个rsc来 var rsc = new double[randselect][]; for (int j = 0; j < randselect; ++j) { rsc[j] = new double[60]; Array.Copy(SCQ[randpoints[rc][j]], rsc[j], 60); } #endregion var costmat = Jim.OCR.ShapeContext2D.ShapeContext.HistCost2(rsc, templatesc[i]); var matches = costmat.Select( row => row.Select((d, c) => new ValueIndexPair<double> { Value = d, Index = c }) .OrderBy(d => d.Value).First()).ToArray(); Vector2 L = Vector2.Zero; double M = 0; for (int j = 0; j < randselect; ++j) { int u = randpoints[rc][j], mu = matches[j].Index; double d = matches[j].Value; Vector2 pu = Q_Points[u], pmu = templatePoints[i][mu]; M += (1 - d); L += (1 - d) * (pu - pmu); } L /= M; rsc_matches[i] = new Tuple<double, Vector2> { First = matches.Sum(r => r.Value), Second = L }; } var best_template = rsc_matches.Select((mt, i) => new { Match = mt, i }) .OrderBy(t => t.Match.First) .First(); rscmatch[rc] = new Tuple<int, double, Vector2> { First = best_template.i, Second = best_template.Match.First, Third = best_template.Match.Second }; string label = templateChars[best_template.i]; g.DrawString(label, new Font("Arial", 48), Brushes.Green, new PointF((float)best_template.Match.Second.X, (float)best_template.Match.Second.Y)); } #endregion //Font f = new Font("Arial", 12); //var G = new Tuple<int, int, double>[templatecount][]; // <u, m(u), d> //#region 为每个Si挑选合适的Gi //{ // var costmats = new double[templatecount][,]; // for (int i = 0; i < templatecount; ++i) { // double[,] SCi = templatesc[i]; // costmats[i] = Jim.OCR.ShapeContext2D.ShapeContext.HistCost(SCQ, SCi); // G[i] = new Tuple<int, int, double>[sq * ss]; // for (int u = 0; u < sq; ++u) { // for (int j = 0; j < ss; ++j) { // G[i][u * ss + j] = new Tuple<int, int, double> { // First = u, // Second = j, // Third = costmats[i][u, j] // }; // } // } // Array.Sort(G[i], (da, db) => da.Third.CompareTo(db.Third)); // } //} //#endregion //var d_Q_S = new double[templatecount]; //#region 求出每个Si和Q的d(Q, Si) //{ // for (int i = 0; i < templatecount; ++i) { // var Gi = G[i].Take(k); // foreach (var g in Gi) { // int u = g.First, mu = g.Second; // double d = g.Third; // double Nu = G.Average(gi => gi.First(t => t.First == u).Third); // d_Q_S[i] += d / Nu; // } // d_Q_S[i] /= k; // } //} //#endregion //var firstmG = new Tuple<Tuple<int, int, double>[], double, int>[m]; // <G, d, i> <=> <<u, m(u), d>[], d, i> //#region 根据d(Q, Si)截取前20个最好的Gi //{ // var firstmdQS = d_Q_S.Select((d, i) => new ValueIndexPair<double> { Value = d, Index = i }) // .OrderBy(p => p.Value) // .Take(firstmG.Length).ToArray(); // for (int p = 0; p < firstmG.Length; ++p) { // double d = firstmdQS[p].Value; // int i = firstmdQS[p].Index; // firstmG[p] = new Tuple<Tuple<int, int, double>[], double, int> { // First = G[i].Take(k).ToArray(), // Second = d, // Third = i // }; // } //} //#endregion //#region 计算每个G的位置 //var L = new Vector2[m]; //{ // for (int i = 0; i < m; ++i) { // L[i] = Vector2.Zero; // double Mi = 0; // var Gi = firstmG[i]; // foreach (var u_mu_d in Gi.First) { // int u = u_mu_d.First, mu = u_mu_d.Second; // double d = u_mu_d.Third; // Vector2 pu = Q_Points[u], pmu = templatePoints[Gi.Third][mu]; // L[i] += (1 - d) * (pu - pmu); // Mi += (1 - d); // } // L[i] /= Mi; // g.DrawString(templateChars[Gi.Third], new Font("Arial", 12), Brushes.Green, // new PointF((float)L[i].X, (float)L[i].Y)); // } //} //#endregion mmg.Save(Path.Combine(@"D:\Play Data\测试玩意", filename + ".bmp")); Debug("{0}\t用时{1}ms.", filename, timer.Stop()); } #endregion }
private static double GetOffset(Tuple<double[], double>[] stripped, List<double> tmp) { //these should all be the same, but they ain't dammit. Am I misunderstanding things, or are doubles this crappy in this situation? var foo = stripped.Select(s => 1 / s.Item2 - Dot(tmp.ToArray(), s.Item1)).ToArray(); return foo.Average(); //.First(); }