Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Make this Java Function (selectBestKmeans2Cluster) into a algorithm. The one thing I need you to do is try to minimize the algorithm so that it
Make this Java Function (selectBestKmeans2Cluster) into a algorithm. The one thing I need you to do is try to minimize the algorithm so that it doesn't exceed 35 lines or a maximum of 40 lines and use the notations & algorithm should be like the image given below. 1. "private Double[] selectBestKmeans2Cluster() { int KMEANS_PERIOD = 50; ArrayListcluster1 = new ArrayList (); ArrayList cluster2 = new ArrayList (); Double[] cluster1Center = new Double[]{(double) (MapConsts.MAP_HEIGHT / 2), 0d}; Double[] cluster2Center = new Double[]{(double) (-1 * MapConsts.MAP_HEIGHT / 2), 0d}; String start_time = formatter.format(date); for (int i = 0; i (1 - diffWeightRation) || (1 + diffWeightRation) > clusterSumWeightRatio) && clusterCentersDist > MIN_CLUSTER_CENTER_DIST) { instantRelocateByBeacon = true; } clusterCenters = new Double[][]{ cluster1Center, cluster2Center, }; if (cluster1Weight > cluster2Weight) { return cluster1Center; } else { return cluster2Center; } } public void applyLandmarkProximityMeasurements(ArrayList importantNearBeacons) { for (Particle particle : this.particles) { // Log.e(TAG, "Prob before update:"+particle.probability); particle.updateProbs(importantNearBeacons); // Log.e(TAG, "Prob after update:"+particle.probability); } normalizeWeights(); // Todo: I didn't research about influence of Neff and its related resampling effects double Neff = calc_Neff(); if (this.numParticles (); particlesHistory.addAll(particles); } } public ArrayList > getParticles(int randomParticleFactor) { ArrayList > particlesData = new ArrayList >(); for (int i = 0; i tempParticleData = new ArrayList (); tempParticleData.add(particle.x); tempParticleData.add(particle.y); tempParticleData.add(particle.h); particlesData.add(tempParticleData); } } // // for (Particle particle : particles) { // ArrayList tempParticleData = new ArrayList (); // tempParticleData.add(particle.x); // tempParticleData.add(particle.y); // tempParticleData.add(particle.h); // particlesData.add(tempParticleData); // } return particlesData; } public void normalizeWeights() { Double sumWeight = 0d; for (Particle particle : this.particles) { sumWeight += particle.probability; } for (Particle particle : this.particles) { particle.probability /= sumWeight; } particlesHistory = new ArrayList (); particlesHistory.addAll(particles); } public double calc_Neff() { double sumSqrProb = 0d; for (Particle particle : this.particles) { sumSqrProb += Math.sqrt(particle.probability); } return 1.0d / sumSqrProb; } @Override public String toString() { String res = ""; for (int i = 0; i Algorithm 1: K-Means Algorithm Input: E = {C1, C2, ..., en} (set of entities to be clustered) k (number of clusters) MaxIters (limit of iterations) Output: C = {C1,C2, ..., Ci} (set of cluster centroids) L = {lle) e = 1,2,...,n} (set of cluster labels of E) foreach c EC do | Ci - ej e E (e.g. random selection) end foreach e; e E do | le:) - argmin Distance(:, C;) {i...k} end changed false; iter 0; repeat foreach CEC do | UpdateCluster(c); end foreach ei e E do min Dist - argmin Distance lei, ci) je {1...k}; if min Dist Elle) then (e;) - min Dist; changed - true; end end iter + + until changed = true and iter S Max Iters; Algorithm 1: K-Means Algorithm Input: E = {C1, C2, ..., en} (set of entities to be clustered) k (number of clusters) MaxIters (limit of iterations) Output: C = {C1,C2, ..., Ci} (set of cluster centroids) L = {lle) e = 1,2,...,n} (set of cluster labels of E) foreach c EC do | Ci - ej e E (e.g. random selection) end foreach e; e E do | le:) - argmin Distance(:, C;) {i...k} end changed false; iter 0; repeat foreach CEC do | UpdateCluster(c); end foreach ei e E do min Dist - argmin Distance lei, ci) je {1...k}; if min Dist Elle) then (e;) - min Dist; changed - true; end end iter + + until changed = true and iter S Max Iters
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started