-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔍 Tune search values (spsa) + define limits and steps in code (#730)
- Add `SPSAAttribute<T>` to define in the code param limits and steps - Use it for all search tunable parameters in `Configuration.EngineSettings` - Add `NMP_DepthIncrement` and `NMP_DepthDivisor` instead of having them hardcoded - Fix `see_badcapturereduction` UCI handling - Add `ob_spsa`, `ob_spsa_pretty` and `wf_spsa` UCI commands to print spsa inputs - Add WF tuned values
- Loading branch information
1 parent
bfbec00
commit b4e88ae
Showing
6 changed files
with
295 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Numerics; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Lynx; | ||
|
||
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] | ||
internal class SPSAAttribute<T> : Attribute | ||
where T : INumberBase<T>, IMultiplyOperators<T, T, T>, IConvertible, IParsable<T>, ISpanParsable<T> | ||
{ | ||
private static readonly T _hundred; | ||
|
||
public T MinValue { get; } | ||
public T MaxValue { get; } | ||
public T Step { get; } | ||
|
||
#pragma warning disable S3963 // "static" fields should be initialized inline | ||
static SPSAAttribute() | ||
#pragma warning restore S3963 // "static" fields should be initialized inline | ||
{ | ||
_hundred = T.Zero; | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
_hundred += T.One; | ||
} | ||
} | ||
|
||
public SPSAAttribute(T minValue, T maxValue, T step) | ||
{ | ||
if (typeof(T) == typeof(double)) | ||
{ | ||
minValue *= _hundred; | ||
maxValue *= _hundred; | ||
step *= _hundred; | ||
} | ||
|
||
MinValue = minValue; | ||
MaxValue = maxValue; | ||
Step = step; | ||
} | ||
|
||
public string ToOBString(PropertyInfo property) | ||
{ | ||
T val = GetPropertyValue(property); | ||
|
||
return $"{property.Name}, int, {val}, {MinValue}, {MaxValue}, {Step}, {Configuration.EngineSettings.SPSA_OB_R_end}"; | ||
} | ||
|
||
private static T GetPropertyValue(PropertyInfo property) | ||
{ | ||
T val = (T)property.GetValue(Configuration.EngineSettings)!; | ||
|
||
if (typeof(T) == typeof(double)) | ||
{ | ||
val *= _hundred; | ||
} | ||
|
||
return val; | ||
} | ||
|
||
public string ToOBPrettyString(PropertyInfo property) | ||
{ | ||
T val = GetPropertyValue(property); | ||
|
||
return $"{property.Name,-35} {"int",-5} {val,-5} {MinValue,-5} {MaxValue,-5} {Step,-5} {Configuration.EngineSettings.SPSA_OB_R_end,-5}"; | ||
} | ||
|
||
public KeyValuePair<string, JsonNode?> ToWeatherFactoryString(PropertyInfo property) | ||
{ | ||
T val = GetPropertyValue(property); | ||
|
||
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code | ||
return KeyValuePair.Create( | ||
property.Name, | ||
JsonSerializer.SerializeToNode(new | ||
{ | ||
value = val, | ||
min_value = MinValue, | ||
max_value = MaxValue, | ||
step = Step, | ||
})); | ||
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code | ||
} | ||
} |
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.
b4e88ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Progress check
40+0.4, Hash 256, no draw agreements or resignations, 8moves_v3.epd: