Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, March 28, 2024

File: [Platon] / doc / diplomova-praca-rajo / scripts / entropy.awk (download)

Revision 1.1, Thu Jul 24 17:50:08 2003 UTC (20 years, 8 months ago) by rajo

Diploma Thesis of Lubomir Host.
Title: Metoda Monte Carlo vo fyzike nizkoteplotnej plazmy. (Slovak language)

#!/usr/bin/awk -f

# entropy.awk - compute entropy from distribution function
#
# Input file is in format:
#
#  1:real_time 2:relat_time  3:x   4:F(x>0,t)   5:F(x<0,t)   6:v   7:F(v>0,t)   8:F(v<0,t)
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# entropy = - Sum_i(f_i * ln(f_i))
# f_i - probability that the velocity of ion has a value between u_i and u_i + du

# $Platon$

BEGIN {
    entropy = 0.0;
    sum     = 0.0;
    time1   = 0.0;
    time2   = 0.0;
    f_max_v = 1.0;
    print   "\n#\n# ENTROPY\n# Data format: 1:real_time    2:relat_time    3:entropy    4:sum\n"
}

# ignore!
/^## Data format/ {
    next;
}

# reinitialize maximum speed --> speed step
/^## PARAM:  f_max_v/ {
    f_max_v = $5;
    printf "#@ value of f_max_v initialized to %g\n", f_max_v;
}

# print comments and continue
/^#/ {
    print;
    next;
}

# ignore empty lines
/^$/ {
    next;
}

# next time step
time1 != $1 {
    printf "%g    %g    %g    %g\n", time1, time2, entropy / f_max_v, sum;
    time1 = $1;
    time2 = $2;
    # clear entropy for next time step
    entropy = 0.0;
    sum     = 0.0;
}

# prevent log(0) = -infty
$7 != 0.0 {
        entropy -= $7 * log($7);
        sum     += $7;
}

$8 != 0.0 {
        entropy -= $8 * log($8);
        sum     += $8;
}


# vim: cindent


Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top