Skip to content

Commit

Permalink
jacoco integration, full test coverage for tensors
Browse files Browse the repository at this point in the history
  • Loading branch information
maniospas committed Jul 20, 2021
1 parent ab559f8 commit c86a36f
Show file tree
Hide file tree
Showing 360 changed files with 6,269 additions and 1,305 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
downloads/
downloads/
JGNN/target/
13 changes: 13 additions & 0 deletions JGNN/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: java

# Cobertura is not supported in JDK11 so you must downgrade the JDK that Travis uses if you want to use Cobertura with Travis.
# https://github.com/cobertura/cobertura/issues/381
jdk:
- openjdk8

sudo: false # faster builds

script: "mvn cobertura:cobertura"

after_success:
- bash <(curl -s https://codecov.io/bash)
27 changes: 27 additions & 0 deletions JGNN/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>


<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>

<dependencies>
<dependency>
Expand Down
32 changes: 32 additions & 0 deletions JGNN/src/main/java/mklab/JGNN/core/Distribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,37 @@
* @author Emmanouil Krasanakis
*/
public interface Distribution {
/**
* Sets the distribution's seed. This should yield reproducible sampling.
* @param seed The distribution's new seed.
* @return <code>this</code> Distribution.
*/
public Distribution setSeed(long seed);
/**
* Retrieves a new sample from the distribution.
* @return A double value.
*/
public double sample();
/**
* Sets the mean of the distribution.
* @param mean The new mean.
* @return <code>this</code> Distribution.
*/
public Distribution setMean(double mean);
/**
* Sets the standard deviation of the distribution.
* @param std The new standard deviation.
* @return <code>this</code> Distribution.
*/
public Distribution setDeviation(double std);
/**
* Retrieves the distribution's mean.
* @return The mean value.
*/
public double getMean();
/**
* Retrieves the distribution's standard deviation.
* @return The standard deviation.
*/
public double getDeviation();
}
121 changes: 101 additions & 20 deletions JGNN/src/main/java/mklab/JGNN/core/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import mklab.JGNN.core.matrix.AccessRow;
import mklab.JGNN.core.matrix.AccessCol;
import mklab.JGNN.core.matrix.DenseMatrix;
import mklab.JGNN.core.matrix.SparseMatrix;
import mklab.JGNN.core.matrix.TransposedMatrix;
import mklab.JGNN.core.tensor.DenseTensor;
import mklab.JGNN.core.tensor.SparseTensor;

import java.util.Map.Entry;

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

public Matrix(long rows, long cols) {
super(rows*cols);
protected Matrix(long rows, long cols) {
init(rows*cols);
this.rows = rows;
this.cols = cols;
}

/**
* Retrieves an iterable that traverses (row, col) entry pairs
* of non zero entries.
* @return An Entry iterable.
* @see #getNonZeroElements()
*/
public abstract Iterable<Entry<Long, Long>> getNonZeroEntries();

protected Matrix() {
}


/**
* Creates a Matrix with the same class and dimensions and all element set to zero.
* @return A Matrix with the same class and dimensions.
* @see #zeroCopy(long, long)
*/
@Override
public final Matrix zeroCopy() {
return zeroCopy(rows, cols);
}

/**
* Creates a Matrix with the same class and dimensions and all element set to zero. This
* checks that the copy has a total number of elements equal to the given size.
* @param size The desired size of the matrix.
* @return A Matrix with the same class and dimensions.
* @throws RuntimeException If the desired
* @see #zeroCopy(long, long)
*/
@Override
public final Tensor zeroCopy(long size) {
if(size!=size())
throw new RuntimeException("Desired atrix size "+size+" can only be equal to rows "+rows+" * "+cols);
return zeroCopy(rows, cols);
}
/**
* Creates a matrix of the same class and all element set to zero, but with
* a given number of rows and columns.
* @param row The number of rows of the matrix.
* @param cols The number of columns of the matrix.
* @return A Matrix of the same class.
* @see #zeroCopy()
*/
public abstract Matrix zeroCopy(long rows, long cols);

/**
* Retrieves the number of rows of a matrix.
* @return The number of rows.
*/
public final long getRows() {
return rows;
}

/**
* Retrieves the number of columns of a matrix.
* @return The number of columns.
*/
public final long getCols() {
return cols;
}

/**
* Retrieves the values stored at matrix elements.
* @param row The element's row.
* @param col The element's column.
* @return The value corresponding t element (row, col).
*/
public final double get(long row, long col) {
if(row<0 || col<0 || row>=rows || col>=cols)
throw new IllegalArgumentException("Element out of range ("+row+","+col+") for "+describe());
return get(row+col*rows);
}


/**
* Stores values at matrix elements.
* @param row The element's row.
* @param col The element's column.
* @param value The value to store.
* @return <code>this</code> Matrix instance.
*/
public final Matrix put(long row, long col, double value) {
put(row+col*rows, value);
return this;
Expand Down Expand Up @@ -210,11 +255,19 @@ public Matrix onesMask() {
}
return ones;
}

/**
* Creates a copy of the Matrix that holds its normalized Laplacian transformation.
* @return A new Matrix of the same dimensions.
* @see #setToLaplacian()
*/
public Matrix laplacian() {
return ((Matrix)copy()).setToLaplacian();
}

/**
* Sets the Matrix to its normalized Laplacian transformation by appropriately adjusting its element values.
* @return <code>this</code> Matrix instance.
* @see #laplacian()
*/
public Matrix setToLaplacian() {
HashMap<Long, Double> outDegrees = new HashMap<Long, Double>();
HashMap<Long, Double> inDegrees = new HashMap<Long, Double>();
Expand Down Expand Up @@ -251,7 +304,8 @@ public Tensor getRow(long row) {
* also edits the original matrix.
* No new memory is allocated for matrix values.
* @param col The given column.
* @return A {@link AccessCol} of the corresponding row.
* @return A {@link AccessCol} of the corresponding column.
* @see #accessColumns()
*/
public Tensor getCol(long col) {
return new AccessCol(this, col);
Expand All @@ -272,15 +326,42 @@ public String toString() {
return res.toString();
}

public final static Matrix fromSparseColumns(List<Tensor> tensors) {
/*public final static Matrix fromColumns(List<Tensor> tensors) {
Matrix ret = new SparseMatrix(tensors.get(0).size(), tensors.size());
for(int col=0;col<tensors.size();col++)
for(long row : tensors.get(col).getNonZeroElements())
ret.put(row, col, tensors.get(col).get(row));
return ret;
}*/
/**
* Organizes matrix rows to a list of tensors that share entries.
* This operation does not allocate memory for matrix elements and editing
* tensor elements edits the original matrix's elements.
* @return A list of {@link AccessRow}.
* @see #getCol(long)
* @see #accessColumns()
*/
public final List<Tensor> accessRows() {
List<Tensor> ret = new ArrayList<Tensor>();
for(long row=0;row<getRows();row++)
ret.add(getRow(row));
return ret;
}

public final List<Tensor> toSparseColumns() {
/**
* Organizes matrix columns to a list of tensors that share entries.
* This operation does not allocate memory for matrix elements and editing
* tensor elements edits the original matrix's elements.
* @return A list of {@link AccessCol}.
* @see #getCol(long)
* @see #acceRows()
*/
public final List<Tensor> accessColumns() {
List<Tensor> ret = new ArrayList<Tensor>();
for(long col=0;col<getCols();col++)
ret.add(getCol(col));
return ret;
}
/*public final List<Tensor> toSparseColumns() {
List<Tensor> ret = new ArrayList<Tensor>();
for(long col=0;col<getCols();col++)
ret.add(new SparseTensor(getRows()));
Expand All @@ -290,7 +371,7 @@ public final List<Tensor> toSparseColumns() {
ret.get((int)col).put(row, get(row, col));
}
return ret;
}
}*/

/**
* Converts a given value to a JGNN-compatible 1x1 matrix.
Expand Down
2 changes: 1 addition & 1 deletion JGNN/src/main/java/mklab/JGNN/core/NNOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean isConstant() {
return false;
}

final void clearPrediction() {
public final void clearPrediction() {
ThreadData data = data();
if(data.lastOutput==null)
return;
Expand Down
Loading

0 comments on commit c86a36f

Please sign in to comment.