[Yasomi-commits] r44 - in trunk/yasomi: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Apr 30 14:27:33 CEST 2011
Author: frossi
Date: 2011-04-30 14:27:33 +0200 (Sat, 30 Apr 2011)
New Revision: 44
Modified:
trunk/yasomi/ChangeLog
trunk/yasomi/src/bmu.c
trunk/yasomi/src/bmu.h
trunk/yasomi/src/neighborhood.c
trunk/yasomi/src/neighborhood.h
Log:
Added new C functions for a finer grain calculation of best matching units and of neighborhood functions (building blocks for stochastic SOM).
Modified: trunk/yasomi/ChangeLog
===================================================================
--- trunk/yasomi/ChangeLog 2011-03-06 11:06:20 UTC (rev 43)
+++ trunk/yasomi/ChangeLog 2011-04-30 12:27:33 UTC (rev 44)
@@ -1,6 +1,16 @@
+2011-04-30 Fabrice Rossi <Fabrice dot Rossi at apiacoa dot org>
+
+ * src/neighborhood.c (neighborhood_single): new function that computes the neighborhood values around a single unit rather than around all units.
+
+ * src/neighborhood.h: header of the new function (see above).
+
+ * src/bmu.c (bmu_single_full_data): new function that computes the bmu for a vector given the full data.
+
+ * src/bmu.h: header of the new function (see above).
+
2010-10-22 Fabrice Rossi <Fabrice dot Rossi at apiacoa dot org>
- * man/sominit.pca.dist.Rd: added the weight parameters to the documention.
+ * man/sominit.pca.dist.Rd: added the weight parameters to the documention.
* demo/som-iris.R: fixed a parameter misspecification
@@ -12,7 +22,7 @@
2009-08-03 Fabrice Rossi <Fabrice dot Rossi at apiacoa dot org>
- * R/som.R (sominit.pca.default): first implementation of the weighted version of the PCA. Based on princomp, to be revised.
+ * R/som.R (sominit.pca.default): first implementation of the weighted version of the PCA. Based on princomp, to be revised.
* inst/doc/kernel.Rnw: started to work on this vignette
@@ -22,7 +32,7 @@
* R/kmeans.R (prototypes.random): the "cluster" method takes now into account the weights
- * man/sominit.random.Rd: modified to reflect the new rule for weighting values in random convex combinations.
+ * man/sominit.random.Rd: modified to reflect the new rule for weighting values in random convex combinations.
* R/kmeans.R (convex.prototypes.random): the "random" method takes now into account the weights
@@ -53,7 +63,7 @@
* DESCRIPTION (Suggests): colorspace is used in the vignettes
- * inst/doc/introduction.Rnw: added hierarchical clustering of the
+ * inst/doc/introduction.Rnw: added hierarchical clustering of the results.
* R/graphics.R (hitMap): use with.grid instead of with.cells for consistency
@@ -129,7 +139,7 @@
* NAMESPACE: new function
- * R/generic.R (batchkmeans): new generic function for kmeans
+ * R/generic.R (batchkmeans): new generic function for kmeans
* R/kmeans.R (batchkmeans.default): new file: kmeans implementations
@@ -500,7 +510,7 @@
* R/relational.R (predict.relationalsom): prediction for relational som (new function)
- * R/quality.R (error.quantisation.som): generic version when no new data is used.
+ * R/quality.R (error.quantisation.som): generic version when no new data is used.
(error.quantisation.somnum): numerical version
(error.quantisation.relationalsom): relational version
@@ -890,5 +900,5 @@
* demo/som-iris.R: updated this demo to use the distance.grid function
- * R/som.R (somPCAInit): fixed a small bug in the eigenvector attribution
+ * R/som.R (somPCAInit): fixed a small bug in the eigenvector attribution
Modified: trunk/yasomi/src/bmu.c
===================================================================
--- trunk/yasomi/src/bmu.c 2011-03-06 11:06:20 UTC (rev 43)
+++ trunk/yasomi/src/bmu.c 2011-04-30 12:27:33 UTC (rev 44)
@@ -169,3 +169,29 @@
}
+void bmu_single_full_data(double *proto,int *nproto,double *data,int *ndata,
+ int *dim,int *indiv,int *winner,double *error) {
+ double bestDist,dist,tmp;
+ int i=*indiv,j,k;
+ int bestSoFar;
+ int dataSize=*ndata,protoSize=*nproto,dimension=*dim;
+
+ bestDist = R_PosInf;
+ bestSoFar = -1;
+ /* loop on prototypes */
+ for(j = 0; j < protoSize; j++) {
+ dist = 0;
+ /* loop on dimensions */
+ for(k = 0; k < dimension; k++) {
+ tmp = data[i + k * dataSize] - proto[j + k * protoSize];
+ dist += tmp * tmp;
+ }
+ if(dist < bestDist) {
+ bestDist = dist;
+ bestSoFar = j;
+ }
+ }
+ *winner = bestSoFar;
+ *error = bestDist;
+}
+
Modified: trunk/yasomi/src/bmu.h
===================================================================
--- trunk/yasomi/src/bmu.h 2011-03-06 11:06:20 UTC (rev 43)
+++ trunk/yasomi/src/bmu.h 2011-04-30 12:27:33 UTC (rev 44)
@@ -18,5 +18,8 @@
void bmu_single(double *proto,int *nproto,double *one_data,int *dim,
int *winner,double *error);
+void bmu_single_full_data(double *proto,int *nproto,double *data,int *ndata,
+ int *dim,int *indiv,int *winner,double *error);
+
#endif /* !YASOMI_BMU_H */
Modified: trunk/yasomi/src/neighborhood.c
===================================================================
--- trunk/yasomi/src/neighborhood.c 2011-03-06 11:06:20 UTC (rev 43)
+++ trunk/yasomi/src/neighborhood.c 2011-04-30 12:27:33 UTC (rev 44)
@@ -45,3 +45,40 @@
}
}
}
+
+void neighborhood_single(double *distances,double *nv,int *nbUnit,
+ double *radius,int *kernelType,int *isNormalized)
+{
+ int i;
+ double tmp;
+ kernel_type eKernelType = (kernel_type) *kernelType;
+ int nb=*nbUnit;
+ double theRadius=*radius;
+
+ switch(eKernelType) {
+ case gaussian:
+ /* Gaussian kernel */
+ theRadius /= 3;
+ for(i = 0 ; i < nb; i++) {
+ tmp = distances[i]/theRadius;
+ nv[i] = exp (-0.5*tmp*tmp);
+ }
+ break;
+ case linear:
+ /* Linear kernel */
+ for(i = 0 ; i < nb; i++) {
+ tmp = distances[i];
+ nv[i] = tmp < theRadius ? (1-tmp/theRadius) : 0;
+ }
+ break;
+ }
+ if(*isNormalized) {
+ tmp = 0;
+ for(i = 0 ; i < nb; i++) {
+ tmp += nv[i];
+ }
+ for(i = 0 ; i < nb; i++) {
+ nv[i] /= tmp;
+ }
+ }
+}
Modified: trunk/yasomi/src/neighborhood.h
===================================================================
--- trunk/yasomi/src/neighborhood.h 2011-03-06 11:06:20 UTC (rev 43)
+++ trunk/yasomi/src/neighborhood.h 2011-04-30 12:27:33 UTC (rev 44)
@@ -9,4 +9,7 @@
void neighborhood(double *distances,double *nv,int nbUnit,double radius,
int kernelType,int isNormalized);
+void neighborhood_single(double *distances,double *nv,int *nbUnit,
+ double *radius,int *kernelType,int *isNormalized);
+
#endif /* !YASOMI_NEIGHBORHOOD_H */
More information about the Yasomi-commits
mailing list