Skip to content

Commit cfe9cd7

Browse files
committed
7-11
0 parents  commit cfe9cd7

35 files changed

+939
-0
lines changed

.classpath

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_45"/>
5+
<classpathentry kind="lib" path="lib/jts-1.8.jar"/>
6+
<classpathentry kind="lib" path="lib/macrofocus-common.jar"/>
7+
<classpathentry kind="lib" path="lib/macrofocus-data.jar"/>
8+
<classpathentry kind="lib" path="lib/poi-3.5-FINAL.jar"/>
9+
<classpathentry kind="lib" path="lib/poi-ooxml-3.5-FINAL.jar"/>
10+
<classpathentry kind="lib" path="lib/xom-1.2.10.jar"/>
11+
<classpathentry kind="lib" path="lib/jxl.jar"/>
12+
<classpathentry kind="output" path="bin"/>
13+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>ProbabilisticCube</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

.~lock.test2.xls#

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,root,localhost.localdomain,11.07.2015 09:09,file:///root/.config/libreoffice/4;
4.07 KB
Binary file not shown.

bin/edu/pcube/convolution/FFT.class

3.38 KB
Binary file not shown.

bin/edu/pcube/cube/Cube.class

1.35 KB
Binary file not shown.

bin/edu/pcube/cube/Cuboid.class

7.67 KB
Binary file not shown.

bin/edu/pcube/cube/Dimensions.class

997 Bytes
Binary file not shown.
3.65 KB
Binary file not shown.
Binary file not shown.
1.21 KB
Binary file not shown.

bin/edu/pcube/example/Sample.xls

420 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

bin/edu/pcube/util/Data.class

3.92 KB
Binary file not shown.

lib/jts-1.8.jar

473 KB
Binary file not shown.

lib/jxl.jar

709 KB
Binary file not shown.

lib/macrofocus-common.jar

255 KB
Binary file not shown.

lib/macrofocus-data.jar

791 KB
Binary file not shown.

lib/poi-3.5-FINAL.jar

1.45 MB
Binary file not shown.

lib/poi-ooxml-3.5-FINAL.jar

382 KB
Binary file not shown.

lib/xom-1.2.10.jar

