SciLib.Math
Class vector

java.lang.Object
  extended by SciLib.Math.vector

public class vector
extends java.lang.Object

This class defines a dynamic vector of type double.


Constructor Summary
vector()
          Allocates an empty vector.
vector(double[] vec)
          Allocates a vector from the array vec.
vector(int n)
          Allocates a vector of size n with initialized values 0.
vector(int[] vec)
          Allocates a vector from the array vec.
vector(vector x)
          Make a copy of the vector x.
 
Method Summary
 void abs()
          change the vector to its absolute values.
static vector abs(vector v)
          change the vector to its absolute values.
 void add(double x)
          Add an element of value x to the vector.
 void append(vector x)
          Append a vector x to this vector
 int argmax()
          Compute the index of the maximum element in the vector.
 int argmin()
          Compute the index of the minimum element in the vector.
 void concat(vector x)
          Append a vector x to this vector
 double distance(vector x)
          compute the distance between this point vector to a vector x
static double distance(vector x, vector y)
          compute the distance between to point vector
static double dot(integerVector i1, vector x, integerVector i2, vector y)
          compute the dot product of the two sparse vectors x, y
static double dot(vector x, vector y)
          compute the dot product of the two vectors x, y
 double elementAt(int i)
          return the value of vector at index i.
static vector generate(double from, double to, double inc)
          Make a uniform vector that has elements from a double "from" to a double "to", the values are increased by a value "inc" .
static vector generate(int from, int to)
          create a uniform vector that has elements from an integer "from" to an integer "to".
 double[] getData()
          Make an array of type double that contains all data of the vector.
static vector linspace(double from, double to)
          Make a uniform vector of the default size 100 whose elements have values from a double "from" to a double "to".
static vector linspace(double from, double to, int n)
          Make a uniform vector of the size n whose elements have values from a double "from" to a double "to".
 void load(java.lang.String fileName)
          Load data from a file to a vector.
 double max()
          return the maximum value of the vector.
 double min()
          return the minimum value of the vector.
 void minus(vector x)
          minus this vector with the vector x and store the result in this vector.
static vector minus(vector x, vector y)
          minus two vector x, y.
 double mult(vector x)
          Compute the scalar product of this vector with the vector x.
static double mult(vector x, vector y)
          Compute the scalar product of two vectors with x, y.
 double norm()
          Compute the norm of the vector.
 void normalize()
          normalize the vector so that its norm is equal to 1.
static vector ones(int n)
          Make a vector of length n whose elements have value 1.
 void plus(vector x)
          plus this vector with the vector x and store the result in this vector
static vector plus(vector x, vector y)
          plus two vector x, y.
 void pointByPointMult(vector x)
          Time each element of this vector with each element of x and store the result in this in this vector.
 void print()
          Print all elements of the vector using System.out.
 void print(int n)
          print all elements of the vector with n decimal digits using System.out.
 void random()
          Fill this vector with random values between 0 and 1.
 void random(double a, double b)
          Fill this vector with random values between a and b.
 void read(java.lang.String fileName)
          Read data from a file to a vector.
 void resize(int n)
          Change the size of the vector to n.
 void roundUp(int n)
          Round up all elements of the vector to n decimal digits.
static vector roundUp(vector x, int n)
          Round up all elements of the vector to n decimal digits.
 void scale(double s)
          Scaling all elements of vector with a factor s.
 void setElementAt(double x, int i)
          change the value of element at index i with the double x.
 int size()
          Return the length of the vector.
 double squareDistance(vector x)
          compute the square distance between this point vector to a vector x
static double squareDistance(vector x, vector y)
          compute the square distance between to point vector
 double squareNorm()
          return the square of the norm of the vector.
 vector subvector(int from)
          make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to the end of this vector.
 vector subvector(int from, int to)
          Make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to an intger "to".
 java.lang.String toString()
          create a String that contains the elements of the vector.
 java.lang.String toString(int n)
          create a String that contains the elements of the vector with n decimal digits format.
 void translate(double s)
          plus all elements of the vector with factor s.
 void trimToSize()
          Remove all the unused elements of the vector.
 void write(java.lang.String fileName)
          Write all elements of the vector to a file.
 void write(java.lang.String fileName, int n)
          Write all elements of the vector to a file with the n deimal digits format.
