<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Threshold Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.controls {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.control-group {
background: #f8f9fa;
padding: 15px;
border-radius: 10px;
border: 2px solid #e9ecef;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
color: #495057;
}
input, button {
width: 100%;
padding: 10px;
border: 1px solid #ced4da;
border-radius: 5px;
font-size: 14px;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
cursor: pointer;
font-weight: bold;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.results {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 20px;
}
.result-box {
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
border-left: 5px solid #667eea;
}
.result-box h3 {
margin-top: 0;
color: #333;
}
.threshold-result {
font-size: 24px;
font-weight: bold;
color: #667eea;
text-align: center;
margin: 10px 0;
}
.stats {
font-family: monospace;
background: #fff;
padding: 15px;
border-radius: 5px;
margin-top: 10px;
}
.histogram {
margin-top: 20px;
}
.bar {
display: flex;
align-items: center;
margin: 2px 0;
}
.bar-label {
width: 60px;
font-size: 12px;
text-align: right;
margin-right: 10px;
}
.bar-fill {
height: 15px;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 3px;
transition: width 0.3s ease;
}
.bar-count {
margin-left: 10px;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>🎯 Threshold Calculator für 90%-Quantil</h1>
<div class="controls">
<div class="control-group">
<label for="samples">Anzahl Samples:</label>
<input type="number" id="samples" value="10000" min="1000">
</div>
<div class="control-group">
<label for="maxM">Maximaler m-Wert:</label>
<input type="number" id="maxM" value="60" min="10">
</div>
<div class="control-group">
<label for="targetPercentile">Ziel-Percentil (%):</label>
<input type="number" id="targetPercentile" value="90" min="50" max="99" step="0.1">
</div>
<div class="control-group">
<button onclick="calculateThreshold()">🔄 Threshold berechnen</button>
</div>
</div>
<div class="results">
<div class="result-box">
<h3>📊 Ergebnis</h3>
<div id="thresholdResult" class="threshold-result">-</div>
<div id="stats" class="stats"></div>
</div>
<div class="result-box">
<h3>📈 Verteilung</h3>
<div id="histogram" class="histogram"></div>
</div>
</div>
</div>
<script>
// Deine ursprüngliche Funktion
function f(a, b, c, m, n) {
return (a * 10 + b * 30 + c * 20) / (m + n * 20);
}
// Generiere einen einzelnen Wert basierend auf deiner Logik
function generateValue(m) {
let a = Math.max(1, Math.floor(m / 10));
let b = Math.floor(Math.random() * 4);
let c = a - 1;
// Beide n-Werte testen
let values = [];
values.push(f(a, b, c, m, 1.0));
values.push(f(a, b, c, m, 2.5));
return values;
}
function calculateThreshold() {
const samples = parseInt(document.getElementById('samples').value);
const maxM = parseInt(document.getElementById('maxM').value);
const targetPercentile = parseFloat(document.getElementById('targetPercentile').value);
let allValues = [];
// Sammle viele Samples
for (let i = 0; i < samples; i++) {
const m = Math.floor(Math.random() * (maxM + 1));
const values = generateValue(m);
allValues.push(...values);
}
// Sortiere die Werte
allValues.sort((a, b) => a - b);
// Berechne das gewünschte Percentil
const index = Math.floor((targetPercentile / 100) * allValues.length);
const threshold = allValues[index];
// Teste den Threshold
let above = 0;
let total = 0;
for (let m = 0; m <= maxM; m++) {
for (let test = 0; test < 100; test++) {
const values = generateValue(m);
values.forEach(val => {
total++;
if (val >= threshold) above++;
});
}
}
const actualPercentage = (above / total) * 100;
// Zeige Ergebnisse
document.getElementById('thresholdResult').textContent = threshold.toFixed(3);
const stats = `
Threshold: ${threshold.toFixed(3)}
Tatsächlich über Threshold: ${actualPercentage.toFixed(1)}%
Ziel war: ${targetPercentile}%
Samples verwendet: ${allValues.length.toLocaleString()}
Min Wert: ${Math.min(...allValues).toFixed(3)}
Max Wert: ${Math.max(...allValues).toFixed(3)}
Median: ${allValues[Math.floor(allValues.length/2)].toFixed(3)}
`;
document.getElementById('stats').textContent = stats;
// Erstelle Histogram
createHistogram(allValues, threshold);
}
function createHistogram(values, threshold) {
const bins = 20;
const min = Math.min(...values);
const max = Math.max(...values);
const binSize = (max - min) / bins;
const histogram = new Array(bins).fill(0);
values.forEach(val => {
const bin = Math.min(bins - 1, Math.floor((val - min) / binSize));
histogram[bin]++;
});
const maxCount = Math.max(...histogram);
const histogramDiv = document.getElementById('histogram');
histogramDiv.innerHTML = '';
histogram.forEach((count, i) => {
const binStart = min + i * binSize;
const binEnd = min + (i + 1) * binSize;
const isThresholdBin = threshold >= binStart && threshold < binEnd;
const bar = document.createElement('div');
bar.className = 'bar';
const width = (count / maxCount) * 100;
bar.innerHTML = `
<div class="bar-label">${binStart.toFixed(1)}</div>
<div class="bar-fill" style="width: ${width}%; ${isThresholdBin ? 'background: #ff6b6b;' : ''}"></div>
<div class="bar-count">${count}</div>
`;
histogramDiv.appendChild(bar);
});
}
// Initialer Durchlauf
calculateThreshold();
</script>
</body>
</html>