Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/bin
/target
.Rproj.user
.idea/
*.iml

418 changes: 418 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/libraries/Maven__com_goldmansachs_gs_collections_6_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/libraries/Maven__joda_time_joda_time_2_8_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -190,7 +190,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand Down Expand Up @@ -219,25 +219,30 @@
</profiles>

<dependencies>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections</artifactId>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/net/seninp/gi/GrammarRuleRecord.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.seninp.gi;

import com.gs.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.ArrayList;
import java.util.Arrays;

Expand All @@ -22,7 +24,7 @@ public class GrammarRuleRecord {
private String expandedRuleString;

/* The indexes at which the rule occurs in the discretized time series. */
private ArrayList<Integer> timeSeriesOccurrenceIndexes = new ArrayList<Integer>();
private IntHashSet timeSeriesOccurrenceIndexes = new IntHashSet();

/* This rule intervals on the original time series. */
private ArrayList<RuleInterval> ruleIntervals;
Expand All @@ -40,7 +42,7 @@ public class GrammarRuleRecord {
private int maxLength;

/* The rule mean length - i.e. mean value of all subsequences corresponding to the rule. */
private Integer meanLength;
private int meanLength;

/* The rule mean period - i.e. the mean length of intra-rule intervals. */
private double period;
Expand All @@ -58,7 +60,7 @@ public int ruleNumber() {
return ruleNumber;
}

public Integer getMeanLength() {
public int getMeanLength() {
return meanLength;
}

Expand Down Expand Up @@ -123,19 +125,21 @@ public void setExpandedRuleString(String expandedRuleString) {
}

public String occurrencesToString() {
return Arrays.toString(this.timeSeriesOccurrenceIndexes
.toArray(new Integer[this.timeSeriesOccurrenceIndexes.size()]));
// return Arrays.toString(this.timeSeriesOccurrenceIndexes
// .toArray(new Integer[this.timeSeriesOccurrenceIndexes.size()]));
return timeSeriesOccurrenceIndexes.toString();
}

public ArrayList<Integer> getOccurrences() {
public IntHashSet getOccurrences() {
return this.timeSeriesOccurrenceIndexes;
}

public void setOccurrences(int[] indexes) {
this.timeSeriesOccurrenceIndexes = new ArrayList<Integer>();
for (Integer idx : indexes) {
this.timeSeriesOccurrenceIndexes.add(idx);
}
public void setOccurrences(IntHashSet indexes) {
this.timeSeriesOccurrenceIndexes = indexes;
// this.timeSeriesOccurrenceIndexes = new ArrayList<Integer>();
// for (Integer idx : indexes.) {
// this.timeSeriesOccurrenceIndexes.add(idx);
// }
}

public double getPeriod() {
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/net/seninp/gi/GrammarRules.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package net.seninp.gi;

import com.gs.collections.impl.map.mutable.primitive.IntObjectHashMap;

import java.util.Iterator;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;

public class GrammarRules implements Iterable<GrammarRuleRecord> {

private SortedMap<Integer, GrammarRuleRecord> rules;
//private SortedMap<Integer, GrammarRuleRecord> rules;

final IntObjectHashMap<GrammarRuleRecord> rules = new IntObjectHashMap();

public GrammarRules() {
super();
this.rules = new TreeMap<Integer, GrammarRuleRecord>();
//this.rules = new TreeMap<Integer, GrammarRuleRecord>();
}

@Override
public String toString() {
return rules.values().stream().map(x -> x.toString()).collect(Collectors.joining(", ")).toString();
}

public void addRule(GrammarRuleRecord arrRule) {
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/net/seninp/gi/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
public class Interval {

private int start;
private int end;
private double coverage;
final private int start;
final private int end;
final private double coverage;

/**
* Constructor; start inclusive, end exclusive.
Expand All @@ -29,21 +29,22 @@ public double getCoverage() {
return coverage;
}

public void setCoverage(double coverage) {
/*public void setCoverage(double coverage) {
this.coverage = coverage;
}

public void setStart(int start) {
this.start = start;
}
public void setEnd(int end) {
this.end = end;
}

*/
public int getStart() {
return this.start;
}

public void setEnd(int end) {
this.end = end;
}

public int getEnd() {
return this.end;
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/net/seninp/gi/repair/DigramFrequencies.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.seninp.gi.repair;

import java.util.ArrayList;
import java.util.Collections;
import com.gs.collections.impl.list.mutable.FastList;
import com.gs.collections.impl.map.mutable.primitive.IntObjectHashMap;

import java.util.HashMap;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
* Implements the digram frequency queue.
Expand All @@ -15,18 +16,18 @@
public class DigramFrequencies {

/** A map of strings to digram frequencies. */
private HashMap<String, DigramFrequencyEntry> digramsToEntries;
private final LinkedHashMap<String, DigramFrequencyEntry> digramsToEntries;

/** A map of buckets, each bucket is the frequency number pointing on the collection of entries. */
private SortedMap<Integer, ArrayList<DigramFrequencyEntry>> bucketsToEntries;
private final IntObjectHashMap<List<DigramFrequencyEntry>> bucketsToEntries;

/**
* Constructor. Inits data structures.
*/
public DigramFrequencies() {
super();
digramsToEntries = new HashMap<String, DigramFrequencyEntry>();
bucketsToEntries = new TreeMap<Integer, ArrayList<DigramFrequencyEntry>>();
digramsToEntries = new LinkedHashMap();
bucketsToEntries = new IntObjectHashMap();
}

/**
Expand All @@ -37,9 +38,9 @@ public DigramFrequencies() {
public void put(DigramFrequencyEntry digramFrequencyEntry) {
this.digramsToEntries.put(digramFrequencyEntry.getDigram(), digramFrequencyEntry);
Integer freq = digramFrequencyEntry.getFrequency();
ArrayList<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(freq);
List<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(freq);
if (null == bucket) {
bucket = new ArrayList<DigramFrequencyEntry>();
bucket = new FastList<DigramFrequencyEntry>();
this.bucketsToEntries.put(freq, bucket);
}
bucket.add(digramFrequencyEntry);
Expand All @@ -64,20 +65,20 @@ public DigramFrequencyEntry get(String string) {
public void incrementFrequency(DigramFrequencyEntry entry, int increment) {

// findout the old bucket and remove this entry
ArrayList<DigramFrequencyEntry> oldBucket = this.bucketsToEntries.get(entry.getFrequency());
List<DigramFrequencyEntry> oldBucket = this.bucketsToEntries.get(entry.getFrequency());
oldBucket.remove(entry);
if (oldBucket.isEmpty()) {
this.bucketsToEntries.remove(entry.getFrequency());
}

// get the increment added
int newFreq = entry.getFrequency() + increment;
entry.setFrequency(newFreq);

int newFreq = entry.add(increment);

// put into the new bucket
ArrayList<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(newFreq);
List<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(newFreq);
if (null == bucket) {
bucket = new ArrayList<DigramFrequencyEntry>();
bucket = new FastList(1);
this.bucketsToEntries.put(newFreq, bucket);
}
bucket.add(entry);
Expand All @@ -97,7 +98,8 @@ public DigramFrequencyEntry getTop() {
}
else {
// by the default there are no empty buckets
Integer maxBucket = Collections.max(bucketsToEntries.keySet());
int maxBucket = bucketsToEntries.keysView().max();
//Integer maxBucket = Collections.max(bucketsToEntries.keySet());
return bucketsToEntries.get(maxBucket).get(0);
}
}
Expand All @@ -116,7 +118,7 @@ public void remove(String digramStr) {
else {
// get its frequency and the corresponding bucket
int freq = entry.getFrequency();
ArrayList<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(freq);
List<DigramFrequencyEntry> bucket = this.bucketsToEntries.get(freq);
if (!bucket.remove(entry)) {
throw (new RuntimeException("There was an error!"));
}
Expand Down
Loading