Skip to content

Commit

Permalink
cluster: remove commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
gilliek committed Oct 4, 2017
1 parent d8b819a commit f6b92c6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
7 changes: 1 addition & 6 deletions cluster/kmodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (km *KModes) FitModel(X *mat.Dense) error {
// Perform initial centers update - because iteration() starts with label
// assignements.
for i := 0; i < km.ClustersNumber; i++ {
//find new values for clusters centers
// Find new values for clusters centers.
newCentroid := make([]float64, xCols)
for j := 0; j < xCols; j++ {
val, empty := findHighestMapValue(km.FrequencyTable[i][j])
Expand All @@ -112,16 +112,11 @@ func (km *KModes) FitModel(X *mat.Dense) error {
km.ClusterCentroids.SetRow(i, newCentroid)
}

//var lastCost float64
//lastCost = math.MaxFloat64

for i := 0; i < km.MaxIterationNumber; i++ {
_, change, err := km.iteration(X)
if err != nil {
return fmt.Errorf("KMeans error at iteration %d: %v", i, err)
}
//lastCost = cost
//if cost > lastCost || change == false {
if change == false {

km.IsFitted = true
Expand Down
20 changes: 0 additions & 20 deletions cluster/kprototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,11 @@ func (km *KPrototypes) FitModel(X *mat.Dense) error {
km.ClusterCentroidsNum.SetRow(i, newCenter)
}

//var lastCost float64
//lastCost = math.MaxFloat64

for i := 0; i < km.MaxIterationNumber; i++ {
_, change, err := km.iteration(xNum, xCat)
if err != nil {
return fmt.Errorf("KMeans error at iteration %d: %v", i, err)
}
//lastCost = cost
//if cost > lastCost || change == false {
if change == false {
km.IsFitted = true
return nil
Expand All @@ -200,7 +195,6 @@ func (km *KPrototypes) iteration(xNum, xCat *mat.Dense) (float64, bool, error) {

// Find closest cluster for all data vectors - assign new labels.
xRowsNum, xNumCols := xNum.Dims()
//xRowsCat, xColsCat := xCat.Dims()
_, xColsCat := xCat.Dims()

for i := 0; i < xRowsNum; i++ {
Expand Down Expand Up @@ -235,20 +229,6 @@ func (km *KPrototypes) iteration(xNum, xCat *mat.Dense) (float64, bool, error) {

}

/*//check for empty clusters - if such cluster is found reassign the center and return
for i := 0; i < km.ClustersNumber; i++ {
if km.LabelsCounter[i] == 0 {
fmt.Println("oh no, there is an empty cluster! ", km.ClusterCentroidsCat.RowView(i))
num := rand.Intn(xRowsCat)
vectorCat := xCat.RawRowView(num)
vectorNum := xNum.RawRowView(num)
fmt.Println("New vectors are: ", vectorCat, vectorNum)
km.ClusterCentroidsCat.SetRow(i, vectorCat)
km.ClusterCentroidsNum.SetRow(i, vectorNum)
return totalCost, true, nil
}
}*/

// Recompute cluster centers for all clusters with changes.
for i, elem := range changed {
if elem == true {
Expand Down

0 comments on commit f6b92c6

Please sign in to comment.