Skip to content

Commit c86a36f

Browse files
committed
jacoco integration, full test coverage for tensors
1 parent ab559f8 commit c86a36f

File tree

360 files changed

+6269
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+6269
-1305
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
downloads/
1+
downloads/
2+
JGNN/target/

JGNN/.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: java
2+
3+
# Cobertura is not supported in JDK11 so you must downgrade the JDK that Travis uses if you want to use Cobertura with Travis.
4+
# https://github.com/cobertura/cobertura/issues/381
5+
jdk:
6+
- openjdk8
7+
8+
sudo: false # faster builds
9+
10+
script: "mvn cobertura:cobertura"
11+
12+
after_success:
13+
- bash <(curl -s https://codecov.io/bash)

JGNN/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@
1515
<maven.compiler.target>1.8</maven.compiler.target>
1616
<maven.compiler.source>1.8</maven.compiler.source>
1717
</properties>
18+
19+
20+
<build>
21+
<sourceDirectory>src/main/java</sourceDirectory>
22+
<plugins>
23+
<plugin>
24+
<groupId>org.jacoco</groupId>
25+
<artifactId>jacoco-maven-plugin</artifactId>
26+
<version>0.8.2</version>
27+
<executions>
28+
<execution>
29+
<goals>
30+
<goal>prepare-agent</goal>
31+
</goals>
32+
</execution>
33+
<execution>
34+
<id>report</id>
35+
<phase>prepare-package</phase>
36+
<goals>
37+
<goal>report</goal>
38+
</goals>
39+
</execution>
40+
</executions>
41+
</plugin>
42+
</plugins>
43+
44+
</build>
1845

1946
<dependencies>
2047
<dependency>

JGNN/src/main/java/mklab/JGNN/core/Distribution.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,37 @@
77
* @author Emmanouil Krasanakis
88
*/
99
public interface Distribution {
10+
/**
11+
* Sets the distribution's seed. This should yield reproducible sampling.
12+
* @param seed The distribution's new seed.
13+
* @return <code>this</code> Distribution.
14+
*/
15+
public Distribution setSeed(long seed);
16+
/**
17+
* Retrieves a new sample from the distribution.
18+
* @return A double value.
19+
*/
1020
public double sample();
21+
/**
22+
* Sets the mean of the distribution.
23+
* @param mean The new mean.
24+
* @return <code>this</code> Distribution.
25+
*/
26+
public Distribution setMean(double mean);
27+
/**
28+
* Sets the standard deviation of the distribution.
29+
* @param std The new standard deviation.
30+
* @return <code>this</code> Distribution.
31+
*/
32+
public Distribution setDeviation(double std);
33+
/**
34+
* Retrieves the distribution's mean.
35+
* @return The mean value.
36+
*/
37+
public double getMean();
38+
/**
39+
* Retrieves the distribution's standard deviation.
40+
* @return The standard deviation.
41+
*/
42+
public double getDeviation();
1143
}

JGNN/src/main/java/mklab/JGNN/core/Matrix.java

Lines changed: 101 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import mklab.JGNN.core.matrix.AccessRow;
88
import mklab.JGNN.core.matrix.AccessCol;
99
import mklab.JGNN.core.matrix.DenseMatrix;
10-
import mklab.JGNN.core.matrix.SparseMatrix;
1110
import mklab.JGNN.core.matrix.TransposedMatrix;
1211
import mklab.JGNN.core.tensor.DenseTensor;
13-
import mklab.JGNN.core.tensor.SparseTensor;
1412

1513
import java.util.Map.Entry;
1614

@@ -27,38 +25,85 @@ public abstract class Matrix extends Tensor {
2725
private long rows;
2826
private long cols;
2927

30-
public Matrix(long rows, long cols) {
31-
super(rows*cols);
28+
protected Matrix(long rows, long cols) {
29+
init(rows*cols);
3230
this.rows = rows;
3331
this.cols = cols;
3432
}
3533

34+
/**
35+
* Retrieves an iterable that traverses (row, col) entry pairs
36+
* of non zero entries.
37+
* @return An Entry iterable.
38+
* @see #getNonZeroElements()
39+
*/
3640
public abstract Iterable<Entry<Long, Long>> getNonZeroEntries();
37-
38-
protected Matrix() {
39-
}
40-
41+
42+
/**
43+
* Creates a Matrix with the same class and dimensions and all element set to zero.
44+
* @return A Matrix with the same class and dimensions.
45+
* @see #zeroCopy(long, long)
46+
*/
4147
@Override
4248
public final Matrix zeroCopy() {
4349
return zeroCopy(rows, cols);
4450
}
45-
51+
/**
52+
* Creates a Matrix with the same class and dimensions and all element set to zero. This
53+
* checks that the copy has a total number of elements equal to the given size.
54+
* @param size The desired size of the matrix.
55+
* @return A Matrix with the same class and dimensions.
56+
* @throws RuntimeException If the desired
57+
* @see #zeroCopy(long, long)
58+
*/
59+
@Override
60+
public final Tensor zeroCopy(long size) {
61+
if(size!=size())
62+
throw new RuntimeException("Desired atrix size "+size+" can only be equal to rows "+rows+" * "+cols);
63+
return zeroCopy(rows, cols);
64+
}
65+
/**
66+
* Creates a matrix of the same class and all element set to zero, but with
67+
* a given number of rows and columns.
68+
* @param row The number of rows of the matrix.
69+
* @param cols The number of columns of the matrix.
70+
* @return A Matrix of the same class.
71+
* @see #zeroCopy()
72+
*/
4673
public abstract Matrix zeroCopy(long rows, long cols);
47-
74+
/**
75+
* Retrieves the number of rows of a matrix.
76+
* @return The number of rows.
77+
*/
4878
public final long getRows() {
4979
return rows;
5080
}
51-
81+
/**
82+
* Retrieves the number of columns of a matrix.
83+
* @return The number of columns.
84+
*/
5285
public final long getCols() {
5386
return cols;
5487
}
55-
88+
/**
89+
* Retrieves the values stored at matrix elements.
90+
* @param row The element's row.
91+
* @param col The element's column.
92+
* @return The value corresponding t element (row, col).
93+
*/
5694
public final double get(long row, long col) {
5795
if(row<0 || col<0 || row>=rows || col>=cols)
5896
throw new IllegalArgumentException("Element out of range ("+row+","+col+") for "+describe());
5997
return get(row+col*rows);
6098
}
61-
99+
100+
/**
101+
* Stores values at matrix elements.
102+
* @param row The element's row.
103+
* @param col The element's column.
104+
* @param value The value to store.
105+
* @return <code>this</code> Matrix instance.
106+
*/
62107
public final Matrix put(long row, long col, double value) {
63108
put(row+col*rows, value);
64109
return this;
@@ -210,11 +255,19 @@ public Matrix onesMask() {
210255
}
211256
return ones;
212257
}
213-
258+
/**
259+
* Creates a copy of the Matrix that holds its normalized Laplacian transformation.
260+
* @return A new Matrix of the same dimensions.
261+
* @see #setToLaplacian()
262+
*/
214263
public Matrix laplacian() {
215264
return ((Matrix)copy()).setToLaplacian();
216265
}
217-
266+
/**
267+
* Sets the Matrix to its normalized Laplacian transformation by appropriately adjusting its element values.
268+
* @return <code>this</code> Matrix instance.
269+
* @see #laplacian()
270+
*/
218271
public Matrix setToLaplacian() {
219272
HashMap<Long, Double> outDegrees = new HashMap<Long, Double>();
220273
HashMap<Long, Double> inDegrees = new HashMap<Long, Double>();
@@ -251,7 +304,8 @@ public Tensor getRow(long row) {
251304
* also edits the original matrix.
252305
* No new memory is allocated for matrix values.
253306
* @param col The given column.
254-
* @return A {@link AccessCol} of the corresponding row.
307+
* @return A {@link AccessCol} of the corresponding column.
308+
* @see #accessColumns()
255309
*/
256310
public Tensor getCol(long col) {
257311
return new AccessCol(this, col);
@@ -272,15 +326,42 @@ public String toString() {
272326
return res.toString();
273327
}
274328

275-
public final static Matrix fromSparseColumns(List<Tensor> tensors) {
329+
/*public final static Matrix fromColumns(List<Tensor> tensors) {
276330
Matrix ret = new SparseMatrix(tensors.get(0).size(), tensors.size());
277331
for(int col=0;col<tensors.size();col++)
278332
for(long row : tensors.get(col).getNonZeroElements())
279333
ret.put(row, col, tensors.get(col).get(row));
280334
return ret;
335+
}*/
336+
/**
337+
* Organizes matrix rows to a list of tensors that share entries.
338+
* This operation does not allocate memory for matrix elements and editing
339+
* tensor elements edits the original matrix's elements.
340+
* @return A list of {@link AccessRow}.
341+
* @see #getCol(long)
342+
* @see #accessColumns()
343+
*/
344+
public final List<Tensor> accessRows() {
345+
List<Tensor> ret = new ArrayList<Tensor>();
346+
for(long row=0;row<getRows();row++)
347+
ret.add(getRow(row));
348+
return ret;
281349
}
282-
283-
public final List<Tensor> toSparseColumns() {
350+
/**
351+
* Organizes matrix columns to a list of tensors that share entries.
352+
* This operation does not allocate memory for matrix elements and editing
353+
* tensor elements edits the original matrix's elements.
354+
* @return A list of {@link AccessCol}.
355+
* @see #getCol(long)
356+
* @see #acceRows()
357+
*/
358+
public final List<Tensor> accessColumns() {
359+
List<Tensor> ret = new ArrayList<Tensor>();
360+
for(long col=0;col<getCols();col++)
361+
ret.add(getCol(col));
362+
return ret;
363+
}
364+
/*public final List<Tensor> toSparseColumns() {
284365
List<Tensor> ret = new ArrayList<Tensor>();
285366
for(long col=0;col<getCols();col++)
286367
ret.add(new SparseTensor(getRows()));
@@ -290,7 +371,7 @@ public final List<Tensor> toSparseColumns() {
290371
ret.get((int)col).put(row, get(row, col));
291372
}
292373
return ret;
293-
}
374+
}*/
294375

295376
/**
296377
* Converts a given value to a JGNN-compatible 1x1 matrix.

JGNN/src/main/java/mklab/JGNN/core/NNOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public boolean isConstant() {
7171
return false;
7272
}
7373

74-
final void clearPrediction() {
74+
public final void clearPrediction() {
7575
ThreadData data = data();
7676
if(data.lastOutput==null)
7777
return;

0 commit comments

Comments
 (0)