Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DXSdata committed Nov 28, 2017
1 parent 160a32f commit 15162e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions nBayes/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ public class Analyzer
private float I = 0;
private float invI = 0;

private float _prediction = float.NaN;
private float _prediction;

private Entry item;
private Index first;
private Index second;
private float tolerance;

bool calculated = false;

public Analyzer(Entry item, Index first, Index second, float tolerance = .05f)
{
this.item = item;
Expand All @@ -26,7 +28,7 @@ public float Prediction
{
get
{
if (float.IsNaN(_prediction))
if (!calculated)
_prediction = GetPrediction();

return _prediction;
Expand Down Expand Up @@ -69,6 +71,9 @@ private float GetPrediction()
}

float prediction = CombineProbability();

calculated = true;

return prediction;
}

Expand Down
7 changes: 6 additions & 1 deletion nBayes/FileIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public void Open()
using (Stream stream = File.OpenRead(this.filePath))
{
XmlSerializer serializer = new XmlSerializer(typeof(IndexTable<string, int>));
index.table = serializer.Deserialize(stream) as IndexTable<string, int>;
try
{
index.table = serializer.Deserialize(stream) as IndexTable<string, int>;
}
catch(InvalidOperationException) //e.g. if file empty
{}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions nBayes/nBayes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<StartupObject />

<PackageId>nBayes.DXSdata</PackageId>
<PackageVersion>3.0.0</PackageVersion>
<PackageVersion>3.0.1</PackageVersion>
<Authors>DXSdata</Authors>
<Description>Fork of joelmartinez/nBayes, ported for usage with .NET Core / .NET Standard</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -19,7 +19,7 @@ Changed framework for the sample project back from netstandard to netcoreapp, ot
<PackageTags>Bayes nBayes classifier .NET Core Standard DXSdata</PackageTags>
<PackageProjectUrl>http://www.dxsdata.com/2017/07/bayes-classifier-library-for-net-core/</PackageProjectUrl>
<Title>nBayes for .NET Core</Title>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl>https://github.com/DXSdata/nBayes</RepositoryUrl>
Expand Down

0 comments on commit 15162e1

Please sign in to comment.