|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.clusterers.AlgVector
Class for performing operations on an algebraic vector of floating-point values.
Field Summary | |
protected double[] |
m_Elements
The values of the matrix |
Constructor Summary | |
AlgVector(double[] array)
Constructs a vector using a given array. |
|
AlgVector(Instance instance)
Constructs a vector using an instance. |
|
AlgVector(Instances format,
java.util.Random random)
Constructs a vector using a given data format. |
|
AlgVector(int n)
Constructs a vector and initializes it with default values. |
Method Summary | |
AlgVector |
add(AlgVector other)
Returns the sum of this vector with another. |
void |
changeLength(double len)
Changes the length of a vector. |
double |
dotMultiply(AlgVector b)
Returns the inner (or dot) product of two vectors |
Instance |
getAsInstance(Instances model)
Gets the elements of the vector as an instance. |
double |
getElement(int index)
Returns the value of a cell in the matrix. |
double[] |
getElements(int index)
Gets the elements of the vector and returns them as double array. |
protected void |
initialize()
Creates and returns a clone of this object. |
protected void |
initialize(java.util.Random random)
Resets the elements to the default value which is 0.0. |
static void |
main(java.lang.String[] ops)
Main method for testing this class. |
double |
norm()
Returns the norm of the vector |
void |
normVector()
Norms this vector to length 1.0 |
int |
numElements()
Returns the number of elements in the vector. |
void |
scalarMultiply(double s)
Computes the scalar product of this vector with a scalar |
void |
setElement(int index,
double value)
Sets an element of the matrix to the given value. |
void |
setElements(double[] elements)
Sets the elements of the vector to values of the given array. |
AlgVector |
substract(AlgVector other)
Returns the difference of this vector minus another. |
java.lang.String |
toString()
Converts a vector to a string |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected double[] m_Elements
Constructor Detail |
public AlgVector(int n)
n
- the number of elementspublic AlgVector(double[] array) throws java.lang.Exception
array
- the values of the matrixpublic AlgVector(Instances format, java.util.Random random) throws java.lang.Exception
public AlgVector(Instance instance) throws java.lang.Exception
instance
- with numeric attributes, that AlgVector gets build from
if
- instance doesn't have access to the data format
java.lang.Exception
Method Detail |
protected void initialize()
java.lang.CloneNotSupportedException
- if an error occurs
public Object clone() throws CloneNotSupportedException {
Matrix m = (Matrix)super.clone();
m.m_Elements = new double[numRows()][numColumns()];
for (int r = 0; r < numRows(); r++) {
for (int c = 0; c < numColumns(); c++) {
m.m_Elements[r][c] = m_Elements[r][c];
}
}
return m;
}
/**
Writes out a matrix.
java.lang.Exception
- if an error occurs
public void write(Writer w) throws Exception {
w.write("% Rows\tColumns\n");
w.write("" + numRows() + "\t" + numColumns() + "\n");
w.write("% Matrix elements\n");
for(int i = 0; i < numRows(); i++) {
for(int j = 0; j < numColumns(); j++) {
w.write("" + m_Elements[i][j] + "\t");
}
w.write("\n");
}
w.flush();
}
/**
Resets the elements to the default value which is 0.0.protected void initialize(java.util.Random random)
public final double getElement(int index)
index
- the row's index
public final int numElements()
public final void setElement(int index, double value)
index
- the elements indexvalue
- the new valuepublic final void setElements(double[] elements)
elements
- an array of doublespublic double[] getElements(int index)
public Instance getAsInstance(Instances model) throws java.lang.Exception
if
- length of vector is not number of numerical attributes
java.lang.Exception
public java.lang.String toString()
public final AlgVector add(AlgVector other)
public final AlgVector substract(AlgVector other)
public final double dotMultiply(AlgVector b)
b
- the multiplication matrix
public final void scalarMultiply(double s)
s
- the scalarpublic void changeLength(double len)
public double norm()
public final void normVector()
public static void main(java.lang.String[] ops)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |