-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b2e226
commit c24f281
Showing
8 changed files
with
192 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
namespace Schafkopf.Training.Tests; | ||
// namespace Schafkopf.Training.Tests; | ||
|
||
public class ReplayMemoryTests | ||
{ | ||
[Fact] | ||
public void Test_CanFillCacheUntilOverflow() | ||
{ | ||
var memory = new ReplayMemory(100); | ||
// public class ReplayMemoryTests | ||
// { | ||
// [Fact] | ||
// public void Test_CanFillCacheUntilOverflow() | ||
// { | ||
// var memory = new ReplayMemory(100); | ||
|
||
for (int i = 0; i < 50; i++) | ||
memory.Append(new SarsExp()); | ||
// for (int i = 0; i < 50; i++) | ||
// memory.Append(new SarsExp()); | ||
|
||
Assert.Equal(50, memory.Size); | ||
// Assert.Equal(50, memory.Size); | ||
|
||
for (int i = 0; i < 50; i++) | ||
memory.Append(new SarsExp()); | ||
// for (int i = 0; i < 50; i++) | ||
// memory.Append(new SarsExp()); | ||
|
||
Assert.Equal(100, memory.Size); | ||
} | ||
// Assert.Equal(100, memory.Size); | ||
// } | ||
|
||
[Fact] | ||
public void Test_CanInsertIntoOverflowingCache() | ||
{ | ||
var memory = new ReplayMemory(100); | ||
// [Fact] | ||
// public void Test_CanInsertIntoOverflowingCache() | ||
// { | ||
// var memory = new ReplayMemory(100); | ||
|
||
for (int i = 0; i < 200; i++) | ||
memory.Append(new SarsExp()); | ||
// for (int i = 0; i < 200; i++) | ||
// memory.Append(new SarsExp()); | ||
|
||
Assert.Equal(100, memory.Size); | ||
} | ||
// Assert.Equal(100, memory.Size); | ||
// } | ||
|
||
[Fact(Skip = "requires the states to be initialized with unique data")] | ||
public void Test_CanReplaceOverflowingDataWithNewData() | ||
{ | ||
var memory = new ReplayMemory(100); | ||
var overflowingData = Enumerable.Range(0, 50).Select(x => new SarsExp()).ToArray(); | ||
var insertedData = Enumerable.Range(0, 100).Select(x => new SarsExp()).ToArray(); | ||
// [Fact(Skip = "requires the states to be initialized with unique data")] | ||
// public void Test_CanReplaceOverflowingDataWithNewData() | ||
// { | ||
// var memory = new ReplayMemory(100); | ||
// var overflowingData = Enumerable.Range(0, 50).Select(x => new SarsExp()).ToArray(); | ||
// var insertedData = Enumerable.Range(0, 100).Select(x => new SarsExp()).ToArray(); | ||
|
||
foreach (var exp in overflowingData) | ||
memory.Append(exp); | ||
foreach (var exp in insertedData) | ||
memory.Append(exp); | ||
// foreach (var exp in overflowingData) | ||
// memory.Append(exp); | ||
// foreach (var exp in insertedData) | ||
// memory.Append(exp); | ||
|
||
Assert.True(overflowingData.All(exp => !memory.Contains(exp))); | ||
Assert.True(insertedData.All(exp => memory.Contains(exp))); | ||
} | ||
} | ||
// Assert.True(overflowingData.All(exp => !memory.Contains(exp))); | ||
// Assert.True(insertedData.All(exp => memory.Contains(exp))); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Schafkopf.Training; | ||
|
||
public class UniformDistribution | ||
{ | ||
public UniformDistribution(int? seed = null) | ||
=> rng = seed != null ? new Random(seed.Value) : new Random(); | ||
|
||
private Random rng; | ||
|
||
public int Sample(ReadOnlySpan<double> probs) | ||
{ | ||
double p = rng.NextDouble(); | ||
double sum = 0; | ||
for (int i = 0; i < probs.Length - 1; i++) | ||
{ | ||
sum += probs[i]; | ||
if (p < sum) | ||
return i; | ||
} | ||
return probs.Length - 1; | ||
} | ||
|
||
public int Sample(int numClasses) => rng.Next(0, numClasses); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.