こたつむりの備忘録

研究・技術的なことをメモしていきます

ボーズ分布

前回に続いてボーズ分布を可視化します。
※やっぱりPCサイトでしか表示されません。。

justice-vsbr.hatenablog.com

なんで急にボーズ分布なんだみたいな話は今度別で書く予定…書きたい…

関数以外は前回と同じなので関数のコードだけ載せます。

def plot_BE_distribution(x, beta=1, mu=-1):
    f = 1.0 / (np.exp(beta * (x - mu)) - 1.0)
    p = beta / (- np.log(1 - np.exp(beta * mu))) * f
    source = plt.ColumnDataSource(data=dict(x=x, f=f, p=p))
    
    y_range=(0, 1)
    freq = plt.figure(
        plot_height=200, plot_width=300, toolbar_location='below',
        title='ボーズ分布関数', y_range=y_range)
    loglog = plt.figure(
        plot_height=200, plot_width=300, toolbar_location='below',
        title='ボーズ分布関数(両対数)', x_axis_type='log', y_axis_type='log')
    prob = plt.figure(
        plot_height=200, plot_width=300, toolbar_location='below',
        title='規格化されたボーズ分布関数', y_range=y_range)
    freq.line('x', 'f', source=source)
    loglog.line('x', 'f', source=source)
    prob.line('x', 'p', source=source)
    
    temp_slider = models.Slider(start=0.01, end=1.0, value=beta, step=0.01, title='inverse temperature')
    pot_slider = models.Slider(start=-10, end=-0.01, value=mu, step=0.01, title='chemical potential')
    
    callback = models.CustomJS(args=dict(source=source, temp=temp_slider, pot=pot_slider), code="""
    const data = source.data;
    const beta = temp.value;
    const mu = pot.value;
    const x = data['x'];
    const f = data['f'];
    const p = data['p'];
    for (var i = 0; i < x.length; i++) {
        f[i] = 1.0 / (Math.exp(beta * (x[i] - mu)) - 1.0);
        p[i] = beta / (- Math.log(1.0 - Math.exp(beta * mu))) * f[i];
    }
    source.change.emit();
    """)
    
    temp_slider.js_on_change('value', callback)
    pot_slider.js_on_change('value', callback)
    
    layout = layouts.row(layouts.column(prob, freq, loglog), layouts.column(temp_slider, pot_slider))
    return layout