yawn.util
Class Pattern

java.lang.Object
  extended by yawn.util.Pattern

public class Pattern
extends java.lang.Object

A pattern (or vector or stimuli) of real numbers (double). $Id: Pattern.java,v 1.12 2005/04/07 17:28:30 supermarti Exp $

Version:
$Revision: 1.12 $
Author:
Luis Martí (luis dot marti at uc3m dot es)

Field Summary
static java.lang.String ELEMENT_SEPARATOR
           
 
Constructor Summary
Pattern()
          Creates a zero elements Pattern.
Pattern(double[] source)
          Creates a Pattern whose elements are copied from source.
Pattern(int size)
          Creates a Pattern of the desired size initialized to zero.
Pattern(Pattern source)
          Creates a Pattern whose elements are copied from source.
 
Method Summary
 Pattern add(double operand)
          Scalar addition.
 Pattern add(Pattern operand)
          Element-wise addition.
 void appendComponent(double value)
          Appends an element to the Pattern.
 double[] asDoubleArray()
          The elements of this Pattern as a double[].
protected  void checkEqualSize(Pattern comp)
          Checks if a Pattern has equal size.
 java.lang.Object clone()
           
 double dist(Pattern other)
          Calculates an Euclidean distance from this Pattern.
 boolean equals(Pattern other)
           
 double getComponent(int i)
          Returns the i -nary element of the Pattern.
 double innerProduct(Pattern operand)
          Calculates the inner product of two Patterns.
 Pattern multiply(double operand)
          Scalar multipication.
 double norm1()
          Calculates a norm1 (sum of absolute values) of the Pattern.
 double norm2()
          Calculates a norm2 (square root of the sum of the squared values) of the Pattern.
static Pattern parsePattern(java.lang.String str)
          Parses a String into a Pattern.
 void randomize(double min, double max)
          Randomizes this Pattern with values bounded by min and max.
 void setAllComponents(double value)
          Sets all Pattern elements to value.
 void setComponent(double value, int i)
          Sets element of index i to value.
 void setComponents(Pattern orig)
          Sets elements to the ones of orig.
 int size()
           
 Pattern substract(Pattern operand)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ELEMENT_SEPARATOR

public static final java.lang.String ELEMENT_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

Pattern

public Pattern()
Creates a zero elements Pattern.


Pattern

public Pattern(double[] source)
Creates a Pattern whose elements are copied from source.

Parameters:
source - the array from which elements are copied

Pattern

public Pattern(int size)
Creates a Pattern of the desired size initialized to zero.

Parameters:
size - the dimension of the new Pattern

Pattern

public Pattern(Pattern source)
Creates a Pattern whose elements are copied from source.

Parameters:
source - the Pattern to be used as source
Method Detail

add

public Pattern add(Pattern operand)
Element-wise addition.

Parameters:
operand - the Pattern to add
Returns:
the result of the operation

add

public Pattern add(double operand)
Scalar addition.

Parameters:
operand - the amount to add
Returns:
the result of the sum

appendComponent

public void appendComponent(double value)
Appends an element to the Pattern. Note that is an inefficient operation and should be rarely used.

Parameters:
value - the value of the element to append

asDoubleArray

public double[] asDoubleArray()
The elements of this Pattern as a double[].

Returns:
the double[]

checkEqualSize

protected void checkEqualSize(Pattern comp)
Checks if a Pattern has equal size.

Parameters:
comp - Pattern to test with
Throws:
java.lang.ArrayIndexOutOfBoundsException

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

dist

public double dist(Pattern other)
Calculates an Euclidean distance from this Pattern.

Parameters:
other - the Pattern to measure the distance with
Returns:
the distance

equals

public boolean equals(Pattern other)

getComponent

public double getComponent(int i)
Returns the i -nary element of the Pattern.

Parameters:
i - the index of the desired element
Returns:
the value of the element

innerProduct

public double innerProduct(Pattern operand)
Calculates the inner product of two Patterns.

Parameters:
operand - the Pattern to be used in calculation
Returns:
the inner product

multiply

public Pattern multiply(double operand)
Scalar multipication.

Parameters:
operand - the amount to multiply
Returns:
the resulting Pattern

norm1

public double norm1()
Calculates a norm1 (sum of absolute values) of the Pattern.

Returns:
the norm

norm2

public double norm2()
Calculates a norm2 (square root of the sum of the squared values) of the Pattern.

Returns:
the norm

setAllComponents

public void setAllComponents(double value)
Sets all Pattern elements to value.

Parameters:
value - the value to set

setComponent

public void setComponent(double value,
                         int i)
Sets element of index i to value.

Parameters:
value - the value to set
i - index of the element to set
Throws:
java.lang.IndexOutOfBoundsException

setComponents

public void setComponents(Pattern orig)
Sets elements to the ones of orig.

Parameters:
orig - the Pattern with the elements to set

size

public int size()
Returns:
the elements count of this Pattern

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

parsePattern

public static Pattern parsePattern(java.lang.String str)
Parses a String into a Pattern. Elements are separated by Pattern.ELEMENT_SEPARATOR

Parameters:
str - the String to parse
Returns:
the resulting Pattern
See Also:
ELEMENT_SEPARATOR

randomize

public void randomize(double min,
                      double max)
Randomizes this Pattern with values bounded by min and max. It does not initializes the random number generator.

Parameters:
min - lower bound
max - higher bound

substract

public Pattern substract(Pattern operand)


Copyright © 2003-2005 GIAA, Universidad Carlos III de Madrid. All Rights Reserved.