internal bool Propose(out IterationState iterationState) { RequireFalse(IsComplete); if (_currentIteration.IsntFound()) { for (_currentIteration = 0; _currentIteration < _iterations; ++_currentIteration) { if (IsNaN(_errorData.Rows[_currentIteration].Field <double>(0))) { break; } } } RequireFalse(IsComplete); if (_currentIteration == 0) { ProposeInitial(out iterationState); } else { ResumeIteration(out iterationState); } return(true); }
public void PartitionBooleanGrouping() { var(evens, odds) = Enumerable.Range(0, 10) .GroupBy(x => x % 2 == 0) .Partition((t, f) => Tuple.Create(t, f)); Assert.That(evens, Is.EquivalentTo(new[] { 0, 2, 4, 6, 8 })); Assert.That(odds, Is.EquivalentTo(new[] { 1, 3, 5, 7, 9 })); }
public void PartitionNullableBooleanGrouping() { var xs = new int?[] { 1, 2, 3, null, 5, 6, 7, null, 9, 10 }; var(lt5, gte5, nils) = xs.GroupBy(x => x != null ? x < 5 : (bool?)null) .Partition((t, f, n) => Tuple.Create(t, f, n)); Assert.That(lt5, Is.EquivalentTo(new[] { 1, 2, 3 })); Assert.That(gte5, Is.EquivalentTo(new[] { 5, 6, 7, 9, 10 })); Assert.That(nils, Is.EquivalentTo(new int?[] { null, null })); }
internal bool Propose( NumDataColumn independentData, Arr <NumDataColumn> outputData, out IterationState iterationState ) { RequireTrue(_currentIteration >= 0); RequireTrue(_currentIteration == 0 || !IsNaN(_currentLogLikelihood)); RequireFalse(IsComplete); double proposedLogLikelihood; try { proposedLogLikelihood = GetProposalLogLikelihood( independentData, outputData ); } catch (Exception ex) { FaultChain(ex); iterationState = default; return(false); } ProcessCurrentProposal(proposedLogLikelihood); // M-H + bookkeeping (parameters) var currentChainDataRow = _chainData.Rows[_currentIteration]; var indexNextModelParameter = _currentIteration == 0 ? NOT_FOUND : _modelParameters.FindIndex( mp => IsNaN(currentChainDataRow.Field <double>(ToAcceptColumnName(mp.Name))) ); var isIterationComplete = indexNextModelParameter.IsntFound(); if (isIterationComplete) { StorePosterior(); // model outputs collected } var isLastIteration = (_currentIteration + 1) == _iterations; if (isIterationComplete && isLastIteration) { ++_currentIteration; var currentValues = _modelParameters .Select(mp => (mp.Name, Value: currentChainDataRow.Field <double>(mp.Name))) .ToArr(); iterationState = (_currentIteration, currentValues, default); return(false); } if (isIterationComplete) { UpdateModelOutputs(); // M-H + bookkeeping (error models) var doAdjustForAcceptRate = !IsNaN(_targetAcceptRate) && _currentIteration > _burnIn && _currentIteration % ACCEPT_RATE_ADJUST_INTERVAL == 0; if (doAdjustForAcceptRate) { AdjustForAcceptRate(); } // done - advance and initialize next iteration using current ++_currentIteration; indexNextModelParameter = 0; var nextChainDataRow = _chainData.Rows[_currentIteration]; _modelParameters.Iter( mp => nextChainDataRow[mp.Name] = currentChainDataRow[mp.Name] ); _modelParameters.Iter( mp => nextChainDataRow[ToLLColumnName(mp.Name)] = currentChainDataRow[ToLLColumnName(mp.Name)] ); currentChainDataRow = nextChainDataRow; } _currentProposal = _modelParameters[indexNextModelParameter].GetProposal(); var proposedValues = _modelParameters .Select(mp => ( mp.Name, Value: mp.Name == _currentProposal.Name ? _currentProposal.Value : currentChainDataRow.Field <double>(mp.Name) ) ) .ToArr(); if (isIterationComplete) // meaning was completed... { // ...so include update for client var currentValues = _modelParameters .Select(mp => (mp.Name, Value: currentChainDataRow.Field <double>(mp.Name))) .ToArr(); iterationState = (_currentIteration, currentValues, proposedValues); return(true); } iterationState = (_currentIteration, default, proposedValues);
ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9>( this Tuple <T1, T2, T3, T4, T5, T6, T7, Tuple <T8, T9> > value) { return(CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7, ValueTuple.Create(value.Rest.Item1, value.Rest.Item2))); }
ToValueTuple <T1, T2, T3, T4, T5, T6, T7>( this Tuple <T1, T2, T3, T4, T5, T6, T7> value) { return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7)); }
ToTuple <T1, T2, T3, T4, T5, T6>( this ValueTuple <T1, T2, T3, T4, T5, T6> value) { return(Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6)); }
public static Func <T1, T2, Unit> ToFunc <T1, T2>(this Action <T1, T2> action) => (T1 t1, T2 t2) => { action(t1, t2); return(Unit.Create()); };
public static Unit ForEach <T>(this List <T> @this, Action <T> action) { @this.Map(action.ToFunc()); return(Unit.Create()); }
ToValueTuple <T1>( this Tuple <T1> value) { return(ValueTuple.Create(value.Item1)); }
/// <summary>Returns a value that indicates whether the current <see cref="T:System.ValueTuple`4" /> instance is equal to a specified <see cref="T:System.ValueTuple`4" /> instance.</summary> /// <param name="other">The value tuple to compare with this instance.</param> /// <returns> /// <see langword="true" /> if the current instance is equal to the specified tuple; otherwise, <see langword="false" />.</returns> // Token: 0x06000429 RID: 1065 RVA: 0x0000B230 File Offset: 0x00009430 public bool Equals(ValueTuple <T1, T2, T3, T4> other) { return(EqualityComparer <T1> .Default.Equals(this.Item1, other.Item1) && EqualityComparer <T2> .Default.Equals(this.Item2, other.Item2) && EqualityComparer <T3> .Default.Equals(this.Item3, other.Item3) && EqualityComparer <T4> .Default.Equals(this.Item4, other.Item4)); }
// Token: 0x06000430 RID: 1072 RVA: 0x0000B544 File Offset: 0x00009744 private int GetHashCodeCore(IEqualityComparer comparer) { return(ValueTuple.CombineHashCodes(comparer.GetHashCode(this.Item1), comparer.GetHashCode(this.Item2), comparer.GetHashCode(this.Item3), comparer.GetHashCode(this.Item4))); }
/// <summary>Calculates the hash code for the current <see cref="T:System.ValueTuple`4" /> instance.</summary> /// <returns>The hash code for the current <see cref="T:System.ValueTuple`4" /> instance. </returns> // Token: 0x0600042E RID: 1070 RVA: 0x0000B4E8 File Offset: 0x000096E8 public override int GetHashCode() { return(ValueTuple.CombineHashCodes(EqualityComparer <T1> .Default.GetHashCode(this.Item1), EqualityComparer <T2> .Default.GetHashCode(this.Item2), EqualityComparer <T3> .Default.GetHashCode(this.Item3), EqualityComparer <T4> .Default.GetHashCode(this.Item4))); }
public bool Equals(ValueTuple <T1, T2, T3> obj) { return(_t1Comparer.Equals(Item1, obj.Item1) && _t2Comparer.Equals(Item2, obj.Item2) && _t3Comparer.Equals(Item3, obj.Item3)); }
ToTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>( this ValueTuple <T1, T2, T3, T4, T5, T6, T7, ValueTuple <T8, T9, T10, T11, T12, T13, T14> > value) { return(CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7, Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7))); }
ToValueTuple <T1, T2>( this Tuple <T1, T2> value) { return(ValueTuple.Create(value.Item1, value.Item2)); }
ToValueTuple <T1, T2, T3>( this Tuple <T1, T2, T3> value) { return(ValueTuple.Create(value.Item1, value.Item2, value.Item3)); }
public static Func <T, Unit> ToFunc <T>(this Action <T> action) => t => { action(t); return(Unit.Create()); };
ToValueTuple <T1, T2, T3, T4, T5>( this Tuple <T1, T2, T3, T4, T5> value) { return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5)); }
public static Func <Unit> ToFunc(this Action action) => () => { action(); return(Unit.Create()); };
ToTuple <T1, T2, T3, T4>( this ValueTuple <T1, T2, T3, T4> value) { return(Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4)); }