306 KB
Binary file not shown.
+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package edu.pcube.convolution;
2+
3+
public class Complex {
4+
private final double re; // the real part
5+
private final double im; // the imaginary part
6+
7+
// create a new object with the given real and imaginary parts
8+
public Complex(double real, double imag) {
9+
re = real;
10+
im = imag;
11+
}
12+
13+
// return a string representation of the invoking Complex object
14+
public String toString() {
15+
if (im == 0) return re + "";
16+
if (re == 0) return im + "i";
17+
if (im < 0) return re + " - " + (-im) + "i";
18+
return re + " + " + im + "i";
19+
}
20+
21+
// return abs/modulus/magnitude and angle/phase/argument
22+
public double abs() { return Math.hypot(re, im); } // Math.sqrt(re*re + im*im)
23+
public double phase() { return Math.atan2(im, re); } // between -pi and pi
24+
25+
// return a new Complex object whose value is (this + b)
26+
public Complex plus(Complex b) {
27+
Complex a = this; // invoking object
28+
double real = a.re + b.re;
29+
double imag = a.im + b.im;
30+
return new Complex(real, imag);
31+
}
32+
33+
// return a new Complex object whose value is (this - b)
34+
public Complex minus(Complex b) {
35+
Complex a = this;
36+
double real = a.re - b.re;
37+
double imag = a.im - b.im;
38+
return new Complex(real, imag);
39+
}
40+
41+
// return a new Complex object whose value is (this * b)
42+
public Complex times(Complex b) {
43+
Complex a = this;
44+
double real = a.re * b.re - a.im * b.im;
45+
double imag = a.re * b.im + a.im * b.re;
46+
return new Complex(real, imag);
47+
}
48+
49+
// scalar multiplication
50+
// return a new object whose value is (this * alpha)
51+
public Complex times(double alpha) {
52+
return new Complex(alpha * re, alpha * im);
53+
}
54+
55+
// return a new Complex object whose value is the conjugate of this
56+
public Complex conjugate() { return new Complex(re, -im); }
57+
58+
// return a new Complex object whose value is the reciprocal of this
59+
public Complex reciprocal() {
60+
double scale = re*re + im*im;
61+
return new Complex(re / scale, -im / scale);
62+
}
63+
64+
// return the real or imaginary part
65+
public double re() { return re; }
66+
public double im() { return im; }
67+
68+
// return a / b
69+
public Complex divides(Complex b) {
70+
Complex a = this;
71+
return a.times(b.reciprocal());
72+
}
73+
74+
// return a new Complex object whose value is the complex exponential of this
75+
public Complex exp() {
76+
return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
77+
}
78+
79+
// return a new Complex object whose value is the complex sine of this
80+
public Complex sin() {
81+
return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re) * Math.sinh(im));
82+
}
83+
84+
// return a new Complex object whose value is the complex cosine of this
85+
public Complex cos() {
86+
return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
87+
}
88+
89+
// return a new Complex object whose value is the complex tangent of this
90+
public Complex tan() {
91+
return sin().divides(cos());
92+
}
93+
94+
95+
96+
// a static version of plus
97+
public static Complex plus(Complex a, Complex b) {
98+
double real = a.re + b.re;
99+
double imag = a.im + b.im;
100+
Complex sum = new Complex(real, imag);
101+
return sum;
102+
}
103+
104+
105+
106+
// sample client for testing
107+
public static void main(String[] args) {
108+
Complex a = new Complex(5.0, 6.0);
109+
Complex b = new Complex(-3.0, 4.0);
110+
111+
System.out.println("a = " + a);
112+
System.out.println("b = " + b);
113+
System.out.println("Re(a) = " + a.re());
114+
System.out.println("Im(a) = " + a.im());
115+
System.out.println("b + a = " + b.plus(a));
116+
System.out.println("a - b = " + a.minus(b));
117+
System.out.println("a * b = " + a.times(b));
118+
System.out.println("b * a = " + b.times(a));
119+
System.out.println("a / b = " + a.divides(b));
120+
System.out.println("(a / b) * b = " + a.divides(b).times(b));
121+
System.out.println("conj(a) = " + a.conjugate());
122+
System.out.println("|a| = " + a.abs());
123+
System.out.println("tan(a) = " + a.tan());
124+
}
125+
126+
}

