-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
132 lines (126 loc) · 5.15 KB
/
Program.cs
File metadata and controls
132 lines (126 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using PerformanceCalculator;
using System.Text;
using McMaster.Extensions.CommandLineUtils;
using osu.Framework.Logging;
using osu.Game.Beatmaps.Formats;
using osu.Game.Online;
using PerformanceCalculator.Simulate;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Difficulty;
using osu.Game.Rulesets.Osu.Difficulty.Skills;
using System.Reflection;
namespace MassBalancer
{
public class Program
{
public static readonly EndpointConfiguration ENDPOINT_CONFIGURATION = new ProductionEndpointConfiguration();
const int NUM_REGRESSIONS = 20;
const double STEP_MULT = 1.05;
private static ScoreSimulatorInfo FromCsvLine(string line)
{
string[] fields = line.Split(",");
return new ScoreSimulatorInfo(
mapID: int.Parse(fields[0]),
countOk: int.Parse(fields[1]),
countMeh: int.Parse(fields[2]),
countMiss: int.Parse(fields[3]),
targetPP: int.Parse(fields[4]),
combo: int.Parse(fields[5]),
name: fields[6],
mods: fields[7]
);
}
private static IEnumerable<ScoreSimulatorInfo> FromCsv(string filename)
{
using (var reader = new StreamReader(filename))
{
string line;
while ((line = reader.ReadLine()) != null)
yield return FromCsvLine(line);
}
}
public static void Main(string[] args)
{
List<ScoreSimulatorInfo> plays = FromCsv("scores.csv").ToList();
Constants constants = new Constants();
IEnumerable<PropertyInfo> consts = typeof(Constants).GetProperties(BindingFlags.Instance | BindingFlags.Public);
double initialDeviation = DifferenceDev(plays);
for (int i = 0; i < NUM_REGRESSIONS; i++)
{
foreach (var property in consts)
{
Constant current = Constant.GetFromProperty(property, constants);
current.Value /= STEP_MULT;
RunPlays(plays);
Constants.performanceMultiplier *= plays.Average(x => x.targetPP) / plays.Average(x => x.ppValue);
double decreaseDeviation = DifferenceDev(plays);
current.Value *= STEP_MULT * STEP_MULT;
RunPlays(plays);
Constants.performanceMultiplier *= plays.Average(x => x.targetPP) / plays.Average(x => x.ppValue);
double increaseDeviation = DifferenceDev(plays);
current.Value /= STEP_MULT;
if (decreaseDeviation > initialDeviation && increaseDeviation > decreaseDeviation);
else if (decreaseDeviation < increaseDeviation)
{
current.Value /= STEP_MULT;
initialDeviation = decreaseDeviation;
}
else
{
current.Value *= STEP_MULT;
initialDeviation = increaseDeviation;
}
}
Console.WriteLine($"Deviation at {i}: {initialDeviation}");
Console.WriteLine(constants);
}
RunPlays(plays, true);
Console.WriteLine(constants);
}
private static void RunPlays(List<ScoreSimulatorInfo> plays, bool showOutput=false)
{
if (!showOutput)
{
RunPlaysParallel(plays);
return;
}
foreach (var play in plays)
{
play.SetAttribs();
if (showOutput) Console.WriteLine($"{play.name.PadLeft(plays.Max(p => p.name.Length))}: PP - {play.ppValue:F2}. Target - {play.targetPP:F2}. Diff - {play.difference:F2}");
}
}
public static void RunPlaysParallel(List<ScoreSimulatorInfo> plays)
{
Parallel.ForEach(plays, play =>
{
play.SetAttribs();
});
}
public static double DifferenceDev(List<ScoreSimulatorInfo> plays)
{
IEnumerable<double> ppDiff = plays.Select(p => p.difference);
double mean = ppDiff.Average();
return Math.Sqrt(ppDiff.Sum(x => Math.Pow(x - mean, 2)) / ppDiff.Count());
}
public static double DifferenceMean(List<ScoreSimulatorInfo> plays)
{
IEnumerable<double> ppDiff = plays.Select(p => p.difference);
return ppDiff.Average();
}
public static double RatioDev(List<ScoreSimulatorInfo> plays)
{
IEnumerable<double> ppDiff = plays.Select(p => p.ratio);
double mean = ppDiff.Average();
return Math.Sqrt(ppDiff.Sum(x => Math.Pow(x - mean, 2)) / ppDiff.Count());
}
public static double RatioMean(List<ScoreSimulatorInfo> plays)
{
IEnumerable<double> ppDiff = plays.Select(p => p.ratio);
return ppDiff.Average();
}
}
}