view release on metacpan or search on metacpan
perl/examples/ex3_kcluster view on Meta::CPAN
$i=0;
foreach(@{$clusters}) {
printf("Gene %2d belongs to cluster %2d\n",$i++,$_);
}
printf("\n");
printf("Within-cluster sum of distances is %f\n", $error);
printf("\n");
printf("Clustering second data set:\n\n");
($clusters, $error, $found) = kcluster(
%params,
data => $data2,
mask => $mask2,
weight => $weight2,
);
$i=0;
foreach(@{$clusters}) {
src/cluster.c view on Meta::CPAN
i++;
j--;
if (i<=j) loop = 1;
}
} while (loop); /* Decide which half the median is in. */
if (even) {
if (j == nl && i == nr) {
/* Special case, n even, j = n/2 & i = j + 1, so the median is
* between the two halves of the series. Find max. of the first
* half & min. of the second half, then average.
*/
int k;
double xmax = x[0];
double xmin = x[n-1];
for (k = lo; k <= j; k++) xmax = max(xmax, x[k]);
for (k = i; k <= hi; k++) xmin = min(xmin, x[k]);
return 0.5*(xmin + xmax);
}
if (j<nl) lo = i;
if (i>nr) hi = j;
src/cluster.c view on Meta::CPAN
distmatrix (input) double**
A ragged array containing the distance matrix. The number of columns in each
row is one less than the row index.
ip (output) int*
A pointer to the integer that is to receive the first index of the pair with
the shortest distance.
jp (output) int*
A pointer to the integer that is to receive the second index of the pair with
the shortest distance.
*/
{
int i, j;
double temp;
double distance = distmatrix[1][0];
*ip = 1;
*jp = 0;
for (i = 1; i < n; i++) {
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double result = 0.0;
double tweight = 0;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================ */
{
double result = 0.;
double tweight = 0;
int i;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double result = 0.;
double sum1 = 0.;
double sum2 = 0.;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double result = 0.;
double sum1 = 0.;
double sum2 = 0.;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double result = 0.;
double denom1 = 0.;
double denom2 = 0.;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double result = 0.;
double denom1 = 0.;
double denom2 = 0.;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
int i;
int m = 0;
double* rank1;
src/cluster.c view on Meta::CPAN
=========
n (input) int
The number of elements in a row or column. If transpose == 0, then n is the
number of columns; otherwise, n is the number of rows.
data1 (input) double array
The data array containing the first vector.
data2 (input) double array
The data array containing the second vector.
mask1 (input) int array
This array which elements in data1 are missing. If mask1[i][j] == 0, then
data1[i][j] is missing.
mask2 (input) int array
This array which elements in data2 are missing. If mask2[i][j] == 0, then
data2[i][j] is missing.
weight (input) double[ncolumns] if transpose == 0,
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
index1 (input) int
Index of the first row or column.
index2 (input) int
Index of the second row or column.
transpose (input) int
If transpose == 0, the distance between two rows in the matrix is calculated.
Otherwise, the distance between two columns in the matrix is calculated.
============================================================================
*/
{
double con = 0;
double dis = 0;
double exx = 0;
src/cluster.c view on Meta::CPAN
=======
This routine returns a uniform random number between 0.0 and 1.0. Both 0.0
and 1.0 are excluded. This random number generator is described in:
Pierre l'Ecuyer
Efficient and Portable Combined Random Number Generators
Communications of the ACM, Volume 31, Number 6, June 1988, pages 742-749, 774.
The first time this routine is called, it initializes the random number
generator using the current time. First, the current epoch time in seconds is
used as a seed for the random number generator in the C library. The first two
random numbers generated by this generator are used to initialize the random
number generator implemented in this routine.
Arguments
=========
None.
src/cluster.c view on Meta::CPAN
weight (input) double[ncolumns] if transpose == 0;
double[nrows] otherwise
The weights that are used to calculate the distance. This is equivalent
to including the jth data point weight[j] times in the calculation. The
weights can be non-integer.
n1 (input) int
The number of elements in the first cluster.
n2 (input) int
The number of elements in the second cluster.
index1 (input) int[n1]
Identifies which genes/samples belong to the first cluster.
index2 (input) int[n2]
Identifies which genes/samples belong to the second cluster.
dist (input) char
Defines which distance measure is used, as given by the table:
dist == 'e': Euclidean distance
dist == 'b': City-block distance
dist == 'c': correlation
dist == 'a': absolute value of the correlation
dist == 'u': uncentered correlation
dist == 'x': absolute uncentered correlation
dist == 's': Spearman's rank correlation