Граф коммитов

197 Коммитов

Автор SHA1 Сообщение Дата
Ivan Korostelev a1cbadd391
Simplify TryComputePoint() (#229)
Automaton is pointmass if it has only 1 support string.

This implementation is also faster than previous one.
2020-04-14 12:09:38 +01:00
msdmkats 520f5d2767
Special functions testing improvements, NormalCdfLn bugfix. (#233)
- Moved arguments and expected result values for special function tests from inlined code to csv files.
- Added a python script to compute expected result values for tested special functions in high precision.
- Improved accuracy of NormalCdfLn for `x < -8`. Truncated series was too short, test used to pass, because the expected value itself was incorrect.
2020-04-08 18:13:08 +03:00
Tom Minka 911c2d1444
CSharpWriter uses G17 to write doubles and G9 to write singles, for correct round-trip behavior (#235) 2020-04-08 10:44:34 +01:00
Andrey Kurdyumov 27200bd649
Update to .NET Core 3.1 (#232)
* Update to .NET Core 3.1

This update was faily trivial change of project properties with only one caveat
```
error CS0104: 'Range' is an ambiguous reference between 'Microsoft.ML.Probabilistic.Models.Range' and 'System.Range'
```

which require sprinkling everywhere following line of code
```
using Range = Microsoft.ML.Probabilistic.Models.Range;
```

* Update build definition to use more modern images
- Windows 2019 for .NET Core 3.1
- Mac OS 10.14 (Specifically https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops)

Co-authored-by: Tom Minka <8955276+tminka@users.noreply.github.com>
2020-04-07 20:30:04 +01:00
Tom Minka 46bdd9dc49
More accurate messages for IsBetween, IsPositive, Plus, Max (#230)
* Use g17 when printing doubles
* Re-enabled GammaUpperRegularized tests
* MMath.LargestDoubleSum fix for 32-bit
2020-04-02 19:02:51 +01:00
Jonathan Tims 57f5a6c7b3
Merge branch 'master' into jotims/pr/fix-prefix-build 2020-03-19 10:32:31 +00:00
Jonathan Tims 205d26f4a1 wip 2020-03-18 23:13:59 +00:00
Tom Minka 9b2cbe9619
Improved TruncatedGamma support (#222)
Improved accuracy of TruncatedGamma.GetMeanAndVariance, GetMeanPower, GetNormalizer, Sample
Improved accuracy of Factor.TruncatedGammaFromShapeAndRate
GammaFromShapeAndRateOp_Slow.SampleAverageConditional handles sample=0
GammaFromShapeAndRateOp_Slow.RateAverageConditional handles rate=0
Improved accuracy of MMath.ExpMinus1, Gamma, GammaUpper
Gamma.SetShapeAndScale throws if shape is infinite
Added TruncatedGamma.GetMode
Added MMath.ToStringExact, GammaUpperScale
Changed uses of :r to :g17 numeric format string
MMath.IndexOfMinimum takes IEnumerable
PowerOp supports GammaPower = TruncatedGamma ^ y
2020-03-13 00:28:01 +00:00
Ivan Korostelev 085a5a4675
Remove Owner field from State (#220)
It really is not required - at all points it is known with which automaton we operate right now.

Also, where only state index was needed we store now the int index instead of fat State object
which contains extra information.
2020-03-11 16:28:08 +00:00
Ivan Korostelev 0c2f2859f5
Improve support enumeration in StringAutomata (#218)
Contracts has been changed: `TryEnumerateSupport()` does not throw if it encounters non-enumerable automata.

- Implementation of `TryEnumerateSupport` was changed a lot:
  - It avoids recursion (and "stacked IEnumerables")
  - An optimization has been added - traversing states with single point-mass forward transition
    (90+% of real-world cases) is cheaper, because it avoids some extra allocations

Also "is enumerable" status is cached. It is set proactively at automaton construction
in 2 common cases which are cheap to detect:
  - automaton with self-loops can not be enumerated
  - automaton with only forward transitions (and thus no loops) can always be enumerated

In all other cases this flag is calculated lazily on first enumeration try.
2020-03-03 20:46:05 +00:00
Ivan Korostelev 7bd784335d
Replace ReadOnlyArray with ImmutableArray look-alike (#217)
`System.Collections.Immutable` has `ImmutableArray` that serves the same purpose as
`ReadOnlyArray` but has different API. This type is available (without extra dependencies)
only in netcore, so can't be used in Infer.NET which has to support netframework.
Until netframework support can be dropped reimplement a subset of `ImmutableArray`
in Infer.NET codebase.
2020-02-29 09:49:41 +00:00
msdmkats 5cd2718883
Special functions use auto-generated truncated series (#207)
* Python tool to generate expressions for truncated series.
* Using the generated series in special functions
* Test projects set Optimize=true in Release configuration

Co-authored-by: Tom Minka <8955276+tminka@users.noreply.github.com>
2020-02-07 12:57:20 +00:00
John Guiver 053bac1751
Log probability override in DiscreteChar (#206)
Log probability override for Discrete char
2020-01-13 14:27:31 +00:00
Tom Minka 75ae71f2b5
DependencyAnalysisTransform fix (#211)
Fixed an issue where DependencyAnalysisTransform would give incorrect SkipIfUniform dependencies, causing statements to be incorrectly pruned from the generated code.
Removed FactorManager.AnyItem. Added FactorManager.All.
GaussianProductOp.AAverageConditional handles uniform B.
MMath.ChooseLn handles more cases.
2020-01-07 20:22:52 +00:00
Ivan Korostelev 54eea9b343
Make CheckStateCount() behave as expected (#210) 2020-01-07 18:23:12 +00:00
msdmkats 482f807bab
Power series abstraction (#201)
- Introduced an abstraction for truncated power series
- Introduced an abstraction for power series
- Made [Di|Tri|Tetra]Gamma[Ln] use it
- Added internal interface to recompute power series used in MMath and make them longer/shorter depending on the necessary precision. It can be used in tests.

Currently, power series computation is rather primitive (cut-off some precomputed series at a point where it used to be cut as long as the precision in <= 53, don't cut-off otherwise).
2019-12-17 17:13:31 +03:00
Jonathan Tims daa1058627 Use license and icon rather than licenseUrl and iconUrl which are now deprecated. (#200)
o Marked each non-packing assembly as "IsPackage=false" because the default is to package the assemblies. Done this via a common.props import.
o Switched to using integrated CSProj NuGet properties. Done this via a nuget-properties.props import.
o Switched to using msbuild in release.yml rather than nuget, since nuget.exe does not support the new spec.
o Added a LearnersNuGet project to be the "csproj" host for the learners nuspec (since the learners nuget does not correspond to any particular existing csproj project).
o Updated ClickThroughModel.csproj and ClinicalTrial.csproj and Image_Classifier.cs and MontyHall.csproj to new-style csprojs because otherwise new msbuild commands reject them.
o Made release.yml msbuild calls multiprocess to speed them up.
o Factored out some common properties into the common.props file.
2019-12-04 14:39:03 +00:00
Tom Minka 57c888024c
Improved GammaPower implementation (#195)
GammaPower creates a point mass whenever Rate would be infinite.
Added GammaPower.FromMeanAndMeanLog.
Improved numerical accuracy of GammaPower.GetLogProb, GetMean, and GetMode.
Added GammaPowerEstimator
GammaProductOp supports GammaPower distributions.
GammaProductOp handles uniform message from product.
Added GammaPowerProductOp_Laplace
Fixed PowerOp for GammaPower distributions.
Added PlusGammaOp for GammaPower distributions.
MMath.GammaUpper has an unregularized option.
Added TruncatedGamma.GetMeanPower.
PowerOp supports TruncatedGamma.
Swapped the argument order of (internal) MMath.LargestDoubleProduct and LargestDoubleRatio.
2019-11-13 14:31:12 +00:00
Ivan Korostelev d6e7d5b975
Make MaxStateCount overrides thread local (#194)
UnlimitedStatesComputation() is used temporary to alter maximal size of automaton
which is defined my MaxStateCount. Using it from different threads could mess up the limit.
Now each threads gets its own limit.

Also, the default MaxStateCount limit is increased to 300k, because that is what the biggest String inference customer uses.
2019-11-07 16:44:54 +00:00
Ivan Korostelev fe41d89eba
Fix DiscreteChar.Complement() & Simplify ranges operations (#192)
After recent refactoring that removed `ProbabilityOutsideRanges`, `DiscreteChar.Complement()` 
started to work incorrectly in case ranges were going one after another.

For example DiscreteChar.Point('\0').Complement() was equal to uniform distribution, i.e. still included the \0 char.
2019-11-05 14:42:28 +00:00
Ivan Korostelev 1f54bc32f7
Precise sums in automaton determinization (#189)
Automaton determinization procedure used to keep a running total of weights for each state.
That sum was maintained by adding weights for next open segment and substracting weights
for closed segments. If the weights of segments differ a lot (LogValue difference is bigger than 100)
than due to numerical issues sum could become zero after subtraction which lead to dropping
of transition and automaton language truncation.

Now the weights sum is recalculated from scratch each time. It also results in loss of precision,
but it is important that the precision is lost only for very large weights, not very small ones. So
no accidental zeroing of weights is happening and language is not truncated.

It doesn't really impact runtime because `WeightedStateSet` construction enumerated all weights
anyway (to normalize them), so in the worst case slowdown is at most constant.
And in average case (where we maintain  1 or 2 destination states per transition) the runtime
is actually better due to lower constant costs.

New test (`AutomatonTests.Determinize11`) was added, it used to fail with previous implementation.

To make this change I had to rewrite code substantially which in my opinion makes it easier to follow:
- The determinization procedure now makes use of `CharSegmentsEnumerator` helper class
  which enumerates over all char segments from multiple char distributions. These segments are
  non-overlapping.
- `WeightedStateSetBuilder` now handles duplicate state indices in `Add()` call. Previously deduplication
  had to happen via accumulating sum in `Dictionary<int, WeightSum>`
2019-10-29 18:18:50 +00:00
Tom Minka f44d7f3a26
Gaussian.GetMean throws if Precision == 0, instead of returning 0. (#183)
ExpOp.ExpAverageConditional correctly handles improper d.
InnerQuantiles/OuterQuantiles check for an empty quantiles array.
2019-10-03 19:47:01 +01:00
Tom Minka 625228bc40 Gaussian.GetLogProb is more accurate for large precision.
DoubleIsBetweenOp fix.
MMath.LargestDoubleSum works in 32-bit.
2019-09-21 20:02:10 +01:00
Tom Minka cfc8128143 MMath.LargestDoubleProduct is more efficient 2019-09-21 20:02:10 +01:00
Tom Minka e642655221
Merge branch 'master' into InnerProduct 2019-09-21 14:25:03 +01:00
Tom Minka a11a745a84
Merge branch 'master' into ivkorost/remove-try-determinize-assert 2019-09-18 15:49:07 +01:00
Ivan Korostelev cfe60e308a Remove wrong Debug.Assert()
String automaton determinization supports infinite weights.
2019-09-18 11:17:15 +01:00
Ivan Korostelev c4c36c1f4b Replace custom enums for caches with bool? type.
Also, fix assert in Automaton.DataContainer.With()
2019-09-18 10:35:32 +01:00
Ivan Korostelev 1893477580 Fix comments 2019-09-17 14:02:06 +01:00
Ivan Korostelev 2d5ce49ea3 Add a test with large automaton 2019-09-17 13:58:23 +01:00
Ivan Korostelev 5fdb6c0779 Use explicit stack in Automaton.IsZero() & cache call result 2019-09-17 13:54:55 +01:00
Tom Minka 2c6a925066 Gaussian constructor reduces precision to avoid overflow, instead of creating a point mass.
Fixed corner cases in MMath.LargestDoubleProduct and NormalCdfIntegral.
Improved accuracy of DoubleIsBetweenOp.
Loosened the tolerance of GaussianIsBetweenCRCC_IsMonotonicInXMean and GaussianIsBetweenCRCC_IsMonotonicInXPrecision, to be fixed later.
2019-08-30 17:36:29 +01:00
Tom Minka 4ecd6d19fc GaussianOp.PrecisionAverageConditional_Point correctly handles corner cases 2019-08-30 17:36:29 +01:00
Tom Minka a280a6272f Added GatedInnerProductVectorTest and missing overloads of InnerProductOp 2019-08-23 16:03:05 +01:00
Tom Minka 98e07ae335 AutomatonTests.Determinize10 is OpenBug 2019-08-22 18:09:39 +01:00
Tom Minka 9e7dfcf7f2 InnerProduct supports fixed output when B vector has zero or one nonzero element.
ExpOp_Slow handles GammaPower messages.
GammaPower implements division by constant.
2019-08-22 14:53:06 +01:00
Tom Minka 397642ff2a Improved numerical accuracy of GaussianOp, DoubleIsBetweenOp, and MMath.NormalCdf2.
Fixed cases where MMath.NormalCdf, DoubleIsBetweenOp, IsPositiveOp, DoublePlusOp would throw.
JaggedSubarrayOp uses ForceProper.
PlusDoubleOp gracefully handles improper distributions on input.
Added MMath.NormalCdfIntegral, NormalCdfDiff, NormalCdfExtended.
Added ExtendedDouble class.
MeanVarianceAccumulator correctly handles weight=0.
Region.GetLogVolume has a lower bound.
Variables with PointEstimate do not use JaggedSubarrayWithMarginal.
2019-06-25 23:23:09 +01:00
Tom Minka 63fe682bed OuterQuantiles and InnerQuantiles can be serialized and compared.
Their second constructor is now a factory method.
2019-06-13 22:35:24 +01:00
Tom Minka b7ab86af1b InnerQuantiles and OuterQuantiles throw on infinite quantiles. InnerQuantiles.GetLogProb and GetQuantile are non-decreasing. 2019-06-07 20:36:09 +01:00
Ivan Korostelev 70ae46cd79
Fix DiscreteChar.Sample() (#153)
Due to refactoring mistake `sampleProb / prob * intervalLength`
turned into `sampleProb / (prob * intervalLength)` which is obviosly incorrect.

Fixed that + added a rudimentary test for `DiscreteChar.Sample()`
2019-05-28 15:52:38 +01:00
Elena Pochernina 97c8995e4f Added test for StringFormatOp parallel run (#147)
Made `ArgumentCountToNames` cache thread-safety.
After that another exception appeared with `ArgsToValidatingAutomaton` dictionary (reference null exception). Making the dictionary concurrent fixed this error.
2019-04-24 11:20:23 +01:00
Ivan Korostelev e486a155b9
Automaton determinization improvements (#144)
* Determinization doesn't change language of the automaton anymore.
  2 new tests were added which check that it doesn't happen.
  Previously all very low probability transitions (with probability of less than e^-35) were removed.
  That was done because of 2 reasons:
  - some probabilities were represented in linear space. And e^-35 is as low resolution
    as you can get with regular doubles. (That is, if one probability = 1 and another is e^-35,
    then when you add them together, second one is indistinguishable from zero).
    This was fixed when discrete charprobabilities
  - Trying to determinize some non-determinizable automata lead to explosion of low-probability
    states and transitions which led to a very poor performance.
    (E.g. `AutomatonNormalizationPerformance3` test). Now a smarter strategy for detecting
    these non-determinizable automata is used - during traversal all sets of states from root
    are remembered. If automaton comes to the same set of states but with different weights
    than it stops immediately, because otherwise it will be caught in infinite loop
* `Equals()` and `GetHashCode()` for `WeightedStateSet` take into account only high 32 bits of weight.
  This coupled with normalization of weights allows to reuse already added states with
  very close weights. This speeds up the "PropertyInferencePerformanceTest" 2.5x due to
  smaller intermediate automata.
* Weighted sets of size one are handled specially in `TryDeterminize` - they don't need to be
  determinized and can be copied into result almost as is. (Unless they have non-deterministic
  transitions. Simple heuristic of "has different destination states" is used to detect that
  and fallback to slow general path).
* Representation for `WeightedStateSet` is changed from (int -> float) dictionary to
  sorted array of (int, float) pairs. As an optimization, a common case of single-element
  set does not allocate any arrays.
* Determinization code for `ListAutomaton` was removed, because it has never worked
2019-04-23 15:30:16 +01:00
Ivan Korostelev faf55fffb9
Do not fail in MergeParallelTransitions when transition weights are high (#149)
Transition weights may become infinite when going from log space into value space. And
`SetToSum()` which is used by `MergerParallelTransitions` can't handle 2 inifnite weights at once.
To solve this, transitions weights are normalized by max weight prior to passing into `SetToSum()`
2019-04-20 00:10:13 +01:00
Tom Minka 8398c1d4f7
ModelCompiler.TraceAllMessages activates Tracing.Trace for all variables (#145)
Tracing.Trace uses System.Diagnostics.Trace.
Added DifficultyAbility.fs to TestFSharp.
2019-04-01 22:52:22 +01:00
Ivan Korostelev 9ab76c6b7c
Change transitions range representation in Automaton.StateData (#140)
* Pair (FirstTranstiionIndex, LastTransitionIndex) changed to pair
  (FirstTransitionIndex, TransitionsCount).
* Introduced Automaton.Builder.LinkedStateData struct which
  mirrors Automaton.StateData but represents transitions as linked list.
  Previously Automaton.StateData was reused for this purpose.
  That was confusing.
2019-03-26 19:20:27 +00:00
Ivan Korostelev 036f9bfd71
Store log probabilities inside DiscreteChar (#137)
In some edge cases StringAutomaton needs to represent extremely
low probabilities of character transitions. To be able to do that,
instead of storing probabilities as double values they are stored
as `Weight` structs already used by automatons. Weight stores logarithm
of value instead of value itself.
2019-03-21 13:49:06 +00:00
Tom Minka c0a5734c98
Gamma.GetQuantile supports Shape != 1. (#131)
GammaPower implements GetProbLessThan and GetQuantile.
GammaPower.GetMeanPower does not throw on infinity.
2019-03-15 10:52:39 +00:00
Ivan Korostelev a2a3498f6f
Cache TryDeterminize() call results & add proper support for enum constant to Compiler (#127)
TryDeterminized() tried to do something even if it is known that automaton is already determinized
or non-determinizable.

Because automaton state is immutable, it is possible to store determinization state alongside with it.
There are 3 states:
* Unknown - TryDeterminize() was never called for this automaton
* IsDeterminized - TryDeterminized() successfully determinized automaton
* IsNonDeterminizable - TryDeterminize() was called but didn't succeed.

Because determinization state depends on maximum number of states,
`TryDeterminize(int maxStatesCount)` method was removed in favour of using defaults.
Because this overload was never used in practice.

Also, as an implementation detail an enum type was exposed as part of automaton quoting interface.
Compiler generated incorrect C# code for quoting enum constants. Fixed that.
2019-03-13 01:00:16 +00:00
Ivan Korostelev dc0b30487e
Add operator overloads to Weight class (#121) 2019-03-12 13:18:33 +00:00
Ivan Korostelev 6d2ce9a993
Get rid of recursive implementations (#125)
We finally reached a point where automatons are big enough that recursive implementations
of algorithms fail with `StackOverflowException`.

There are 4 tests which test operations with big automatons (100k states):
* `TryComputePointLargeAutomaton`
* `SetToProductLargeAutomaton`
* `GetLogNormalizerLargeAutomaton`
* `ProjectSourceLargeAutomaton`

All four used to fail before code was rewritten to use explicit stack instead of recursive calls.
All changes except one didn't change algorithms used, code was almost mechanically changed
to use stack.

The only exception - automaton simplification. Old code used recursion in very non-trivial way.
It was rewritten from scratch, using different algorithm: instead of extraction of generalized
sequences and then reinserting them back new code merges states directly in automaton.
(There's a comment at the beginning of Simplify() method explaining all operations)
2019-03-11 11:33:29 +00:00
Tom Minka 702874f9aa
ComputeMovieGenre allows any number of genres (#124) 2019-03-09 09:48:27 +00:00
Tom Minka 7ec8af439b
Removed msbuild instructions for mono (#120)
RegexpFormattingSettings ctor sets UseLazyQuantifier.
ProductExpOp fix.
General code cleanup.
2019-03-08 22:13:18 +00:00
Ivan Korostelev f55a968362 Turn Automaton.UsesGroups into property & optimize SetGroups() (#118)
* Turn UseGroups into a property, and calculate it at automaton construction time

* Do not clear groups if they are not used anyway
2019-03-08 09:23:26 +00:00
Tom Minka b5f62d3300 TryComputePointLargeAutomaton is OpenBug 2019-01-26 10:17:49 +00:00
Tom Minka 85107a3f88 VectorSoftmax_PointSoftmax_Throws allows any exception type. 2019-01-24 22:10:36 +00:00
Tom Minka f567d68bfa Added QuantileEstimator.Inflate 2019-01-24 22:10:36 +00:00
Ivan Korostelev 65e6981ee0
Convert Automaton.StateData to value type (#95)
To reduce memory pressure automaton data (states and transitions) was
converted from classess to structs and "vectorized" into just two large arrays.

Now, one state costs just 16 bytes and one transition costs 24 bytes.
Previously cost was at least twice of that, due to additional indirection,
object headers and pre-reservation of arrays capacity: 8 bytes pre reference
to state + 16 bytes per state header + 24 bytes per transitions array per state).
In practice memory consumption by automatons was reduced approximately
by the factor of 3.

Important changes:
  * `Automaton.StateData` is now a struct instead of class.
  * All transitions of automaton are stored in single array instead of
    "transition array per state"
  * Automatons can not be mutated. All immutable data was moved
    to new `DataContainer` struct.
  * New Automaton.Builder class was introduces for construction
    of new automatons from scratch. All mutation is done through
   "copy to builder, mutate, get immutable data" pattern.
  * Widely used `AppendInPlace()` method is not actually inplace anymore
    and became way more expensive. Multiple `AppendInPlace()` calls
    should be replaced with 1 `Automaton.Builder` instance with
    multiple `Builder.Append()` calls. Places which were hot in profiler were rewritten.
    `AppendInPlace()` will be removed completely in separate pull-request.

Technical changes:
  * `Optional<>` struct was moved into Containers namespace. Logically it is
     a container of "0-or-1" elements.
  * To enforce immutable data-structures new `ReadOnlyArray`, `ReadOnlyArraySegment`
    and `ReadOnlyArraySegment` enumerator structs were introduced. They wrap regular
    arrays but do not allow to mutate them. Unlike `ReadOnlyList<>` these are value types
    and do not introduce any memory-costs.
  * In quite a few places Tuples were replaced with ValueTuples.
  * Most recursive helper methods were "inlined" as local functions at their call-sites.
    Not strictly necessary, but mady refactoring a lot easier by bringing related code together.
  * Some code was reformated/updated to more modern style. Either by tooling or manually.
2019-01-23 09:57:54 +00:00
Tom Minka 04e329f63f
Softmax factor throws when output is observed under VMP. (#102)
* Softmax factor throws when output is observed under VMP.

* VectorSoftmaxOp_KM11.XAverageLogarithm allows softmax to be a point mass as long as some x[i] is a point mass.
Fixes #101
2019-01-21 19:54:49 +00:00
Tom Minka 305f5c9583 QuantileEstimator allocates buffers when needed 2019-01-18 20:01:45 +00:00
Tom Minka a741aed54c DenseVector.SetToLeastSquares avoids overflow. 2019-01-17 22:58:19 +00:00
Tom Minka 9f20867b92
Added IrregularQuantiles. (#93)
* Added IrregularQuantiles

* IrregularQuantiles throws ArgumentOutOfRangeException

* Added Region.Equals and CompareTo

* BlogTests.Handedness is a test

* BallCountingTest comment

* More documentation and testing
2018-12-12 18:18:20 +00:00
Tom Minka 13def19155
MixtureOfGaussians tutorial uses the recommended modern style for initializing a VariableArray. (#91) 2018-12-03 16:03:59 +00:00
Vijay 87250fd293
Merge branch 'master' into avishar/ROC-Curve 2018-11-23 01:08:47 +00:00
Vijay Sharma 13a5513088 - Renamed struct to FalseAndTruePositiveRate
- Reverted order of arguments to be false then true
2018-11-23 01:04:38 +00:00
Ivan Korostelev 2526d2d2e7
Support value type distributions in Automatons and make DiscreteChar a struct (#72)
Automatons didn't support value types for TElementDistribution because they used
null values as a sentinel for epsilon transitions. PairDistributions (and Transducers)
didn't support them because one element of pair can be null.

General idea of this PR: wrap distributions into a struct that can answer if it's value is null.
Like `Nullable<T>` but also suitable for reference types.

Changes done:
  1. `Utilities.Option<T>` is introduced. It behaves like `Nullable<T>` but can be constructed
     from (null) references. It has the same guarantee - if `HasValue` returns true then
     `Value` is guaranteed to return valid non-null result.
  2. `Argument.CheckIfNotNull` can have value type as a generic parameter. Obviosly
     for value types this function is a no-op. But it allows to write generic code that
     checks if argument is not null if it is a reference type, and does not check anything
     otherwise.
  3. `Utilities.Option<T>` is used everywhere in `Automaton` interfaces. But the
     `ElementDistribution` inside `Automaton.Transition` is stored as 2 fields:
     `hasElementDistribution` and `elementDistribution`. Due to careful structure
     layout (`hasElementDistribution` is packed with `group` field), this takes
     8 bytes less space then simple `Option<TElementDistribution>`.

All these changes are done with single purpose - to convert DiscreteChar from class
to struct. That saves 24 bytes per transition in StringAutomaton. That is a lot.

Benchmarking shows no performance penalty for introducing Optional<>.
JIT does a good job of optimizing it away.
2018-11-09 16:03:27 +00:00
Ivan Korostelev e900bfa7e6
Do not store Owner and Index properties in States (#69)
Owner and Index properties bring 2 issues:
1. They were taking 16 bytes (after aligning everything)
2. They complicate serialization due to cyclic references

Changes made:
1. State class is split in 2 parts: StateData and State. StateData is stored inside Automaton, State is created on demand and acts as a fat-reference to which allows to read/modify StateData that it references and carries around additional properties - Owner and Index.
2. Introduced StateCollection class which wraps List<StateData> and acts like ReadOnlyList<State> but does StateData to State conversion on demand

C# compiler and .NET runtime are good at optimizing away all StateData->State wrapping. No performance degradation was measured in my tests.

Binary serialization remains backward-compatible, but JSON/BinaryFormatter/DataContract ones are changed.
2018-11-05 14:38:15 +00:00
Tom Minka fcb8a8ec90
Added CausalityExample, Crowdsourcing, and CrowdsourcingWithWords examples from the user guide. (#67)
Added CausalityExample, Crowdsourcing, and CrowdsourcingWithWords examples from the user guide.
Modernized the BayesianPCA example.
Example projects that support .NET Core now build under DebugCore and ReleaseCore.
Removed spurious app.config files.
2018-11-03 16:13:33 +00:00
Vijay Sharma 247199a84e Added ReceiverOperatingCharacteristic struct 2018-10-31 23:07:45 +00:00
Vijay Sharma 0430e1113d Tests uses nameof in more places. 2018-10-30 21:12:37 +00:00
Vijay Sharma 9edce44cf4 Learners.LearnersTests uses nameof in more places. 2018-10-30 21:04:08 +00:00
Vijay Sharma 65944763a4 Added PrecisionRecall type for Metrics.PrecisionRecallCurve 2018-10-30 18:22:31 +00:00
Vijay Sharma 2e5a34b848 Renamed EmpiricalAndPredictedProbability to CalibrationPair 2018-10-30 14:25:02 +00:00
Vijay Sharma 18f2983069 Updated EmpiricalProbabilityCalibrationPoint to be named EmpiricalAndPredictedProbability. 2018-10-30 14:22:23 +00:00
Vijay Sharma 007eee5c78 - Added EmpiricalProbabilityCalibrationPoint struct to replace usage of Pair<double, double> in ClassifierEvaluator
- ClassifierEvaluatorTests uses XUnit.Assert for collection equivalency checks
2018-10-30 13:57:06 +00:00
Tom Minka 0114565ad3 QuantileEstimator.GetProbLessThan uses empirical cdf 2018-10-29 16:33:56 +00:00
Tom Minka c966b93213 TransformResults members are read-only. 2018-10-29 16:33:56 +00:00
Tom Minka 2b55afde22 BranchAndBound looks ahead one step. 2018-10-29 16:33:56 +00:00
Ivan Korostelev de12a5845a Add more complicated test 2018-10-25 13:39:57 +01:00
Ivan Korostelev 69cc3197e5 Test automaton serialization 2018-10-25 13:39:57 +01:00
Tom Minka 3b2ad3b05d
Fixed a corner case in DoubleIsBetweenOp. (#47)
* Fixed a corner case in DoubleIsBetweenOp.

* InnerQuantiles.GetProbLessThan checks for NaN
2018-10-24 21:29:54 +01:00
Tom Minka 6c8684e447
MMath.Median fix. (#43)
Gamma supports GetQuantile when Shape=1.
2018-10-22 23:33:43 +01:00
Tom Minka 83af41db89
Added CsvMapping code from the documentation. (#42) 2018-10-20 19:26:51 +01:00
Tom Minka 31eaa62221
Removed redundant 'open' statements from F# examples. (#41) 2018-10-20 07:52:30 +01:00
Tom Minka 7a82a6d25e
Fixed DoubleIsBetweenOp for 32-bit (#39)
* Fixed DoubleIsBetweenOp for 32-bit.

* Fixed MMath.LargestDoubleProduct for 32-bit.
2018-10-19 15:21:03 +01:00
Tom Minka 990d567941
MMath.LargestDoubleProduct fix. (#37)
* LargestDoubleProduct includes exception messages

* MMath.LargestDoubleProduct fix.

* Region.GetMidpoint fix

* Fixed issues in MMath.LargestDoubleProduct and LargestDoubleSum.  Added MMath.Average.

* Fixes to MMath.NormalCdf, NormalCdfRatio, DoubleIsBetweenOp.

* BranchAndBound.Search converges faster.
2018-10-18 22:29:33 +01:00
Tom Minka 79905f740d Fixed an edge case in InnerQuantiles.GetQuantile. 2018-10-15 23:34:59 +01:00
Tom Minka fe253eb525 TwoCoins example uses 'engine'. 2018-10-15 23:34:59 +01:00
Tom Minka d3ec3012ed Clarified the installation and building steps in the README. 2018-10-12 11:31:21 +01:00
msdmkats c8ab5eea6f
Pinned net core runtime version in netcoretest.sh. (#23) 2018-10-11 18:07:19 +03:00
Tom Minka 88c75fee2b Fixed issue in QuantileEstimator when a single point was retained.
Fixed EndCoupledChainsTest2.
Added MMath.NextDouble and PreviousDouble.
Split up EpTests.
Added Hidden attributes to factors that should not appear in Factor Manager.
HtmlTransformChainView shows errors.
README clarifies that Mono is optional.
2018-10-10 18:30:38 +01:00
msdmkats c003b11dad
Rename Infer2 -> Infer (#20) 2018-10-10 15:39:20 +03:00
Mikhail d323c0f02e
Test fixing (#17)
* Error, when assemblies with empty location are loaded, is fixed

* 'netcoretest.sh' script is a bit fixed
2018-10-10 00:34:04 +03:00
msdmkats da95ea9027
Use .NET Core 2.1 (#15)
* Use .NET Core 2.1.
* Update net sdk version in build definitions.
2018-10-08 14:52:39 +03:00
Yordan Zaykov 71b2cd6354 Improved readability of ML.NET sample. Now aligned with https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/matchup-app-infer-net 2018-10-06 01:01:19 +01:00
Mikhail 03e3d0fa8c Fixed tests, that can't be run using TestAllCompilerOptions (#6)
* Fixed tests that fails if invoked from TestAllCompilerOptions.
2018-10-05 15:33:54 +03:00
Sergey B. Berezin b50f69a477
PR build definitions in YAML (#1)
PR build definitions for MSBuild (Windows) and .NET Core (all operating systems)
2018-10-03 00:30:01 +03:00
dotnet-bot 73207ecc9c
Initial commit 2018-10-01 11:32:06 -07:00