File size: 4,061 Bytes
dc68796
afc7627
dc68796
 
afc7627
dc68796
 
afc7627
dc68796
 
 
b375146
dc68796
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
$(document).ready(function(){
    $('#jailbreak-intro').on('click', 'span', function(e) {
        e.preventDefault();
        if (!$(this).hasClass('selected')) {
            $('#jailbreak-intro-label > span').removeClass('selected');
            $(this).addClass('selected');
            let cur_img = $(this).text();
            var diagram = document.getElementById("jailbreak-intro-img");
            diagram.src = "images/metrics/intro-"+cur_img+".png";
        }
    });
    $('#refusal-loss-formula-list').on('click', 'a', function(e) {
        e.preventDefault();
        if (!$(this).hasClass('selected')) {
            $('.formula').hide(200);
            $('.formula-list > a').removeClass('selected');
            $(this).addClass('selected');
            var target = $(this).attr('href');
            $(target).show(200);
        }
    });

    var diagram = document.getElementById("reliability-diagram"), cifar100_ece_data;
    $.getJSON("images/cifar100/cifar100_ece_value.json", function(data) {cifar100_ece_data = data;});
    $('input[type=radio][name=models]').change(function() {diagram.src = updateFigurePath();});
    $('input[type=radio][name=datasets]').change(function() {diagram.src = updateFigurePath();});
    $('input[type=radio][name=calibration_tool]').change(function() {
        if(this.value !== 'ts') $("#ts-slider").slider('disable');
        else $("#ts-slider").slider('enable');
        diagram.src = updateFigurePath();
    });

    var bin_handle = $("#bin-num");
    $( "#bin-slider" ).slider({
        step: 1,
        min: 4,
        max: 40,
        value: 15,
        create: function() {bin_handle.text($(this).slider("value"));},
        slide: function(event, ui) {bin_handle.text(ui.value);diagram.src = updateFigurePath(ui.value);},
    });

    var ts_handle = $("#temp-scale");
    $("#ts-slider").slider({
        step: 0.2,
        min: 1.0,
        max: 1.8,
        value: 1.0,
        disabled: true,
        create: function() {ts_handle.text($(this).slider("value"));},
        slide: function( event, ui ) {ts_handle.text(ui.value);diagram.src = updateFigurePath($('#bin-slider').slider("option", "value"),ui.value);},
    });

    function updateFigurePath(bin_num=$('#bin-slider').slider("option", "value"),temp=$('#ts-slider').slider("option", "value")) {
        var cur_dataset = $("input[type='radio'][name='datasets']:checked").val(),
            cur_model = $("input[type='radio'][name='models']:checked").val(),
            cur_tool = $("input[type='radio'][name='calibration_tool']:checked").val(),
            actualOnly = document.getElementById("ActualOnly").checked ? "_actual" : "";
        var bin_num_text = (bin_num < 10) ? "0" + bin_num.toString() : bin_num.toString();
        var ece_board = document.getElementById("ece-value");
        if (cur_tool === "ts")
        {
            var ts_text = "_t" + (temp*100).toString();
            if (ts_text === "_t100") {
                ece_board.innerText = parseFloat(cifar100_ece_data[cur_model]["none"][bin_num]).toFixed(5);
                return "images/" + cur_dataset + "/" + cur_model + "/none/" + "bin" + bin_num_text + actualOnly + ".png";
            }
            else
            {
                ece_board.innerText = parseFloat(cifar100_ece_data[cur_model][cur_tool][temp.toString()][bin_num]).toFixed(5);
                return "images/"+cur_dataset+"/"+cur_model+"/"+cur_tool+"/"+"bin"+bin_num_text+ts_text+actualOnly+".png";
            }
        }
        else
        {
            ece_board.innerText = parseFloat(cifar100_ece_data[cur_model][cur_tool][bin_num]).toFixed(5);
            return "images/"+cur_dataset+"/"+cur_model+"/"+cur_tool+"/"+"bin"+bin_num_text+actualOnly+".png";
        }
    }
});

function figureOption() {
    var checkBox = document.getElementById("ActualOnly");
    var diagram = document.getElementById("reliability-diagram");
    if (checkBox.checked) diagram.src = diagram.src.replace(".png", "_actual.png");
    else diagram.src = diagram.src.replace("_actual.png", ".png");
}