Skip to content

Commit

Permalink
import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samypr100 committed Sep 21, 2024
1 parent 2c5bc6a commit cb3f00e
Show file tree
Hide file tree
Showing 41 changed files with 103 additions and 60 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/Clust4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
* The absolute super type for all clust4j objects (models and datasets)
* that should be able to commonly serialize their data.
*
* @author Taylor G Smith
*/
public abstract class Clust4j implements java.io.Serializable {
public abstract class Clust4j implements Serializable {
private static final long serialVersionUID = -4522135376738501625L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
Expand Down Expand Up @@ -95,7 +96,7 @@ static interface Initializer {
int[] getInitialCentroidSeeds(AbstractCentroidClusterer model, double[][] X, int k, final Random seed);
}

public static enum InitializationStrategy implements java.io.Serializable, Initializer, NamedEntity {
public static enum InitializationStrategy implements Serializable, Initializer, NamedEntity {
AUTO {
@Override
public int[] getInitialCentroidSeeds(AbstractCentroidClusterer model, double[][] X, int k, final Random seed) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/AbstractClusterer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -50,7 +51,7 @@
*/
public abstract class AbstractClusterer
extends BaseModel
implements Loggable, NamedEntity, java.io.Serializable, MetricValidator {
implements Loggable, NamedEntity, Serializable, MetricValidator {

private static final long serialVersionUID = -3623527903903305017L;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/AffinityPropagation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.clust4j.GlobalState;
import com.clust4j.except.ModelNotFitException;
import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.metrics.pairwise.GeometricallySeparable;
Expand Down Expand Up @@ -291,7 +292,7 @@ public String getName() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.AFFINITY_PROP;
return Log.Tag.Algo.AFFINITY_PROP;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/clust4j/algo/BaseClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
import com.clust4j.metrics.scoring.UnsupervisedMetric;
import org.apache.commons.math3.linear.RealMatrix;

import java.io.Serializable;

import static com.clust4j.metrics.scoring.UnsupervisedMetric.SILHOUETTE;

/**
* An interface for classifiers, both supervised and unsupervised.
*
* @author Taylor G Smith
*/
public interface BaseClassifier extends java.io.Serializable {
public interface BaseClassifier extends Serializable {
public final static SupervisedMetric DEF_SUPERVISED_METRIC = SupervisedMetric.BINOMIAL_ACCURACY;
public final static UnsupervisedMetric DEF_UNSUPERVISED_METRIC = SILHOUETTE;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/BaseModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import com.clust4j.utils.SynchronicityLock;
import com.clust4j.utils.TableFormatter;

import java.io.Serializable;
import java.text.NumberFormat;

abstract public class BaseModel extends Clust4j implements java.io.Serializable {
abstract public class BaseModel extends Clust4j implements Serializable {
private static final long serialVersionUID = 4707757741169405063L;
public final static TableFormatter formatter;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/clust4j/algo/BoruvkaAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;

/**
* A graph traversal algorithm used in identifying the minimum spanning tree
* in a graph for which all edge weights are distinct. Used in conjunction with
Expand All @@ -32,7 +34,7 @@
* @author Taylor G Smith
* @see <a href="https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm">Boruvka's algorithm</a>
*/
class BoruvkaAlgorithm implements java.io.Serializable {
class BoruvkaAlgorithm implements Serializable {
private static final long serialVersionUID = 3935595821188876442L;

// the initialization reorganizes the trees
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/CentroidLearner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.RealMatrix;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

public interface CentroidLearner extends java.io.Serializable {
public interface CentroidLearner extends Serializable {
/**
* A standalone mixin class to handle predictions from {@link CentroidLearner}
* classes that are also a {@link BaseClassifier} and a subclass of {@link AbstractClusterer}.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/clust4j/algo/ConvergeablePlanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*******************************************************************************/
package com.clust4j.algo;

interface ConvergeablePlanner extends java.io.Serializable {
import java.io.Serializable;

interface ConvergeablePlanner extends Serializable {
/**
* The maximum number of iterations the algorithm
* is permitted before aborting without converging
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/DBSCAN.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package com.clust4j.algo;

import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.metrics.pairwise.GeometricallySeparable;
Expand Down Expand Up @@ -297,7 +298,7 @@ protected DBSCAN fit() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.DBSCAN;
return Log.Tag.Algo.DBSCAN;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/HDBSCAN.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.clust4j.algo;

import com.clust4j.GlobalState;
import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.log.Loggable;
Expand Down Expand Up @@ -1457,7 +1458,7 @@ public int[] getLabels() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.HDBSCAN;
return Log.Tag.Algo.HDBSCAN;
}

@Override
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/clust4j/algo/HierarchicalAgglomerative.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.clust4j.NamedEntity;
import com.clust4j.kernel.CircularKernel;
import com.clust4j.kernel.LogKernel;
import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.metrics.pairwise.Distance;
Expand All @@ -30,6 +31,7 @@
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;

Expand Down Expand Up @@ -79,7 +81,7 @@ interface LinkageTreeBuilder extends MetricValidator {
*
* @author Taylor G Smith
*/
public enum Linkage implements java.io.Serializable, LinkageTreeBuilder {
public enum Linkage implements Serializable, LinkageTreeBuilder {
AVERAGE {
@Override
public AverageLinkageTree buildTree(HierarchicalAgglomerative h) {
Expand Down Expand Up @@ -185,7 +187,7 @@ final protected ModelSummary modelSummary() {
*
* @author Taylor G Smith
*/
protected static class EfficientDistanceMatrix implements java.io.Serializable {
protected static class EfficientDistanceMatrix implements Serializable {
private static final long serialVersionUID = -7329893729526766664L;
final protected double[] dists;

Expand Down Expand Up @@ -295,7 +297,7 @@ else if (i > j)
}
}

abstract class HierarchicalDendrogram implements java.io.Serializable, NamedEntity {
abstract class HierarchicalDendrogram implements Serializable, NamedEntity {
private static final long serialVersionUID = 5295537901834851676L;
public final HierarchicalAgglomerative ref;
public final GeometricallySeparable dist;
Expand Down Expand Up @@ -598,7 +600,7 @@ public int[] getLabels() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.AGGLOMERATIVE;
return Log.Tag.Algo.AGGLOMERATIVE;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/KMeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.clust4j.algo;

import com.clust4j.except.NaNException;
import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.metrics.pairwise.Distance;
Expand Down Expand Up @@ -213,7 +214,7 @@ protected KMeans fit() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.KMEANS;
return Log.Tag.Algo.KMEANS;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/LabelEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import com.clust4j.except.ModelNotFitException;
import com.clust4j.utils.VecUtils;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.TreeMap;

public class LabelEncoder extends BaseModel implements java.io.Serializable {
public class LabelEncoder extends BaseModel implements Serializable {
private static final long serialVersionUID = 6618077714920820376L;

final int[] rawLabels;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/clust4j/algo/MeanShift.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.clust4j.except.ModelNotFitException;
import com.clust4j.kernel.GaussianKernel;
import com.clust4j.kernel.RadialBasisKernel;
import com.clust4j.log.Log;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.log.LogTimer;
import com.clust4j.log.Loggable;
Expand All @@ -32,6 +33,7 @@
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -343,7 +345,7 @@ final protected static double autoEstimateBW(NearestNeighbors nn, double[][] dat
*/
static class ParallelBandwidthEstimator
extends ParallelChunkingTask<Double>
implements java.io.Serializable {
implements Serializable {

private static final long serialVersionUID = 1171269106158790138L;
final NearestNeighbors nn;
Expand Down Expand Up @@ -577,7 +579,7 @@ else if (!seen_k)
*
* @author Taylor G Smith
*/
static abstract class CenterIntensity implements java.io.Serializable, Iterable<MeanShiftSeed> {
static abstract class CenterIntensity implements Serializable, Iterable<MeanShiftSeed> {
private static final long serialVersionUID = -6535787295158719610L;

abstract int getIters();
Expand Down Expand Up @@ -860,7 +862,7 @@ public String getName() {

@Override
public Algo getLoggerTag() {
return com.clust4j.log.Log.Tag.Algo.MEANSHIFT;
return Log.Tag.Algo.MEANSHIFT;
}


Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/clust4j/algo/NearestNeighborHeapSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.Arrays;

import static com.clust4j.GlobalState.Mathematics.*;
Expand All @@ -41,7 +42,7 @@
* @author Taylor G Smith
* @see <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neighbors/binary_tree.pxi">sklearn BinaryTree</a>
*/
abstract class NearestNeighborHeapSearch implements java.io.Serializable {
abstract class NearestNeighborHeapSearch implements Serializable {
private static final long serialVersionUID = -5617532034886067210L;

final static public int DEF_LEAF_SIZE = 40;
Expand Down Expand Up @@ -202,7 +203,7 @@ interface Density {
*
* @author Taylor G Smith
*/
public static enum PartialKernelDensity implements Density, java.io.Serializable {
public static enum PartialKernelDensity implements Density, Serializable {
LOG_COSINE {
@Override
public double getDensity(double dist, double h) {
Expand Down Expand Up @@ -295,7 +296,7 @@ public double getNorm(double h, int d) {
* @author Taylor G Smith
*/
// Tested: passing
public static class MutableDouble implements Comparable<Double>, java.io.Serializable {
public static class MutableDouble implements Comparable<Double>, Serializable {
private static final long serialVersionUID = -4636023903600763877L;
public Double value = 0.0;

Expand All @@ -318,7 +319,7 @@ public int compareTo(final Double n) {
* @author Taylor G Smith
*/
// Tested: passing
public static class NodeData implements DeepCloneable, java.io.Serializable {
public static class NodeData implements DeepCloneable, Serializable {
private static final long serialVersionUID = -2469826821608908612L;
int idx_start, idx_end;
boolean is_leaf;
Expand Down Expand Up @@ -383,7 +384,7 @@ public int start() {
*
* @author Taylor G Smith
*/
abstract static class Heap implements java.io.Serializable {
abstract static class Heap implements Serializable {
private static final long serialVersionUID = 8073174366388667577L;

abstract static class Node {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/clust4j/algo/Neighborhood.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.clust4j.utils.MatUtils;
import com.clust4j.utils.MatrixFormatter;

import java.io.Serializable;

public class Neighborhood
extends EntryPair<double[][], int[][]>
implements DeepCloneable, java.io.Serializable {
implements DeepCloneable, Serializable {

private static final long serialVersionUID = 2016176782694689004L;
private static final MatrixFormatter fmt = new MatrixFormatter();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/clust4j/algo/NoiseyClusterer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package com.clust4j.algo;

import java.io.Serializable;

/**
* Any cluster that does not force a prediction for every
* single point is considered a "noisey clusterer." This interface
Expand All @@ -26,7 +28,7 @@
* @see {@link DBSCAN}
* @see {@link MeanShift}
*/
public interface NoiseyClusterer extends java.io.Serializable {
public interface NoiseyClusterer extends Serializable {
final public static int NOISE_CLASS = -1;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clust4j/algo/ParallelChunkingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.clust4j.utils.MatrixFormatter;
import org.apache.commons.math3.util.FastMath;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;
Expand All @@ -38,7 +39,7 @@ public abstract class ParallelChunkingTask<T> extends RecursiveTask<T> implement
*
* @author Taylor G Smith
*/
public static class Chunk implements java.io.Serializable {
public static class Chunk implements Serializable {
private static final long serialVersionUID = -4981036399670388292L;
final double[][] chunk;
final public int start;
Expand Down
Loading

0 comments on commit cb3f00e

Please sign in to comment.