Jan-12-2020, 10:12 AM
It seems that my loop function does not work and I do not understand why..
I get a result 2 and I should get this list of number:2 2 2 2 1 2 1 1 2 1.
My code:
The clustering algorithm
Given a set of N measurements, (r1, r2, . . . , rN ), we will initially assign the odd-numbered measurements to
class 1 and the even numbered measurements to class 2. Then the following two steps are repeated:
• Update step: Compute the mean value (average) of the measurements within each cluster.
• Assignment step: Assign each measurement to the cluster with the closest mean value. In case of a tie,
assign the measurement to cluster 1.
Repeat the above steps until the cluster assignments do not change. It can not be determined in advance how
many steps will be needed before the clustering assignment stabilizes.
Problem definition
Create a function that takes as an input a vector of reflectance measurements and returns a vector of cluster
assignments computed using the algorithm described above.
Can anyone help me out? Thank you in advance for your help!
I get a result 2 and I should get this list of number:2 2 2 2 1 2 1 1 2 1.
My code:
import numpy as np import math def clusterAnalysis(reflectance): ref=np.size(reflectance) even1=np.any(ref %2==0) uneven1=np.any(ref%2>0) even2="2" uneven2="1" even3=(np.mean(even1)) uneven3=(np.mean(uneven1)) while ref==even1: clusterAssigments="2" if ref==uneven1: clusterAssigments="1" else:ref==even1 and ref==uneven3 clusterAssigments="2" return clusterAssigments print(clusterAnalysis(np.array([1.7, 1.6, 1.3, 1.3, 2.8, 1.4, 2.8, 2.6, 1.6, 2.7])))The assigment:
The clustering algorithm
Given a set of N measurements, (r1, r2, . . . , rN ), we will initially assign the odd-numbered measurements to
class 1 and the even numbered measurements to class 2. Then the following two steps are repeated:
• Update step: Compute the mean value (average) of the measurements within each cluster.
• Assignment step: Assign each measurement to the cluster with the closest mean value. In case of a tie,
assign the measurement to cluster 1.
Repeat the above steps until the cluster assignments do not change. It can not be determined in advance how
many steps will be needed before the clustering assignment stabilizes.
Problem definition
Create a function that takes as an input a vector of reflectance measurements and returns a vector of cluster
assignments computed using the algorithm described above.
Can anyone help me out? Thank you in advance for your help!