summaryrefslogtreecommitdiffstats
path: root/DataStructure/ratioElem.java
blob: 365f2f8fe9b3542ff2a1f26063000d0d78045dec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package DataStructure;

class ratioElem {
	SingleBTS top;
	SingleBTS bottom;
	double ratioDL;
	double ratioUL;
	double varDL;
	double varUL;

	public ratioElem(SingleBTS top, SingleBTS bottom) {
		// if (top==null||bottom==null){
		// return null;
		// }

		this.top = top;
		this.bottom = bottom;

		// double topUL = top.getDldB();
		// double bottomUL = bottom.getDldB();

		// ratioDL = top.getDldB() - bottom.getDldB();
		ratioDL = top.getStrictDLdBAverage() - bottom.getStrictDLdBAverage();
		ratioUL = top.getUldB() - bottom.getUldB();
		// varDL = Math.sqrt(Math.pow(top.getVarianceDLdB(), 2));
		// - Math.pow(bottom.getVarianceDLdB(), 2));
		// varUL = Math.sqrt(Math.pow(top.getVarianceULdB(), 2)
		// - Math.pow(bottom.getVarianceULdB(), 2));
		varDL = top.getVarianceDLdB() + bottom.getVarianceDLdB();
		varUL = top.getVarianceULdB() + bottom.getVarianceULdB();
		// if (varDL != 0 && varDL != Double.NaN) {
		// System.out.println("var ungleich 0");
		// }
	}

	public String toString() {
		return "RatioDL: " + ratioDL + ", varDl: " + varDL + " (" + top.ARFCN
				+ "-" + bottom.ARFCN + ")";
	}

	public double probability(ratioElem vector) {

		if (top.ARFCN != vector.top.ARFCN
				|| bottom.ARFCN != vector.bottom.ARFCN) {
			System.out.println("Sortierung falsch!");
		}

		if (Double.isNaN(vector.ratioDL) || Double.isNaN(this.ratioDL)) {
			System.out.println("das sollte nicht passieren");
			if (Double.isNaN(vector.ratioDL) && Double.isNaN(this.ratioDL)) {
				// ratio between both bts cannot been built. This means top or
				// bottom bts is not received. let's say a cell phone has a poor
				// antenna, than this would not neccesarily mean that the
				// probability of beeing there is one. It can although be used
				// to
				// boost the probability
				return 1;
			} else
				return 0;
		}

		if (vector.varDL == 0 && this.varDL == 0) {
			if (Math.abs(vector.ratioDL - this.ratioDL) <= 1) {
				return 1;
			} else {
				return 0;
			}
		}

		/*
		 * if (this.ratioDL == Double.NaN && vector.ratioDL == Double.NaN) {
		 * return 1; } else if (this.ratioDL != Double.NaN && vector.ratioDL ==
		 * Double.NaN) { return Double.MIN_VALUE; } else if (this.ratioDL ==
		 * Double.NaN && vector.ratioDL != Double.NaN) { return
		 * Double.MIN_VALUE; } else if (this.ratioDL == 0 && vector.ratioDL ==
		 * 0) { return 1; } else if (this.ratioDL == 0 && vector.ratioDL ==
		 * Double.NaN) { return 1; } else if (this.ratioDL == Double.NaN &&
		 * vector.ratioDL == 0) { return 1; }
		 * 
		 * else
		 */if (vector.varDL == 0 && this.varDL != 0) {
			// compute just value at given point. No integration!
			double std = Math.sqrt(varDL);
			double x = vector.ratioDL;
			double u = this.ratioDL;
			double sqrtPI = Math.sqrt(2 * Math.PI);
			double exp = Math.exp(-0.5 * Math.pow((x - u) / std, 2));
			double result = (1 / (std * sqrtPI)) * exp;
			if (Double.isNaN(result))
				return 0;
			return result;
		} else if (this.varDL == 0 && vector.varDL != 0) {
			// compute just value at given point. No integration!
			double std = Math.sqrt(vector.varDL);
			double x = ratioDL;
			double u = vector.ratioDL;
			double sqrtPI = Math.sqrt(2 * Math.PI);
			double exp = Math.exp(-0.5 * Math.pow((x - u) / std, 2));
			double result = (1 / (std * sqrtPI)) * exp;
			if (Double.isNaN(result))
				return 0;
			return result;
		} else {
			// integration!
			// System.out.println("Integration now implemented!");
			return new NormDistribution(ratioDL, varDL)
					.intersection(new NormDistribution(vector.ratioDL,
							vector.varDL));

		}

	}

}