1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 10:33:22 +08:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Jay Lawton
fbc3000765
Merge 544ba25743 into f09d8f097a 2024-12-03 14:17:55 +00:00
Jay Lawton
544ba25743 move norm and bellcurve into diffcalcutils 2024-12-04 00:17:40 +10:00
4 changed files with 26 additions and 21 deletions

View File

@ -21,14 +21,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
return -multiplier * Math.Pow(Math.Cos(denominator * Math.PI * ratio), power);
}
/// <summary>
/// Gives a bonus for target ratio using a bell-shaped function.
/// </summary>
private static double bellCurve(double ratio, double targetRatio, double width, double multiplier)
{
return multiplier * Math.Exp(Math.E * -(Math.Pow(ratio - targetRatio, 2) / Math.Pow(width, 2)));
}
/// <summary>
/// Calculates the difficulty of a given ratio using a combination of periodic penalties and bonuses.
/// </summary>
@ -45,10 +37,10 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
difficulty += terms;
// Give bonus to near-1 ratios
difficulty += bellCurve(ratio, 1, 0.5, 1);
difficulty += DifficultyCalculationUtils.BellCurve(ratio, 1, 0.5);
// Penalise ratios that are VERY near 1
difficulty -= bellCurve(ratio, 1, 0.3, 1);
// Penalize ratios that are VERY near 1
difficulty -= DifficultyCalculationUtils.BellCurve(ratio, 1, 0.3);
return difficulty / Math.Sqrt(8);
}

View File

@ -8,6 +8,7 @@ using osu.Game.Beatmaps;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Difficulty.Utils;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
@ -215,8 +216,8 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
double staminaPeak = staminaPeaks[i] * 0.0317;
double readingPeak = readingPeaks[i] * reading_skill_multiplier;
double peak = norm(1.5, colourPeak, staminaPeak);
peak = norm(2, peak, rhythmPeak, readingPeak);
double peak = DifficultyCalculationUtils.Norm(1.5, colourPeak, staminaPeak);
peak = DifficultyCalculationUtils.Norm(2, peak, rhythmPeak, readingPeak);
// Sections with 0 strain are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871).
// These sections will not contribute to the difficulty.
@ -263,12 +264,5 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
return 10.43 * Math.Log(sr / 8 + 1);
}
/// <summary>
/// Returns the <i>p</i>-norm of an <i>n</i>-dimensional vector.
/// </summary>
/// <param name="p">The value of <i>p</i> to calculate the norm for.</param>
/// <param name="values">The coefficients of the vector.</param>
private double norm(double p, params double[] values) => Math.Pow(values.Sum(x => Math.Pow(x, p)), 1 / p);
}
}

View File

@ -156,7 +156,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
double n = totalHits;
// Proportion of greats + goods hit.
double p = Math.Max(0, totalSuccessfulHits - 0.1 * h100) / n;
double p = Math.Max(0, totalSuccessfulHits - 0.0005 * countOk) / n;
// We can be 99% confident that p is at least this value.
double pLowerBound = (n * p + z * z / 2) / (n + z * z) - z / (n + z * z) * Math.Sqrt(n * p * (1 - p) + z * z / 4);

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
namespace osu.Game.Rulesets.Difficulty.Utils
{
@ -46,5 +47,23 @@ namespace osu.Game.Rulesets.Difficulty.Utils
/// <param name="exponent">Exponent</param>
/// <returns>The output of logistic function</returns>
public static double Logistic(double exponent, double maxValue = 1) => maxValue / (1 + Math.Exp(exponent));
/// <summary>
/// Calculates a Gaussian-based bell curve function (https://en.wikipedia.org/wiki/Gaussian_function)
/// </summary>
/// <param name="x">Value to calculate the function for</param>
/// <param name="mean">The mean (center) of the bell curve</param>
/// <param name="width">The width (spread) of the curve</param>
/// <param name="multiplier">Multiplier to adjust the curve's height</param>
/// <returns>The output of the bell curve function of <paramref name="x"/></returns>
public static double BellCurve(double x, double mean, double width, double multiplier = 1.0) => multiplier * Math.Exp(Math.E * -(Math.Pow(x - mean, 2) / Math.Pow(width, 2)));
/// <summary>
/// Returns the <i>p</i>-norm of an <i>n</i>-dimensional vector (https://en.wikipedia.org/wiki/Norm_(mathematics))
/// </summary>
/// <param name="p">The value of <i>p</i> to calculate the norm for.</param>
/// <param name="values">The coefficients of the vector.</param>
/// <returns>The <i>p</i>-norm of the vector.</returns>
public static double Norm(double p, params double[] values) => Math.Pow(values.Sum(x => Math.Pow(x, p)), 1 / p);
}
}