[ return ]

distributed.pl



#
# file: distributed.pl
#
#   Main function: &value_to_gauss()
#     - transforms a scalar value into a gaussian-coded value.
#
#
#
#     Copyright (C) 1995 Andrew H. Fagg (af0a@robotics.usc.edu)
#     
#     This program is free software; you can redistribute it and/or
#     modify it under the terms of the GNU General Public License
#     as published by the Free Software Foundation; either version 2
#     of the License, or any later version.
#     
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#     
#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#


$GAUSS_THRESH = 0.05;

sub threshold
{
    local($val, $thresh) = @_;

    return(($val > $thresh) ? $val : 0);
};

sub max
{
    local($x, $y) = @_;
    return(($x > $y) ? $x : $y);
};

sub square 
{
    local($val) = @_;
    return($val * $val);
};

sub gauss

{
    local($mean, $position, $std) = @_;

    return((1/(2.5066*$std)) * exp(-0.5 * (&square(($position - $mean)/$std))));

};


sub ngauss

{
    local($mean, $position, $std) = @_;

    return(exp(-0.5 * (&square(($position - $mean)/$std))));

};

sub value_to_gauss
{
    local($val, $min, $max, $std, $size, $pad) = @_;
    local($gain, $step, @out, $cur, $i);
    
    @out = ();
    $gain = 1/&gauss(0, 0, $std);
    $step = ($max - $min) / ($size - $pad * 2 - 1);
    for($cur = $min - $pad * $step, $i =0; $i < $size;
	++$i, $cur += $step)
    {
	push(@out, (&threshold(&gauss($val, $cur, $std) * $gain, $GAUSS_THRESH)));
    };
	
    return @out;
};

#
#  sub compute_max_gauss
#
#  Computes the 2 indices in the gaussian array that have the max value.
# Return = (index of left one (smaller index), match at that index)
#
#  The other index is +1 and the match value is 1-
#
#

sub compute_max_gauss
{
    local($val, $min, $max, $std, $size, $pad) = @_;
    local($step);
    
    $step = ($max - $min) / ($size - $pad * 2 - 1);

    $point = ($val-$min)/$step + $pad;
    return(int($point), 1 - $point + int($point));
};


1;


[ return ]