Util
Class Utils

java.lang.Object
  |
  +--Util.Utils

public class Utils
extends java.lang.Object


Constructor Summary
Utils()
           
 
Method Summary
static double[] averageVector(double[] x, double[] y)
          This function calculates the average values of 2 vectors(double arrays)
static void beginLatexDocument(java.io.PrintWriter file, java.lang.String title)
          Function used at some point to output to a latex file
static java.lang.String complement(java.lang.String s1, java.lang.String s2)
          Function returns the complement of a string
static double distance(double[] x, double[] y)
          Calculates the Eucledian distance between two arrays.
static double distance1(double[] x, double[] y)
          This function calculates distances between 2 arrays where the arrays can have wild-cards (values <0).
static java.lang.String doubleArrayString(double[] x)
          Function writes a double array to a string where each double only gets 5 places, cf.
static java.lang.String doubleString(double x, int l)
          Function forms a string of a double value with a given string length.
static void endLatexDocument(java.io.PrintWriter file)
          Function used at some point to output to a latex file
static void error(java.lang.String mess)
          Error message.
static int index(double x)
           
static int indexOf(java.util.List l, IntArray a)
           
static int indexOfContainingElement(java.util.List l, IntArray a)
           
static int indexOfPart(java.util.List l, IntArray a)
           
static java.lang.String largestSubString(java.lang.String s1, java.lang.String s2)
          Returns the largest substring of two strings if the substring is either at the start or at the end of both strings and if the substring is not equal to either of the two strings.
static void printGlobalLexicon(java.util.List lAgents, java.io.PrintWriter lexFile, char type, int iter)
          Function to print the 'global' lexicon
static void printGrammar(java.util.List lAgents, java.io.PrintWriter lexFile, char type, int iter)
          Function to print the grammars of the entire population.
static void printLexiconColumns(java.util.List lAgents, java.io.PrintWriter lexFile, char type, int lg)
          Function to write the lexicon in some format to the lexFile
static void printLexiconLatexTabel(java.util.List lAgents, java.io.PrintWriter lexFile, char type, int lg)
          Function used at some point to output to a latex file
static java.lang.String printStringArray(java.lang.String[] s)
           
static java.lang.String removeSubstring(java.lang.String s1, java.lang.String s2)
          Function to remove a string from another string
static java.lang.String substring(java.lang.String s1, java.lang.String s2)
          This function is used to get the largest substring under certain conditions.
static double variance(double[][] x, int N, int dim)
          Function to calculate the average variance in the columns of a matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

distance

public static double distance(double[] x,
                              double[] y)
Calculates the Eucledian distance between two arrays.

Parameters:
x - double array 1
y - double array 2
Returns:
distance between x and y, or -1 if the dimensions of x and y differ.

distance1

public static double distance1(double[] x,
                               double[] y)
This function calculates distances between 2 arrays where the arrays can have wild-cards (values <0).

Parameters:
x - double array 1
y - double array 2
Returns:
Eucledian distance between x and y for all non-negative dimensions

averageVector

public static double[] averageVector(double[] x,
                                     double[] y)
This function calculates the average values of 2 vectors(double arrays)

Parameters:
x - vector 1
y - vector 2
Returns:
a vector where each element is the average of the two input vectors

doubleArrayString

public static java.lang.String doubleArrayString(double[] x)
Function writes a double array to a string where each double only gets 5 places, cf. doubleString(x,5)

Parameters:
x - the double array
Returns:
the string

doubleString

public static java.lang.String doubleString(double x,
                                            int l)
Function forms a string of a double value with a given string length. E.g. doubleString(0.33333333,5) returns "0.333"

Parameters:
x - the double value
l - the string length
Returns:
string value of the double x with length l

printGlobalLexicon

public static void printGlobalLexicon(java.util.List lAgents,
                                      java.io.PrintWriter lexFile,
                                      char type,
                                      int iter)
Function to print the 'global' lexicon


printGrammar

public static void printGrammar(java.util.List lAgents,
                                java.io.PrintWriter lexFile,
                                char type,
                                int iter)
Function to print the grammars of the entire population.


beginLatexDocument

public static void beginLatexDocument(java.io.PrintWriter file,
                                      java.lang.String title)
Function used at some point to output to a latex file


endLatexDocument

public static void endLatexDocument(java.io.PrintWriter file)
Function used at some point to output to a latex file


printLexiconLatexTabel

public static void printLexiconLatexTabel(java.util.List lAgents,
                                          java.io.PrintWriter lexFile,
                                          char type,
                                          int lg)
Function used at some point to output to a latex file


printLexiconColumns

public static void printLexiconColumns(java.util.List lAgents,
                                       java.io.PrintWriter lexFile,
                                       char type,
                                       int lg)
Function to write the lexicon in some format to the lexFile


removeSubstring

public static java.lang.String removeSubstring(java.lang.String s1,
                                               java.lang.String s2)
Function to remove a string from another string

Parameters:
s1 - string 1
s2 - string 2
Returns:
the remainder of string s1 after removal of string s2

substring

public static java.lang.String substring(java.lang.String s1,
                                         java.lang.String s2)
This function is used to get the largest substring under certain conditions. These conditions are: if the substring starts or ends in one string, it must also start or end in the other, and it must either start or end at the strings


complement

public static java.lang.String complement(java.lang.String s1,
                                          java.lang.String s2)
Function returns the complement of a string

Parameters:
s1 - string 1
s2 - string 2
Returns:
the substring of s1 that is unequal to s2, with the restriction that s1 must start or end with s2. Otherwise it returns null.

largestSubString

public static java.lang.String largestSubString(java.lang.String s1,
                                                java.lang.String s2)
Returns the largest substring of two strings if the substring is either at the start or at the end of both strings and if the substring is not equal to either of the two strings.


indexOf

public static int indexOf(java.util.List l,
                          IntArray a)
Parameters:
l - a list of IntArrays
a - an IntArray
Returns:
the index of a in l (-1 if a is not in l)

indexOfPart

public static int indexOfPart(java.util.List l,
                              IntArray a)

indexOfContainingElement

public static int indexOfContainingElement(java.util.List l,
                                           IntArray a)

error

public static void error(java.lang.String mess)
Error message. Outputs the error message to the standard output and exits the program.


variance

public static double variance(double[][] x,
                              int N,
                              int dim)
Function to calculate the average variance in the columns of a matrix. This is used to calculate the variance between a set of meanings.

Parameters:
x - the matrix
N - the number of columns
dim - the number of rows
Returns:
the avarage variance of the columns

printStringArray

public static java.lang.String printStringArray(java.lang.String[] s)
Returns:
a string of an array of strings

index

public static int index(double x)
Parameters:
x - a double value (between 0 and 1)
Returns:
an integer between 0 and 9: 0 if x<0.1, 1 if 0.1<=x<0.2, ... ,9 if 0.9<=x