static vector zeros(int n)
          Make a vector of length n whose elements have value 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

vector

public vector()
Allocates an empty vector.


vector

public vector(int n)
Allocates a vector of size n with initialized values 0.

Parameters:
n - The length of the vector

vector

public vector(double[] vec)
Allocates a vector from the array vec.

Parameters:
vec - An array of type double

vector

public vector(int[] vec)
Allocates a vector from the array vec.

Parameters:
vec - An array of type double

vector

public vector(vector x)
Make a copy of the vector x.

Parameters:
x - A vector
Method Detail

abs

public final void abs()
change the vector to its absolute values.


abs

public static final vector abs(vector v)
change the vector to its absolute values.


add

public void add(double x)
Add an element of value x to the vector.

Parameters:
x - A double value

append

public void append(vector x)
Append a vector x to this vector

Parameters:
x - A vector

argmax

public final int argmax()
Compute the index of the maximum element in the vector.

Returns:
An integer

argmin

public final int argmin()
Compute the index of the minimum element in the vector.

Returns:
An integer

concat

public void concat(vector x)
Append a vector x to this vector

Parameters:
x - A vector

squareDistance

public double squareDistance(vector x)
compute the square distance between this point vector to a vector x

Parameters:
x - A vector
Returns:
A double value

squareDistance

public static double squareDistance(vector x,
                                    vector y)
compute the square distance between to point vector

Parameters:
x - A vector
y - A vector
Returns:
A double value

distance

public double distance(vector x)
compute the distance between this point vector to a vector x

Parameters:
x - A vector
Returns:
A double value

dot

public static double dot(vector x,
                         vector y)
compute the dot product of the two vectors x, y

Parameters:
x - A vector
y - A vector
Returns:
A double value

dot

public static double dot(integerVector i1,
                         vector x,
                         integerVector i2,
                         vector y)
compute the dot product of the two sparse vectors x, y

Parameters:
i1 - stores indexes of nozero elements of x, An integerVector
x - A vector
i2 - stores indexes of nozero elements of y, An integerVector
y - A vector
Returns:
A double value

distance

public static double distance(vector x,
                              vector y)
compute the distance between to point vector

Parameters:
x - A vector
y - A vector
Returns:
A double value

elementAt

public double elementAt(int i)
                 throws java.lang.ArrayIndexOutOfBoundsException
return the value of vector at index i.

Parameters:
i - An integer
Throws:
java.lang.ArrayIndexOutOfBoundsException

generate

public static vector generate(int from,
                              int to)
create a uniform vector that has elements from an integer "from" to an integer "to".

Parameters:
from - An integer
to - An integer
Returns:
A vector

generate

public static vector generate(double from,
                              double to,
                              double inc)
Make a uniform vector that has elements from a double "from" to a double "to", the values are increased by a value "inc" .

Parameters:
from - A double
to - A double
Returns:
A vector

getData

public double[] getData()
Make an array of type double that contains all data of the vector.

Returns:
An array

linspace

public static vector linspace(double from,
                              double to)
Make a uniform vector of the default size 100 whose elements have values from a double "from" to a double "to".

Parameters:
from - A double
to - A double
Returns:
A vector

linspace

public static vector linspace(double from,
                              double to,
                              int n)
Make a uniform vector of the size n whose elements have values from a double "from" to a double "to".

Parameters:
from - A double
to - A double
n - The number of elements
Returns:
A vector

load

public void load(java.lang.String fileName)
Load data from a file to a vector.

Parameters:
fileName - A String

max

public final double max()
return the maximum value of the vector.

Returns:
A double value

min

public final double min()
return the minimum value of the vector.

Returns:
A double value

minus

public void minus(vector x)
           throws SizeException
minus this vector with the vector x and store the result in this vector.

