Algoritma fuzzy c means fcm java c++ contoh program
-
Upload
ymygrexcomp -
Category
Education
-
view
529 -
download
57
Transcript of Algoritma fuzzy c means fcm java c++ contoh program
Contoh Program Source Code /
Algoritma Fuzzy C-Means FCM Java C++
Algoritma Fuzzy C-Means FCM Java C++
Fuzzy C-Means (FCM)Fuzzy C-Means (FCM) adl salah satu algoritma fuzzy clustering. Fuzzy
C-Means (FCM) adl suatu teknik pengclusteran data yg keberadaan setiaptitik data dlm suatu cluster ditentukan oleh derajat keanggotaan. Teknik inipertama kali diperkenalkan oleh Jim Bezdek pd tahun 1981.
Konsep dasar FCM yaitu menentukan pusat cluster , yg akanmenandai lokasi rata-rata unt setiap cluster. dg cara memperbaiki pusatcluster & derajat keanggotaan setiap titik data secara berulang, maka akandapat dilihat bahwa pusat cluster akan bergerak menuju lokasi yg tepat.Perulangan ini didasarkan pd pada minimisasi fungsi obyektif ygmenggambarkan jarak dr titik data yg diberikan ke pusat cluster ygterbobot oleh derajat keanggotaan titik data tsb.
Algoritma Fuzzy C-Means (FCM) Java C++
Algoritma Fuzzy C-Means FCM Java C++
Logika fuzzy pertama kali dikembangkan oleh Lot섙ௐ A. Zadeh ,seorang ilmuan Amerika Serikat berkebangsaan Iran dr universitasCalifornia di Barkeley, melalui tulisannya pd tahun 1965.( Munir, R. 2005).
Fuzzy secara bahasa diartikan sbg kabur / samar-samar. Suatu nilaidapat bernilai benar / salah secara bersamaan. dlm fuzzy dikenal derajatkeanggotaan yg memiliki rentang nilai 0 (nol) hingga 1(satu). Berbeda dghimpunan tegas yg memiliki nilai 1 / 0 (ya / tidak).
Logika fuzzy adl suatu cara yg tepat unt memetakan suatu ruanginput kedalam suatu ruang output , mempunyai nilai kontinyu. Fuzzydinyatakan dlm derajat dr suatu keanggotaan & derajat dr kebenaran.Oleh sebab itu sesuatu dapat dikatakan sebagian benar & sebagian salahpd waktu yg sama (Kusumadewi. 2003).
ClusteringClustering adl suatu metode pengelompokan berdasarkan ukuran
kedekatan (kemiripan).Clustering beda dg group, kalau group berartikelompok yg sama,kondisinya kalau tdk ya pasti bukankelompoknya.Tetapi kalau cluster tdk harus sama akan tetapipengelompokannya berdasarkan pd kedekatan dr suatu karakteristiksample yg ada
Macam-macam metode clustering :
CARI TUTORIAL + SOURCE CODE
GIVE YOUR SUPPORT
6,1 rb orang menyukai ini. Jadilah yangpertama di antara teman Anda.
Suka
ARTIKEL TERKAIT
.
LIST TUTORIAL
Berbasis Metode Statistikk
Algoritma Genetika TSP DenganJava
Tutorial Kriptogra섙ௐ Dengan JavaC++
Naive Bayes Classi섙ௐcation VisualBasic
Kriptogra섙ௐ Rijndael AES Java C++Python
Pengenalan Wajah DenganEigenface
Metode Secant C/C++ Java
PCA Pengenalan WajahEigenface (Face Recognition)
Naive Bayes Classi섙ௐcation JavaVB
Travelling Salesman problem(TSP) C/C++
Algoritma Fuzzy C-Means FCMJava C++
ACO
Adaboost
Adaptive Resonance Theory
Fuzzy C-MeansFuzzy clustering adl proses menentukan derajat keanggotaan , &
kemudian memakainya dg memasukkannya kedalam elemen datakedalam satu kelompok cluster / lebih.
Hal ini akan memberikan informasi kesamaan dr setiap objek. Satu drsekian banyaknya algoritma fuzzy clustering yg dipakai adl algoritma fuzzyclustering c means. Vektor dr fuzzy clustering, V={v1, v2, v3,…, vc} ,adl sebuah fungsi objektif yg di defenisikan dg derajat keanggotaan drdata Xj & pusat cluster Vj .
Algoritma fuzzy clustering c means membagi data yg tersedia dr setiapelemen data berhingga lalu memasukkannya kedalam bagian dr koleksicluster yg dipengaruhi oleh beberapa kriteria yg diberikan. Berikan satukumpulan data berhingga. X= {x1,…, xn } & pusat data.
Dimana μ ij adl derajat keanggotaan dr Xj & pusat cluster adlsebuah bagian dr keanggotaan matriks [μ ij] . d2 adalahakar drEuclidean distance & m adl parameter fuzzy yg rata-rata derajat kekaburandr setiap data derajat keanggotaan tdk lebih besar dr 1,0 Ravichandran(2009).
Output dr Fuzzy C-Means adl deretan pusat cluster & beberapa derajatkeanggotaan unt tiap-tiap titik data. Informasi ini dapat dipakai untmembangun suatu fuzzy inference system .
Output dr FCM bukan adl fuzzy inference system, namun adl deretanpusat cluster & beberapa derajat keanggotaan unt tiap-tiap titik data.Informasi ini dapat dipakai unt membangun suatu fuzzy inference system.
Algoritma Fuzzy C-means clustering adl sbg berikut :
1. Menentukan:
Matriks X yg adl data yg akan dicluster, berukuran k x j, dg k =jumlah data yg akan di-cluster & j = jumlah variabel/atribut (kriteria).
2. Menentukan :
a. Jumlah cluster yg akan dibentuk (n >c ≥ 2). b. pembobot (w > 1) . c. Maksimum iterasi (max n) .
Hirarchical clustering method : pd kasus untjumlah kelompok blm ditentukan terlebih dulu,contoh data-data hasil survey kuisioner. Macam-metode jenis ini: Single Lingkage,CompleteLinkage,Average Linkage dll.
Non Hirarchical clustering method : Jumlahkelompok telah ditentukan terlebih dulu.Metode ygdipakai : K-Means.
Berbasis Fuzzy : Fuzzy CMeans
Berbasis Neural Network : Kohonen SOM, LVQ
Metode lain unt optimasi centroid / lebar cluster : Genetik Algoritma (GA)
Advanced Encryption Standard
AES
Agglomerative Clustering
AHP
Analytical Hierarchy Process
ANFIS
ANN
Annealing
Ant Colony Optimization
Aplikasi n-Tier
Apriori
ARIMA (Box-Jenkins)
Aritmetika Modulo
ART
Arti섙ௐcial Bee Colony (ABC)
Arti섙ௐcial Neural Network
B-Tree
Backpropagation
Bacterial foraging optimizationalgorithm (BFOA)
Bayesian Network
Bi-Polar Slope One
Biometrik
Bit-Plane Complexity
Blind signature
Blow섙ௐsh
BPCS
Breadth-First Search ( BFS )
Brute Force
Buble Sort
Burrows WheelerTransformation
BWT
C-Means
C4.5
Caesar
CART (Classi섙ௐcation AndRegression Trees)
Case Based Reasoning
CBR
Certainty Factor (CF)
Cipher
Cipher Block Chaining (CBC)
CISM
Clonal Selection
CLONALG
Clustering
COBIT
d. Kriteria penghentian/treshold ( ɛ = nilai positif yg sangat kecil). e. Menentukan fungsi obyektif awal ( P0 ).
3. Membentuk matriks partisi awal U (derajat keanggotaan dlmcluster) dg ukuran k x i; matriks partisi biasanya dibuat acak, , dg k =jumlah data yg akan di-cluster & i = jumlah cluster
4. Hitung pusat cluster ( V ) unt setiap cluster, memakai rumus :
Keterangan :
Vij = pusat cluster pd cluster ke-i & atribut ke-j. μik = data partisi (pada matriks U) pd cluster ke-i & data
ke-k. Xk j = data (pada matriks U) pd atribut ke-j & data ke-k. w = pembobot.
5. Hitung nilai obyektif ( Pn ) dg rumus :
Keterangan :
μik = data partisi (pada matriks U) pd cluster ke-i & datake-k.
dik = fungsi ukuran jarak unt jarak Euclidean pd pusatcluster ke-i & data ke-k.
w = pembobot. Pn = nilai obyektif pd iterasi ke-n.
6. Perbaiki derajat keanggotaan setiap data pd setiap cluster (perbaikimatriks partisi)
dengan :
Keterangan :
μik = data partisi (pada matriks U) pd pusat cluster ke-i& data ke-k.
dik = fungsi ukuran jarak unt jarak Euclidean pd pusatcluster ke-i & data ke-k.
djk = fungsi ukuran jarak unt jarak Euclidean pd pusatcluster ke-j & data ke-k.
w = pembobot. Xkj = data (pada matriks U) pd atribut ke-j & data ke-k.
7. Menghentikan iterasi jika pusat cluster V tdk berubah. Alternatifkriteria penghentian adalah jika perubahan nilai error kurang dr treshold
Conjugate Gradient
CRC
Cyclic Redundancy Code
Data Encryption Standard ( DES )
Data Mining
DCPChiper
Delta Rule
Deteksi Mata
Deteksi Wajah
Digital Signal Processing (DSP)
Digital Signature
Dijkstra
Discrete Cosine Transform (DCT)
Discrete Wavelet Transform
Djikstra
DTW
Dynamic Source Routing
ECDSA
Eigenface
Elgamal
Elliptic Curve Cryptography(ECC)
Enkripsi Dekripsi
Enterprise Resource Planning
ERP
Euclid
Expectation Maximization
Extendible Hashing
Face Detection
Face Extractor
Face Recognition
Fast Data Encipherment ( FEAL )
FCFS
FCM
Filterbank
Fireꍹجحتy FA
First Come First Server
Fisherface
Floyd Warshall
Forecasting
Forward Chaining
FP-Growth
Fuzzy
Fuzzy ART
Fuzzy C-Means
|Pn - Pn-1| < ɛ . Alternatif adl ketika perulangan melebihi maksimumiterasi ( n > max n) . Jika iterasi blm berhenti, kembali ke langkah 4.
8. Jika iterasi berhenti, ditentukan cluster dr tiap-tiap data . Cluster dipilihberdasarkan nilai matriks partisi terbesar.
CONTOH PROGRAM
JAVA : Contoh Program Algoritma Fuzzy C-Means(FCM) Berikut ini adalah contoh penerapan program implementasi algoritmafuzzy c-means dengan menggunakan bahasa pemrograman Java.
Source Code Java
1. import java.awt.Point;
2. import java.awt.image.ColorModel;
3. import java.awt.image.DataBuffer;
4. import java.awt.image.Raster;
5. import java.awt.image.SampleModel;
6. import java.awt.image.WritableRaster;
7. import java.util.Random;
8. import javax.media.jai.PlanarImage;
9. import javax.media.jai.TiledImage;
10. import com.sun.media.jai.codecimpl.util.RasterFactory;
11. import common.ImageProcessingTask;
12.
13. /**
14. * This class implements a basic Fuzzy C‐Means clustering algorithm as an
15. * image processing task.
16. */
17. public class FuzzyCMeansImageClustering extends ImageProcessingTask
18. {
19. // A copy of the input image.
20. private PlanarImage pInput;
21. // The input image dimensions.
22. private int width,height,numBands;
23. // Some clustering parameters.
24. private int maxIterations,numClusters;
25. // The FCM additional parameters and membership function values.
26. private float fuzziness; // "m"
27. private float[][][] membership;
28. // The iteration counter will be global so we can get its value on the
29. // middle of the clustering process.
30. private int iteration;
31. // A metric of clustering "quality", called "j" as in the equations.
32. private double j = Float.MAX_VALUE;
33. // A small value, if the difference of the cluster "quality" does not
34. // changes beyond this value, we consider the clustering converged.
35. private double epsilon;
36. // This flag will be true when the clustering has finished.
37. private boolean hasFinished = false;
38. private long position;
39. // The cluster centers.
Gauss-Jordan
Gaussian
Generate & Test
Genetika
Graph Coloring
greedy
Green Computing
Guaranteed Scheduling (GS)
Haar Cascade Classi섙ௐer
Hash
Hash Satu Arah
Hidden Markov Model (HMM)
Histogram Equalization
Hopcroft Tarjan Planarity
Hopcroft–Karp
Hop섙ௐeld
Hu㗊喟man
Hybrid
ID3 (Iterative Dichotomiser 3)
Identity Based Encryption
image processing
Implementasi
Independent ComponentAnalysis (ICA)
Iris Recognition
IS Strategic Planning
Jaringan Syaraf Tiruan (JST)
Josephus Problem
JST
K-means
K-Nearest Neighbors (KNN)
KASUMI
knowledge management
Kohonen
kriptogra섙ௐ
Kruskal
Latent Semantic Indexing
Least Signi섙ௐcant Bit (LSB)
Linear Programming
Linked List
Logika Fuzzy
LOKI
LOOK
Low Bit Coding
LSB
LSI
Mac
40. private float[][] clusterCenters;
41. // A big array with all the input data and a small one for a single pixel.
42. private int[] inputData;
43. private float[] aPixel;
44. // A big array with the output data (cluster indexes).
45. private short[][] outputData;
46.
47. /**
48. * The constructor for the class, which sets the input image, the number of
49. * desired clusters, the maximum number of iterations, the fuzziness ("m"
50. * value) and a value that will be used to decide whether the convergence
51. * has stopped. It also allocates the required memory.
52. */
53. public FuzzyCMeansImageClustering(PlanarImage pInput,int numClusters,int maxIterations,
54. float fuzziness,double epsilon)
55. {
56. this.pInput = pInput;
57. // Get the image dimensions.
58. width = pInput.getWidth();
59. height = pInput.getHeight();
60. numBands = pInput.getSampleModel().getNumBands();
61. // Get some clustering parameters.
62. this.numClusters = numClusters;
63. this.maxIterations = maxIterations;
64. this.fuzziness = fuzziness;
65. this.epsilon = epsilon;
66. iteration = 0;
67. // We need arrays to store the clusters' centers, validity tags and membership values.
68. clusterCenters = new float[numClusters][numBands];
69. membership = new float[width][height][numClusters];
70. // Gets the raster for the input image.
71. Raster raster = pInput.getData();
72. // Gets the whole image data on memory. Get memory for a single pixel too.
73. inputData = new int[width*height*numBands];
74. aPixel = new float[numBands];
75. // Gets memory for the output data (cluster indexes).
76. outputData = new short[width][height];
77. raster.getPixels(0,0,width,height,inputData);
78. // Initialize the membership functions randomly.
79. Random generator = new Random(); // easier to debug if a seed is used
80. // For each data point (in the membership function table)
81. for(int h=0;h<height;h++)
82. for(int w=0;w<width;w++)
83. {
84. // For each cluster's membership assign a random value.
85. float sum = 0f;
86. for(int c=0;c<numClusters;c++)
87. {
88. membership[w][h][c] = 0.01f+generator.nextFloat();
89. sum += membership[w][h][c];
90. }
Maksimum Likelihood
Mamdani
MANET
MDF
Mel-frequency CepstrumCoe▢톌cients (MFCC)
Metode Fisherface
Metode Gra섙ௐk
metode LSB
Metode Mamdani
Metode Secant
MFCC
Minimax
Minimum Spanning Tree
mobile
Mobile Ad hoc Network
Modi섙ௐed Direction Feature
Monte Carlo
MTVRP
Naive Bayes
Naive Bayes Classi섙ௐer
negascout
Neural Network
Newton Raphson
One Way Hash
Online Learning
Open Shortest Path First
Open System Interconnection
Optimasi
OS X
OSI
OSPF
Otsu
Pagerank
Parity Coding
Particle Swarm Optimization(PSO)
Pattern Recognition
PCA
Pemrograman Linear
Pencarian Akar
Pencarian Jalur Terpendek
Pencarian Linear
Pencocokan Sidik Jari
Pengenalan Iris Mata
Pengenalan Objeck
Pengenalan Pola
91. // Normalize so the sum of MFs for a particular data point will be equal to 1.
92. for(int c=0;c<numClusters;c++) membership[w][h][c] /= sum;
93. }
94. // Initialize the global position value.
95. position = 0;
96. }
97.
98. /**
99. * This method performs the bulk of the processing. It runs the classic
100. * Fuzzy C‐Means clustering algorithm:
101. */
102. public void run()
103. {
104. double lastJ;
105. // Calculate the initial objective function just for kicks.
106. lastJ = calculateObjectiveFunction();
107. // Do all required iterations (until the clustering converges)
108. for(iteration=0;iteration<maxIterations;iteration++)
109. {
110. // Calculate cluster centers from MFs.
111. calculateClusterCentersFromMFs();
112. // Then calculate the MFs from the cluster centers !
113. calculateMFsFromClusterCenters();
114. // Then see how our objective function is going.
115. j = calculateObjectiveFunction();
116. if (Math.abs(lastJ‐j) < epsilon) break;
117. lastJ = j;
118. } // end of the iterations loop.
119. hasFinished = true;
120. // Means that all calculations are done, too.
121. position = getSize();
122. }
123.
124. /**
125. * This method calculates the cluster centers from the membership
126. * functions.
127. */
128. private void calculateClusterCentersFromMFs()
129. {
130. float top,bottom;
131. // For each band and cluster
132. for(int b=0;b<numBands;b++)
133. for(int c=0;c<numClusters;c++)
134. {
135. // For all data points calculate the top and bottom parts of the equation.
136. top = bottom = 0;
137. for(int h=0;h<height;h++)
138. for(int w=0;w<width;w++)
139. {
140. // Index will help locate the pixel data position.
141. int index = (h*width+w)*numBands;
142. top += Math.pow(membership[w][h][c],fuzziness)*inputData[index+b];
Pengenalan Suara
Pengenalan Ucapan
Pengenalan Wajah
Pengolahan Citra
Pengolahan Citra Digital
Pengukuran Garis-Garis TelapakTangan
Penjadwalan
Penjadwalan CPU
Peramalan
Perataan Histogram
Perceptron
Persamaan Linier
Pewarnaan Graf
Pewarnaan Simpul Graph
Pohon Hu㗊喟man
Prim
Principal Component Analisys
Quantum
Random Waypoint
RC4
RC6
real time tracking
Recognition
Recurrent Neural Network
Recursive Best First Search(RBFS)
Recursive Large First
Recursive Largest First
Region of Interest (ROI)
Rijndael
Risk Management
RLF
RMSE
RNN
Root Mean square Error
RSA
RWP
SAFER
Secant
Secret Sharing Scheme
Secure And Fast EncryptionRoutine (SAFER)
Self Organizing Map (SOM)
Semut
SHA (Secure Hash Algorithm)
SHA-256
Sidik Jari
.
143. bottom += Math.pow(membership[w][h][c],fuzziness);
144. }
145. // Calculate the cluster center.
146. clusterCenters[c][b] = top/bottom;
147. // Upgrade the position vector (batch).
148. position += width*height;
149. }
150. }
151.
152. /**
153. * This method calculates the membership functions from the cluster
154. * centers.
155. */
156. private void calculateMFsFromClusterCenters()
157. {
158. float sumTerms;
159. // For each cluster and data point
160. for(int c=0;c<numClusters;c++)
161. for(int h=0;h<height;h++)
162. for(int w=0;w<width;w++)
163. {
164. // Get a pixel (as a single array).
165. int index = (h*width+w)*numBands;
166. for(int b=0;b<numBands;b++)
167. aPixel[b] = inputData[index+b];
168. // Top is the distance of this data point to the cluster being read.
169. float top = calcDistance(aPixel,clusterCenters[c]);
170. // Bottom is the sum of distances from this data point to all clusters.
171. sumTerms = 0f;
172. for(int ck=0;ck<numClusters;ck++)
173. {
174. float thisDistance = calcDistance(aPixel,clusterCenters[ck]);
175. sumTerms += Math.pow(top/thisDistance,(2f/(fuzziness‐1f)));
176. }
177. // Then the MF can be calculated as...
178. membership[w][h][c] =
179. (float)(1f/sumTerms);
180. // Upgrade the position vector (batch).
181. position += (numBands+numClusters);
182. }
183. }
184.
185. /*
186. * This method calculates the objective function ("j") which reflects the
187. * quality of the clustering.
188. */
189. private double calculateObjectiveFunction()
190. {
191. double j = 0;
192. // For all data values and clusters
193. for(int h=0;h<height;h++)
194. for(int w=0;w<width;w++)
195. for(int c=0;c<numClusters;c++)
196. {
Simulated Annealing
SISP
Sistem Biometrika
Sistem Veri섙ௐkasi Biometrik
Slope One
Slope One predictors
sorting
Source Code
Spanning Tree
Speech
Speech Recognition
Steganogra섙ௐ
Steganography
Stream Cipher
Support Vector Machine (SVM)
Tabu Search
Tanda Tangan Digital
Technopreneurship
Teorema Bayes
Thresholding
Transformasi Burrows Wheeler
Transformasi Fourier
Transformasi Wavelet Diskrit
Transformasi Wavelet Kontinu
Traveling Salesman Problem
Travelling Salesman (TSP)
Travelling Salesman problem
TSP
Tsukamoto
Two섙ௐsh
Vernam Cipher
Video Encryption Algorithm(VEA)
Video Watermarking
Vigenere Cipher
Viola Jones
Voice Recognition
Watermarking
WDM
Web Service
Weighted Slope One
Welch dan Powell
Welsh Powell
WMS
197. // Get the current pixel data.
198. int index = (h*width+w)*numBands;
199. for(int b=0;b<numBands;b++)
200. aPixel[b] = inputData[index+b];
201. // Calculate the distance between a pixel and a cluster center.
202. float distancePixelToCluster = calcDistance(aPixel,clusterCenters[c]);
203. j += distancePixelToCluster*Math.pow(membership[w][h][c],fuzziness);
204. // Upgrade the position vector (batch).
205. position += (2*numBands);
206. }
207. return j;
208. }
209.
210. /**
211. * This method calculates the Euclidean distance between two N‐dimensional
212. * vectors.
213. */
214. private float calcDistance(float[] a1,float[] a2)
215. {
216. float distance = 0f;
217. for(int e=0;e<a1.length;e++) distance += (a1[e]‐a2[e])*(a1[e]‐a2[e]);
218. return (float)Math.sqrt(distance);
219. }
220.
221. /**
222. * This method returns the estimated size (steps) for this task.
223. */
224. public long getSize()
225. {
226. // Return the estimated size for this task:
227. return (long)maxIterations* // The maximum number of iterations times
228. (
229. (numClusters*width*height*(2*numBands))+ // Step 0 of method run()
230. (width*height*numBands*numClusters)+ // Step 1 of method run()
231. (numClusters*width*height*(numBands+numClusters))+ // Step 2 of run()
232. (numClusters*width*height*(2*numBands)) // Step 3 of method run()
233. );
234. }
235.
236. /**
237. * This method returns a measure of the progress of the algorithm.
238. */
239. public long getPosition()
240. {
241. return position;
242. }
243.
244. /**
245. * This method returns true if the clustering has finished.
246. */
247. public boolean isFinished()
248. {
249. return (position == getSize());
250. }
251.
252. /**
253. * This method will return a rank image, i.e. an image which pixels are
254. * the cluster centers of the Nth best choice for the classification.
255. */
256. public TiledImage getRankedImage(int rank)
257. {
258. // Create a SampleModel for the output data (same number of bands as the input image).
259. SampleModel sampleModel =
260. RasterFactory.createBandedSampleModel(DataBuffer.TYPE_INT,width,height,numBands);
261. // Create a WritableRaster using that sample model.
262. WritableRaster raster =
263. RasterFactory.createWritableRaster(sampleModel,new Point(0,0));
264. // A pixel array will contain all bands for a specific x,y.
265. int[] pixelArray = new int[numBands];
266. // For all pixels in the image...
267. for(int h=0;h<height;h++)
268. for(int w=0;w<width;w++)
269. {
270. // Get the class (cluster center) for that pixel with the specified rank.
271. int aCluster = getRankedIndex(membership[w][h],rank);
272. // Fill the array with that cluster center.
273. for(int band=0;band<numBands;band++) pixelArray[band] = (int)clusterCenters[aCluster][band];
274. // Put it on the raster.
275. raster.setPixel(w,h,pixelArray);
276. }
277. // Set the raster on the output image.
278. TiledImage pOutput = new TiledImage(pInput,false);
279. pOutput.setData(raster);
280. return pOutput;
281. }
282.
283. /**
284. * This method will return a membership function image, i.e.
285. */
286. public TiledImage getRankedMFImage(int rank)
287. {
288. // Create a SampleModel for the output data (1 band only).
289. SampleModel sampleModel =
290. RasterFactory.createBandedSampleModel(DataBuffer.TYPE_BYTE,
291. width,height,1);
292. // Create a compatible ColorModel.
293. ColorModel colorModel = PlanarImage.createColorModel(sampleModel);
294. // Create a WritableRaster.
295. WritableRaster raster =
296. RasterFactory.createWritableRaster(sampleModel,new Point(0,0));
297. // For all pixels in the image...
298. for(int h=0;h<height;h++)
299. for(int w=0;w<width;w++)
300. {
301. // Get the membership function (considering the rank) for that pixel.
302. int aCluster = (int)(255*getRankedMF(membership[w][h],rank));
303. // Put it on the raster.
304. raster.setPixel(w,h,new int[]{aCluster});
305. }
306. // Set the raster on the output image.
307. TiledImage pOutput = new TiledImage(0,0,width,height,0,0,sampleModel,colorModel);
308. pOutput.setData(raster);
309. return pOutput;
310. }
311.
312. /**
313. * This method returns the ranked index of a cluster from an array
314. * containing the membership functions.
315. */
316. private int getRankedIndex(float[] data,int rank)
317. {
318. // Create temporary arrays for the indexes and the data.
319. int[] indexes = new int[data.length];
320. float[] tempData = new float[data.length];
321. // Fill those arrays.
322. for(int i=0;i<indexes.length;i++)
323. {
324. indexes[i] = i;
325. tempData[i] = data[i];
326. }
327. // Sort both arrays together, using data as the sorting key.
328. for(int i=0;i<indexes.length‐1;i++)
329. for(int j=i;j<indexes.length;j++)
330. {
331. if (tempData[i] < tempData[j])
332. {
333. int tempI= indexes[i];
334. indexes[i] = indexes[j];
335. indexes[j] = tempI;
336. float tempD = tempData[i];
337. tempData[i] = tempData[j];
338. tempData[j] = tempD;
339. }
340. }
341. // Return the cluster index for the rank we want.
342. return indexes[rank];
343. }
344.
345. /**
346. * This method returns the ranked membership function of a cluster
347. */
348. private float getRankedMF(float[] data,int rank)
349. {
350. // Create temporary arrays for the indexes and the data.
351. int[] indexes = new int[data.length];
352. float[] tempData = new float[data.length];
353. // Fill those arrays.
354. for(int i=0;i<indexes.length;i++)
355. {
356. indexes[i] = i;
357. tempData[i] = data[i];
358. }
359. // Sort both arrays together, using data as the sorting key.
360. for(int i=0;i<indexes.length‐1;i++)
361. for(int j=i;j<indexes.length;j++)
362. {
363. if (tempData[i] < tempData[j])
364. {
365. int tempI= indexes[i];
366. indexes[i] = indexes[j];
367. indexes[j] = tempI;
368. float tempD = tempData[i];
369. tempData[i] = tempData[j];
370. tempData[j] = tempD;
371. }
372. }
373. // Return the cluster index for the rank we want.
374. return tempData[rank];
375. }
376.
377. /**
378. * This method returns the Partition Coefficient measure of cluster validity
379. */
380. public double getPartitionCoefficient()
381. {
382. double pc = 0;
383. // For all data values and clusters
384. for(int h=0;h<height;h++)
385. for(int w=0;w<width;w++)
386. for(int c=0;c<numClusters;c++)
387. pc += membership[w][h][c]*membership[w][h][c];
388. pc = pc/(height*width);
389. return pc;
390. }
391.
392. /**
393. * This method returns the Partition Entropy measure of cluster validity
394. */
395. public double getPartitionEntropy()
396. {
397. double pe = 0;
398. // For all data values and clusters
399. for(int h=0;h<height;h++)
400. for(int w=0;w<width;w++)
401. for(int c=0;c<numClusters;c++)
402. pe += membership[w][h][c]*Math.log(membership[w][h][c]);
403. pe = ‐pe/(height*width);
404. return pe;
405. }
406.
407. /**
408. * This method returns the Compactness and Separation measure of cluster validity
C++ : Contoh Program Algoritma Fuzzy C-Means(FCM) Berikut ini adalah contoh penerapan program implementasi algoritmafuzzy c-means dengan menggunakan bahasa pemrograman C++.
FCM.C
409. */
410. public double getCompactnessAndSeparation()
411. {
412. double cs = 0;
413. // For all data values and clusters
414. for(int h=0;h<height;h++)
415. for(int w=0;w<width;w++)
416. {
417. // Get the current pixel data.
418. int index = (h*width+w)*numBands;
419. for(int b=0;b<numBands;b++)
420. aPixel[b] = inputData[index+b];
421. for(int c=0;c<numClusters;c++)
422. {
423. // Calculate the distance between a pixel and a cluster center.
424. float distancePixelToCluster = calcSquaredDistance(aPixel,clusterCenters[c]);
425. cs += membership[w][h][c]*membership[w][h][c]*
426. distancePixelToCluster*distancePixelToCluster;
427. }
428. }
429. cs /= (height*width);
430. // Calculate minimum distance between ALL clusters
431. float minDist = Float.MAX_VALUE;
432. for(int c1=0;c1<numClusters‐1;c1++)
433. for(int c2=c1+1;c2<numClusters;c2++)
434. {
435. float distance = calcSquaredDistance(clusterCenters[c1],clusterCenters[c2]);
436. minDist = Math.min(minDist,distance);
437. }
438. cs = cs/(minDist*minDist);
439. return cs;
440. }
441.
442. /**
443. * This method calculates the squared distance between two N‐dimensional
444. */
445. private float calcSquaredDistance(float[] a1,float[] a2)
446. {
447. float distance = 0f;
448. for(int e=0;e<a1.length;e++) distance += (a1[e]‐a2[e])*(a1[e]‐a2[e]);
449. return (float)distance;
450. }
451.
452. }
453.
Source Code C++
1. #define MAX_DATA_POINTS 10000
2. #define MAX_CLUSTER 100
3. #define MAX_DATA_DIMENSION 5
4. #include <math.h>
5. #include <stdio.h>
6. #include <stdlib.h>
7. #include <string.h>
8.
9. int num_data_points;
10. int num_clusters;
11. int num_dimensions;
12. double low_high[MAX_DATA_DIMENSION][2];
13. double degree_of_memb[MAX_DATA_POINTS][MAX_CLUSTER];
14. double epsilon;
15. double fuzziness;
16. double data_point[MAX_DATA_POINTS][MAX_DATA_DIMENSION];
17. double cluster_centre[MAX_CLUSTER][MAX_DATA_DIMENSION];
18.
19. int
20. init(char *fname) {
21. int i, j, r, rval;
22. FILE *f;
23. double s;
24. if ((f = fopen(fname, "r")) == NULL) {
25. printf("Gagal membuka file input.");
26. return ‐1;
27. }
28. fscanf(f, "%d %d %d", &num_data_points, &num_clusters, &num_dimensions);
29. if (num_clusters > MAX_CLUSTER) {
30. printf("Jumlah cluster harus < %d\n", MAX_CLUSTER);
31. goto failure;
32. }
33. if (num_data_points > MAX_DATA_POINTS) {
34. printf("Jumlah titik data harus < %d\n", MAX_DATA_POINTS);
35. goto failure;
36. }
37. if (num_dimensions > MAX_DATA_DIMENSION) {
38. printf("Jumlah dimensi harus >= 1.0 and < %d\n",
39. MAX_DATA_DIMENSION);
40. goto failure;
41. }
42. fscanf(f, "%lf", &fuzziness);
43. if (fuzziness <= 1.0) {
44. printf("Koefisien Fuzzyness harus > 1.0\n");
45. goto failure;
46. }
47. fscanf(f, "%lf", &epsilon);
48. if (epsilon <= 0.0 || epsilon > 1.0) {
49. printf("Kriteria terminasi harus > 0.0 and <= 1.0\n");
50. goto failure;
51. }
52. for (i = 0; i < num_data_points; i) {
53. for (j = 0; j < num_dimensions; j) {
54. fscanf(f, "%lf", &data_point[i][j]);
55. if (data_point[i][j] < low_high[j][0])
56. low_high[j][0] = data_point[i][j];
57. if (data_point[i][j] > low_high[j][1])
58. low_high[j][1] = data_point[i][j];
59. }
60. }
61. for (i = 0; i < num_data_points; i) {
62. s = 0.0;
63. r = 100;
64. for (j = 1; j < num_clusters; j) {
65. rval = rand() % (r 1);
66. r ‐= rval;
67. degree_of_memb[i][j] = rval / 100.0;
68. s = degree_of_memb[i][j];
69. }
70. degree_of_memb[i][0] = 1.0 ‐ s;
71. }
72. fclose(f);
73. return 0;
74. failure:
75. fclose(f);
76. exit(1);
77. }
78.
79. int
80. calculate_centre_vectors() {
81. int i, j, k;
82. double numerator, denominator;
83. double t[MAX_DATA_POINTS][MAX_CLUSTER];
84. for (i = 0; i < num_data_points; i) {
85. for (j = 0; j < num_clusters; j) {
86. t[i][j] = pow(degree_of_memb[i][j], fuzziness);
87. }
88. }
89. for (j = 0; j < num_clusters; j) {
90. for (k = 0; k < num_dimensions; k) {
91. numerator = 0.0;
92. denominator = 0.0;
93. for (i = 0; i < num_data_points; i) {
94. numerator = t[i][j] * data_point[i][k];
95. denominator = t[i][j];
96. }
97. cluster_centre[j][k] = numerator / denominator;
98. }
99. }
100. return 0;
101. }
102.
103. double
104. get_norm(int i, int j) {
105. int k;
106. double sum = 0.0;
107. for (k = 0; k < num_dimensions; k) {
108. sum = pow(data_point[i][k] ‐ cluster_centre[j][k], 2);
109. }
110. return sqrt(sum);
111. }
112.
113. double
114. get_new_value(int i, int j) {
115. int k;
116. double t, p, sum;
117. sum = 0.0;
118. p = 2 / (fuzziness ‐ 1);
119. for (k = 0; k < num_clusters; k) {
120. t = get_norm(i, j) / get_norm(i, k);
121. t = pow(t, p);
122. sum = t;
123. }
124. return 1.0 / sum;
125. }
126.
127. double
128. update_degree_of_membership() {
129. int i, j;
130. double new_uij;
131. double max_diff = 0.0, diff;
132. for (j = 0; j < num_clusters; j) {
133. for (i = 0; i < num_data_points; i) {
134. new_uij = get_new_value(i, j);
135. diff = new_uij ‐ degree_of_memb[i][j];
136. if (diff > max_diff)
137. max_diff = diff;
138. degree_of_memb[i][j] = new_uij;
139. }
140. }
141. return max_diff;
142. }
143.
144. int
145. fcm(char *fname) {
146. double max_diff;
147. init(fname);
148. do {
149. calculate_centre_vectors();
150. max_diff = update_degree_of_membership();
151. } while (max_diff > epsilon);
152. return 0;
153. }
154.
155. int
156. gnuplot_membership_matrix() {
157. int i, j, cluster;
158. char fname[100];
159. double highest;
160. FILE * f[MAX_CLUSTER];
161. if (num_dimensions != 2) {
162. printf("Merencanakan cluster hanya bekerja ketika\n");
163. printf("jumlah dimensi adl dua. Ini akan membuat\n");
164. printf("plot dua dimensi poin klaster.\n");
165. exit(1);
166. }
167. for (j = 0; j < num_clusters; j) {
168. sprintf(fname, "cluster.%d", j);
169. if ((f[j] = fopen(fname, "w")) == NULL) {
170. printf("Tidak dapat membuat %s\n", fname);
171. for (i = 0; i < j; i) {
172. fclose(f[i]);
173. sprintf(fname, "cluster.%d", i);
174. remove(fname);
175. }
176. return ‐1;
177. }
178. fprintf(f[j], "#Titik data unt klaster: %d\n", j);
179. }
180. for (i = 0; i < num_data_points; i) {
181. cluster = 0;
182. highest = 0.0;
183. for (j = 0; j < num_clusters; j) {
184. if (degree_of_memb[i][j] > highest) {
185. highest = degree_of_memb[i][j];
186. cluster = j;
187. }
188. }
189. fprintf(f[cluster], "%lf %lf\n", data_point[i][0], data_point[i][1]);
190. }
191. for (j = 0; j < num_clusters; j) {
192. fclose(f[j]);
193. }
194. if ((f[0] = fopen("gnuplot.script", "w")) == NULL) {
195. printf("Tidak dapat membuat gnuplot.script.\n");
196. for (i = 0; i < j; i) {
197. fclose(f[i]);
198. sprintf(fname, "cluster.%d", i);
199. remove(fname);
200. }
201. return ‐1;
202. }
203. fprintf(f[0], "set terminal png medium\n");
204. fprintf(f[0], "set output \"cluster_plot.png\"\n");
205. fprintf(f[0], "set title \"FCM clustering\"\n");
206. fprintf(f[0], "set xlabel \"x‐coordinate\"\n");
207. fprintf(f[0], "set ylabel \"y‐coordinate\"\n");
208. fprintf(f[0], "set xrange [%lf : %lf]\n", low_high[0][0], low_high[0][1]);
209. fprintf(f[0], "set yrange [%lf : %lf]\n", low_high[1][0], low_high[1][1]);
210. fprintf(f[0],
211. "plot 'cluster.0' using 1:2 with points pt 7 ps 1 lc 1 notitle");
212. for (j = 1; j < num_clusters; j) {
213. sprintf(fname, "cluster.%d", j);
214. fprintf(f[0],
215. ",\\\n'%s' using 1:2 with points pt 7 ps 1 lc %d notitle",
216. fname, j 1);
217. }
218. fprintf(f[0], "\n");
219. fclose(f[0]);
220. return 0;
221. }
222.
223. void
224. print_data_points(char *fname) {
225. int i, j;
226. FILE *f;
227. if (fname == NULL)
228. f = stdout;
229. else if ((f = fopen(fname, "w")) == NULL) {
230. printf("Cannot create output file.\n");
231. exit(1);
232. }
233. fprintf(f, "Data points:\n");
234. for (i = 0; i < num_data_points; i) {
235. printf("Data[%d]: ", i);
236. for (j = 0; j < num_dimensions; j) {
237. printf("%.5lf ", data_point[i][j]);
238. }
239. printf("\n");
240. }
241. if (fname == NULL)
242. fclose(f);
243. }
244.
245. void
246. print_membership_matrix(char *fname) {
247. int i, j;
248. FILE *f;
249. if (fname == NULL)
250. f = stdout;
251. else if ((f = fopen(fname, "w")) == NULL) {
252. printf("Cannot create output file.\n");
253. exit(1);
254. }
255. fprintf(f, "Membership matrix:\n");
256. for (i = 0; i < num_data_points; i) {
257. fprintf(f, "Data[%d]: ", i);
258. for (j = 0; j < num_clusters; j) {
259. fprintf(f, "%lf ", degree_of_memb[i][j]);
260. }
261. fprintf(f, "\n");
262. }
263. if (fname == NULL)
264. fclose(f);
265. }
266.
267. int
268. main(int argc, char **argv) {
269. printf
270. ("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n");
271. if (argc != 2) {
272. printf("USAGE: fcm <input file>\n");
273. exit(1);
274. }
275. fcm(argv[1]);
276. printf("Jumlah titik data: %d\n", num_data_points);
277. printf("Jumlah cluster: %d\n", num_clusters);
278. printf("Jumlah dimensi data titik: %d\n", num_dimensions);
279. printf("Margin akurasi: %lf\n", epsilon);
280. print_membership_matrix("membership.matrix");
281. gnuplot_membership_matrix();
282. printf
283. ("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n");
gen.c
Source Code C++
284. printf("Program berhasil dijalankan...\n");
285. printf("Menyimpan matriks keanggotaan dlm file 'membership.matrix'\n\n");
286. printf("Jika poin di bidang (2 dimensi)\n");
287. printf("script gnuplot dihasilkan dlm file 'gnuplot.script', and\n");
288. printf("data gnuplot dlm file klaster.[0]... \n\n");
289. printf
290. ("Proses 'gnuplot.script' to generate graph: 'cluster_plot.png'\n\n");
291. printf
292. ("CATATAN: Sementara menghasilkan data gnuplot, unt masing‐masing titik data\n");
293. printf("cluster yg sesuai adl salah satu yg memiliki tertinggi\n");
294. printf("derajat keanggotaan ditemukan di 'membership.matrix'.\n");
295. printf
296. ("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n");
297. return 0;
298. }
299.
1. /**
2. * Ini menghasilkan data unt menguji algoritma FCM.
3. */
4. #include <math.h>
5. #include <stdio.h>
6. #include <stdlib.h>
7. #include <string.h>
8.
9. /* Jumlah maksimum cluster diperbolehkan oleh implementasi ini. */
10. #define MAX_CLUSTER 100
11.
12. /* Jumlah maksimum titik data yg harus dihasilkan. */
13. #define MAX_DATA 10000
14.
15. /* Jumlah maksimum dimensi dr data titik. */
16. #define MAX_DATA_DIMENSION 5
17.
18. int main(int argc, char **argv) {
19. int n, c, d, i, j;
20. int l[MAX_DATA_DIMENSION], h[MAX_DATA_DIMENSION];
21. double epsilon, m;
22. FILE *f;
23. if (argc != 2) {
24. printf("memakai: gen <filename>\n");
25. exit(1);
26. }
27. printf("\nProgram ini menghasilkan titik data acak\n");
28. printf("untuk menguji algoritma FCM.\n\n");
29. do {
30. printf("Masukkan jumlah titik data.\n");
31. printf("Nilai harus >= 1 & < %d: ", MAX_DATA);
HOME JASA PROGRAMMER HARGA ORDER ABOUT TUTORIAL
32. if (scanf("%d", &n) == EOF)
33. continue;
34. } while (n < 1 || n > MAX_DATA);
35. do {
36. printf("Masukkan jumlah cluster.\n");
37. printf("Nilai harus >= 2 and < %d: ", MAX_CLUSTER);
38. if (scanf("%d", &c) == EOF)
39. continue;
40. } while (c < 2 || c > MAX_CLUSTER);
41. do {
42. printf("asukkan kriteria terminasi (epsilon).\n");
43. printf("Nilai harus >= 0.0 & <= 1.0: ");
44. if (scanf("%lf", &epsilon) == EOF)
45. continue;
46. } while (epsilon < 0 || epsilon > 1.0);
47. do {
48. printf("Masukkan koefisien fuzzyness.\n");
49. printf("Nilai harus > 1.0: ");
50. if (scanf("%lf", &m) == EOF)
51. continue;
52. } while (m <= 1.0);
53. do {
54. printf("Masukkan jumlah dimensi.\n");
55. printf("Nilai harus >= 1 & < %d: ", MAX_DATA_DIMENSION);
56. if (scanf("%d", &d) == EOF)
57. continue;
58. } while (d < 1 || d > MAX_DATA_DIMENSION);
59. printf("\nProgram ini akan menghasilkan acak titik data dg memakai\n");
60. printf("terendah & tertinggi nilai diperbolehkan unt dimensi tertentu.\n");
61. printf("Nilai tertinggi harus lebih besar dr nilai terendah\n");
62. printf("untuk dimensi tertentu.\n");
63. for (i = 0; i < d; i) {
64. do {
65. printf("Masukkan nilai terendah unt dimensi [%d]: ", i);
66. if (scanf("%d", &l[i]) == EOF)
67. continue;
68. printf("Masukkan nilai tertinggi unt dimensi[%d]: ", i);
69. if (scanf("%d", &h[i]) == EOF)
70. continue;
71. } while (l[i] >= h[i]);
72. }
73.
74. if ((f = fopen(argv[1], "w")) == NULL) {
75. printf("Gagal membuat file data baru bernama %s\n", argv[1]);
76. exit(1);
77. }
78. fprintf(f, "%d %d %d\n", n, c, d);
79. fprintf(f, "%lf %lf\n", m, epsilon);
80. for (i = 0; i < n; i) {
81. for (j = 0; j < d; j) {
82. fprintf(f, "%d ", (rand() % (h[j] ‐ l[j] + 1)) + l[j]);
83. }
84. fprintf(f, "\n");
85. }
86. fclose(f);
87. return 0;
4
Suka
1
POSTING LEBIH BARU POSTING LAMA
Konsultasi GratisJika ada yang ingin di tanyakan, Kamu bisa melakukan konsultasigratis kepada team metode-algoritma.com melalui form di bawah.Mohon isi email dengan benar, karena hasil konsultasi akan dikirimkan ke email kamu.
Name: *
EMail: *
Subject: *
Message: *
Send message!
All fields marked with * are required.
Metode Algoritma
Email: [email protected]
Indonesia Mampang Raya XII No. 30 A Jakarta, Indonesia sms :(+62) 85625 49338
Singapore 238B Thomson Road #17-00 Tower B Novena Square Singapore sms :(+65) 6415 3540
Company
Tentang Kami Fakta serta Figur Mengapa memilih kami Model Pengerjaan Aplikasi Model Konsultasi Prosedur serta Proses kerjasama Pertanyaan serta Jawaban Persetujuan
88. }
89.
Testimonials Contact Sitemap Blog Tutorial + Source Code
Service
Jasa murah programmer : pembuatan program untuk umum dan mahasiswa ( Tesis, Skripsi, Tugas Akhir )
JAKARTA BANDUNG SURABAYA YOGYAKARTA MALANG PALEMBANG SEMARANG MEDAN BOGOR BALI DENPASAR LAMPUNG SOLOSURABAYA BANDUNG
Portfolio
Implementasi Algoritma Steganogra섙ௐ Kriptogra섙ௐ Watermaking Keamanan Data Pengenalan Objek Wajah Suara Wavelet Quantization Implentasi Model Forecasting Implementasi Data Minging Kecerdasan Buatan (AI) Decision Support Systems Sistem Ahli (ES) Implementasi Shortest Path Mikrotik serta Robotika Networking Keamanan Jaringan Histogram Pemetaan Mobile Expert System Dan lainnya
Technology
C# .NetPHPAS3 Java Delphi Matlab Objective C Visual Basic iOS Android Blackberry Symbian OS Windows Phone
Copyright © 2013 metode-algoritma.com Allright Reserved|about|sitemap|