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

197 Коммитов

Автор SHA1 Сообщение Дата
Jonathan Tims e4ca47a7d8
Bump net6.0 target to net8.0 (#475)
Bump net6.0 target to net8.0.
2024-09-05 00:51:09 +01:00
Tom Minka deb5869e8e
FastSumOp.ArrayAverageConditional handles nearly improper sums (#474)
ParallelScheduleTransform inserts try/catch blocks that throw InferenceException when UseLocals=true
2024-08-29 11:33:32 +01:00
Tom Minka 07fd9fe2ad
Added DenseVector.SetToMinNormSolution (#473) 2024-08-13 11:48:46 +01:00
Tom Minka 5c5e3f08e6
DiscreteChar has ConstructionAttribute (#463)
* LoggingTransform normalizes names
* Compiler requires PointEstimate to be initialised
2024-03-07 00:21:29 +00:00
Tom Minka 3e567fcd0c
Scheduler fix for RecommenderSystem (#457)
* Added RecommenderSystem.largeData option.  RecommenderSystem checks evidence.
* GaussianOp.FindZeroes and GetRoots handle edge cases
* GaussianProductOp.ProductAverageConditional handles an edge case
* SemanticWebTest4 runs 2 iterations
* AndOrXorTest2 is OpenBug
2024-01-11 15:28:05 +00:00
Jonathan Tims 0f03d49b5e
Remove Type.GetType from InferDataContractResolver (#454)
For compliance, we do not want to apply Type.GetType to any data string we are given in-case it leads to harmful types being used. Even using Type.GetType and then checking the type afterwards is not compliant because it may inadvertently load assemblies we did not intend.

Therefore we create an explicit list of allowed types, and parse the type string to direct construction of the required type from the allowed list.

The nice thing about constructing directly from the allowed list is that even if there is a bug in the parsing code, or the string has been tampered with, it is impossible for us to end up with a type that is not a combination of types on the allowed list.
2024-01-03 16:05:36 +00:00
Jonathan Tims 89a884e6d6 w 2023-10-18 23:26:41 +01:00
Jonathan Tims 50e5d076b8 w 2023-10-18 14:51:35 +01:00
Jonathan Tims dcbb50483e w 2023-10-05 17:40:00 +01:00
Jonathan Tims 2fa8e109d7 w 2023-10-05 15:20:37 +01:00
Jonathan Tims e941d29a21 w 2023-10-04 19:45:38 +01:00
Tom Minka 5b8f332463
SequenceDistribution implements IsPartialUniform (#447) 2023-09-20 16:16:27 +01:00
Tom Minka e139be6539
Added Discrete.Truncate (#446)
* Added DiscreteEstimator.Add(DiscreteEstimator)
2023-08-07 16:04:29 +01:00
Jonathan Tims f58de0d67a w 2023-07-31 11:25:05 +01:00
Tom Minka 5bd86ece6b
Fixed Rand.Sample, Vector.MaxDiff and GreaterThan (#440)
* Fixed a bug in Rand.Sample that could cause it to return a value that should have zero probability.
* Added MMath.AbsDiffAllowingNaNs
* Fixed SparseVector.MaxDiff
* DependencyGraphView, ModelView, TaskGraphView implement IDisposable
* Added missing evidence methods
* Added Vector.All(Vector, Func)
2023-05-20 18:25:36 +01:00
Tom Minka 968e3b2e8a
LogisticOp and DoublePlusOp and MaxGaussianOp handle improper messages (#439)
* Added missing evidence methods
* Added ModelCompiler.UseTracingTransform
2023-04-24 19:38:33 +01:00
Tom Minka 5b7d93b1b6
Swapped arguments of IEstimatedDistribution.GetExpectation (#438)
* Added EnumerableExtensions.TakeRandom
* Added Rand.LogGamma
* Added MMath.RisingFactorialLn
* Moved GammaProbBetween to MMath
* Added missing overload of DiscreteEstimator.Add
* CSharpWriter writes nicer array initializers
* GaussianProductOpBase.AAverageConditional handles uniform Product
* Increased accuracy of TruncatedGamma.GetMeanPower
* Improved accuracy of GaussianFromMeanAndVarianceOp.VarianceAverageConditional
* Improved accuracy of Gamma.FromDerivatives and GetDerivatives
* Improved accuracy of IsBetweenGaussianOp.XAverageConditional and GammaPower.GetLogMeanPower
* Increased accuracy of MMath.GammaUpper, TruncatedGamma.GetLogProb
* Improved accuracy of MMath.GammaProbBetween
* Improved accuracy of Gamma.GetLogProb, GetLogNormalizer, GammaPower.GetLogProb
* TruncatedGamma_GetMeanPower_WithinBounds is no longer OpenBug
* GammaUpper_IsDecreasingInX is OpenBug
2023-03-25 18:07:52 +00:00
Andrii Kurdiumov 2354ca6056
Add comment to Python test project about solution config (#437) 2023-03-09 16:30:21 +00:00
Jonathan Tims b904a5beb9
Add .net6.0-windows as a target (#433)
Add .net6.0-windows as a target so that Visualizer features are available on .NET 6.0 when targeting Windows (while preserving the cross-platform net6.0 target).

I have changed our minimum .NET 4xx dependency from net462 to net472 because this is the minimum version supported by the version of the automatic graph layout package that supports net6.0-windows.

It is possible to still use net462 and in this case to use the previous version of automatic graph layout; but the increased complexity doesn't seem worth it.
2023-01-06 10:19:03 +00:00
Tom Minka 3a11b4a1aa
Fix last change to StocAnalysisTransform (#431) 2022-12-31 20:07:44 +00:00
Tom Minka 8b7c7c54e1
Power operator and Math.Pow support a constant base variable. (#429) 2022-12-30 13:14:00 +00:00
Tom Minka fb7dbc00ac
ModelBuilder inserts checked expressions (#425)
* ModelCompiler handles checked expressions
* StocAnalysisTransform replaces constraint assignments with Constrain.Equal
* Fixed VariablePointOpBase.LogEvidenceRatio
* Fixed ConstrainEqualOp.AverageLogFactor
2022-11-11 03:06:23 +00:00
Tom Minka 88a13d8fb6
Added ClassifierModels.DenseBinaryVectorModel (#423)
* Improved accuracy of Gamma.FromDerivatives
2022-11-01 16:37:09 +00:00
Tom Minka 9eed4e8e93
Added Interval arithmetic classes (#421) 2022-10-19 12:13:34 +01:00
Tom Minka 9d4f267962
Resolve warnings (#419) 2022-09-12 21:39:48 +01:00
Pavel Myshkov d39c5863f0 Return negative infinity in logsumexp on empty input 2022-09-10 13:44:30 +01:00
Andrii Kurdiumov 5cedd14dc0
Update to .NET 6 (#391)
* Disable warning for usage of WebClient in Evaluator
* vmImage: windows-latest
* Adjust to new DeflateStream behaviour in .NET 6
2022-08-23 15:38:02 +01:00
Pavel Myshkov 638771287d
Remove duplicate references to FSharp.Core (#416) 2022-08-22 20:51:23 +01:00
Tom Minka 27b37fefe4
Use .NET 4.6.2 instead of 4.6.1 (#415)
* QuantileEstimator throws on NaN arguments
2022-08-22 17:09:01 +01:00
Tom Minka b4169dfaaa
Compiler handles initialized constrained variable arrays (#412)
* MMath.Max, Min, Median throw InvalidOperationException on empty sequences.
* Increased precision of MaxGaussianOp.
* InnerProductArrayOp.AAverageConditional handles innerProduct near uniform.
* MaxOfOthersOp has internal flag for Monte Carlo.
2022-07-26 21:03:32 +01:00
Ivan Korostelev 5d8f736006
Micro-optimize StringAutomaton.Product and StringTransducer.ProjectSource (#411)
In our project these 2 methods are very hot. They are near-optimal algorithmically but implementation
wasn't efficient due to use of convenient abstractions and JIT in netframework4.7.2 being not very sophisticated.
(dotnet7 optimizes original code a lot better, but due to various reasons we can't migrate to it yet).

List of micro-optimizations in no particular order:
- ReadOnlyArray<> now returns values by reference
  - It means it can't implement IReadOnlyList<> interface anymore. But it wasn't used through interface anywhere anyway
- GenerationalDictionary<> now accesses hash-table cells by reference
- GenerationalDictionary.GetOrAdd() method added which replaces 2 calls to TryGetValue()+Add()
- Automaton.Builder now manages its dynamically growing arrays on its own instead of using List<>.
  This reduces indirection and allows to access elements by reference
- Automaton.Transition.ElementDistribution is not Option<TElementDistribution> anymore. Boxing of
  element distribution into Option<> was not optimized out by JIT.
  - New API is a little less safe (because this property can be used only for non-epsilon transitions) but more efficient.
  - Transition.OptionalElementDistribution property was added for non-performance critical parts of the code.
- StringManipulator is now a struct (value type). It allows to monomorphize generic class and inline calls to its methods.
  With classes (reference types) calls had to be dynamically dispatched.
- Automaton.Product() and TransducerBase.ProjectSource() were rewritten without use of StateCollection, State
  and ReadOnlyArraySegment<> types. These types provided convenient APIs but JIT was not ablet to eliminate
  their overhead.

This PR speeds up methods mentioned in PR title by about 30%.
2022-07-22 15:13:12 +01:00
dependabot[bot] 6809c84080
Bump Newtonsoft.Json from 11.0.2 to 13.0.1 in /test/Tests (#407)
Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 11.0.2 to 13.0.1.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/11.0.2...13.0.1)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-23 18:20:24 +01:00
Tom Minka 55d26a7138
Added Variable.ParallelCopy (#404)
* VectorGaussian.SetToRatio correctly enforces forceProper
* BeliefPropagationGateEnterPartialOp.ValueAverageConditional double-checks for conflicting values
* Added ReplicateOp_Divide_NoInit
* PlusProductHierarchyTest is OpenBug
* MatrixVectorProduct has optional check
* Deterministic gates track the number of cases
2022-05-03 22:27:20 +01:00
Tom Minka ca25068ead
WetGlassSprinklerRainModel has flexible state counts (#402)
* Expanded CausalityExample
* Variable.Dirichlet and Discrete check the array size
* IterativeProcessTransform ensures Marginal methods have unique names
* DependencyGraph.initializedEdges overrides required edges
* DependencyAnalysisTransform requires gated definitions to fully precede their uses
2022-04-08 20:14:57 +01:00
Tom Minka 68a10ac833
Rprop stepsize is lower bounded (#398)
Reduced the number of false "excess memory" warnings from GateTransform.
2022-03-02 21:10:46 +00:00
Tom Minka 45d2e593ba
Improved accuracy of MMath.WeightedAverage and GaussianProductOp (#395)
* RpropBufferData.EnsureConvergence = false
* GetJaggedItemsOp and GetItemsFromJaggedOp use IReadOnlyList
2022-02-16 14:58:03 +00:00
Andrii Kurdiumov 1b4c479339
.NET 5 instead of .NET Core 3.1 (#273)
* Rename netcoreapp3.1 to net5.0 in all files
* Remove references to Microsoft.NET.Sdk.WindowsDesktop
* WinForms/WPF examples use net5.0-windows
2022-01-26 13:22:26 +00:00
Tom Minka 9b28c62294
Improved support for computing derivatives (#390)
* Inferred constant variables are not inlined
* Added Factor.ProbLessThan, ProbBetween, Quantile, Integral, Apply.
* ModelCompiler handles Delegate-valued variables.
* RatioGaussianOp handles ratio instead of ProductOp.
* ExpOp_Slow and LogOp_EP can compute derivatives
* Refactored ConstantFoldingTransform out of ModelAnalysisTransform
* CodeBuilder.MethodRefExpr takes arguments.
* Added VariableInformation.NeedsMarginalDividedByPrior and CodeRecognizer.NeedsMarginalDividedByPrior
* MessageTransform does not use a distribution for the forward message of a constant.
2022-01-25 21:41:52 +00:00
Tom Minka b6dd9630f5
DiscreteEnumAreEqualOp supports VMP (#387) 2022-01-08 18:47:02 +00:00
Tom Minka 079250ef67
Observed Beta variables support a Gamma-distributed pseudocount if the other pseudocount is always 1 (#386)
* ShowFactorManager shows more patterns
* Tidy up code
2022-01-07 18:07:48 +00:00
Tom Minka 791d11a8a1
MMath.WeightedAverage fix (#379) 2021-12-26 20:03:11 +00:00
Tom Minka 5f394f9b8a
Added IClassifierMapping.LabelToString and ParseLabel. (#378)
BinaryNativeClassifierMapping and MulticlassNativeClassifierMapping serialize labels as strings. Incremented CustomSerializationVersion for each.
BinaryNativeClassifierMapping does not serialize labels when TLabel is bool.
IReader.ReadObject is generic.
2021-12-14 11:33:00 +00:00
Tom Minka 3c825f2d29
BayesPointMachineClassifier.CreateGaussianPriorBinaryClassifier is public. (#376)
* Added Variable.Max(int,int).
* Compiler warns about excess memory consumption in more cases when it should, and fewer cases when it shouldn't.
* TransformBrowser shows attributes by default.
* Updated FactorDocs
2021-12-10 23:37:00 +00:00
Tom Minka 6c6fb65dd2
BayesPointMachineClassifier can be serialized as text (#373)
* BayesPointMachineClassifier.LoadBackwardCompatibleBinaryClassifier and SaveForwardCompatible use text or binary depending on the file extension
* Added IWriter and IReader, WrappedBinaryWriter, WrappedBinaryReader, WrappedTextWriter, WrappedTextReader
* Changed uses of BinaryWriter to IWriter
* Changed uses of BinaryReader to IReader
* LearnersTests uses same xunit version as other tests
2021-11-29 23:08:58 +00:00
Ivan Korostelev 2376606055
Remove Pair<> and introduce IntPair (#369)
C# now has a built-in type to represent pairs - `ValueTupe<>`. `Pair<>` was eliminated in favour of it.

At the same time a new type - `IntPair` was introduced. It is faster than `ValueTuple<int, int>` when `.Equals()` is called often.
It makes some common string operations which do many lookups by `IntPair` keys up to 10% faster.
2021-09-30 17:11:04 +01:00
Ivan Korostelev 376918bfd6
Reduce GC pressure induced by string operations (#362)
A lot of automata operations create large short-lived data structures.
Those are now cached in thread local static fields. This saves a lot of allocations and consequently - causes less GC pressure.

To do so also a new container is introduced - `GenerationalDictionary` which can be cleared in constant time and reuses memory after the Clear.

These changes reduce amount of memory allocations done by `StringInferencePerformanceTests` from 4Gb to 2Gb. Another 1 Gb is allocated by `FindStronlyConnectedComponents` which will be fixed in separate PR, it is harder to introduce caching in there. Another 1Gb is set up of the tests (creation of test data).
2021-09-29 18:28:15 +01:00
Tom Minka 591117241e
All-zero Discrete is not a point mass (#368) 2021-09-29 11:19:15 +01:00
Tom Minka 76ec66dcca
Changed the BCC confusion matrix prior (#367)
Changed the BCC confusion matrix prior so that TrueLabels can be inferred when LabelCount==2.
Fixed serialization of BCC posteriors.  BCC posteriors now save to the Results folder.
Fixed serialization example code.
2021-09-29 07:09:38 +01:00
Tom Minka c90ad0bf1e
Discrete distribution can be all zero (#364)
Added Discrete.Zero and IsZero.
IntegerPlusOp allows result to be the same object as an input.
2021-09-23 17:16:56 +01:00
Ivan Korostelev 8370c9e8e7
Simplify discrete char implementation (#361)
There are two changes:
1. (major) `LogProbabilityOverride` was removed from `DiscreteChar` and `ImmutableDiscreteChar`
    This was an unsound functionality that is not used and was complicating the implementation of char distributions
2. (minor) `ImmutableDiscreteChar.Multiply` may reuse immutable discrete char in more cases out of the box. 
   This reduces the GC pressure a little bit.
2021-09-14 21:53:05 +01:00