Parameters:
x - A vector
Throws:
SizeException

minus

public static vector minus(vector x,
                           vector y)
                    throws SizeException
minus two vector x, y. The result is stored in a new vector

Parameters:
x - A vector
y - A vector
Returns:
A vector that is equal to x - y
Throws:
SizeException

mult

public double mult(vector x)
            throws SizeException
Compute the scalar product of this vector with the vector x.

Parameters:
x - A vector
Returns:
A double value
Throws:
SizeException

mult

public static double mult(vector x,
                          vector y)
                   throws SizeException
Compute the scalar product of two vectors with x, y.

Parameters:
x - A vector
y - A vector
Returns:
A double value
Throws:
SizeException

norm

public final double norm()
Compute the norm of the vector.

Returns:
A double value

normalize

public final void normalize()
normalize the vector so that its norm is equal to 1.


ones

public static vector ones(int n)
Make a vector of length n whose elements have value 1.


plus

public void plus(vector x)
          throws SizeException
plus this vector with the vector x and store the result in this vector

Parameters:
x - A vector
Throws:
SizeException

plus

public static vector plus(vector x,
                          vector y)
                   throws SizeException
plus two vector x, y. The result is stored in a new vector

Parameters:
x - A vector
y - A vector
Returns:
A vector that is equal to x + y
Throws:
SizeException

pointByPointMult

public void pointByPointMult(vector x)
                      throws SizeException
Time each element of this vector with each element of x and store the result in this in this vector.

Throws:
SizeException

print

public void print()
Print all elements of the vector using System.out.


print

public void print(int n)
print all elements of the vector with n decimal digits using System.out.

Parameters:
n - The number of decimal digits

random

public void random()
Fill this vector with random values between 0 and 1.


random

public void random(double a,
                   double b)
Fill this vector with random values between a and b.

Parameters:
a - A double value
b - A double value

read

public void read(java.lang.String fileName)
Read data from a file to a vector.

Parameters:
fileName - a String

resize

public void resize(int n)
Change the size of the vector to n.

Parameters:
n - The new length of the vector

roundUp

public void roundUp(int n)
Round up all elements of the vector to n decimal digits.

Parameters:
n - The number of decimal digits

roundUp

public static vector roundUp(vector x,
                             int n)
Round up all elements of the vector to n decimal digits.

Parameters:
n - The number of decimal digits
Returns:
A roundUp vector

scale

public void scale(double s)
Scaling all elements of vector with a factor s.

Parameters:
s - A double value that is the sacling factor

setElementAt

public void setElementAt(double x,
                         int i)
                  throws java.lang.ArrayIndexOutOfBoundsException
change the value of element at index i with the double x.

Parameters:
x - A double value
i - An integer
Throws:
java.lang.ArrayIndexOutOfBoundsException

size

public final int size()
Return the length of the vector.

Returns:
An integer

squareNorm

public final double squareNorm()
return the square of the norm of the vector.

Returns:
A double value

subvector

public vector subvector(int from,
                        int to)
Make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to an intger "to".

Parameters:
from - start index
to - end index
Returns:
A vector

subvector

public vector subvector(int from)
make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to the end of this vector.

Parameters:
from - start index
Returns:
A vector

toString

public java.lang.String toString()
create a String that contains the elements of the vector.

Overrides:
toString in class java.lang.Object
Returns:
A String

toString

public java.lang.String toString(int n)
create a String that contains the elements of the vector with n decimal digits format.

Parameters:
n - The number of decimal digits
Returns:
A String

translate

public void translate(double s)
plus all elements of the vector with factor s.

Parameters:
s - A double value

trimToSize

public void trimToSize()
Remove all the unused elements of the vector.


write

public void write(java.lang.String fileName)
Write all elements of the vector to a file.

Parameters:
fileName - A String

write

public void write(java.lang.String fileName,
                  int n)
Write all elements of the vector to a file with the n deimal digits format.

Parameters:
fileName - A String

zeros

public static vector zeros(int n)
Make a vector of length n whose elements have value 0.

Parameters:
n - An integer