jsat.distributions.kernels
Class KernelPoints
- java.lang.Object
-
- jsat.distributions.kernels.KernelPoints
-
public class KernelPoints extends java.lang.ObjectThis class represents a list ofKernelPointobjects. This is done to avoid excessive memory duplication that can occur when multiple KernelPoints are in use at the same time.
-
-
Constructor Summary
Constructors Constructor and Description KernelPoints(KernelPoints toCopy)Copy constructorKernelPoints(KernelTrick k, int points, double errorTolerance)Creates a new set of kernel points that uses one unified gram matrix for each KernelPointKernelPoints(KernelTrick k, int points, double errorTolerance, boolean mergeGrams)Creates a new set of kernel points
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddNewKernelPoint()Adds a new Kernel Point to the internal list this object represents.KernelPointsclone()doubledist(int k, KernelPoint x)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and the given KernelPointdoubledist(int k, KernelPoints X, int j)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and thej'th KernelPoint in the given setdoubledist(int k, Vec x, java.util.List<java.lang.Double> qi)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and the given vectordoubledot(int k, KernelPoint x)Computes the dot product between thek'th KernelPoint and the given KernelPointdoubledot(int k, KernelPoints X, int j)Computes the dot product between thek'th KernelPoint and thej'th KernelPoint in the given set of points.doubledot(int k, Vec x, java.util.List<java.lang.Double> qi)Computes the dot product between thek'th KernelPoint and the given vector in the kernel space.double[]dot(Vec x, java.util.List<java.lang.Double> qi)Computes the dot product between each KernelPoint in this set and the given vector in the kernel space.intgetBasisSize()Returns the number of basis vectors in use.KernelPoint.BudgetStrategygetBudgetStrategy()Returns the budget method useddoublegetErrorTolerance()Returns the error tolerance that is used depending on theKernelPoint.BudgetStrategyin useKernelTrickgetKernel()intgetMaxBudget()Returns the current maximum budget for support vectorsjava.util.List<Vec>getRawBasisVecs()Returns a list of the raw vectors being used by the kernel points.doublegetSqrdNorm(int k)Returns the squared 2 norm value of thek'th KernelPointvoidmutableAdd(int k, double c, Vec x_t, java.util.List<java.lang.Double> qi)Alters ones of the KernelPoint objects by adding / subtracting a vector from itvoidmutableAdd(Vec x_t, Vec cs, java.util.List<java.lang.Double> qi)Alters some of the KernelPoints by adding / subtracting a vector from itvoidmutableMultiply(double c)Alters all the KernelPoint objects contained in this set by the same constant valuevoidmutableMultiply(int k, double c)Alters thek'th KernelPoint by multiplying it with a constant valuevoidsetBudgetStrategy(KernelPoint.BudgetStrategy budgetStrategy)Sets the method used for maintaining the budget of support vectors.voidsetErrorTolerance(double errorTolerance)Sets the error tolerance used for projection maintenance strategies such asKernelPoint.BudgetStrategy.PROJECTIONvoidsetMaxBudget(int maxBudget)Sets the maximum budget for support vectors to allow.intsize()Returns the number of KernelPoints stored in this set
-
-
-
Constructor Detail
-
KernelPoints
public KernelPoints(KernelTrick k, int points, double errorTolerance)
Creates a new set of kernel points that uses one unified gram matrix for each KernelPoint- Parameters:
k- the kernel trick to use in which to represent a vector in the kernel spacepoints- the initial number of kernel points to store in this seterrorTolerance- the maximum error allowed for projecting a vector instead of adding it to the basis set
-
KernelPoints
public KernelPoints(KernelTrick k, int points, double errorTolerance, boolean mergeGrams)
Creates a new set of kernel points- Parameters:
k- the kernel trick to use in which to represent a vector in the kernel spacepoints- the initial number of kernel points to store in this seterrorTolerance- the maximum error allowed for projecting a vector instead of adding it to the basis setmergeGrams- whether or not to merge the gram matrices of each KernelPoint.
-
KernelPoints
public KernelPoints(KernelPoints toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setBudgetStrategy
public void setBudgetStrategy(KernelPoint.BudgetStrategy budgetStrategy)
Sets the method used for maintaining the budget of support vectors. This method must be called before any vectors are added to the KernelPoint.
The budget maintenance strategy used controls the time complexity and memory use of the model.- Parameters:
budgetStrategy- the budget maintenance strategy
-
getBudgetStrategy
public KernelPoint.BudgetStrategy getBudgetStrategy()
Returns the budget method used- Returns:
- the budget method used
-
getKernel
public KernelTrick getKernel()
-
setErrorTolerance
public void setErrorTolerance(double errorTolerance)
Sets the error tolerance used for projection maintenance strategies such asKernelPoint.BudgetStrategy.PROJECTION- Parameters:
errorTolerance- the error tolerance in [0, 1]
-
getErrorTolerance
public double getErrorTolerance()
Returns the error tolerance that is used depending on theKernelPoint.BudgetStrategyin use- Returns:
- the error tolerance value
-
setMaxBudget
public void setMaxBudget(int maxBudget)
Sets the maximum budget for support vectors to allow. Setting toInteger.MAX_VALUEis essentially an unbounded number of support vectors. Increasing the budget after adding the first vector is always allowed, but it may not be possible to reduce the number of current support vectors is above the desired budget.- Parameters:
maxBudget- the maximum number of allowed support vectors
-
getMaxBudget
public int getMaxBudget()
Returns the current maximum budget for support vectors- Returns:
- the maximum budget for support vectors
-
getSqrdNorm
public double getSqrdNorm(int k)
Returns the squared 2 norm value of thek'th KernelPoint- Parameters:
k- the KernelPoint to get the norm of- Returns:
- the squared 2 norm of the
k'th KernelPoint
-
dot
public double dot(int k, Vec x, java.util.List<java.lang.Double> qi)Computes the dot product between thek'th KernelPoint and the given vector in the kernel space.- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productx- the vector to contribute to the dot productqi- the query information for the vector, ornullonly if the kernel in use does not support acceleration.- Returns:
- the dot product between the
k'th KernelPoint and the given vector
-
dot
public double[] dot(Vec x, java.util.List<java.lang.Double> qi)
Computes the dot product between each KernelPoint in this set and the given vector in the kernel space. The results are equivalent to an array and setting each value usingdot(int, jsat.linear.Vec, java.util.List)
This method should be faster than computing the dot products individual since it avoids redundant kernel computations- Parameters:
x- the vector to contribute to the dot productqi- the query information for the vector, ornullonly if the kernel in use does not support acceleration.- Returns:
- an array where the i'th index contains the dot product of the i'th KernelPoint and the given vector
-
dot
public double dot(int k, KernelPoint x)Computes the dot product between thek'th KernelPoint and the given KernelPoint- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productx- the other KernelPoint to contribute to the dot product- Returns:
- the dot product between the
k'th KernelPoint and the given KernelPoint
-
dot
public double dot(int k, KernelPoints X, int j)Computes the dot product between thek'th KernelPoint and thej'th KernelPoint in the given set of points.- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productX- the other set of KernelPointsj- the index of the KernelPoint in the given set to contribute to the dot product- Returns:
- the dot product between the
k'th KernelPoint and thej'th KernelPoint in the given set
-
dist
public double dist(int k, Vec x, java.util.List<java.lang.Double> qi)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and the given vector- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productx- the point to get the Euclidean distance toqi- the query information for the vector, ornullonly if the kernel in use does not support acceleration.- Returns:
- the Euclidean distance between the
k'th KernelPoint andxin the kernel space
-
dist
public double dist(int k, KernelPoint x)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and the given KernelPoint- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productx- the kernel point to get the Euclidean distance to- Returns:
- the Euclidean distance between the
k'th KernelPoint andxin the kernel space
-
dist
public double dist(int k, KernelPoints X, int j)Computes the Euclidean distance in the kernel space between thek'th KernelPoint and thej'th KernelPoint in the given set- Parameters:
k- the index of the KernelPoint in this set to contribute to the dot productX- the other set of kernel points to obtain the target KernelPointj- the index of the KernelPoint in the given set to contribute to the dot product- Returns:
- the Euclidean distance between the
k'th KernelPoint and thej'th KernelPoint in the other set
-
mutableMultiply
public void mutableMultiply(int k, double c)Alters thek'th KernelPoint by multiplying it with a constant value- Parameters:
k- the index of the KernelPoint to modifyc- the constant to multiply the KernelPoint by
-
mutableMultiply
public void mutableMultiply(double c)
Alters all the KernelPoint objects contained in this set by the same constant value- Parameters:
c- the constant to multiply the KernelPoints by
-
mutableAdd
public void mutableAdd(int k, double c, Vec x_t, java.util.List<java.lang.Double> qi)Alters ones of the KernelPoint objects by adding / subtracting a vector from it- Parameters:
k- the index of the KernelPoint to usec- the constant to multiply the vector being added byx_t- the vector to add to the kernel pointqi- the query information for the vector, ornullonly if the kernel in use does not support acceleration.
-
mutableAdd
public void mutableAdd(Vec x_t, Vec cs, java.util.List<java.lang.Double> qi)
Alters some of the KernelPoints by adding / subtracting a vector from it- Parameters:
x_t- the vector to add to the kernel pointcs- the array with the constant multiplies. Each non zero incsis a constant to update one of the vectors by. The vector updated is the one corresponding to the index of the non zero valueqi- the query information for the vector, ornullonly if the kernel in use does not support acceleration.
-
addNewKernelPoint
public void addNewKernelPoint()
Adds a new Kernel Point to the internal list this object represents. The new Kernel Point will be equivalent to creating a new KernelPoint directly.
-
getBasisSize
public int getBasisSize()
Returns the number of basis vectors in use. If a vector has been added to more than one Kernel Point it may get double counted (or more), so the value returned may not be reasonable in that case.- Returns:
- the number of basis vectors in use
-
getRawBasisVecs
public java.util.List<Vec> getRawBasisVecs()
Returns a list of the raw vectors being used by the kernel points. Altering this vectors will alter the same vectors used by these objects and will cause inconsistent results.- Returns:
- the list of raw basis vectors used by the Kernel points
-
size
public int size()
Returns the number of KernelPoints stored in this set- Returns:
- the number of KernelPoints stored in this set
-
clone
public KernelPoints clone()
- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG