|
@@ -1,12 +1,6 @@
|
|
|
-import javafx.scene.layout.Pane;
|
|
|
-import javafx.stage.Stage;
|
|
|
-
|
|
|
-import javax.xml.transform.Result;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
public class MeanShift {
|
|
|
public ArrayList<Double> pointx;
|
|
@@ -74,7 +68,6 @@ public class MeanShift {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
public ArrayList<ResultDataType> MainLoop() throws FileNotFoundException {
|
|
|
ArrayList<Integer> numlist = new ArrayList<>();
|
|
|
ArrayList<Integer> numlist_used = new ArrayList<>();
|
|
@@ -83,28 +76,12 @@ public class MeanShift {
|
|
|
ArrayList<Integer> numlist_center = new ArrayList<>();
|
|
|
ArrayList<Double> centerx_history = new ArrayList<>();
|
|
|
ArrayList<Double> centery_history = new ArrayList<>();
|
|
|
-
|
|
|
-
|
|
|
-// ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numlist_used);
|
|
|
-// ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numlist_unused);
|
|
|
-// ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numlist_class);
|
|
|
-// ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numlist_center);
|
|
|
-// ArrayList<Integer> numlist_forcal = new ArrayList<>(numlist);
|
|
|
-
|
|
|
-
|
|
|
for (int i = 0; i < pointx.size() ; i++){
|
|
|
numlist.add(i);
|
|
|
}
|
|
|
numlist_unused = numlist;
|
|
|
- /////////////////////////////////////////ppppppppppppppppppppppppppp
|
|
|
-// Set<Integer> hashset = new HashSet<>();//?
|
|
|
int count_for_outside_loop = 0;
|
|
|
-
|
|
|
-
|
|
|
while (!numlist_unused.isEmpty()){
|
|
|
-// System.out.println(numlist_unused);
|
|
|
-// System.out.println("centerx_history is "+centerx_history);
|
|
|
-// System.out.println("centery_history is "+centery_history);
|
|
|
count_for_outside_loop = count_for_outside_loop + 1;
|
|
|
int num = PickUpAPointNum(numlist_unused);
|
|
|
ArrayList<Integer> NuminsideR = new ArrayList<>();
|
|
@@ -119,8 +96,6 @@ public class MeanShift {
|
|
|
int count_for_inside_loop = 0;
|
|
|
while(true){
|
|
|
count_for_inside_loop = count_for_inside_loop + 1;
|
|
|
-// System.out.println("!!!outside loop is " + count_for_outside_loop);
|
|
|
-// System.out.println("!!!inside loop is " + count_for_inside_loop);
|
|
|
NuminsideR = FindPointinsideR(centerx,centery);
|
|
|
double[] mh = CalculateMh(NuminsideR,centerx,centery);
|
|
|
centerx_next_test = centerx + mh[0];
|
|
@@ -136,53 +111,35 @@ public class MeanShift {
|
|
|
System.out.println("第 " + count_for_outside_loop + " 次外循环,漂移结束。");
|
|
|
break;
|
|
|
}
|
|
|
-// NuminsideR = FindPointinsideR(centerx,centery);
|
|
|
}
|
|
|
int max = 0;
|
|
|
int compare_density_count=0;
|
|
|
ArrayList<Integer> count_num_cd = new ArrayList<>();
|
|
|
-// System.out.println("head:centerx_history.size() is " + centerx_history.size());
|
|
|
for(int i = 0 ; i < centerx_history.size();i++){
|
|
|
-// int max;
|
|
|
- /////////////
|
|
|
if(CalculateDistance(centerx,centery,centerx_history.get(i),centery_history.get(i)) < 2*R){
|
|
|
count_num_cd.add(i);
|
|
|
-// System.out.println("count_num_cd.add " + i);
|
|
|
}
|
|
|
else {
|
|
|
-// System.out.println("centerx and centery is " + centerx + " " + centery);
|
|
|
-// System.out.println("centerx_history and centery_history is " + centerx_history.get(i) + " " + centery_history.get(i));
|
|
|
-// System.out.println("the distance is " + CalculateDistance(centerx,centery,centerx_history.get(i),centery_history.get(i)));
|
|
|
-// System.out.println(" the num in ");
|
|
|
-
|
|
|
max += 1;
|
|
|
}
|
|
|
- /////////////
|
|
|
}
|
|
|
-// System.out.println("max is" + max);
|
|
|
if(max == centerx_history.size()){
|
|
|
System.out.println("第 " + count_for_outside_loop + " 次外循环。该循环的圆心和历史收敛圆心距离大于2R。");
|
|
|
-
|
|
|
-// result.add(new ResultDataType(NuminsideR));
|
|
|
centerx_history.add(centerx);
|
|
|
centery_history.add(centery);
|
|
|
numlist_center.add(num);
|
|
|
numlist_class.addAll(NuminsideR);
|
|
|
-
|
|
|
ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numlist_used);
|
|
|
ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numlist_unused);
|
|
|
ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numlist_class);
|
|
|
ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numlist_center);
|
|
|
ArrayList<Integer> numlist_forcal = new ArrayList<>(numlist);
|
|
|
-
|
|
|
numlist_class_forcal.removeAll(numlist_center_forcal);
|
|
|
numlist_center_forcal.addAll(numlist_center_forcal);
|
|
|
-
|
|
|
numlist_used_forcal = numlist_center_forcal;
|
|
|
numlist_forcal.removeAll(numlist_used_forcal);
|
|
|
numlist_unused_forcal = numlist_forcal;
|
|
|
numlist_unused = numlist_unused_forcal;
|
|
|
-// numlist_unused.remove(inital_num);
|
|
|
}
|
|
|
else{
|
|
|
ArrayList<Integer> cd_NuminsideR = new ArrayList<>();
|
|
@@ -198,82 +155,38 @@ public class MeanShift {
|
|
|
ArrayList<Double> centery_history_to_disappear = new ArrayList<>();
|
|
|
for(int i = 0 ; i < temp_for_count_num_cd ; i++){
|
|
|
if(NuminsideR.size() > cd_NuminsideR.get(i)){
|
|
|
-// ArrayList<Integer> centerx_history_forcal = new ArrayList<>(centerx_history);
|
|
|
-// System.out.println("NuminsideR.size() is " + NuminsideR.size());
|
|
|
-// System.out.println("cd_NuminsideR.get(i) is " + cd_NuminsideR.get(i));
|
|
|
compare_density_count = compare_density_count + 1;
|
|
|
-
|
|
|
-// System.out.println("i is " + i);
|
|
|
-// System.out.println("count_num_cd.get(i) is " + count_num_cd.get(i) );
|
|
|
-// System.out.println("tail:centerx_history.size() is " + centerx_history.size());
|
|
|
-// System.out.println("tail:centerx_history is " + centerx_history);
|
|
|
-// System.out.println("centerx_history.get(count_num_cd.get(i)) " + centerx_history.get(count_num_cd.get(i)));
|
|
|
-// System.out.println("centerx_history.get(count_num_cd.get(i)) is " +centerx_history.get(count_num_cd.get(i)));
|
|
|
-
|
|
|
ArrayList<Integer> the_circle_disappear= FindPointinsideR(centerx_history.get(count_num_cd.get(i)),centery_history.get(count_num_cd.get(i)));
|
|
|
centerx_history_to_disappear.add(centerx_history.get(count_num_cd.get(i)));
|
|
|
centery_history_to_disappear.add(centery_history.get(count_num_cd.get(i)));
|
|
|
- ///////////////////////////////////////////////
|
|
|
- //p
|
|
|
-// centerx_history.remove((int)count_num_cd.get(i));
|
|
|
-// centery_history.remove((int)count_num_cd.get(i));
|
|
|
- //p
|
|
|
- ///////////////////////////////////////////////
|
|
|
-
|
|
|
- ///////////
|
|
|
-// System.out.println("the i is : " + i);
|
|
|
-// System.out.println("count_num_cd before remove is " + count_num_cd);
|
|
|
- ////////////////////////////////////
|
|
|
-// count_num_cd.remove(i);
|
|
|
- ///////////////////////////////////
|
|
|
-// System.out.println("count_num_cd after remove is " + count_num_cd);
|
|
|
- ////////////
|
|
|
-// System.out.println("for test !!!!!!!!!!" + the_circle_disappear);
|
|
|
numlist_class.removeAll((ArrayList<Integer>)the_circle_disappear);
|
|
|
-// numlist_unused.remove(inital_num);
|
|
|
}
|
|
|
}
|
|
|
for(int i = 0 ; i < centerx_history_to_disappear.size(); i++){
|
|
|
centerx_history.remove(centerx_history_to_disappear.get(i));
|
|
|
centery_history.remove(centery_history_to_disappear.get(i));
|
|
|
}
|
|
|
-
|
|
|
if(compare_density_count == cd_NuminsideR.size()){
|
|
|
System.out.println("当前收敛圆比和它重叠的历史收敛的圆密度都大");
|
|
|
- /////////////////////////////
|
|
|
-// for(int i = 0; i < count_num_cd.size(); i++){
|
|
|
-// ArrayList<Integer> the_circle_disappear= FindPointinsideR(centerx_history.get(count_num_cd.get(i)),centery_history.get(count_num_cd.get(i)));
|
|
|
-// centerx_history.remove((int)count_num_cd.get(i));
|
|
|
-// centery_history.remove((int)count_num_cd.get(i));
|
|
|
-// numlist_class.removeAll(the_circle_disappear);
|
|
|
-// }
|
|
|
- //////////////////////////////////
|
|
|
centerx_history.add(centerx);
|
|
|
centery_history.add(centery);
|
|
|
numlist_center.add(num);
|
|
|
numlist_class.addAll(NuminsideR);
|
|
|
-
|
|
|
ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numlist_used);
|
|
|
ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numlist_unused);
|
|
|
ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numlist_class);
|
|
|
ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numlist_center);
|
|
|
ArrayList<Integer> numlist_forcal = new ArrayList<>(numlist);
|
|
|
-
|
|
|
numlist_class_forcal.removeAll(numlist_center_forcal);
|
|
|
numlist_center_forcal.addAll(numlist_center_forcal);
|
|
|
numlist_used_forcal = numlist_center_forcal;
|
|
|
numlist_forcal.removeAll(numlist_used_forcal);
|
|
|
numlist_unused_forcal = numlist_forcal;
|
|
|
numlist_unused = numlist_unused_forcal;
|
|
|
-// numlist_unused.remove(inital_num);
|
|
|
}
|
|
|
}
|
|
|
numlist_unused.remove((Integer)inital_num);
|
|
|
-// System.out.println(numlist_unused);
|
|
|
}
|
|
|
-// System.out.println("centerxlist is" + centerx_history);
|
|
|
-// System.out.println("centerylist is" + centery_history);
|
|
|
-///////////////////////////////////////////
|
|
|
for(int i = 0 ; i < centerx_history.size();i++){
|
|
|
ArrayList<Integer> out_NuminsideR = FindPointinsideR(centerx_history.get(i),centery_history.get(i));
|
|
|
result.add(new ResultDataType(out_NuminsideR));
|
|
@@ -291,7 +204,6 @@ public class MeanShift {
|
|
|
TestData_OutPut.println(centerx_history.get(i) + " " + centery_history.get(i));
|
|
|
}
|
|
|
TestData_OutPut.close();
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
|