public double EuclideanDistance(IrisItem irisITem) { return Math.Sqrt(Math.Pow(irisITem.PanjangSepal - PanjangSepal, 2) + Math.Pow(irisITem.LebarSepal - LebarSepal, 2) + Math.Pow(irisITem.PanjangPetal - PanjangPetal, 2) + Math.Pow(irisITem.LebarPetal - LebarPetal, 2)); }
public double[] countHiddenValue(IrisItem irisItem, Matrix gausianMatrix, int jumlahCluster) { double[] hiddenValue = new double[jumlahCluster]; double[] iris = irisItem.toArray(); double[,] gausian = gausianMatrix.ToArray(); for (int i = 0; i < jumlahCluster; i++) { double temp = 0; for (int j = 0; j < iris.Length; j++) { temp += (iris[j] * gausianMatrix[i, j]); } temp = 1 / (1 + Math.Exp(-1 * temp)); temp = (temp > 0.6) ? 1 : 0; hiddenValue[i] = temp; } return hiddenValue; }
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { listIrisItem.Clear(); using (System.IO.StreamReader reader = new System.IO.StreamReader(openFileDialog1.FileName)) { try { while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] arrayItem = line.Split(new char[1] {','}); double temp = 0d; IrisItem item = new IrisItem(); item.Nama = arrayItem[4]; item.PanjangSepal = (double.TryParse(arrayItem[0], out temp)) ? temp : 0; item.LebarSepal = (double.TryParse(arrayItem[1], out temp)) ? temp : 0; item.PanjangPetal = (double.TryParse(arrayItem[2], out temp)) ? temp : 0; item.LebarPetal = (double.TryParse(arrayItem[3], out temp)) ? temp : 0; item.setTarget(); listIrisItem.Add(item); } } catch (Exception ex) { General.ShowError(ex.Message); } } txtFilePath.Text = openFileDialog1.FileName; DisplayData(); }
public Matrix getBobot(IrisItem item, List<ClusterItem> listCluster) { double[,] temp = new double[listCluster.Count, 4]; double[] iris = item.toArray(); for (int i = 0; i < listCluster.Count; i++) { for (int j = 0; j < iris.Length; j++) { temp[i, j] = getBobot(listCluster[i].toArray(), iris[j], getVariance(listCluster[i].toArray(), listCluster.Count)); } } Matrix gausianMatrix = DenseMatrix.OfArray(temp); return gausianMatrix; }