src/edu/pcube/convolution/FFT.java

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package edu.pcube.convolution;
2+
3+
import java.util.Arrays;
4+
5+
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
6+
7+
8+
public class FFT {
9+
10+
// compute the FFT of x[], assuming its length is a power of 2
11+
public static Complex[] fft(Complex[] x) {
12+
int N = x.length;
13+
14+
// base case
15+
if (N == 1) return new Complex[] { x[0] };
16+
17+
// radix 2 Cooley-Tukey FFT
18+
if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); }
19+
20+
// fft of even terms
21+
Complex[] even = new Complex[N/2];
22+
for (int k = 0; k < N/2; k++) {
23+
even[k] = x[2*k];
24+
}
25+
Complex[] q = fft(even);
26+
27+
// fft of odd terms
28+
Complex[] odd = even; // reuse the array
29+
for (int k = 0; k < N/2; k++) {
30+
odd[k] = x[2*k + 1];
31+
}
32+
Complex[] r = fft(odd);
33+
34+
// combine
35+
Complex[] y = new Complex[N];
36+
for (int k = 0; k < N/2; k++) {
37+
double kth = -2 * k * Math.PI / N;
38+
Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
39+
y[k] = q[k].plus(wk.times(r[k]));
40+
y[k + N/2] = q[k].minus(wk.times(r[k]));
41+
}
42+
return y;
43+
}
44+
45+
46+
// compute the inverse FFT of x[], assuming its length is a power of 2
47+
public static Complex[] ifft(Complex[] x) {
48+
int N = x.length;
49+
Complex[] y = new Complex[N];
50+
51+
// take conjugate
52+
for (int i = 0; i < N; i++) {
53+
y[i] = x[i].conjugate();
54+
}
55+
56+
// compute forward FFT
57+
y = fft(y);
58+
59+
// take conjugate again
60+
for (int i = 0; i < N; i++) {
61+
y[i] = y[i].conjugate();
62+
}
63+
64+
// divide by N
65+
for (int i = 0; i < N; i++) {
66+
y[i] = y[i].times(1.0 / N);
67+
}
68+
69+
return y;
70+
71+
}
72+
73+
// compute the circular convolution of x and y
74+
public static Complex[] cconvolve(Complex[] x, Complex[] y) {
75+
76+
// should probably pad x and y with 0s so that they have same length
77+
// and are powers of 2
78+
if (x.length != y.length) { throw new RuntimeException("Dimensions don't agree"); }
79+
80+
int N = x.length;
81+
82+
// compute FFT of each sequence
83+
Complex[] a = fft(x);
84+
Complex[] b = fft(y);
85+
86+
// point-wise multiply
87+
Complex[] c = new Complex[N];
88+
for (int i = 0; i < N; i++) {
89+
c[i] = a[i].times(b[i]);
90+
}
91+
92+
// compute inverse FFT
93+
return ifft(c);
94+
}
95+
96+
private static boolean is2Pow(int n) {
97+
// TODO Auto-generated method stub
98+
int result = ((n&(n-1))==0) ? (1) : (0);
99+
if(result==1){
100+
return true;
101+
}else {
102+
return false;
103+
}
104+
}
105+
106+
107+
// compute the linear convolution of x and y
108+
public static Complex[] convolve(Complex[] x, Complex[] y) {
109+
Complex ZERO = new Complex(0, 0);
110+
111+
Complex[] a = new Complex[2*x.length];
112+
for (int i = 0; i < x.length; i++) a[i] = x[i];
113+
for (int i = x.length; i < 2*x.length; i++) a[i] = ZERO;
114+
115+
Complex[] b = new Complex[2*y.length];
116+
for (int i = 0; i < y.length; i++) b[i] = y[i];
117+
for (int i = y.length; i < 2*y.length; i++) b[i] = ZERO;
118+
119+
return cconvolve(a, b);
120+
}
121+
122+
// display an array of Complex numbers to standard output
123+
public static void show(Complex[] x, String title) {
124+
System.out.println(title);
125+
System.out.println("-------------------");
126+
for (int i = 0; i < x.length; i++) {
127+
System.out.println(x[i]);
128+
}
129+
System.out.println();
130+
}
131+
132+
public static void main(String[] args) {
133+
int N = 3;
134+
135+
Complex[] x = new Complex[N];
136+
Complex[] y = new Complex[N];
137+
// original data
138+
for (int i = 0; i < N; i++) {
139+
x[i] = new Complex(1, 0);
140+
y[i] = new Complex(1, 0);
141+
}
142+
Complex[] d = convolve(x, y);
143+
show(d, "d = convolve(x, y)");
144+
145+
}
146+
}

src/edu/pcube/cube/Cube.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package edu.pcube.cube;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import edu.pcube.datastore.InMemoryDataStore;
7+
8+
9+
/**
10+
* Models a multidimensional dataset, where that data are aggregated across an arbitrary number of dimensions.
11+
* It can also be seen as a lattice of cuboids.
12+
*/
13+
public class Cube {
14+
15+
private final InMemoryDataStore inMemoryDataStore;
16+
private Dimensions baseCellDimension;
17+
private final Cuboid baseCuboid;
18+
19+
private Map<Cuboid, Cuboid> child = new HashMap<Cuboid, Cuboid>();
20+
21+
public Cube(InMemoryDataStore inMemoryDataStore) {
22+
this.inMemoryDataStore = inMemoryDataStore;
23+
this.baseCellDimension=Dimensions.create(this.inMemoryDataStore.getBaseDimensions());
24+
this.baseCuboid = new Cuboid(this, baseCellDimension);
25+
}
26+
27+
public InMemoryDataStore getDataFrame() {
28+
return inMemoryDataStore;
29+
}
30+
31+
public Dimensions getBaseCellDimension() {
32+
return baseCellDimension;
33+
}
34+
35+
public Cuboid getBaseCuboid() {
36+
return baseCuboid;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)